Sha256: ea51eefcfebd01943b3d3d4143ec5bd798f72709e5283ded60c25b3f41bf105a
Contents?: true
Size: 1.02 KB
Versions: 3
Compression:
Stored size: 1.02 KB
Contents
# # https://adventofcode.com/2018/day/25 part 1 (there is only 1 # # Uses Point4D, but not much to see here. # require 'cem' lines = File.readlines("inputs/day25_input.txt") input = [] lines.each { |line| if line =~ /^\s*([+-]?\d+),([+-]?\d+),([+-]?\d+),([+-]?\d+)\s*$/ v1 = $1.to_i v2 = $2.to_i v3 = $3.to_i v4 = $4.to_i input << Point4D.new(v1,v2,v3,v4) else raise line.inspect end } constellations = [] input.each { |p| if c = constellations.find { |c| c.any? { |p2| p2.manhattan(p) <= 3 } } c << p else constellations << [p] end } loop do count = constellations.count { |c| c.size > 0 } constellations.each_with_index { |c,i| constellations.each_with_index { |d,j| next if j <= i if c.any? { |p| d.any? { |p2| p2.manhattan(p) <= 3 } } c.push(*d) d.clear end } } break if count == constellations.count { |c| c.size > 0 } end puts "Part 1: #{constellations.count { |c| c.size > 0 }}"
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cem-0.1.7 | examples/aoc2018/day25.rb |
cem-0.1.6 | examples/aoc2018/day25.rb |
cem-0.1.5 | examples/aoc2018/day25.rb |