“I have been told that any encryption becomes safer if the underlying
algorithm is maximally obscured, what is most conveniently done by
coding it in Haskell.” – rankk
Functional programming is terribly addicting! Partly I think the
completely different way of thinking makes it feel like learning
programming, and falling in love with it, all over again. Partly there’s
this evil sense of satisfaction from using $s (and later
<$>s and =<<s and
&&&s) to improve readability for initiated
Haskellers and worsen it for everybody else. Partly it’s because
Learn You a Haskell for Great
Good! is such a fun read — there are too many funny bits to list
but my favorite so far is when the author analyzes the first verse of
Avril Lavigne’s Girlfriend.
Although I think my code in Haskell tends to be more readable than in
other languages, code obfuscation in Haskell is almost natural: all you
have to do is refactor the wrong function to be “pointfree”, which means
that even though it’s a function that takes arguments, you define it
without parameters by manipulating and joining a bunch of other
functions. Example (plus a few other tiny obfuscations):
Okay, but seriously now. I wrote this about my journey to learn
functional programming in the
programming babble post half a
year ago:
The main obstacle I have is that it’s hard to optimize or get
asymptotics when computation is expensive (a big problem if you’re
trying to learn through Project Euler problems, particularly ones with
lots of primes).
This is beautiful. Why do they have to make it sound all mysterious and difficult? That’s (the reciprocal of) the golden ratio, by the way.
Transcript since the resolution is far from awesome: “Most angiosperms have alternate phyllotaxy, with leaves arranged in an ascending spiral around the stem, each successive leaf emerging 137.5° from the site of the previous one. Why 137.5°? Mathematical analyses suggest that this angle minimizes shading of the lower leaves by those above.
Stopped by a friend’s house a few days ago to do homework, which
somehow devolved into me analyzing what programming language I should
try to learn next in a corner, which is completely irrelevant to the
rest of this post. Oops.
Anyway, in normal-math-curriculum-land, my classmates are now
learning about matrices. How to add them, how to multiply them, how to
calculate the determinant and stuff. Being a nice person, and feeling
somewhat guilty for my grade stability despite the number of study hours
I siphoned off to puzzles and the like, I was eager to help confront the
monster. Said classmate basically asked me what they were for.
Well, what a hard question. But of course given the curriculum it’s
the only interesting problem I think could be asked.
When I was hurrying through the high-school curriculum I remember
having to learn the same thing and not having any idea what the heck was
happening. Matrices appeared in that section as a messy, burdensome way
to solve equations and never again, at least not in an interesting
enough way to make me remember. I don’t have my precalc textbook, but a
supplementary precalc book completely confirms my impressions and
“matrix” doesn’t even appear in my calculus textbook index. They
virtually failed to show up in olympiad training too. I learned that
Po-Shen Loh knew how to
kill
a bunch of combinatorics problems with them (PDF), but not in the
slightest how to do that myself.
Somewhere else, during what I’m guessing was random independent
exploration, I happened upon the signed-permutation-rule (a.k.a.
Leibniz
formula) for evaluating determinants, which made a lot more sense
for me and looked more beautiful and symmetric
and I was annoyed when both of my linear algebra textbooks defined it
first with cofactor expansion. Even though they quickly proved you could
expand along any row or column, and one also followed up with the
permutation formula a few sections later, it still felt uglier to me.
Yes, it’s impossible to understand that equation without knowledge of
permutations and their signs, but I’m very much a permutations kind of
guy. Sue me.
[edit: okay guys I’m surprised at many people come here with search
queries looking for solutions. If you want IMO solutions,
the
corresponding AoPS forum invariably has many of them. This is
probably late-ish, but just in case.]
Day 2 of the contest.
Did you know that in Chinese [or Mandarin, whatever] “four” is
unlucky because it’s a homophone for “death”, and hospitals tend to skip
it in floors or ward numbers?
Did you know that there was going to be an anecdote involving the
seventh Artemis Fowl book but I couldn’t make it work so instead you
have a weird and utterly disconnected metareference to something
deleted?
I don’t know, it sounded cool at the time.
Problem 4. Find all functions f: Z → Z such that,
for all integers a,b,c that satisfy a+b+c = 0, the following equality
holds: \[f(a)^2+f(b)^2+f(c)^2=2f(a)f(b)+2f(b)f(c)+2f(c)f(a).\]
(Here Z denotes the set of integers.)
An innocent-looking functional equation, but once you start trying it
you discover that there’s quite some depth to it. Random guessing can
yield that \(f(x) = x^2\) is a
solution, so I proved inductively that after dividing out a constant
f(1) then the remaining part of f is a perfect square. Letting \(f(x) = f(1)g(x)^2\) with g(x) a nonnegative
integer and factorizing the original equation, I got an auxiliary
functional equation equivalent to the original equation.
Casework on small values of g, and the surprises started coming hard
and fast. First: wow there’s an extra odd-even solution! Then: woah
there’s another mod 4 solution! What is this madness?
I could spend all day coming up with post titles like this one.
Really, I could. Anyway, after receiving the letter gently reminding me
to turn in the official IMO report in Chinese, I finished that first and
turned it in. This, plus the fact that I don’t have any way to do any of
my summer homework yet, should make continued blogging much easier.
These months of preparation and anticipation, and in just over two
days it will be behind us forever.
Thus were my thoughts at 3:30 in the morning, which were a much worse
method of preparation than that which I used for the APMO, which
involved trying for the first time to put my compass in its box and
staring at a cryptic crossword. Twisted thoughts as I lay innocently in
bed, trying to preserve my spirit and mathematical function. I got up at
6:30 and ate a breakfast nervously with the team.
We dispersed into the contest hall. Flat squarish white tables in
orderly rows greeted us. They were considerably smaller than the
arm-span tables we had last year in the Netherlands’ stadium, but the
space was still ample compared to the ones we took our practice tests on
at home. I floundered a bit looking for whoever was supposed to check
our stuff for forbidden items, but none of the proctors paid any
attention to that, so I flipped through my own jacket pockets
paranoidly.
But preparation was too brief, and there were at least fifteen
minutes left with nothing to do except try not to panic. I managed to
fill these fifteen minutes by doing elaborate breathing exercises,
raising and flapping my arms, counting down seconds, focusing on a color
word, meditating badly, clearing out everything nonmathematical from my
mind with a symbolic gesture. This is not a very coherent description,
but I wasn’t feeling very coherent.
I opened an eye halfway and watched as the clock ticked down the last
few seconds. The starting signal sounded. I opened up the problem
envelope…
Who knew coming up with strangely cryptic and illogical but
nice-sounding post titles was so much fun!?
Okay, this break in storytelling is mainly brought to you by generic
summer laziness, as well as possibly a tiny bit of chemotherapy adverse
effect. There is only a little perfectionism involved, and that’s
because this post contains a long awkward situation (you might have
guessed already). I guess this is what it feels like to have oodles of
stuff to blog about, but not enough motivation. Heck, these few days
with running the TAIMC have long filled my list of rant topics with
juicy stories until it’s near-bursting. But I need to end this self-pity
party before I get carried away, so… back to the action.
Stranded in a foreign country at least 20 degrees Celsius below our
comfort zone, having worn the same clothes for 36 hours of airplane
travel, and still with less than 48 hours until the contest and zero
out of six compasses, we were running out of options.
A quick inventory of clothes showed that, after including the vests
and caps in the backpacks we got, we probably had just enough clothes to
survive the cruel frigid environment. So, reluctantly, we left the games
room and hit the street to hunt down some underwear and socks to change
into. Not to mention toothbrushes and some T-shirts and jackets for good
measure, because the inside of the hotel was not the right temperature
for full cold-resistance gear.
Some haphazard wandering up and down the streets later, we found a
store that suited our needs and picked up some clothes. The underwear
came in two sizes: too loose and too tight. We picked the latter. Oh
well, it would only be for a day or so… right?
We finally arrived at the hotel at 3:30, meeting another local from
Taiwan, Mr. Chen, who helped us carry some of our stuff off the bus.
Po-Chiang, our guide, was waiting inside. We took more pictures and
finally lugged the meager stuff we had off to our hotel rooms.
At least, we tried. I started to realize that there was much more to
this hotel than it seemed.
Firstly, of course, was the confusing placement of rooms with numbers
starting with 4 and 5 on the fourth floor (which would be the fifth
floor by our numbering system, where the lobby is floor 1; but here the
lobby was assigned 0. Off-by-one errors just waiting to happen here.)
Secondly were the completely indecipherable signs. I don’t remember the
details, but the first signs we saw read something like “560 ~ 540:
left; 520 ~ 540: right”. Occasionally there would be weird slashes or
half-slashes between the numbers instead (later I finally realized they
were slanted, Comic-Sans-style capital Ys, or “and” in Spanish). Are
these closed, open, or half-open intervals? And why the heck are their
upper and lower bounds in a different order!?
We wandered through the corridors, peeking down each one, trying to
figure out whether the numbers were increasing or decreasing and whether
a parity argument (for those of you not fluent in math lingo, that means
odds and evens) allowed for the existence of our room. Who knew the
simple act of finding one’s living quarters could be so mathematically
tasking? In the end, our rooms were in the last corridor, just about
diametrically opposite to the elevators on the half of our floor. Oh
well.
The room was pretty nice overall. The furniture and basic facilities
were quite complete, with a sparkly bathroom and a couple tables and
chairs of various shapes. The closet was big and had a safe, which was
rather important because just about everybody we had met had warned us
over and over again about all the incredibly skilled thieves, muggers,
and pickpockets in Argentina. It was probably much safer (no pun
intended) in the hotel, but with all of these warnings (later we would
even find a notice from the hotel warning us to lock our doors) I was
never entirely certain. There were lots of lights controlled by a set of
confusing switches on either side of our beds. There was at least one
white immovable divider cunningly disguised as a switch, one switch that
didn’t ever seem to do anything, and one that turned everything off. The
last one made a little sense after a while because it had pictures of
stars and a moon on it, but the whole setup was still pretty
non-user-friendly in my opinion.
It’s time to begin the epic blogging journey. The detailed version of
this year’s amazing IMO, because I decided that a perfectionist guy like
myself could not possibly liveblog and be satisfied with both the
quality of the posts and being able to fully enjoy the actual event.
Our story begins in a hotel in Taiwan.
The night before departure, us six contestants and Prof. Lin gathered
in a hotel. This was entirely necessary because our flight left at
something like five o’clock in the morning. After checking over the
flight plans and relevant phone numbers in a conference room, we enjoyed
a pretty extensive buffet dinner, what would easily be the best meal we
would get to have for at least a week, the highlight of which was a fish
steak that looked and tasted exactly like fried egg. Afterwards we did
some emergency shopping and prepared a convenience-store breakfast for
consumption three o’clock the next day.
As I’ve complained before, we have an 11-hour difference to get used
to, and that morning I had gotten myself to sleep as late as 6 AM trying
(successfully, much to my amazement) to complete an iPod OS system
update. I didn’t think I could pass airport security with the sort of
consciousness I had when I finally slept that morning, so I reverted
with the rest of the team to an 11 PM curfew. Oh well. The seven of us
left the hotel after 3 AM, setting off in a huge 30-person bus for the
airport.
Luggage drop-off was mostly uneventful. I realized that the airline
didn’t seem to like passengers bringing two bags onto the airplane, and
decided to distribute my bag with all the winter clothes in it into my
luggage and my backpack. Little did we know what would happen to the
luggage…
Wait, are you serious? Under two weeks left, is that what it’s come
to?
What happened to my majestic plans to go over every functional
equation I failed on, ever? Or to go through a super-intense
geometry-immersion period and actually try to develop some of that crazy
“intuition” thing? And I have finals coming up too! I just
finished a ludicrous deadline-extended geography project that I am
absolutely confident is the crappiest paper of my entire school career
so far! And despite a semester of (slacking) classes, my Spanish is
still only barely at a usable level! Exclamation marks!
Don’t panic… let’s focus on the positive. I am absolutely prepared
with my stationery. I bought three spanking new 0.4mm pens that say “Can
write for 1000 meters!” because all of my current ones are annoyingly
thick and constantly having almost-but-not-quite run out, plus three new
mechanical pencils and enough matching 2B lead to last me through
college. All the pencils and lead are Pentel. I haven’t done any
research, so if something terrible happens in Argentina I know what
company to blame, and I am writing it here so I won’t confuse the
brands. Also, in view of what happened to SCH’s carry-on baggage last
year (luckily there was no geo on Day 1), I got an extra compass I hope
won’t be needed.
While we’re listing all the stuff I have gotten ready: