15-112 Fall 2011 Contest 2
Due Never! (Optional activity)
Contest Date:  Saturday, 10-Dec,
6pm to 8pm (ish)

Read these instructions first!

Section 1 / Phase 1:  Brighten Image
For this encoding, each component (red, green, and blue) of each pixel's rgb value was divided by 32 (with an integer result).  So if the original rgb values of a pixel were (243, 0, 122), then the encoded rgb values would be (7, 0, 3).  Because of this, the resulting encoded image is very dark, as you can see here:  image1-encoded.gif

To decode this image, you need to brighten it by reversing the process described above.  Remember, you may not use an image editor; instead, you must write a Python programmer that solves this!

Section 1 / Phase 2: 
smallestConsecutiveHappysDifferingBy50
Note that the Phase 2 problems were not available on the contest website during the actual contest, but are provided here after the contest for recording purposes.
Find the smallest consecutive pair of happy numbers that differ by 50, where happy numbers are defined here:
     http://en.wikipedia.org/wiki/Happy_number
(Note that you can tell if a number is happy if you get a 1, but it's unhappy if you get a 4 eventually...)  For example, the first two happy numbers are 1 and 7 and they differ by 6, so they are not the correct answer.

Section 2 / Phase 1:  Baboon Steganography
This time, the encoding uses steganography, so the original image is somehow embedded in another, unrelated image (baboons, as it happens), which we will call the distractor image.  Here is the encoded image:  image2-encoded.gif:

To decode this image, go to each pixel, get its rgb value, and take the bottom 3 bits of the red, green, and blue values.  Assemble these into a single 9-bit integer (which you are guaranteed will be less than 256).  That is the grayscale value of the result, so set the red, green, and blue values of the result all to this 9-bit integer value.  For example, if the encoded image has a pixel with RGB values
(243, 0, 122), or, in base 2, (11110011, 00000000, 01111010), then the bottom 3 bits from each are 011, 000, and 010, which concatenated becomes 011000010, which equals 194.  And so the corresponding pixel in the decoded image has an RGB value of (194, 194, 194).

Section 2 / Phase 2:  leastCommonLetters
Find the least common letter(s) Aristotle used in ON SLEEP AND SLEEPLESSNESS:
     http://www.textfiles.com/etext/AUTHORS/ARISTOTLE/aristotle-on-267.txt
Count all the letters on the page, case-insensitively (so "a" and "A" are the same), and ignore all non-letters).

Section 3 / Phase 1:  400 Tiles
This time, we take the original image (which happens to be 800x600) and treat it as a 20x20 grid of cells.  Then we swap cells repeatedly.  Which cells?  For this, we need a pseudorandom number generator.  We will use this one:  start with a "seed" (which we suggest you place in a global variable) equal to 0.  Each call to randint() will update the seed so that it equals
int((22695477*seed + 1) % (2**31)), so each value of the seed depends on the previous value.  Now, the randint() function does not actually return the seed itself, since the lower bits of that value do not act very random.  Instead, it returns (seed>>16).  If you implement randint() properly, the first 4 values it returns will be 0, 346, 130, and 10982 in that order (confirm this!).  Now, we need these to refer to rows and cols, so we take each value %20, producing the values 0, 6, 10, and 2 in that order.  We treat these values as row1, col1, row2, and col2, respectively, so our first step would be to swap cells (0, 6) and (10, 2).  That is the first swap.  We will make one million swaps.  Note that it is possible that (row1,col1) is the same as (row2,col2) -- this still counts as a swap.  Here is the encoded image after one million swaps:  image3-encoded.gif:

To decode this, reverse the encoding process described above.

Section 3 / Phase 2:  pascalsOddMedian
If row 0 of Pascal's Triangle is [1], row 1 is [1,1], and row 2 is [1,2,1], let's define pascalsOddMedian(row) to be the median of the odd numbers in the given row.
What is pascalsOddMedian(20)+pascalsOddMedian(21)?

Good luck!!!


carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem