Finally i manged to complete day 5 - it was hard. Today's puzzles are tricky. I had to back to my school time when I was 15-19 yo - more then 20 years ago to re-learn how to do quadratic equations. class ToyBoat def initialize time_given, record @time_given = time_given @record = record end def get_winning_range delta = @time_given ** 2 - 4 * (@record+1) time1 = (@time_given - Math.sqrt(delta))/2 time1 = time1.ceil time2 = (@time_given + Math.sqrt(delta))/2 time2 = time2.floor (time1..time2) end end time, record = $stdin.read.split(" ").map(&:split) p time = time[1..-1].join.to_i p record = record[1..-1].join.to_i race = ToyBoat.new(time,record) p race p gwr = race.get_winning_range p nums_of_ways = gwr.size
the => result is new to me, so we can assign to variable at the end of block ? cool
Oh yes! Checkout the earlier episode called rightward assignment where we talk a lot about that new Ruby feature
Finally i manged to complete day 5 - it was hard. Today's puzzles are tricky. I had to back to my school time when I was 15-19 yo - more then 20 years ago to re-learn how to do quadratic equations.
class ToyBoat
def initialize time_given, record
@time_given = time_given
@record = record
end
def get_winning_range
delta = @time_given ** 2 - 4 * (@record+1)
time1 = (@time_given - Math.sqrt(delta))/2
time1 = time1.ceil
time2 = (@time_given + Math.sqrt(delta))/2
time2 = time2.floor
(time1..time2)
end
end
time, record = $stdin.read.split("
").map(&:split)
p time = time[1..-1].join.to_i
p record = record[1..-1].join.to_i
race = ToyBoat.new(time,record)
p race
p gwr = race.get_winning_range
p nums_of_ways = gwr.size
Nice job! Way to stay with it.
BTW: What is that vim/neovim plugin that shows warnings while typing?
I'm using ale - github.com/dense-analysis/ale