From 2e1eba56a5bcd2bcc2946d7656d0bfea3b71184c Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 18 Dec 2016 17:18:35 -0800 Subject: [PATCH] [2016][ruby][18.0] solution --- 2016/ruby/day_18.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/2016/ruby/day_18.rb b/2016/ruby/day_18.rb index 6f77297..1ea0030 100644 --- a/2016/ruby/day_18.rb +++ b/2016/ruby/day_18.rb @@ -24,7 +24,17 @@ Row = Struct.new(:tiles) do end end -require 'minitest/autorun' +if __FILE__ == $0 + row = Row.from_s(DATA.read.chomp) + rows = [row] + while rows.size < 40 + rows << rows.last.next + end + p rows.map {|row| row.tiles.count(:safe) }.inject(:+) +end + +require 'minitest' +# require 'minitest/autorun' class TestRow < Minitest::Test def test_row @@ -34,3 +44,6 @@ class TestRow < Minitest::Test assert_equal Row.from_s('.^^^^'), row.next end end + +__END__ +^^.^..^.....^..^..^^...^^.^....^^^.^.^^....^.^^^...^^^^.^^^^.^..^^^^.^^.^.^.^.^.^^...^^..^^^..^.^^^^