Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add 2012 and Round 0

  • Loading branch information...
commit e5b7e9d6df9ea4e57cc3cdfe89394c24822b58e4 1 parent a86fb65
@markmcspadden authored
View
3  2012/round_0/README
@@ -0,0 +1,3 @@
+I got A right.
+
+I got the small set of C right. The large set took forever to run. It was not up to Gscale...I kind of guessed that brute force wouldn't cut it there.
View
BIN  2012/round_0/a.zip
Binary file not shown
View
30 2012/round_0/a/A-small-attempt0.completed.out
@@ -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: you pissed off the chicken lady
+Case #10: for those who speak in a tongue do not speak to other people
+Case #11: nobody understands them since they are speaking mysteries in the spirit
+Case #12: this here is gunpowder activated twenty seven caliber full auto no kickback nailthrowing mayhem
+Case #13: right i forgot here in the states you call it a sausage in the mouth
+Case #14: whoooooooooooooooooooaaaaaaaaa i know c plus plus
+Case #15: you want sell things at me boing zooom
+Case #16: friends dont let friends let scientific progress go boink
+Case #17: dr zaius dr zaius dr zaius dr zaius ooooooooooooh dr zaius
+Case #18: our code jam is like the pythagorean theorem
+Case #19: there is no answer
+Case #20: im commander shepard and this is my favorite problem on the google code jam
+Case #21: oh hai im in ur computer eating your cheezburgers and googleresing your textz
+Case #22: now is the summer of our lack of discontent
+Case #23: oh yeah alright were gonna shake it up with the party bear tonight
+Case #24: oh nooooo goggalor is headed for the orphanage
+Case #25: oh my god lets make out
+Case #26: my name is dug i have just met you and i looove you
+Case #27: by the pricking of my thumbs something wicked this way comes
+Case #28: an eye for an eye and a pigeon for a pigeon
+Case #29: pneumonoultramicroscopicsilicovolcanoconiosis
+Case #30: why do programmers always mix up halloween and christmas
View
31 2012/round_0/a/A-small-attempt0.in
@@ -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
+aej vkddci eww rbc fbkfocs myia
+wep rbedc tbe dvcyo ks y resljc ie ser dvcyo re erbcp vcevmc
+seneia jsicpdrysid rbcx dksfc rbca ypc dvcyoksl xadrcpkcd ks rbc dvkpkr
+rbkd bcpc kd ljsveticp yfrkgyrci rtcsra dcgcs fymkncp wjmm yjre se okfonyfo sykmrbpetksl xyabcx
+pklbr k wepler bcpc ks rbc dryrcd aej fymm kr y dyjdylc ks rbc xejrb
+tbeeeeeeeeeeeeeeeeeeeyyyyyyyyy k oset f vmjd vmjd
+aej tysr dcmm rbksld yr xc neksl qeeex
+wpkcsid iesr mcr wpkcsid mcr dfkcsrkwkf vpelpcdd le nekso
+ip qykjd ip qykjd ip qykjd ip qykjd eeeeeeeeeeeeb ip qykjd
+ejp feic uyx kd mkoc rbc varbylepcys rbcepcx
+rbcpc kd se ysdtcp
+kx fexxysicp dbcvypi ysi rbkd kd xa wygepkrc vpenmcx es rbc leelmc feic uyx
+eb byk kx ks jp fexvjrcp cyrksl aejp fbccqnjplcpd ysi leelmcpcdksl aejp rchrq
+set kd rbc djxxcp ew ejp myfo ew ikdfesrcsr
+eb acyb ympklbr tcpc lessy dbyoc kr jv tkrb rbc vypra ncyp resklbr
+eb seeeee lellymep kd bcyici wep rbc epvbysylc
+eb xa lei mcrd xyoc ejr
+xa syxc kd ijl k bygc ujdr xcr aej ysi k meeegc aej
+na rbc vpkfoksl ew xa rbjxnd dexcrbksl tkfoci rbkd tya fexcd
+ys cac wep ys cac ysi y vklces wep y vklces
+vscjxesejmrpyxkfpedfevkfdkmkfegemfysefeskedkd
+tba ie vpelpyxxcpd ymtyad xkh jv bymmetccs ysi fbpkdrxyd
View
4 2012/round_0/a/A-test.completed.out
@@ -0,0 +1,4 @@
+Case #1: a zoo
+Case #2: our language is impossible to understand
+Case #3: there are twenty six factorial possibilities
+Case #4: so it is okay if you want to just give up
View
5 2012/round_0/a/A-test.in
@@ -0,0 +1,5 @@
+4
+y qee
+ejp mysljylc kd kxveddknmc re jsicpdrysi
+rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd
+de kr kd eoya kw aej tysr re ujdr lkgc jv
View
4 2012/round_0/a/A-test.out
@@ -0,0 +1,4 @@
+Case #1: a zoo
+Case #2: our language is impossible to understand
+Case #3: there are twenty six factorial possibilities
+Case #4: so it is okay if you want to just give up
View
43 2012/round_0/a/README
@@ -0,0 +1,43 @@
+Problem
+
+We have come up with the best possible language here at Google, called Googlerese. To translate text into Googlerese, we take any message and replace each English letter with another English letter. This mapping is one-to-one and onto, which means that the same input letter always gets replaced with the same output letter, and different input letters always get replaced with different output letters. A letter may be replaced by itself. Spaces are left as-is.
+
+For example (and here is a hint!), our awesome translation algorithm includes the following three mappings: 'a' -> 'y', 'o' -> 'e', and 'z' -> 'q'. This means that "a zoo" will become "y qee".
+
+Googlerese is based on the best possible replacement mapping, and we will never change it. It will always be the same. In every test case. We will not tell you the rest of our mapping because that would make the problem too easy, but there are a few examples below that may help.
+
+Given some text in Googlerese, can you translate it to back to normal text?
+
+Solving this problem
+
+Usually, Google Code Jam problems have 1 Small input and 1 Large input. This problem has only 1 Small input. Once you have solved the Small input, you have finished solving this problem.
+
+Input
+
+The first line of the input gives the number of test cases, T. T test cases follow, one per line.
+
+Each line consists of a string G in Googlerese, made up of one or more words containing the letters 'a' - 'z'. There will be exactly one space (' ') character between consecutive words and no spaces at the beginning or at the end of any line.
+
+Output
+
+For each test case, output one line containing "Case #X: S" where X is the case number and S is the string that becomes G in Googlerese.
+
+Limits
+
+1 ≤ T ≤ 30.
+G contains at most 100 characters.
+None of the text is guaranteed to be valid English.
+Sample
+
+Input
+3
+ejp mysljylc kd kxveddknmc re jsicpdrysi
+rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd
+de kr kd eoya kw aej tysr re ujdr lkgc jv
+
+
+Output
+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
+
View
10 2012/round_0/a/a.rb
@@ -0,0 +1,10 @@
+require 'solution'
+
+filename = ARGV[0]
+puts "Starting on #{filename}"
+
+@solution = Solution.new
+@solution.input_file = filename
+@solution.run
+
+puts "Finished. Results at #{@solution.output_file}"
View
37 2012/round_0/a/jam.rb
@@ -0,0 +1,37 @@
+module Jam
+
+ attr_accessor :input, :output, :output_string, :input_file, :output_file, :input_array
+ attr_accessor :cases, :cases_count
+
+ def input
+ @input ||= self.read
+ end
+
+ def cases
+ return @cases unless @cases.nil?
+
+ all = self.input.split("\n")
+ @cases_count = all.shift.to_i
+ @cases = all
+ end
+
+ def cases_count
+ return @cases_count unless @cases.nil?
+
+ self.cases
+ @cases_count
+ end
+
+ def read
+ @input ||= File.read(File.dirname(__FILE__) + "/#{input_file}")
+ end
+
+ def output_file
+ @output_file ||= input_file.gsub(".in",".completed.out")
+ end
+
+ def write
+ File.open(output_file, "w+") { |f| f << output_string }
+ end
+
+end
View
75 2012/round_0/a/solution.rb
@@ -0,0 +1,75 @@
+require 'jam'
+require 'yaml'
+
+class Solution
+ include Jam
+
+ @mapping = {}
+
+ def output_string
+ strings = []
+ output.each_with_index{ |o,i| strings << "Case ##{i+1}: #{o}"}
+ strings.join("\n")
+ end
+
+ def compute
+ self.output = []
+
+ cases.each do |kase|
+ output << kase.to_s.chars.to_a.collect{ |c| self.class.mapping[c] }.join
+ end
+ end
+
+ def run
+ compute
+ write
+ end
+
+ class << self
+ def mapping
+ if @mapping.empty?
+ generate_mapping
+ else
+ @mapping
+ end
+ end
+
+ def generate_mapping
+ sources = File.read('A-test.in').split("\n")
+ translated = File.read('A-test.out').split("\n")
+
+ sources.shift # Remove number of cases
+ translated.each{ |t| t.gsub!(/Case #\d*\: /,"") }
+
+ sources.each_with_index do |source, idx|
+ source_chars = source.chars.to_a
+
+ translate = translated[idx]
+ translate_chars = translate.chars.to_a
+
+ source_chars.each_with_index do |c, idx2|
+ if @mapping[c] && @mapping[c] != translate_chars[idx2]
+ raise "ERROR in #{source} mapping. Trying to map source #{c} to translated #{translate_chars[idx2]} but is already #{@mapping[c]}"
+ else
+ @mapping[c] = translate_chars[idx2]
+ end
+ end
+
+ end
+
+ # Account for a missing link
+ missing_sources = (("a".."z").to_a - @mapping.keys)
+ missing_translates = (("a".."z").to_a - @mapping.values)
+ if !missing_sources.empty?
+ raise "BIG ISSUE" if missing_sources.size > 1 || missing_translates.size > 1
+
+ @mapping[missing_sources.first] = missing_translates.first
+ end
+
+ @mapping
+ end
+
+
+
+ end
+end
View
75 2012/round_0/a/test.rb
@@ -0,0 +1,75 @@
+require 'test/unit'
+
+require 'jam'
+
+class JamTest < Test::Unit::TestCase
+
+ class Me
+ include Jam
+ end
+
+ def setup
+ @solution = Me.new
+ @solution.input_file = 'A-test.in'
+ end
+
+ def test_read
+ @solution.read
+ assert_equal File.read('A-test.in'), @solution.input
+ end
+
+ def test_read
+ @solution.output_string = "Y U NO HAVE OUTPUT?"
+ @solution.write
+ assert_equal File.read('A-test.completed.out'), "Y U NO HAVE OUTPUT?"
+ end
+
+ def test_cases_count
+ assert_equal 4, @solution.cases_count
+ end
+
+ def test_cases
+ cases = ["y qee",
+ "ejp mysljylc kd kxveddknmc re jsicpdrysi",
+ "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd",
+ "de kr kd eoya kw aej tysr re ujdr lkgc jv"]
+ assert_equal cases, @solution.cases
+ end
+
+end
+
+require 'solution'
+
+class SolutionTest < Test::Unit::TestCase
+
+ def setup
+ @solution = Solution.new
+ @solution.input_file = 'A-test.in'
+ end
+
+ def test_mapping
+ mapping = Solution.generate_mapping
+ assert !("a".."z").any?{ |c| !mapping.keys.include?(c) }
+ assert_equal 27, mapping.size # Spaces included
+ end
+
+ def test_output
+ @solution.compute
+ assert_equal ["a zoo",
+ "our language is impossible to understand",
+ "there are twenty six factorial possibilities",
+ "so it is okay if you want to just give up"], @solution.output
+ end
+
+ def test_output_string
+ @solution.compute
+ assert_equal File.read('A-test.out'), @solution.output_string
+ end
+
+ def test_run
+ @solution.run
+ assert_equal File.read('A-test.completed.out'), @solution.output_string
+ end
+
+end
+
View
BIN  2012/round_0/c.zip
Binary file not shown
View
51 2012/round_0/c/C-large.in
@@ -0,0 +1,51 @@
+50
+10000 10001
+1781 7688
+1007465 1919027
+100000 100000
+1032122 1995680
+1216257 1504628
+1216908 1951709
+1021619 1930030
+15048 53617
+1007458 1962726
+388 869
+1067361 1995135
+46739 73395
+1077614 1958584
+1031957 1958036
+72634 74120
+1063961 1954135
+274937 720742
+1 8
+1057393 1928164
+28 93
+1000000 2000000
+1032073 1940559
+1089798 1970754
+100000 999999
+1434814 1780702
+1072799 1964898
+1059864 1967119
+155569 345355
+2578 4229
+72 95
+552 553
+601415 711929
+1275115 1433162
+688042 856983
+594203 673506
+1172008 1490273
+180289 925799
+354653 354653
+1195595 1669305
+5908 5967
+2083 7987
+339 670
+1015539 1982001
+29229 96206
+1006167 1522491
+1117646 1117646
+1021936 1950412
+41215 83080
+1033077 1969448
View
50 2012/round_0/c/C-small-attempt0.completed.out
@@ -0,0 +1,50 @@
+Case #1: 603
+Case #2: 580
+Case #3: 649
+Case #4: 717
+Case #5: 1
+Case #6: 0
+Case #7: 172
+Case #8: 0
+Case #9: 47
+Case #10: 727
+Case #11: 640
+Case #12: 610
+Case #13: 592
+Case #14: 0
+Case #15: 652
+Case #16: 719
+Case #17: 672
+Case #18: 570
+Case #19: 507
+Case #20: 606
+Case #21: 679
+Case #22: 596
+Case #23: 616
+Case #24: 653
+Case #25: 704
+Case #26: 636
+Case #27: 801
+Case #28: 700
+Case #29: 624
+Case #30: 558
+Case #31: 538
+Case #32: 582
+Case #33: 668
+Case #34: 659
+Case #35: 531
+Case #36: 27
+Case #37: 580
+Case #38: 600
+Case #39: 568
+Case #40: 0
+Case #41: 726
+Case #42: 764
+Case #43: 259
+Case #44: 36
+Case #45: 536
+Case #46: 0
+Case #47: 652
+Case #48: 592
+Case #49: 692
+Case #50: 501
View
51 2012/round_0/c/C-small-attempt0.in
@@ -0,0 +1,51 @@
+50
+147 929
+170 940
+152 959
+144 989
+29 45
+1 1
+380 815
+2 4
+701 947
+100 957
+175 977
+183 968
+187 963
+100 101
+168 977
+143 989
+160 981
+159 923
+185 909
+168 952
+155 979
+182 960
+147 936
+103 917
+110 950
+165 965
+100 999
+153 988
+143 936
+190 947
+172 917
+170 941
+119 937
+131 944
+172 911
+19 96
+175 944
+133 913
+178 941
+669 669
+137 987
+103 979
+405 932
+10 99
+188 933
+449 449
+185 994
+136 912
+117 948
+188 910
View
3  2012/round_0/c/C-test-range.in
@@ -0,0 +1,3 @@
+1
+1 1000
+
View
4 2012/round_0/c/C-test.completed.out
@@ -0,0 +1,4 @@
+Case #1: 0
+Case #2: 3
+Case #3: 156
+Case #4: 287
View
5 2012/round_0/c/C-test.in
@@ -0,0 +1,5 @@
+4
+1 9
+10 40
+100 500
+1111 2222
View
4 2012/round_0/c/C-test.out
@@ -0,0 +1,4 @@
+Case #1: 0
+Case #2: 3
+Case #3: 156
+Case #4: 287
View
47 2012/round_0/c/README
@@ -0,0 +1,47 @@
+Problem
+
+Do you ever become frustrated with television because you keep seeing the same things, recycled over and over again? Well I personally don't care about television, but I do sometimes feel that way about numbers.
+
+Let's say a pair of distinct positive integers (n, m) is recycled if you can obtain m by moving some digits from the back of n to the front without changing their order. For example, (12345, 34512) is a recycled pair since you can obtain 34512 by moving 345 from the end of 12345 to the front. Note that n and m must have the same number of digits (excluding leading zeros) in order to be a recycled pair.
+
+Given integers A and B with the same number of digits, how many distinct recycled pairs (n, m) are there with A ≤ n < m ≤ B?
+
+Input
+
+The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing the integers A and B.
+
+Output
+
+For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1), and y is the number of recycled pairs (n, m) with A ≤ n < m ≤ B.
+
+Limits
+
+1 ≤ T ≤ 50.
+A and B have the same number of digits.
+
+Small dataset
+
+1 ≤ A ≤ B ≤ 1000.
+
+Large dataset
+
+1 ≤ A ≤ B ≤ 2000000.
+
+Sample
+
+
+Input
+
+Output
+
+4
+1 9
+10 40
+100 500
+1111 2222
+Case #1: 0
+Case #2: 3
+Case #3: 156
+Case #4: 287
+
+
View
10 2012/round_0/c/c.rb
@@ -0,0 +1,10 @@
+require 'solution'
+
+filename = ARGV[0]
+puts "Starting on #{filename}"
+
+@solution = Solution.new
+@solution.input_file = filename
+@solution.run
+
+puts "Finished. Results at #{@solution.output_file}"
View
37 2012/round_0/c/jam.rb
@@ -0,0 +1,37 @@
+module Jam
+
+ attr_accessor :input, :output, :output_string, :input_file, :output_file, :input_array
+ attr_accessor :cases, :cases_count
+
+ def input
+ @input ||= self.read
+ end
+
+ def cases
+ return @cases unless @cases.nil?
+
+ all = self.input.split("\n")
+ @cases_count = all.shift.to_i
+ @cases = all
+ end
+
+ def cases_count
+ return @cases_count unless @cases.nil?
+
+ self.cases
+ @cases_count
+ end
+
+ def read
+ @input ||= File.read(File.dirname(__FILE__) + "/#{input_file}")
+ end
+
+ def output_file
+ @output_file ||= input_file.gsub(".in",".completed.out")
+ end
+
+ def write
+ File.open(output_file, "w+") { |f| f << output_string }
+ end
+
+end
View
77 2012/round_0/c/solution.rb
@@ -0,0 +1,77 @@
+require 'jam'
+
+class Solution
+ include Jam
+
+ def output
+ @output ||= {}
+ end
+
+ def output_counts
+ @output.inject({}){ |hash,kase| hash.merge!({ kase.first => kase.last.count }) }
+ end
+
+ def output_clean
+ cases.collect do |kase|
+ start_digit, end_digit, key = case_setup(case_array(kase))
+ output_counts[key]
+ end
+ end
+
+ def output_string
+ strings = []
+ output_clean.each_with_index{ |o,i| strings << "Case ##{i+1}: #{o}"}
+ strings.join("\n")
+ end
+
+ # PLEASE MAKE CASE A CLASS
+ def case_setup(array)
+ start_digit = array.first.to_i
+ end_digit = array.last.to_i
+
+ key = "#{start_digit} - #{end_digit}"
+ [start_digit, end_digit, key]
+ end
+
+ def case_array(kase)
+ kase.split(" ")
+ end
+
+ def compute
+ cases.each do |kase|
+ start_digit, end_digit, key = case_setup(case_array(kase))
+
+ self.output[key] = []
+
+ range = (start_digit..end_digit)
+
+ range.each do |i|
+ puts "^^^^^^^^^^^^"
+ puts i
+
+ chars = i.to_s.chars.to_a
+ start = chars.dup
+ aug = []
+ until aug == chars
+ aug = start if aug.empty?
+
+ aug_i = aug.join.to_i
+ if i != aug_i && !self.output[key].include?(aug_i) && range.include?(aug_i)
+ puts "MATCH #{i} and #{aug_i}"
+ self.output[key] << i
+ end
+
+ move = start.shift
+ aug = start
+ aug << move
+ end
+ end
+ end
+ end
+
+ def run
+ compute
+ write
+ end
+
+end
View
79 2012/round_0/c/test.rb
@@ -0,0 +1,79 @@
+require 'test/unit'
+
+require 'jam'
+
+class JamTest < Test::Unit::TestCase
+
+ class Me
+ include Jam
+ end
+
+ def setup
+ @solution = Me.new
+ @solution.input_file = 'C-test.in'
+ end
+
+ def test_read
+ @solution.read
+ assert_equal File.read('C-test.in'), @solution.input
+ end
+
+ def test_read
+ @solution.output_string = "Y U NO HAVE OUTPUT?"
+ @solution.write
+ assert_equal File.read('C-test.completed.out'), "Y U NO HAVE OUTPUT?"
+ end
+
+ def test_cases_count
+ assert_equal 4, @solution.cases_count
+ end
+
+ def test_cases
+ assert_equal ["1 9", "10 40", "100 500", "1111 2222"], @solution.cases
+ end
+
+end
+
+require 'solution'
+
+class SolutionTest < Test::Unit::TestCase
+
+ def setup
+ @solution = Solution.new
+ @solution.input_file = 'C-test.in'
+ end
+
+ # def test_output
+ # @solution.compute
+ # assert_equal [0,3,156,287], @solution.output
+ # end
+
+ # def test_output_counts
+ # @solution.compute
+ # assert_equal [0,3,156,287], @solution.output_counts
+ # end
+
+ def test_output_clean
+ @solution.compute
+ assert_equal [0,3,156,287], @solution.output_clean
+ end
+
+ # Mostly just to ensure it runs fast enough
+ def test_edge
+ @solution.input_file = 'C-test-range.in'
+ @solution.compute
+ assert_equal [946], @solution.output_clean
+ end
+
+ def test_output_string
+ @solution.compute
+ assert_equal File.read('C-test.out'), @solution.output_string
+ end
+
+ def test_run
+ @solution.run
+ assert_equal File.read('C-test.completed.out'), @solution.output_string
+ end
+
+end
+

0 comments on commit e5b7e9d

Please sign in to comment.
Something went wrong with that request. Please try again.