Skip to content

Instantly share code, notes, and snippets.

@raphaelcm
Created June 22, 2012 12:28
Show Gist options
  • Save raphaelcm/2972470 to your computer and use it in GitHub Desktop.
Save raphaelcm/2972470 to your computer and use it in GitHub Desktop.

Revisions

  1. raphaelcm revised this gist Jun 22, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dist.rb
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@

    puts string.join('')

    puts "\nLetter Counts (Expected)"
    puts "\nLetter: Count (Expected)"
    inputs.each do |k, v|
    puts "#{k}: #{v} (#{string.count(k)})"
    end
  2. raphaelcm revised this gist Jun 22, 2012. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions dist.rb
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,7 @@

    total = inputs.values.inject{|sum,x| sum + x }

    counts = {
    'a' => 18,
    'b' => 13,
    'c' => 9
    }
    counts = inputs.dup

    i = 0
    string = []
  3. raphaelcm created this gist Jun 22, 2012.
    35 changes: 35 additions & 0 deletions dist.rb
    Original 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