[2021][ruby][7.x]

pull/2/head
Alpha Chen 3 years ago
parent ff6f142e2b
commit 0c92ce7de7

@ -0,0 +1,9 @@
positions = ARGF.read.split(?,).map(&:to_i)
min, max = positions.minmax
pos = (min..max).min_by {|i|
# positions.sum {|p| (p - i).abs }
positions.sum {|p| n = (p - i).abs; (n * (n + 1)) / 2 }
}
# p positions.sum {|p| (p - pos).abs }
p positions.sum {|p| n = (p - pos).abs; (n * (n + 1)) / 2 }
Loading…
Cancel
Save