added a very good (or very bad) implementation of day 6.
This commit is contained in:
1 parent
4392344bc4
commit
c1731aaff3
2 files changed
+28
No files matched your search
@@ -0,0 +1,26 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
def get_critical_points(time, record)
|
||||||
|
delta = Math.sqrt(time*time - 4 * record)
|
||||||
|
epsilon = 0.000000000001 # math is not life
|
||||||
|
[(time - delta)/2, (time + delta)/2 - epsilon]
|
||||||
|
end
|
||||||
|
|
||||||
|
def number_of_possible_way_to_beat_the_record(time, record)
|
||||||
|
critical_points = get_critical_points(time, record)
|
||||||
|
critical_points[1].floor - critical_points[0].floor
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
inputs = [[56, 334], [71, 1135], [79, 1350], [99, 2430]]
|
||||||
|
part_1 = inputs.map { |x| number_of_possible_way_to_beat_the_record x[0], x[1] }
|
||||||
|
.reduce 1, :*
|
||||||
|
|
||||||
|
puts "Part 1: #{part_1}"
|
||||||
|
|
||||||
|
|
||||||
|
part_2 = number_of_possible_way_to_beat_the_record 56717999, 334113513502430
|
||||||
|
|
||||||
|
puts "Part 2: #{part_2}"
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Time: 56 71 79 99
|
||||||
|
Distance: 334 1135 1350 2430
|
||||||
Reference in new issue
Block a user