We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d768e6 commit f4b66fbCopy full SHA for f4b66fb
06_mancala.rb
@@ -0,0 +1,11 @@
1
+input = (!ARGV.empty? && ARGV.all? { |a| a.match?(/^\d+$/) } ? ARGV : ARGF.read).split.map(&method(:Integer))
2
+
3
+seen = {input.dup.freeze => 0}
4
+puts 1.step { |n|
5
+ max = input.max
6
+ start = input.index(max)
7
+ input[start] = 0
8
+ max.times { |i| input[(start + 1 + i) % input.size] += 1 }
9
+ break [n, n - seen[input]] if seen.has_key?(input)
10
+ seen[input.dup.freeze] = n
11
+}
0 commit comments