Last active
August 29, 2015 14:24
-
-
Save asolkar/c2442c997e09f532bfcb to your computer and use it in GitHub Desktop.
Google for Work Riddles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Google for Work riddles in follow Google+ posts | |
# | |
https://plus.google.com/u/0/+GoogleforWork/posts/iGqi6N9dwY3 | |
https://plus.google.com/u/0/+GoogleforWork/posts/3uyrWjgz9cr | |
https://plus.google.com/u/0/+GoogleforWork/posts/6Z8LKYhJqWd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CaesarCrypt | |
attr_accessor :offset | |
def initialize(offset) | |
@offset = offset | |
@alphabet = ('a'..'z').to_a | |
end | |
def decrypt(st) | |
work(st,-@offset) | |
end | |
def encrypt(st) | |
work(st,@offset) | |
end | |
def work(st, off) | |
sol = Array.new | |
st.split(//).each {|ch| | |
sc = (@alphabet.include?(ch.downcase)) ? | |
@alphabet.rotate(off)[@alphabet.index(ch.downcase)] : | |
ch | |
sol.push((ch.eql?(ch.upcase)) ? sc.upcase : sc) | |
} | |
return sol.join("") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MorseCode | |
def initialize | |
@char = ('A'..'Z').to_a + (0..9).to_a + ['.', ',', ':', '?', '\'', '-', '/', '(', '"', '@', '='] | |
@morse = [ | |
'.-', | |
'-...', | |
'-.-.', | |
'-..', | |
'.', | |
'..-.', | |
'--.', | |
'....', | |
'..', | |
'.---', | |
'-.-', | |
'.-..', | |
'--', | |
'-.', | |
'---', | |
'.--.', | |
'--.-', | |
'.-.', | |
'...', | |
'-', | |
'..-', | |
'...-', | |
'.--', | |
'-..-', | |
'-.--', | |
'--..', | |
'-----', | |
'.----', | |
'..---', | |
'...--', | |
'....-', | |
'.....', | |
'-....', | |
'--...', | |
'---..', | |
'----.', | |
'.-.-.-', | |
'--..--', | |
'---...', | |
'..--..', | |
'.----.', | |
'-....-', | |
'-..-.', | |
'-.--.-', | |
'.-..-.', | |
'.--.-.', | |
'-...-'] | |
end | |
def encode(c) | |
sol = Array.new | |
c.split(//).each {|ch| | |
sol.push(@morse[@char.index(ch)]) | |
} | |
return sol.join(" ") | |
end | |
def decode(c) | |
sol = Array.new | |
c.split(/\s+/).each {|ch| | |
sol.push(@char[@morse.index(ch)]) | |
} | |
return sol.join("") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# First riddle (https://plus.google.com/u/0/+GoogleforWork/posts/iGqi6N9dwY3) | |
# | |
r = "Wuhdw brxu sdvvzrug olnh brxu wrrwkeuxvk. Grq'w ohw dqbergb hovh xvh lw, dqg jhw d qhz rqh hyhub vla prqwkv. Foliirug Vwroo" | |
puts "Riddle 1: #{r}" | |
puts " " + CaesarCrypt.new(3).decrypt(r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Second riddle (https://plus.google.com/u/0/+GoogleforWork/posts/3uyrWjgz9cr) | |
# | |
r = "bddpvout ejggfsfou gps qbttxpse b sfvtf opu Ep" | |
# (0..26).to_a.each {|o| | |
# puts "#{o} -> " + CaesarCrypt.new(o).decrypt(r).split(/\s/).reverse.join(" ") | |
# } | |
puts "Riddle 2: #{r}" | |
puts " " + CaesarCrypt.new(1).decrypt(r).split(/\s/).reverse.join(" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Third riddle (https://plus.google.com/u/0/+GoogleforWork/posts/6Z8LKYhJqWd) | |
# | |
r = "-.- . -.-- ... . -.-. ..- .-. .. - -.-- .- ..- ... . .- -. -.. .- ..- - .... . -. - .. -.-. .- - .. --- -. ... - . .--. - .-- --- .- -.-. - .. ...- .- - ." | |
puts "Riddle 3: #{r}" | |
puts " " + MorseCode.new().decode(r) | |
# puts " " + MorseCode.new().encode(MorseCode.new().decode(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment