change directory names

This commit is contained in:
Pim Kunis 2023-12-04 10:25:33 +01:00
parent 3cff0fc5cf
commit 78b8881016
90 changed files with 0 additions and 0 deletions

50
18/6/input Normal file
View file

@ -0,0 +1,50 @@
135, 127
251, 77
136, 244
123, 169
253, 257
359, 309
100, 247
191, 323
129, 323
76, 284
69, 56
229, 266
74, 216
236, 130
152, 126
174, 319
315, 105
329, 146
288, 51
184, 344
173, 69
293, 80
230, 270
279, 84
107, 163
130, 176
347, 114
133, 331
237, 300
291, 283
246, 297
60, 359
312, 278
242, 76
81, 356
204, 291
187, 335
176, 98
103, 274
357, 144
314, 118
67, 196
156, 265
254, 357
218, 271
118, 94
300, 189
290, 356
354, 91
209, 334

75
18/6/main.rb Normal file
View file

@ -0,0 +1,75 @@
require 'pry'
coords = []
# Parse input file.
File.open("input", "r") do |f|
f.each_line do |line|
x, y = line.split(", ").map(&:chomp).map(&:to_i)
coords.push({
x: x,
y: y,
})
end
end
# Create matrix with correct size
left_bound = right_bound = coords.first[:x]
top_bound = bottom_bound = coords.first[:y]
coords.each do |coord|
if coord[:x] < left_bound
left_bound = coord[:x]
end
if coord[:x] > right_bound
right_bound = coord[:x]
end
if coord[:y] < top_bound
top_bound = coord[:y]
end
if coord[:y] > bottom_bound
bottom_bound = coord[:y]
end
end
height = bottom_bound - top_bound + 1
width = right_bound - left_bound + 1
coords.map!{|coord| {x: coord[:x] - left_bound, y: coord[:y] - top_bound}}
matrix = Array.new(height){Array.new(width){0}}
# Fill the matrix with lowest distance to coordinates
(0...height).each do |y|
(0...width).each do |x|
coords.each_with_index do |coord, i|
distance = (x - coord[:x]).abs + (y - coord[:y]).abs
matrix[y][x] += distance
end
end
end
=begin
# Count the area for each coordinate.
(0...height).each do |y|
(0...width).each do |x|
if (y == 0 || x == 0 || y == height - 1 || x == width - 1) && matrix[y][x][:coords].length == 1
coords[matrix[y][x][:coords].first][:infinite] = true
else
if matrix[y][x][:coords].length == 1
coords[matrix[y][x][:coords].first][:area] += 1
end
end
end
end
=end
puts matrix.flatten.select{|point| point < 10000}.length

5
18/6/sample Normal file
View file

@ -0,0 +1,5 @@
0, 0
0, 10
10, 0
10, 10
3, 4