m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/13/a.rb
diff options
context:
space:
mode:
Diffstat (limited to '13/a.rb')
-rw-r--r--13/a.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/13/a.rb b/13/a.rb
new file mode 100644
index 0000000..ebadaf0
--- /dev/null
+++ b/13/a.rb
@@ -0,0 +1,19 @@
+earliest, notes = File.readlines('input.txt')
+earliest = earliest.to_i
+ids = notes.split(',').filter_map do |id|
+ if id != 'x'
+ id.to_i
+ end
+end
+
+best_wait = ids.max + 1
+best_id = 0
+ids.each do |id|
+ wait = id - (earliest % id)
+ if wait < best_wait
+ best_wait = wait
+ best_id = id
+ end
+end
+
+puts best_wait * best_id