repl.it
@anonymous/

StormyRottenMaggot

Ruby

No description

fork
loading
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def count_normal(people:, generations:, children_per_couple:)
  return people if generations.zero?

  count_normal people: children_per_couple * people / 2.0,
               generations: generations.pred,
               children_per_couple: children_per_couple
end

def count_necromancy(people:, undead: 0, generations:, children_per_couple:)
  return people + undead if generations.zero?

  count_necromancy people: children_per_couple * people / 2.0,
                   undead: people + undead,
                   generations: generations.pred,
                   children_per_couple: children_per_couple
end

without_necromancy = count_normal people: 1000, generations: 4, children_per_couple: 3
with_necromancy    = count_necromancy people: 1000, generations: 4, children_per_couple: 3

puts "Without necromancy: #{without_necromancy}"
puts "With necromancy: #{with_necromancy}"
puts "Ratio with / without: #{with_necromancy / without_necromancy}"
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]