DoorKeeper/tools/calc_advance.rb

39 lines
1.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby
=begin
Copyright 2015, Michele Santullo
This file is part of DoorKeeper.
DoorKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DoorKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
=end
M = 2147483647
def calc(v, arr, m)
index = 0
out = arr.dup
while (v > 0) do
v += arr[index]
#puts "index #{index} - v is #{v}, m is #{m[index]}"
out[index] = v % (m[index] + 1)
v /= (m[index] + 1)
index += 1
end
out
end
p calc(M, [540, 800, 1200, 710], [M - 10, M - 11, M - 12, M - 13])
p calc(M, [M - 1, 800, 1200, 710], [M - 1, 800, M - 1, M - 1])
p calc(1650000, [0, 0, 0, 0], [5300, 2499, 12631, 171244])