Archive

Author Archive

Several of My Quotes

March 16th, 2010 3,817 comments

These are just several of my quotes that I have come up with over the past few years.

“Traitor, see you later” – Me

“There’s something in Canada” – Me

“Stress from my girl, stress from work, stress to drive a man berserk” – Me

“Life is a playground for mistakes” – Me

“I don’t know which one is correct, I just know one of them is wrong” – Me

Categories: College Tags:

Javabat Solutions

March 7th, 2010 751 comments

Warmup-1

Sleep In: Show ▼

Monkey Trouble: Show ▼

Warmup-2

String Times: Show ▼

Front Times: Show ▼

String-1

Hello Name: Show ▼

Make ABBA: Show ▼

Make Tags: Show ▼

Make Out Word: Show ▼

Extra End: Show ▼

First Two: Show ▼

First Half: Show ▼

Without End: Show ▼

Combo String: Show ▼

Categories: Programming Tags:

Hack this Site Programming Problem 2 Solution

February 9th, 2010 714 comments

A few years ago I joined the site, Hack This Site in order to practice coding and see how much I knew.  Although the name is suggestive of illegal material, this site is in no way promoting hacking.  It simply is a site to practice programming and learning better techniques.  One of the challenges, Programming Problem 2 involves writing a program to take an image filled with black and white pixels, find the distance between the white pixels, which are ascii characters.  Convert these ascii characters then into Morse code, which then is translated into numbers and letters.  I spent some time initially looking for a language that could read an image in pixel by pixel and the one I settled on was Python.  This was the second program I had written in Python.

The exact instructions for the program were

The pixels in the above image are numbered 0..99 for the first row, 100..199 for the second row etc. White pixels represent ascii codes. The ascii code for a particular white pixel is equal to the offset from the last white pixel. For example, the first white pixel at location 65 would represent ascii code 65 (‘A’), the next at location 131 would represent ascii code (131 – 65) = 66 (‘B’) and so on.

The text contained in the image is the answer encoded in Morse, where “a test” would be encoded as “.- / – . … -”

You have 15 seconds time to send the solution.

Now of course it says you have 15 seconds which is true and I did do it in 15 seconds, but since this site uses Javascript to count, you can simply disabe javascript to have unlimited time by using the Firefox plugin NoScript.

For example, the image I used was:

which gave the following numbers:

45 46 46 32 45 46 46 32 45 46 46 46 46 32 45 45 45 32 46 45 32 45 46 45 32 46 46 46 32 46 46 46 46 32 46 45 45 45 45 32 46 45 32

which was translated in the following ascii characters

-..  -..  -….  —  .-  -.-  …  ….  .—-  .-

which produced the following output using Morse code to translate:

dd6oaksh1a

The code that I used to program this was:

import Image
def multipleReplace(text, morse_code):
    for key in morse_code:
        text = text.replace(key, morse_code[key])
    return text
morse_code = {' .- ':'a',' -... ':'b',' -.-. ':'c',' -.. ':'d',' . ':'e',
            ' ..-. ':'f',' --. ':'g',' .... ':'h',' .. ':'i',' .--- ':'j',
            ' -.- ':'k',' .-.. ':'l',' -- ':'m',' -. ':'n',' --- ':'o',
            ' .--. ':'p',' --.- ':'q',' .-. ':'r',' ... ':'s',' _ ':'t',
            ' ..- ':'u',' ...- ':'v',' .-- ':'w',' -..- ':'x',' -.-- ':'y',
            ' --.. ':'z',' ----- ':'0',' .---- ':'1',' ..--- ':'2',
            ' ...-- ':'3',' ....- ':'4',' ..... ':'5',' -.... ':'6',
            ' --... ':'7',' ---.. ':'8',' ----. ':'9'}
im = Image.open("C:\PNG.png")
size = im.size
width = size[0]
height = size[1]
L = list()
last = 0
#The loop transforms the image into a list
#If the pixel is white, return 0, otherwise return 1
for i in range (0,height):
    K = list()
    for j in range (0,width):
        checker = (int)(im.getpixel((j,i)))
        if(checker == 1):
            K.append(1)
        else:
            K.append(0)
    L.append(K)
ascii = list()
count = 0
for i in range (0,height):
    for j in range (0,width):
        if(L[i][j] == 1): #determines if the pixel is on
            char = chr(count-last) #converts the distance
            #between the pixels to ascii
            if(char == " "):
                char = "  "
            ascii.append(char)
            last = count
        count+=1
morseCode = " "
for i in range (0,len(ascii)-1):
    morseCode += ascii[i]
morseCode += " "
print multipleReplace(morseCode, morse_code) #replaces the morse code
#with letters and numbers
Categories: Programming Tags: , ,

Walk Right to Avoid Plight

January 14th, 2010 813 comments

Have you ever had one of those awkward encounters when someone else is walking towards you, but neither of you know which way to move as to let the other pass by? usually it leads to several awkward seconds where both of you stare at each other and try to go right or left, but find the other person was trying to go that way too. Sometimes various back and forth movements follow as you each try to find a proper way around the other until one person decides to just stand still and let the other person walk around them. But this is still a waste of a few seconds of commuting time, even making you late, and it can really be frustrating.

My solution to this problem is Just Walk Right.  That way, if everyone follows the same pattern, no one would be forced to encounter another awkward standing moment.

This is also a page on Facebook.  Please fan.

Categories: Fun Tags:

links for 2010-01-12

January 12th, 2010 187 comments
Categories: Link of the Day, Uncategorized Tags: