From c05de086e01733ecb219eb42d7af0b299517159f Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 11 Dec 2024 14:10:47 -0800 Subject: [PATCH] [2024][ruby][11.x] refactoring --- 2024/ruby/day_11.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2024/ruby/day_11.rb b/2024/ruby/day_11.rb index 3f6c8cc..864680b 100644 --- a/2024/ruby/day_11.rb +++ b/2024/ruby/day_11.rb @@ -6,14 +6,15 @@ blink = Hash.new {|h, k| 1 elsif n.zero? h[[1, times-1]] - elsif (s = n.to_s.size) && s.even? - a, b = [n.to_s[0...s/2], n.to_s[s/2..]].map(&:to_i) + elsif n.digits.length.even? + a, b = n.divmod(10**(d.length/2)) h[[a, times-1]] + h[[b, times-1]] else h[[n*2024, times-1]] end } +pp stones.sum { blink[[_1, 6]] } pp stones.sum { blink[[_1, 25]] } pp stones.sum { blink[[_1, 75]] }