This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aurélien Bottazzini
committed
Apr 14, 2012
1 parent
9cd6645
commit 620934c
Showing
11 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
... Code Jam 2012/Qualification Round/Dancing With the Googlers/dancing with the googlers.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
1.upto(gets.to_i) do |case_number| | ||
|
||
line = gets.chomp | ||
numbers = line.split.map(&:to_i) | ||
|
||
n = numbers[0] | ||
s = numbers[1] | ||
p = numbers[2] | ||
t = numbers[3..n+2] | ||
|
||
surprising_for_sure = 0 | ||
googlers = 0 | ||
possibly_surprising = 0 | ||
0.upto(n-1) do |i| | ||
starting_triplet_value = t[i] / 3 | ||
starting_triplet_rem = t[i] % 3 | ||
|
||
if starting_triplet_value >= p | ||
googlers += 1 | ||
possibly_surprising += 1 | ||
elsif starting_triplet_value == p - 1 && starting_triplet_value != 0 | ||
if starting_triplet_rem == 0 | ||
surprising_for_sure += 1 | ||
googlers += 1 | ||
else | ||
googlers += 1 | ||
end | ||
elsif starting_triplet_value == p - 2 | ||
if starting_triplet_rem == 2 | ||
surprising_for_sure += 1 | ||
googlers += 1 | ||
end | ||
end | ||
end | ||
|
||
surprising = s - surprising_for_sure | ||
if surprising > 0 | ||
surprising = surprising - possibly_surprising | ||
end | ||
|
||
if surprising < 0 | ||
surprising = 0 | ||
end | ||
|
||
|
||
#TODO not correct need to include possibly surprising | ||
answer = googlers - surprising | ||
puts "Case ##{case_number}: #{answer}" | ||
end |
5 changes: 5 additions & 0 deletions
5
...le Code Jam/Google Code Jam 2012/Qualification Round/Dancing With the Googlers/samples.in
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
4 | ||
3 1 5 15 13 11 | ||
3 0 8 23 22 21 | ||
2 1 1 8 0 | ||
6 2 8 29 20 8 18 18 21 |
31 changes: 31 additions & 0 deletions
31
...Code Jam/Google Code Jam 2012/Qualification Round/Speaking in Tongues/A-small-attempt0.in
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
30 | ||
ejp mysljylc kd kxveddknmc re jsicpdrysi | ||
rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd | ||
de kr kd eoya kw aej tysr re ujdr lkgc jv | ||
hello i am the google code jam test data | ||
how are you | ||
aynny iynny aynny iynny aynny iynny aynny iynny aynny iynny aynny iynny aynny iynny aynny ieeeeeeeee | ||
y n f i c w l b k u o m x s e v z p d r j g a t h a q set k oset xa ynfd | ||
schr rkxc tesr aej dksl tkrb xc | ||
dtkwr yd rbc tksi zjkcr yd rbc wepcdr drcyia yd rbc xejsryks | ||
k bygc ncdrci wpjkr dvkoc ysi xees set k dbymm ncdr aej rbc lja | ||
cyfb ew jd byd bkd ets dvcfkym lkwr ysi aej oset rbkd tyd xcysr re nc rpjc | ||
ysi kw aej iesr jsicpcdrkxyrc xc k tesr jsicpcdrkxyrc aej | ||
mcr mkvd ie tbyr bysid ie | ||
w ew rte czjymd w ew esc czjymd esc | ||
wep k ncrtccs rbpcc ysi s w ew k czjymd w ew k xksjd esc vmjd w ew k xksjd rte | ||
eb acyb ympklbr tcpc lessy dbyoc kr jv tkrb rbc vypra ncyp resklbr | ||
ks y tepmi ew ikpctemgcd ysi mkesd dexcrkxcd rbc pypcdr fpcyrjpc kd y wpkcsi | ||
aej vkddci eww rbc fbkfocs myia | ||
aej ncrrcp fjr rbc vkqqy ks wejp vkcfcd ncfyjdc kx ser bjslpa csejlb re cyr dkh | ||
kx fexxysicp dbcvypi ysi rbkd kd xa wygepkrc vpenmcx es rbc leelmc feic uyx | ||
lpccrksld fbccdc vevdkfmc rbc sjxncp aej bygc ikymci kd fjppcsrma ejr ew vepofbevd | ||
pklbr k wepler bcpc ks rbc dryrcd aej fymm kr y dyjdylc ks rbc xejrb | ||
ejp feic uyx kd mkoc rbc varbylepcys rbcepcx | ||
rbcpc kd se ysdtcp | ||
rpysdmyrksl rchr kd ser leped drpcslrb | ||
drpcslrb kd leped drpcslrb | ||
ip qykjd ip qykjd ip qykjd ip qykjd eeeeeeeeeeeeb ip qykjd | ||
xa syxc kd ijl k bygc ujdr xcr aej ysi k meeegc aej | ||
wep rbedc tbe dvcyo ks y resljc ie ser dvcyo re erbcp vcevmc | ||
seneia jsicpdrysid rbcx dksfc rbca ypc dvcyoksl xadrcpkcd ks rbc dvkpkr |
7 changes: 7 additions & 0 deletions
7
Google Code Jam/Google Code Jam 2012/Qualification Round/Speaking in Tongues/examples.in
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
3 | ||
ejp mysljylc kd kxveddknmc re jsicpdrysi | ||
our language is impossible to understand | ||
rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd | ||
there are twenty six factorial possibilities | ||
de kr kd eoya kw aej tysr re ujdr lkgc jv | ||
so it is okay if you want to just give up |
17 changes: 17 additions & 0 deletions
17
...le Code Jam/Google Code Jam 2012/Qualification Round/Speaking in Tongues/find_mappings.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
mappings = Hash.new | ||
1.upto(gets.to_i) do |case_number| | ||
line = gets.chomp | ||
translation = gets.chomp | ||
|
||
0.upto(line.size-1) do |i| | ||
if !mappings.key?(line[i]) | ||
mappings[line[i]] = translation[i] | ||
end | ||
end | ||
|
||
end | ||
|
||
mappings['z'] = 'q' | ||
mappings['q'] = 'z' | ||
p mappings.size | ||
puts mappings |
30 changes: 30 additions & 0 deletions
30
Google Code Jam/Google Code Jam 2012/Qualification Round/Speaking in Tongues/output.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Case #1: our language is impossible to understand | ||
Case #2: there are twenty six factorial possibilities | ||
Case #3: so it is okay if you want to just give up | ||
Case #4: xoggk d yl wxo vkkvgo ekso uyl wonw sywy | ||
Case #5: xkf yto akj | ||
Case #6: yabba dabba yabba dabba yabba dabba yabba dabba yabba dabba yabba dabba yabba dabba yabba dooooooooo | ||
Case #7: a b c d e f g h i j k l m n o p q r s t u v y w x y z now i know my abcs | ||
Case #8: next time wont you sing with me | ||
Case #9: swift as the wind quiet as the forest steady as the mountain | ||
Case #10: i have bested fruit spike and moon now i shall best you the guy | ||
Case #11: each of us has his own special gift and you know this was meant to be true | ||
Case #12: and if you dont underestimate me i wont underestimate you | ||
Case #13: let lips do what hands do | ||
Case #14: f of two equals f of one equals one | ||
Case #15: for i between three and n f of i equals f of i minus one plus f of i minus two | ||
Case #16: oh yeah alright were gonna shake it up with the party bear tonight | ||
Case #17: in a world of direwolves and lions sometimes the rarest creature is a friend | ||
Case #18: you pissed off the chicken lady | ||
Case #19: you better cut the pizza in four pieces because im not hungry enough to eat six | ||
Case #20: im commander shepard and this is my favorite problem on the google code jam | ||
Case #21: greetings cheese popsicle the number you have dialed is currently out of porkchops | ||
Case #22: right i forgot here in the states you call it a sausage in the mouth | ||
Case #23: our code jam is like the pythagorean theorem | ||
Case #24: there is no answer | ||
Case #25: translating text is not goros strength | ||
Case #26: strength is goros strength | ||
Case #27: dr zaius dr zaius dr zaius dr zaius ooooooooooooh dr zaius | ||
Case #28: my name is dug i have just met you and i looove you | ||
Case #29: for those who speak in a tongue do not speak to other people | ||
Case #30: nobody understands them since they are speaking mysteries in the spirit |
4 changes: 4 additions & 0 deletions
4
Google Code Jam/Google Code Jam 2012/Qualification Round/Speaking in Tongues/samples.in
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
ejp mysljylc kd kxveddknmc re jsicpdrysi | ||
rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd | ||
de kr kd eoya kw aej tysr re ujdr lkgc jv |
12 changes: 12 additions & 0 deletions
12
...e Jam/Google Code Jam 2012/Qualification Round/Speaking in Tongues/speaking in tongues.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mappings = {"e"=>"o", "j"=>"u", "p"=>"r", " "=>" ", "m"=>"l", "y"=>"a", "s"=>"n", "l"=>"g", "c"=>"e", "k"=>"i", "d"=>"s", "x"=>"m", "v"=>"p", "n"=>"b", "r"=>"t", "i"=>"d", "b"=>"h", "t"=>"w", "a"=>"y", "h"=>"x", "w"=>"f", "f"=>"c", "o"=>"k", "u"=>"j", "g"=>"v", "z"=>"q", "q"=>"z"} | ||
|
||
1.upto(gets.to_i) do |case_number| | ||
|
||
line = gets.chomp | ||
answer = String.new | ||
line.each_char do |char| | ||
answer << mappings[char] | ||
end | ||
puts "Case ##{case_number}: #{answer}" | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
def flow_down x, y | ||
x_flow, y_flow = 0, 0 | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
4 | ||
welcome to codejam | ||
elcomew elcome to code jam | ||
wweellccoommee to code qps jam | ||
wewwelcome to code jam |
20 changes: 20 additions & 0 deletions
20
Google Code Jam/Welcome to Code Jam/welcome_to_code_jam.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pattern = '$welcome to code jam' | ||
|
||
1.upto(gets.to_i) do |case_number| | ||
counts = [1] + [0] * (pattern.length - 1) | ||
gets.chomp.each_char do |char| | ||
new_counts = [] | ||
counts.each_with_index do |old_count, index| | ||
new_counts[index] = (old_count + ((char == pattern[index, 1]) ? | ||
counts[index - 1] : 0)) | ||
end | ||
p new_counts | ||
counts = new_counts | ||
end | ||
p counts | ||
answer = counts.last.to_s | ||
if answer.length > 4 | ||
answer = answer[-4..-1] | ||
end | ||
puts "Case ##{case_number}: #{'0' * (4 - answer.length) + answer}" | ||
end |