tag:blogger.com,1999:blog-24022242074202447382024-03-13T23:03:26.095-07:00Magic Maker ManKevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-2402224207420244738.post-11554318390948826732013-10-26T05:16:00.002-07:002018-12-24T10:25:14.815-08:00ZolpidemAh, Zolpidem.<br />
<br />
Zolpidem is all I want.<br />
Zolpidem is all I need.<br />
Every night when I lack sleep, <br />
Zolpidem I need for peace.<br />
Zolpidem.<br />
<br />
<br />
<br />Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-8524905295686318702013-09-04T06:34:00.002-07:002013-09-04T06:34:18.469-07:00Python DecoratorsI've been learning a lot about Python lately. Specifically about decorators, generators and other multiprocessing.<br />
<br />
Here is a pretty good blog post about decorators:<br />
<br />
<a href="http://pythonconquerstheuniverse.wordpress.com/2012/04/29/python-decorators/">http://pythonconquerstheuniverse.wordpress.com/2012/04/29/python-decorators/</a><br />
<br />
<br />Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-66181905214958887762013-07-20T13:42:00.000-07:002013-07-20T13:42:57.818-07:00Modifying Subtitles with PythonOk, so I have not been completely idle despite my debilitating sickness. I have actually been working on a problem regarding downloaded movies and their subtitles. I noticed that sometimes, movies that I have <i>acquired </i>have no subtitles. And the subtitles that I have downloaded from sites like <a href="http://www.opensubtitles.org/en">opensubtitles.org</a> are not synchronized with the movie itself.<br />
<br />
So I spent an hour or so to write a <a href="https://github.com/enivek/subtitle">simple Python app (now on Github)</a> that will correct the problem. Just determine how far forward to push the subtitles so that it would be in synch with the movie.<br />
<br />
For example, the following will push the subtitle movie by 2 minutes and 3 seconds:<br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
<span style="font-family: "Courier New",Courier,monospace;">python subtitle.py IronMan3.srt 00:02:03,000 </span><br />
<br />
I've tried it on a couple of subtitles. It all works great so far. Of course, it only pushes the subtitles forward -- not backward. It also does not do any error checking. It's also probably not very efficient.<br />
<br />
Ah well, it does the job as I need it so far...<br />
<br />
<br />Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-28197427063235777702013-07-14T10:28:00.001-07:002013-07-14T10:28:48.743-07:00Securing DocumentsSeveral months ago, a NSA contractor named Ed Snowden released confidential information which he had obtained as part of his job. <div><br></div><div>The result of his whistle blowing/traitorous activities was felt around the world. People were outraged that the NSA was monitoring the emails and phone records of ordinary Americans. </div><div><br></div><div>So how can the NSA prevent future breaches like this?</div><div><br></div><div>I think that, for each confidential document, they should separate <i>how</i> they got the information from <i>what</i> the information actually contains. Then just encrypt the how and make it available to those with the proper security clearance.</div><div><br></div><div>For example, suppose you have a confidential document XYZ and that document contains confidential information (the sky is falling) the source of the information (chicken little said so). If you want document XYZ available throughout the organization then just encrypt the source of it. That way even if it does get leaked -- the details of it will be based on the credibility of the leaker and not on the NSA itself. Making it hard to copy files to a physical device also helps. </div><div><br></div><div>Also works for newspaper journalists. </div>Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-4774283925098114772013-07-07T22:20:00.000-07:002013-07-07T22:20:35.174-07:00SickI have been sick for nearly 2 months. No motivation to write any code. Ugh.Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-8476595947592759612013-07-07T22:18:00.000-07:002013-07-07T22:18:09.104-07:00Why Google's Go Programming Language SucksThey say that history repeats itself. Sometimes, this is made quite event in the IT field due to the fast pace of technology. I would hazard to guess that there is a general feeling that when history repeats itself in IT, that is generally considered <i>not </i>a good thing. Unless there is a radical change, reinventing something that has previously existed and touting it as "the next big thing", is not really productive.<br />
<br />
Google's programming language "Go" is a good example. The language was invented at around 2007; After that, Google announced the new programming language to the world at around 2009. So what problem does Go solve? None. It's just a language that is basically like C with a few niceties here and there.<br />
<br />
But really, why does Google Go suck (in my humble opinion)? Let me count the ways.<br />
<br />
<b>1. No Object Oriented Programming.</b><br />
<br />
There is no inheritance, no method overloading, object oriented programming. Other than C or Javascript (which have been around for a while), what language does doesn't have it? OOP is proven and yet the designers of Go have decided to ignore it.<br />
<br />
Why even bother with it then? Just use server-side Javascript with V8 to do everything.<br />
<br />
<b>2. No asserts. </b><br />
<br />
God, why not?<br />
<br />
<b>3. Pointers.</b><br />
<br />
This is perhaps just a personal preference. Coming from a Java/Python background, I simply prefer languages that get out of the way and let me express what I want without having to worry too much about details. Like pointers. I had enough of that when I was doing C. Not that it was <i>that </i>bad, it's just... why put it in a brand new language?<br />
<br />
<b>4. Mascot.</b><br />
<br />
The mascot sucks. Purely, subjective, I know.<br />
<br />
Well, that ends my rant. Basically, Google's Go doesn't really do anything for me at all because I consider it a step back in terms of programming languages. There is an adage "use the right tool for the job". However, sometimes someone invents a tool, slaps "Google" on it, markets and popularizes it, that actually doesn't <i>ever </i>seem to be the right tool for any job.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-83995203283140662882013-06-01T21:50:00.001-07:002013-06-01T21:50:27.509-07:00Iterating in PythonI was looking into creating a function which would convert a dictionary filled with unicode strings to a dictionary filled with non-unicode (ANSI) strings. I'm using Python 2.7.4. I found the answer to this in Stack Overflow post: <a href="http://stackoverflow.com/questions/1254454/fastest-way-to-convert-a-dicts-keys-values-from-unicode-to-str">http://stackoverflow.com/questions/1254454/fastest-way-to-convert-a-dicts-keys-values-from-unicode-to-str</a>, but the given solution didn't quite work for me.<br />
<br />
I discovered that Python treats strings as iterable collections:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">>>> import collections</span><br />
<span style="font-family: Courier New, Courier, monospace;">>>> isinstance(u'abc', collections.Iterable)</span><br />
<span style="font-family: Courier New, Courier, monospace;">True</span><br />
<br />
A unicode string is iterable? It makes sense because I can do this:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">>>> for c in u'abc':</span><br />
<span style="font-family: Courier New, Courier, monospace;">>>> print c</span><br />
<span style="font-family: Courier New, Courier, monospace;">a</span><br />
<span style="font-family: Courier New, Courier, monospace;">b</span><br />
<span style="font-family: Courier New, Courier, monospace;">c</span><br />
<br />
An ordinary string is also iterable:<br />
<span style="font-family: Courier New, Courier, monospace;">>>> import collections</span><br />
<span style="font-family: Courier New, Courier, monospace;">>>> isinstance('abc', collections.Iterable)</span><br />
<span style="font-family: Courier New, Courier, monospace;">True</span><br />
<div>
<br /></div>
This means I need to tweak my function to check to see if an input is a string <i>type</i> first before checking to see if it is iterable. Here's what I got:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">import collections</span><br />
<span style="font-family: Courier New, Courier, monospace;">import types</span><br />
<span style="font-family: Courier New, Courier, monospace;">def convert(in_data):</span><br />
<span style="font-family: Courier New, Courier, monospace;"> if isinstance(in_data, types.StringTypes):</span><br />
<span style="font-family: Courier New, Courier, monospace;"> return in_data.encode('utf-8')</span><br />
<span style="font-family: Courier New, Courier, monospace;"> elif isinstance(in_data, collections.Mapping):</span><br />
<span style="font-family: Courier New, Courier, monospace;"> return {convert(key): convert(value) for key, value in in_data.iteritems()}</span><br />
<span style="font-family: Courier New, Courier, monospace;"> elif isinstance(in_data, collections.Iterable):</span><br />
<span style="font-family: Courier New, Courier, monospace;"> return [convert(element) for element in in_data]</span><br />
<span style="font-family: Courier New, Courier, monospace;"> else:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> return in_data</span><br />
<br />
Now for a quick test:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"> def test1(self):</span><br />
<span style="font-family: Courier New, Courier, monospace;"> unicode_d = {u'key1': u'val1', u'sub_key': {u'name1': u'value1', u'name2': u'value2'},</span><br />
<span style="font-family: Courier New, Courier, monospace;"> u'list': [1, u'a', u'b', 2, [u'you', u'and', u'me', 221, 321]]}</span><br />
<span style="font-family: Courier New, Courier, monospace;"> ansi_d = {'key1': 'val1', 'sub_key': {'name1': 'value1', 'name2': 'value2'},</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 'list': [1, 'a', 'b', 2, ['you', 'and', 'me', 221, 321]]}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> self.assertTrue(convert(unicode_d) == ansi_d)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> self.assertTrue(convert(unicode_d) == convert(ansi_d))</span><br />
<br />
Of course, this function doesn't handle all possibilities like None types. It will also convert sets into lists...<br />
<br />
<br />Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-2629858634329328532013-05-23T12:29:00.000-07:002013-05-23T12:29:34.402-07:00Using NANT with Visual Studio 2012I have used Apache's Ant for quite a while. Now in there is NANT in the C# and .NET world. However Visual Studio only uses MSBUILD. Here's how you make it so that Visual Studio will use NANT instead:<br />
<br />
First, open up the .csproj file and modify the DefaultTargets to "Nant" as follows:<br />
<span style="font-family: Courier New, Courier, monospace;"><Project ToolsVersion="4.0" DefaultTargets="Nant" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></span><br />
<br />
Next, add the following at the bottom of the file:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><Target Name="Nant"></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <Exec Command="CALL nant.exe -D:buildtype=$(Configuration)" /></span><br />
<span style="font-family: Courier New, Courier, monospace;"></Target></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Now, in your NANT's Default.build file, add this as the build target:</span><br />
<span style="font-family: inherit;"><br /></span>
<br />
<span style="font-family: Courier New, Courier, monospace;"> <target name="build" description="Compiles the source code"></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> <echo message="Build Type: ${buildtype}"/></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <property name="debug" value="false"/></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <if test="${buildtype == 'Debug'}"></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <property name="debug" value="true"/></span><br />
<span style="font-family: Courier New, Courier, monospace;"> </if></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <echo message="Debug = ${debug}"/></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> <!-- Make sure the build directory is present --></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <mkdir dir="${build.dir}" unless="${directory::exists('build')}" /></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> <!-- Compile sources --></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <csc target="library" output="${build.dir}\${project::get-name()}.dll" debug="${debug}"></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <sources></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <include name="**/*.cs" /></span><br />
<span style="font-family: Courier New, Courier, monospace;"> </sources></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <references></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <include name="${log4net.dir}\log4net.dll"/></span><br />
<span style="font-family: Courier New, Courier, monospace;"> </references></span><br />
<span style="font-family: Courier New, Courier, monospace;"> </csc></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> <!-- Copy log4net over. --></span><br />
<span style="font-family: Courier New, Courier, monospace;"> <copy file="${log4net.dir}\log4net.dll" tofile="${build.dir}\log4net.dll"/></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> </target></span><br />
<br />
This will use whatever build configuration used in Visual Studio. It will also set debug mode if you build it in Debug (to generate those .pdb files).<br />
<br />
<br />
Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-9134896228088177682013-05-15T09:49:00.001-07:002013-05-15T09:49:34.617-07:00Log4net not foundI have a console application. I added <b>log4net</b> as a reference. I included it in my program with the <b>using</b> keyword. I get an error. <div><br></div><div><i>The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)</i></div><div><i><br></i></div><div>Yes, I really did add it as a reference. Yes, I changed my Target Framework to ".NET Framework 4.5". What now?</div><div><br></div><div>Here's the solution. Include <b>System.Web</b> as a reference to your project. It then compiles successfully! Argh!</div><div><br></div><div>What is even more aggravating is that it still seems to compile <i>after</i> you remove <b>System.Web</b>! Double argh!!</div><div><br></div><div>This is very misleading. And why would a logger need any kind of dependencies is beyond me. </div><div><br></div><div>This kind if thing would never happen in Java. If there was a dependency in one of the libraries it would just throw a runtime exception. Sigh. Oh well. </div><div><br></div>Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-38450759510686218722013-05-13T12:33:00.001-07:002013-05-13T12:34:57.167-07:00Mutable-Immutable Data Transfer Objects in C#<div>
The getters and setters in C# can make implementing POCOs easy. But sometimes when you are writing an API you need an object that can be modified internally but is read-only externally. In my mind, it is ideally better to have both objects strongly related to each other because if you remove one field or property in one, then it is removed for the other.<br />
<br />
So how is this done?</div>
<div>
<br /></div>
<div>
You can't do this:</div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> public class ImmutableThing</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> {</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> int Id { get; }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> string Name { get; }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> public class MutableThing : ImmutableThing </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> {</span></div>
<div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> int Id { get; set; }</span></div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> string Name { get; set; }</span></div>
</div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span></div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br /></span>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">Because the compiler will complain. "<i>Automatically implemented properties must define both get and set accessors.</i>" Having the Immutable object extend the Mutable object yields the same result. </span></div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br /></span></div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);">To solve this, an Interface must be defined:</span></div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"></span><br />
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> public interface IThing</span><br />
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> int Id { get; }</span><br />
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> string Name { get; }</span><br />
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0); font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span></div>
<div>
<span style="-webkit-text-size-adjust: auto; background-color: rgba(255, 255, 255, 0);"><br /></span></div>
<div>
Now have the Immutable object extend from the interface:</div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> public class ImmutableThing : IThing</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> private int id = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> private string name = null;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public ImmutableThing(int id, string name)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> this.id = id;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> this.name = name;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public int Id { get { return id; } }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public string Name { get { return name; } }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<br />
And the Mutable interface:<br />
<span style="font-family: Courier New, Courier, monospace;"> public class MutableThing : IThing</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public int Id { get; set; }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public string Name { get; set; }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<br />
You can have the fields in an abstract class so that you can have methods available for both immutable and mutable objects:<br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: x-small;"> </span>public abstract class AbstractThing</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> protected int id = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> protected string name = null;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br />
public class ImmutableThing : AbstractThing, IThing</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public ImmutableThing(int id, string name)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> base.id = id;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> base.name = name;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public int Id { get { return id; } }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public string Name { get { return name; } }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br />
public class MutableThing : AbstractThing, IThing</span><br />
<span style="font-family: Courier New, Courier, monospace;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public int Id </span><br />
<span style="font-family: Courier New, Courier, monospace;"> { </span><br />
<span style="font-family: Courier New, Courier, monospace;"> get { return id; }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> set { base.id = value; }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public string Name </span><br />
<span style="font-family: Courier New, Courier, monospace;"> { </span><br />
<span style="font-family: Courier New, Courier, monospace;"> get { return name; }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> set { base.name = value; }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<br />
I wish Visual Studio 2012 can tell me right away if it won't compile. I currently have to rebuild it each time.</div>
Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-43267597006323127772013-05-12T22:54:00.001-07:002013-05-12T22:57:36.364-07:00사다리 타기 (Sadari Tagi)Today I learned about <i>Sadari Tagi </i>(사다리 타기) a Korean way of drawing straws. It is a way to randomly assign N number of people to N number of tasks.<br />
<br />
<h4>
Process</h4>
First, a number of vertical lines are drawn, with numbers from 1 to N at the top and the tasks to be completed at the bottom (in random order). The numbers at the top correspond to each person. After that, a random number of staggered lines are drawn which interconnect each column.<br />
<br />
For the picking process, a number is randomly picked. The idea is to follow down the line in the column. When an interconnecting line is first reached, cross over to the next column. After that, continue downward until another interconnecting line is reached. This is done until the task is reached at the end.<br />
<br />
The following is an example. 3 people are supposed to complete 3 tasks. The mapping between person and task is random. The diagram is as follows (I made it horizontal instead of vertical):<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">1 ------------------------------------------ Task 1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> | | |</span><br />
<span style="font-family: Courier New, Courier, monospace;">2 ------------------------------------------ Task 2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> | |</span><br />
<span style="font-family: Courier New, Courier, monospace;">3 ------------------------------------------ Task 3</span><br />
<br />
So there are 3 interconnecting lines between 1 and 2, while there are only 2 interconnecting lines between 2 and 3. The number of interconnecting lines is irrelevant provided that they are staggered.<br />
<br />
Here is an example, suppose 3 individuals (Jay, Sam and Bob) are required to perform three odious tasks. Which individual performs which task? If we use the <i>Sadari Tagi </i>(사다리 타기), we would construct the following diagram:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Jay ------------------------------------------ Task 1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> | | |</span><br />
<span style="font-family: Courier New, Courier, monospace;">Sam ------------------------------------------ Task 2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> | |</span><br />
<span style="font-family: Courier New, Courier, monospace;">Bob ------------------------------------------ Task 3</span><br />
<br />
To find out which task Jay is to do, start from Jay and move down until we hit the first intersection. Keep going down until we hit the second intersection. Keep going down until we reach Task #3.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: red;">Jay -----------</span>------------------------------- Task 1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> <span style="color: red;">|</span> | |</span><br />
<span style="font-family: Courier New, Courier, monospace;">Sam ----------<span style="color: red;">--------</span>------------------------ Task 2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> | <span style="color: red;">|</span></span><br />
<span style="font-family: Courier New, Courier, monospace;">Bob -----------------<span style="color: red;">------------------------- Task 3</span></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
Using the same process, you will see that Sam is assigned to odious Task #2, and Bob is assigned to odious Task #1. <i>(Apologies for the ASCII art!)</i><br />
<br />
<h4>
Question</h4>
My question is how do we know that there will always be a one-to-one mapping between number and task? So, could it be that, depending on the interconnected lines drawn, could it be that Sam and Bob be assigned to the same task? After constructing several such diagrams, I found out that the answer is no.<br />
<br />
But how? The answer, in my mind, is quite simply. Suppose the entire diagram is broken into sections, where each section contains only one interconnecting line. For example, the diagram above is broken into 5 sections:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"> <span style="background-color: #0b5394;"> #1 </span>I<span style="background-color: #0b5394;"> #2 </span>I<span style="background-color: #0b5394;"> #3 </span>I<span style="background-color: #0b5394;"> #4 </span>I<span style="background-color: #0b5394;"> #5 </span></span><br />
<span style="font-family: Courier New, Courier, monospace;">1 <span style="background-color: #0b5394;">--------</span>I<span style="background-color: #0b5394;">------</span>I<span style="background-color: #0b5394;">------</span>I<span style="background-color: #0b5394;">----</span>I<span style="background-color: #0b5394;">-------------</span>- Task 1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> <span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> | </span>I<span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> | </span>I<span style="background-color: #0b5394;"> | </span></span><br />
<span style="font-family: Courier New, Courier, monospace;">2 <span style="background-color: #0b5394;">--------</span>I<span style="background-color: #0b5394;">------</span>I<span style="background-color: #0b5394;">------</span>I<span style="background-color: #0b5394;">----</span>I<span style="background-color: #0b5394;">-------------</span>- Task 2</span><br />
<span style="font-family: Courier New, Courier, monospace;"> <span style="background-color: #0b5394;"> | </span>I<span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> | </span>I<span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> </span> </span><br />
<span style="font-family: Courier New, Courier, monospace;">3 <span style="background-color: #0b5394;">--------</span>I<span style="background-color: #0b5394;">------</span>I<span style="background-color: #0b5394;">------</span>I<span style="background-color: #0b5394;">----</span>I<span style="background-color: #0b5394;">-------------</span>- Task 3</span><br />
<span style="font-family: Courier New, Courier, monospace;"> <span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> </span>I<span style="background-color: #0b5394;"> </span> </span><br />
<br />
For each section, if the process as described above is followed, there is always a one-to-one-mapping between the N numbers and each task. It does not matter how many sections there are, there always be a one-to-one mapping between N numbers and the task.<br />
<br />
It would probably be easier just to draw straws (or randomly pick numbers from a hat) -- however the picking process of going through <i>Sadari Tagi</i> seems a lot more fun and exciting!Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.comtag:blogger.com,1999:blog-2402224207420244738.post-70808384310534993952013-05-10T22:35:00.001-07:002013-05-10T22:37:17.478-07:00Function Call Can be Replaced by Set LiteralI got this warning in PyCharm today: <i>Function call can be replaced by set literal</i><br />
<br />
It was for the following code:<br />
<span style="font-family: Courier New, Courier, monospace;"> hand[unique_id] = set([seat.player])</span><br />
<br />
Basically it means that you don't have to say <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">set([seat.player])</span> you could just do this:<br />
<span style="font-family: 'Courier New', Courier, monospace;"> hand[unique_id] = {seat.player}</span><br />
<br />
It took a while to process what the message was actually saying...<br />
<br />Kevinhttp://www.blogger.com/profile/10110410690640267302noreply@blogger.com