Hi, I'm Leon and this is how I code.

Foo.bar - Origins and Order

Write a function called answer(x, y, z) that takes as input the 3 numbers on the date cards. You may assume that at least one valid representation of a date can be constructed from the cards.

If there is only one valid representation, the function should return it as a string, in the form MM/DD/YY. If there are multiple valid representations, the function should return the string "Ambiguous." Each of x, y, z will be between 1 to 99 inclusive. You may also assume that there are no leap years.

This was the first foo.bar challenge I ever attempted! Originally the code had six test cases, but sorting and using lists to keep track of possible days/months/years was pretty helpful.



Foo.bar - When it Rains it Pours

Write a function called answer(heights) which, given the heights of stacked hutches from left-to-right as a list, computes the total area of standing water accumulated when water is poured from the top and allowed to run off the sides.

The heights array will have at least 1 element and at most 9000 elements. Each element will have a value of at least 1, and at most 100000.

My function barely made it under the time limit! My submitted implementation used 'next(k for k in range(index:heights),200000)', but trinket doesn't support the usage of 'next' so I had to do a little adjustment.



Foo.bar - A Peculiar Balance

There is a scale with an object on the left-hand side, whose mass is given in some number of units. Predictably, the task is to balance the two sides. But there is a catch: You only have this peculiar weight set, having masses 1, 3, 9, 27, ... units. That is, one for each power of 3.

To help Beta get into the room, write a method called answer(x), which outputs a list of strings representing where the weights should be placed, in order for the two sides to be balanced, assuming that weight on the left has mass x units.

I had to look up the algorithm for breaking up numbers into powers of three! Implementation for this was pretty straightforward once I had the method.



Foo.bar - Zombit Infection

A virulent disease has been unleashed onto the rabbit population! Model its spread with the following information:

Rabbits are arranged in an n x n grid, where n is less than 50. The strength of each rabbit's immune system is represented by an integer, the virus can only spread upwards or downwards (not sideways), and the virus' virulence has to be equal to or larger than the rabbit's immune system in order to infect it. Given an initial grid of rabbits and their immune systems, return the end result (with all infected rabbits set to -1).

I ran the infection checking for 100 steps, reasoning that it'd be enough time to infect all the necessary rabbits. There's probably a more efficient/elegant way to do it, though - a breadth-first search, perhaps?



Foo.bar - Minglish

Given an alphabetically-sorted dictionary of Minglish words, write a function called answer(words) that returns a string of letters arranged in correct Minglish Alphabetical order!

This one was pretty straightforward. It took surprisingly long on some test cases - I think the recursive part of the program is what's causing it. It might be better to use object-oriented programming so each letter contains a list of letters it's "superior to".



Foo.bar - Breeding Like Rabbits

Given R(0) = 1, R(1) = 1, R(2) = 2, R(2t+1) = R(t-1) + R(t) + 1 for t >= 1 and R(2t) = R(t) + R(t+1) + t for t > 1:

Write a function answer(str_S) which, given the base-10 string representation of an integer S, returns the largest n such that R(n) = S. Return the answer as a string in base-10 representation.

I couldn't find an algorithm, so I decided to do a bisect search since the series R is strictly increasing. Trinket doesn't deal well with recursion so I've only put in small numbers, but on my computer the code will handle inputs up to 10^25 in under a second!


Miscellaneous projects

After learning Python in CodeAcademy, I decided to try an extension of the bit I found the most fun - making a game! Following the example of Battleship in the course, I decided to make a Hangman game in Python.

Links Out:
resumé   github   linkedin

Questions? Comments? Hiring? Contact me at
LeonJunWei.Lam@students.olin.edu

back to technical page     hop to writing page     return to landing page