diff options
author | Nat Lasseter <user@4574.co.uk> | 2018-12-03 12:36:41 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2018-12-03 12:36:41 +0000 |
commit | 4b0aa584e0e88e3c16d7fcd7328432db80e0650b (patch) | |
tree | 715ae5f659bed9bf8a67642a2cda69cc922d4443 /day03/part1 | |
parent | ac0e849c119cc3cd9709e57521365dd6dc5215a6 (diff) |
[day03part1] Trivial optimisation
Diffstat (limited to 'day03/part1')
-rwxr-xr-x | day03/part1 | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/day03/part1 b/day03/part1 index ae16800..79b9d85 100755 --- a/day03/part1 +++ b/day03/part1 @@ -1,9 +1,7 @@ #!/usr/bin/env ruby cloth = Array.new(1000) do - Array.new(1000) do - Array.new - end + Array.new(1000, 0) end input = $stdin.readlines.map(&:chomp).map do |x| @@ -13,7 +11,7 @@ end input.each do |claim| (claim[1]...(claim[1]+claim[3])).each do |c| (claim[2]...(claim[2]+claim[4])).each do |r| - cloth[c][r] << claim[0] + cloth[c][r] += 1 end end end @@ -22,7 +20,7 @@ clashes = 0 cloth.each do |c| c.each do |r| - clashes += 1 if r.length > 1 + clashes += 1 if r > 1 end end |