Created
June 22, 2012 12:28
-
-
Save raphaelcm/2972470 to your computer and use it in GitHub Desktop.
Revisions
-
raphaelcm revised this gist
Jun 22, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ puts string.join('') puts "\nLetter: Count (Expected)" inputs.each do |k, v| puts "#{k}: #{v} (#{string.count(k)})" end -
raphaelcm revised this gist
Jun 22, 2012 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,11 +8,7 @@ total = inputs.values.inject{|sum,x| sum + x } counts = inputs.dup i = 0 string = [] -
raphaelcm created this gist
Jun 22, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/usr/bin/env ruby inputs = { 'a' => 18, 'b' => 13, 'c' => 9 } total = inputs.values.inject{|sum,x| sum + x } counts = { 'a' => 18, 'b' => 13, 'c' => 9 } i = 0 string = [] while i < total inputs.each do |k, v| counts[k] += v if counts[k] >= total string << k counts[k] -= total i += 1 end end end puts string.join('') puts "\nLetter Counts (Expected)" inputs.each do |k, v| puts "#{k}: #{v} (#{string.count(k)})" end