We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 481401c commit 96bc8afCopy full SHA for 96bc8af
01_equal_to_next.rb
@@ -0,0 +1,10 @@
1
+def match(input, dist:)
2
+ # Doesn't matter whether we go forward or backward,
3
+ # (either way we get a yes on one half of the matching pair)
4
+ # so let's go backward to take advantage of negative index.
5
+ input.each_char.select.with_index { |c, i| c == input[i - dist] }.sum(&method(:Integer))
6
+end
7
+
8
+input = (!ARGV.empty? && ARGV.first.match?(/^\d+$/) ? ARGV.first : ARGF.read).chomp.freeze
9
10
+[1, input.size / 2].each { |n| puts match(input, dist: n) }
0 commit comments