Compare commits
No commits in common. "19c189eee83ebd8cb5521641a58d3e18e49c517f" and "f8d8b7fd7813d741029f433facac7a28d1f3fb0e" have entirely different histories.
19c189eee8
...
f8d8b7fd78
4 changed files with 6 additions and 143 deletions
|
@ -4,4 +4,4 @@ Advent of Code 2018, my solutions, any language
|
||||||
|
|
||||||
- day 1: elixir
|
- day 1: elixir
|
||||||
- day 2: elixir
|
- day 2: elixir
|
||||||
- day 3: python (with a crystal port)
|
- day 3: python
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
lines = [] of String
|
|
||||||
|
|
||||||
|
|
||||||
class Claim
|
|
||||||
def initialize(@cid : String, @p1 : UInt64, @p2 : UInt64,
|
|
||||||
@width : UInt64, @height : UInt64)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cloth = [] of Array(Array(Claim))
|
|
||||||
claims = [] of Claim
|
|
||||||
|
|
||||||
# initialize cloth
|
|
||||||
(0...1000).each do |i|
|
|
||||||
cloth_line = [] of Array(Claim)
|
|
||||||
|
|
||||||
(0...1000).each do |j|
|
|
||||||
# cloth_line << Claim.new("-1", 0, 0, 0, 0)
|
|
||||||
cloth_line << [] of Claim
|
|
||||||
end
|
|
||||||
|
|
||||||
cloth << cloth_line
|
|
||||||
end
|
|
||||||
|
|
||||||
while true
|
|
||||||
line = gets '\n'
|
|
||||||
|
|
||||||
if line.nil?
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
lines << line.strip().gsub(" ", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
lines.each do |line|
|
|
||||||
cid_p, claim_data = line.split('@')
|
|
||||||
p1p2, wh = claim_data.split(':')
|
|
||||||
|
|
||||||
p1, p2 = p1p2.split(',')
|
|
||||||
width, height = wh.split('x')
|
|
||||||
cid = cid_p.gsub("#", "")
|
|
||||||
|
|
||||||
claims << Claim.new(cid, p1.to_u64, p2.to_u64, width.to_u64, height.to_u64)
|
|
||||||
end
|
|
||||||
|
|
||||||
claims.each do |claim|
|
|
||||||
(claim.@p1...claim.@p1 + claim.@width).each do |x|
|
|
||||||
(claim.@p2...claim.@p2 + claim.@height).each do |y|
|
|
||||||
cloth[x][y] << claim
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# check the cloth
|
|
||||||
overlaps = 0
|
|
||||||
|
|
||||||
(0...1000).each do |i|
|
|
||||||
(0...1000).each do |j|
|
|
||||||
claims = cloth[i][j]
|
|
||||||
if claims.size > 1
|
|
||||||
overlaps += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
puts overlaps
|
|
|
@ -32,15 +32,20 @@ def main():
|
||||||
c = Claim(cid, int(p1), int(p2), int(w), int(h))
|
c = Claim(cid, int(p1), int(p2), int(w), int(h))
|
||||||
claims.append(c)
|
claims.append(c)
|
||||||
|
|
||||||
|
pprint.pprint(claims)
|
||||||
print('running claims')
|
print('running claims')
|
||||||
|
|
||||||
for claim in claims:
|
for claim in claims:
|
||||||
|
print(claim)
|
||||||
for i in range(claim.p1, claim.p1 + claim.width):
|
for i in range(claim.p1, claim.p1 + claim.width):
|
||||||
for j in range(claim.p2, claim.p2 + claim.height):
|
for j in range(claim.p2, claim.p2 + claim.height):
|
||||||
|
print('claiming', i, j, claim.cid)
|
||||||
|
|
||||||
if cloth[i][j] is None:
|
if cloth[i][j] is None:
|
||||||
cloth[i][j] = []
|
cloth[i][j] = []
|
||||||
|
|
||||||
cloth[i][j].append(claim)
|
cloth[i][j].append(claim)
|
||||||
|
print('result: ', cloth[i][j])
|
||||||
|
|
||||||
overlap = 0
|
overlap = 0
|
||||||
|
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
lines = [] of String
|
|
||||||
|
|
||||||
|
|
||||||
class Claim
|
|
||||||
def initialize(@cid : String, @p1 : UInt64, @p2 : UInt64,
|
|
||||||
@width : UInt64, @height : UInt64)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cloth = [] of Array(Array(Claim))
|
|
||||||
claims = [] of Claim
|
|
||||||
|
|
||||||
# initialize cloth
|
|
||||||
(0...1000).each do |i|
|
|
||||||
cloth_line = [] of Array(Claim)
|
|
||||||
|
|
||||||
(0...1000).each do |j|
|
|
||||||
# cloth_line << Claim.new("-1", 0, 0, 0, 0)
|
|
||||||
cloth_line << [] of Claim
|
|
||||||
end
|
|
||||||
|
|
||||||
cloth << cloth_line
|
|
||||||
end
|
|
||||||
|
|
||||||
while true
|
|
||||||
line = gets '\n'
|
|
||||||
|
|
||||||
if line.nil?
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
lines << line.strip().gsub(" ", "")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
lines.each do |line|
|
|
||||||
cid_p, claim_data = line.split('@')
|
|
||||||
p1p2, wh = claim_data.split(':')
|
|
||||||
|
|
||||||
p1, p2 = p1p2.split(',')
|
|
||||||
width, height = wh.split('x')
|
|
||||||
cid = cid_p.gsub("#", "")
|
|
||||||
|
|
||||||
claims << Claim.new(cid, p1.to_u64, p2.to_u64, width.to_u64, height.to_u64)
|
|
||||||
end
|
|
||||||
|
|
||||||
claims.each do |claim|
|
|
||||||
(claim.@p1...claim.@p1 + claim.@width).each do |x|
|
|
||||||
(claim.@p2...claim.@p2 + claim.@height).each do |y|
|
|
||||||
cloth[x][y] << claim
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# check the cloth
|
|
||||||
overlaps = Set.new [] of Claim
|
|
||||||
claims_set = claims.to_set
|
|
||||||
|
|
||||||
(0...1000).each do |i|
|
|
||||||
(0...1000).each do |j|
|
|
||||||
claims = cloth[i][j]
|
|
||||||
if claims.size > 1
|
|
||||||
claims.each do |claim|
|
|
||||||
overlaps << claim
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
puts claims_set.size
|
|
||||||
puts overlaps.size
|
|
||||||
|
|
||||||
non_overlap = claims_set - overlaps
|
|
||||||
puts non_overlap
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue