Skip to content

Instantly share code, notes, and snippets.

@fj
Created November 25, 2009 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fj/242482 to your computer and use it in GitHub Desktop.
Save fj/242482 to your computer and use it in GitHub Desktop.
Phone riddle for Karl Leswing. See karl.rb for more details.
;&Bh&A&&AAHBMM#HABBM##BH#Airr;::::;Xr:,,..:::;rriSi:.,:,,,,,,,,,::;::;;;rrsrriS29h;rr:r;:,r@@@@@@@#MM##MMMMB
:S@BX&GhMBHABMMAAHHAAA&2i32sr;:::::ir,.,,.;ss;,,:;S;,,:,,,,,,,,:::::;;;rrrsiisS23hr,.,,:,r@@@@@@#MBBMMBHHHHA
r;@@X2h92Ssii5isssssssir,;95r;;;::,:Xr::;;is;;r;:rr:,,:::,,,.,,:::::rs;;rrsiisS2Xhr.,,..i@@@@@@MhG&&&AG&hhAA
r:H@s;iirrrSS5SS52XXX9&i,,s3s;:::,,,r22XXsr;rrSSir;;::::::,,.,,,:;;;rrrrriSissSSXG; ,i@@@#@@@HG33hhhh&AAGA&
r:i@#&A&&AB#HABBHAHAAHMi,,:XSr;::::;r5A#&r:;rssiissrr;;;;::,.,,::;;;rrrrrsiisi223&hA&@@@@@##A9X993h339GG&G&&
r:;#@B&ABHHBAAHHAAHHAAB5::,sXs;;;;s2h&G5r;;r;;rsiiSiiisrr;:,,,,:;;;;rrrsrrsrsi52hA#@@@@@#@@@BGGAAHBHBBBBMMMH
r:;A@B33322X332553hX52Gh;;,,22r;;i9h3s;::;r;,,,,:::::;rrrr:,,,,:;;rrrssrrsiii55ShAA@@##@#M#@@GGGG&G&AAHHAAHH
r:;9@Aisi;;ih5sssSSisi2hS;,.:3Sri32s;;;;;:::;;;;:::,,,,::r;:,,;rriiisr;;rrssS5S5&GX@@@@Mhi.s@@####@@@@@@@@@#
r;;9@MSrisiAHiiSissssii92;:,.;9s25r;rS2GG3X933hhXX33SSS;:;;::;ri33XSr;rrrrssssS2H2S@@#&,.. r@@@@@@@@@@@@@##
r;;A@BrriSABH33hhhG&M#AS5;:,..rXirr53XXX252X25isissiSiir;;;:;r2S;,:;;;;;;;rssr23Hri@@B: ::; 2@@#######MMHHB
r;rH@@AAAAHABH&G9X9h&H5;Sr:,...s2is55iir;;:::::::::,::::;;;;r2r ,;sr;;rrrrri2B9;s#H;::r;,. ,@#MMMBBBHAAHHH
r;r@@B2523XhMMAAHB###@s,ri;:,.. s9irr;rrrr;;;;::::::::::;;rri; ,;ssr;rrrssS2&BsrsG. Ss:r::. 2@HHHHBBMMM##M
r:i@@@@@@@@@@@@@@@@@@@2,,is;,.. rXs;;;rri2Ssrr;;;:;:::;;;ri: .:::;rrrrrriiS2&Airrih r. s,.,.s@#######@##@#
s:H@@@@@@@@@@@@@@@@@#@A;.:i;::,,..;2irrrrrrsr;;;;;;;;;;ssrir..,:;ri;r;riiS2hAAirrrsA: .;,; , r@@@@@@@@@@@@#
ri@@#&&h322Sir;;;;;;;r5r. ;i;:::,. :23issr;;r;::;;;;;;;;;SS,,,:;:;sSsrs52hAMhs;rrrs&@AXrr, :: ;@@@@@@@@@@@@#
i#@h. ...::::;r2&5,.,ir:::... ,2Airr;;;;;;;r;;;;;:r2:.,::;;sXii52hAHA5srr;r;s5#@Mrr, ,,.r,,:riXA##@@@@
#@@r:;rs522XhAM##@@@#Ahi;;:;5;:::,... ;XSrri5s;;;r;rr;;r2:...,::;52ShAHA92srrrr;;;riGG3,:; .:,; :i9H
@@@B#@@@@@@@@@@#AXX2: .;S;:;X;:,,,.. ,s2S2Xir;rrrs;ri2, ...,::5&&HBAXirrr;;rr;;rrs2X2r,S..:;.:. . ,
@@@@@@@#35is;,,,,,.,:,,;i;:r5r:,,... . .;SSissrrrsSSi. ...,,:2#MAh2srr;;;;;;;;;rrr5XiS:r;::r.: ,;,,:;:. ..
@##@#X:. . ;,:;;:.rs:,:rr;,,..... ,;ri2225s: ...,,:2@&Xir;;rr;;;;;;:;;;;rS2is :,.r,,;:; .. :::
i,,:,. .:, ; .: ;r: ;r,,::;:,,,,........ .,:::...,,,,::iHSr;:;;;;;;;::;;:;;;;riii: : r.:: ...;::...:,
s. .;,;r;:r5; ;. ..,iriS:,;;:,:,,,......,,,,......,:,,,,:::r3r:;;;;;rr;;;;;;::;;;;rsis. , :,,s. .: ;::; .
;..:. .,..,;:.., ,;rss;::::,.... ..............,,,:r;:;;;;:;;;::::,,,::::;;rr;. .:, .:. :... .:.
............................................................................................................
issiiiiiiiiiiiiiiiiiSB@@@#MMG2srr;;;;;rrrrr;;;:::::::::;;;;;;;rrrrrrri2GM#@@HAM@@#&MMGh9ABMMHMMX55SS5555555i
i;rrrrrrrrrrrrrrrrr;i##@@M&9s;:::::,,,............ ..,,,,,,,,:::::;;:rGHMB@@#MAM@h5@@@BB#BBAH@&rrsssiisiiii
iriiiiiiiiiiiiiiiiss#@###&hir;;;;;;:::,,,,,,,,:,,,,,,,::::;;::;;r;rrrriX9B#H@@@@@@@M@@@@@@@M@#@@2i525555522i
iriiiiiiiiiiiiiiiiiH@@@@B#&srr;;;;rr:::::::::::,,,,,,,,::::;;;;;rrrrrrrs9A@#&H#@@@#HB@@@@@@#@@@@2i522555522S
iriiiiiiiiiiiiiiS5A@@#@@@@3rrr;;;;;;:::::::::,,,.,..,,,:::::;;;;;rrrrr;S3M##A999@@@AhA@@@@@@@@@#5iS55555522S
iriisiiiiiiiiiiiiX@@##@@@Birr;;;;;:::::::::,,,,,....,:::::;;;;;;;r;;rrriGBM##GAH9MBhB@@@##@@#@@@3sSS5555525S
iriiiiiiiiiiiiiis5AM#@@#Xiisrr;;;;::::::::,,,,,,,,:,:::::::;::;;;;rr;;ri9HM#MH&#BB#BB@@@@M#@@@@@#5SSS555522S
iriiiiiiiiiiiiiir2@#@#@B2iissrr;;;;:::::::,,:::::::::;;:::::;;;;;;rr;;;s&HBMM9MH&&@AG###@@@@#B@@@M255555522S
iriiiiiiiiiiiiiisB@#HB#MXSiiirrr;;;::::,::::::::::::::::::::;;rr;;;;;;;sGGAh#A@#9h@#hM@@#@@@H#@@@@9S5555552S
iriiiiiiiiiiiiisi#BHB#@M3Siisrrr;;;;::,::::::,::,,,,:::::;riSSsrrr;;;;;r5Ah3#MM##@@@#@#@@@@@@@@@@@AiS555522S
irisiiiiiiiiiiir2###M#@#35Sisr;;;;:::,,,::,,,,,. ....,;s2A#M##HXis;r;;;;;5H#HAMBM@@@@@@@@@@@@@@@@@@Si525222S
iriiiiiiiiiiiiisH@@@M#@#hX5sr;;;;:::,,,.,,.,,::.,;ri9A@@@@MAAAM@@Hi;r;;;:rh@@#@M#@@@@#@@@@@@@@@@#@@Xi522222S
iriiiiiiiiiiiisi#@@@#@@@&Xs;;;;rr;:;,...,,,,;i5sG@@@@@AS:,. ,;2A#hrrr;rrrG@@@##@@###@@@@@@@@##@@@hi552222S
iriiiiiiiiiiiisi#@@@#@@@A3X2SXhh5isr;:::,,,:r9h5933s;;;;;:,,,. .:iA9sr;r;::2@@@#@@@#@@#@@@@@@@@@@@2S552222S
irsiisiiiiiiSisr&@@@##@@M@@@@@@@@@@@@Bhi;:,,:;rr;,.,SAXihAB&2Ss:,.,;rr;;;;;:;H@@@@@#M#@#iS#@@@@@#@Bii522222S
isiiiiiiiiiiiisrs###MA@@@@@#H3A##BM###@Ai;,.,,:;,,;22r ###@MGHS;;:::;;;;;;;:3#MB@@@@@@#2srX@@#@#@9iS522222S
SsiiSiiiiisiiiss;i@@@#M@@B5;riSiX&h3r;sGS:,,,;;;:,rs:. 9A&B5;Ahs;:,,:;;;;;;:S@@###@@@MA&; ;@@@@@@2i2222222S
irSiSiiiiiiiSSiss;sB@@@@@Grs#B,.G#XH2 ;2s:,:;;:;;,:riSi;;s::;rr;:;:,,,:;;;;;;s#@##H##&X32, S@M@#@#SS2555552S
irSSiiSSSiiSiiiisr;;5@@@#h9M#2;:5G2rsrr2r;::;;;:::;rsssr:..,,,,,:,::::::;:;;;iBHM@2sr:,:rs.2@#BB@ArsiiiiiiSS
irSiiiSSSiiiiiiiissr;3@##Xs2AAXSr;::rrsXr;;;;;;:,:::::,,,......,::::;;;;;;;;;h59@@h:., .r,S@#H#@&X9G&AHMM#&
iriiiiiiiiiiiiSiiiisr;i@@2riX2sr;;;;;;25;;;;;r;;::,,,,,,,,,:::::::::;;;;rrr;;rs9M#3: :;,..;S@@#@@M#@@@@@@@#H
iriiiiSiiiiiiiiiiiiisr;#@3issr;;;;;::S2;;siirrr;;:::::;;:::,,:,,,,:::;;;rrrr;;r5GX;r: ,:, ,5@@@@HBBBHHBHHAHA
5riisiisisssssssrrrr;;:;@Airr;;;;;;;S2r;rssiS5irr;:::::::,,,,,,,,,:;;;;rrrrrrrsS95,;: .;r:,5@@@#G&AHAAAHAHBH
XSsisriiiiiS52222X3hGG9X&Girr;;;;;;i5;;;;:;;ri5Sis:,,,,,,,,,..,,::::;;;;rrrrrsiSGX::;;ss;;,A@@@#B#MM##M####B
#!/usr/bin/ruby
require "puzzle"
# Hi Karl! Welcome to your phone number riddle, Ruby style. You'll need both karl.rb and
# puzzle.rb (see below) in the same directory to solve things correctly, but the only
# file you should edit is karl.rb.
# Solve the following riddles. By running this Ruby script and answering the questions
# correctly, you'll generate the phone number of a certain person you know.
#
# //----------//
# // PART ONE //
# //----------//
#
# Replace each question mark with the integer which is the answer to the statement above.
# Hint: all answers lie in the range 0 to 6 inclusive, and no two answers are the same.
s = Array.new(7)
# ?: Square root of Miley Cyrus's age as of November 21, 2009.
s[ ? ] = [*(5..7).map{|i| i * 10 + 7}]
# ?: Number of games won by UVA's football team as of November 20, 2009.
s[ ? ] = [*(1..3).map{|i| i * 10 + 7}]
# ?: Maximum legal length of a high school lacrosse goalie's stick, in feet.
s[ ? ] = [*(84..86)]
# ?: Smallest odd number which cannot be expressed as the sum of the proper
# divisors of any other number. Proper divisors are numbers which divide
# another number with no remainder; for example, [1, 2, 3] are the proper
# divisors of 6.
s[ ? ] = [*(5..7).map{|i| i * 10 + 3}]
# ?: Cardinality of the empty set.
s[ ? ] = [*(4..6)]
# ?: Baker's dozen minus a dozen.
s[ ? ] = [*(1..3).map{|i| i * 10 + 3}]
# ?: Solve for n: 1 + 1/n + 1/n^2 + ... = n.
s[ ? ] = [*(44..46)]
#
# //----------//
# // PART TWO //
# //----------//
#
# Two numbers i and j are coprime if they share no prime factors other than 1; for
# example 12 [2 * 2 * 3] and 35 [5 * 7] are coprime.
#
# Many integers can be expressed as the difference between another integer and the
# number of coprimes below that integer. For example, if you let CP(x) be the number
# of coprimes below x, then 6 is such a number: 10 - CP(10) = 10 - 4 = 6.
#
# Replace the question mark below with the smallest positive integer that cannot be
# expressed as the difference between any integer and the total number of coprimes
# below that integer.
#
sz = ?
# At this point, run "ruby karl.rb". If your answers are right, give the resulting
# phone number a call. Good luck, and happy Thanksgiving!
d = [
s[0]|s[1]|s[3]|s[4]|s[5]|s[6],
s[0]|s[2]|s[3]|s[4]|s[6],
s[1]|s[2]|s[3]|s[4],
s[0]|s[1]|s[2]|s[4]|s[6],
s[1]|s[2]|s[5]|s[4]|s[6],
s[0]|s[1]|s[2]|s[3]|s[4]|s[5]|s[6],
s[0]|s[1]|s[2]|s[3]|s[4]
].map { |el| Grid.from_indices(sz, el) }
[d[2], d[1], d[2], d[5], d[0], d[4], d[3], d[6], d[1], d[5]].each { |d|
d.display
}
#!/usr/bin/ruby
# Quick class I wrote to do some stuff. Hooray.
class Grid
attr_accessor :size, :grid
class << self
attr_reader :f, :t
end
@f = '0'
@t = '1'
def self.from_array(arr)
raise "can't use nil array" if arr.nil?
raise "must be square grid" if arr.length != arr[0].length unless arr.empty?
g = Grid.new(arr.length)
g.grid = arr
g
end
def self.from_indices(grid_size, arr = [])
raise "can't use nil array" if arr.nil?
g = Grid.new(grid_size)
g.grid = []
(grid_size).times { g.grid << self.f * grid_size }
arr.each { |el| g[el / g.size, el % g.size] = self.t }
g
end
def initialize(size = 12)
@size = size
end
def self.from_rule(grid_size, &bl)
g = Grid.new(grid_size)
bl ||= lambda { |c,i| false }
g.grid = []
(s = self.f * grid_size * grid_size).split('').each_with_index { |c, i|
s[i] = self.t if bl.call(c, i)
}
g.grid += s.scan(/.{1,#{grid_size}}/)
g
end
def display(spacing = 1, chars = {:t => '#', :f => ' ', :spacer => ' '})
mapping = chars[:f].to_s + chars[:t].to_s
spacer = chars[:spacer] * spacing
border = "+" + ("-" * @size * (chars[:spacer].length + spacing)) + "+"
puts border
@grid.each { |row|
puts "|" + row.split('').map{|i| (i == self.class.t) ? chars[:t] : chars[:f]}
.join(spacer) + spacer + "|"
}
puts border
return
end
def [](i, j)
self.grid[i][j]
end
def []=(i, j, val)
self.grid[i][j] = val
end
def &(o)
self.op(o) { |l, r, i| l == self.class.t && r == self.class.t }
end
def |(o)
self.op(o) { |l, r, i| l == self.class.t || r == self.class.t }
end
def op(o, &bl)
l = self.grid
r = o.grid
Grid.from_array(
l.zip(r).map { |li,ri|
(0..li.size-1).map { |j|
bl.call(li[j], ri[j], j) ? self.class.t : self.class.f
}.join
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment