When not exploring around Brazil, I’ve been working on lots of my own projects, and doing a lot more messing around with Ruby and Python. I stumbled upon Facebook’s Puzzle Page the other day, which they presumably use to attract nerds to job openings. Anyway, the Mike Korn puzzle caught my eye. I really enjoyed Abstract Algebra and Number Theory back in college, and had to dust off that part of my brain to recall how number partitions work. Of course, I was talking online to my good friend Dan about it. (Sorry Buster, you weren’t around)
Anyway, it seems dumb to completely re-hash the great math and code explanation offered over at 20bits. And I was doubly doh’d to see that he even put in the case statement solution that I thought I was being clever using.
For anyone curious, here is some Ruby code to run through the simulation for entered text, just for fun.
entered_name = "mikekorn" #lowercase and without spaces
alphabet = ("a".."z").to_a
mappings = alphabet.sort_by{rand}
keys_fucked_mapping = Hash[*alphabet.zip(mappings).flatten]
puts "Key Mappings:"
puts "-------------"
p keys_fucked_mapping
puts "------------------------------------------"
def fucked_typing(name_a,keys_fucked_mapping)
fucked_output = String.new
name_a.each do |letter|
fucked_output += keys_fucked_mapping[letter]
end
fucked_output
end
count = 0
what_to_mash = entered_name
begin
what_to_mash = what_to_mash.split(//)
what_to_mash = fucked_typing(what_to_mash,keys_fucked_mapping)
puts what_to_mash
count += 1
end while entered_name.to_s != what_to_mash.to_s
puts "Number of Iterations: #{count}"
If you have a puzzle you’d like me to solve for your job, please feel free to contact me at bazoomercom at gmail.
And ideally you are located in downtown Columbus, Ohio.
Update: no, I don’t want a job with facebook.
No related posts.
1 Comment
Your prog wont find the worse case scenario. It just prints a solution for a random keymap.
Leave Comment