parent
7f25d2bde6
commit
b5bfbcff0b
@ -1,26 +1,17 @@
|
|||||||
histories = ARGF.readlines.map { _1.scan(/-?\d+/).map(&:to_i) }
|
histories = ARGF.readlines.map { _1.scan(/-?\d+/).map(&:to_i) }
|
||||||
|
|
||||||
# part one
|
history_diffs = histories.map {|history|
|
||||||
p histories
|
diffs = [history]
|
||||||
.map {|history|
|
until diffs.last.all?(&:zero?)
|
||||||
diffs = [history]
|
diffs << diffs.last.each_cons(2).map { _2 - _1 }
|
||||||
until diffs.last.all?(&:zero?)
|
end
|
||||||
diffs << diffs.last.each_cons(2).map { _2 - _1 }
|
diffs
|
||||||
end
|
}
|
||||||
|
|
||||||
diffs.sum(&:last)
|
# part one
|
||||||
}
|
p history_diffs.sum { _1.sum(&:last) }
|
||||||
.sum
|
|
||||||
|
|
||||||
# part two
|
# part two
|
||||||
p histories
|
p history_diffs.sum {|diffs|
|
||||||
.map {|history|
|
diffs.map(&:first).reverse.inject { _2 - _1 }
|
||||||
diffs = [history]
|
}
|
||||||
until diffs.last.all?(&:zero?)
|
|
||||||
diffs << diffs.last.each_cons(2).map { _2 - _1 }
|
|
||||||
end
|
|
||||||
|
|
||||||
diffs.map(&:first).reverse.inject { _2 - _1 }
|
|
||||||
}
|
|
||||||
.sum
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue