Created
November 26, 2022 16:25
-
-
Save qgustavor/54b7dedbacf265d2895b6c7c2c6d5301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = [ | |
(e, target, source) => Math.round(e * target / source), | |
(e, target, source) => Math.floor(e * target / source), | |
(e, target, source) => Math.ceil(e * target / source), | |
(e, target, source) => 1 + Math.round((e - 1) * target / source), | |
(e, target, source) => 1 + Math.floor((e - 1) * target / source), | |
(e, target, source) => 1 + Math.ceil((e - 1) * target / source), | |
(e, target, source) => Math.round((e - 1) * target / source), | |
(e, target, source) => Math.floor((e - 1) * target / source), | |
(e, target, source) => Math.ceil((e - 1) * target / source), | |
(e, target, source) => Math.round((e - 1) * target / source) - 1, | |
(e, target, source) => Math.floor((e - 1) * target / source) - 1, | |
(e, target, source) => Math.ceil((e - 1) * target / source) - 1, | |
(e, target, source) => Math.round(e * (target + 1) / (source + 1)), | |
(e, target, source) => Math.floor(e * (target + 1) / (source + 1)), | |
(e, target, source) => Math.ceil(e * (target + 1) / (source + 1)), | |
(e, target, source) => Math.round(e * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.floor(e * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.ceil(e * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.round(e * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.floor(e * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.ceil(e * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.round((e - 1) * (target + 1) / (source + 1)), | |
(e, target, source) => Math.floor((e - 1) * (target + 1) / (source + 1)), | |
(e, target, source) => Math.ceil((e - 1) * (target + 1) / (source + 1)), | |
(e, target, source) => Math.round((e - 1) * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.floor((e - 1) * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.ceil((e - 1) * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.round((e - 1) * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.floor((e - 1) * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.ceil((e - 1) * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.round((e + 1) * (target + 1) / (source + 1)), | |
(e, target, source) => Math.floor((e + 1) * (target + 1) / (source + 1)), | |
(e, target, source) => Math.ceil((e + 1) * (target + 1) / (source + 1)), | |
(e, target, source) => Math.round((e + 1) * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.floor((e + 1) * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.ceil((e + 1) * (target + 1) / (source + 1)) + 1, | |
(e, target, source) => Math.round((e + 1) * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.floor((e + 1) * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.ceil((e + 1) * (target + 1) / (source + 1)) - 1, | |
(e, target, source) => Math.round(e * (target - 1) / (source - 1)), | |
(e, target, source) => Math.floor(e * (target - 1) / (source - 1)), | |
(e, target, source) => Math.ceil(e * (target - 1) / (source - 1)), | |
(e, target, source) => Math.round(e * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.floor(e * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.ceil(e * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.round(e * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.floor(e * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.ceil(e * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.round((e - 1) * (target - 1) / (source - 1)), | |
(e, target, source) => Math.floor((e - 1) * (target - 1) / (source - 1)), | |
(e, target, source) => Math.ceil((e - 1) * (target - 1) / (source - 1)), | |
(e, target, source) => Math.round((e - 1) * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.floor((e - 1) * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.ceil((e - 1) * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.round((e - 1) * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.floor((e - 1) * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.ceil((e - 1) * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.round((e + 1) * (target - 1) / (source - 1)), | |
(e, target, source) => Math.floor((e + 1) * (target - 1) / (source - 1)), | |
(e, target, source) => Math.ceil((e + 1) * (target - 1) / (source - 1)), | |
(e, target, source) => Math.round((e + 1) * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.floor((e + 1) * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.ceil((e + 1) * (target - 1) / (source - 1)) + 1, | |
(e, target, source) => Math.round((e + 1) * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.floor((e + 1) * (target - 1) / (source - 1)) - 1, | |
(e, target, source) => Math.ceil((e + 1) * (target - 1) / (source - 1)) - 1 | |
] | |
const wrappers = [ | |
(fn, e, target, source) => fn(e, target, source), | |
(fn, e, target, source) => e === source ? target : fn(e, target, source) | |
] | |
const assertions = [ | |
// Check conversion between Atachin'chi episode ranges from Amazon's to AniList's | |
[[1, 330, 662], 0], | |
[[2, 330, 662], 1], | |
[[661, 330, 662], 329], | |
[[662, 330, 662], 330], | |
// Check conversion for a normal series | |
[[1, 12, 12], 1], | |
[[2, 12, 12], 2], | |
[[6, 12, 12], 6], | |
[[11, 12, 12], 11], | |
[[12, 12, 12], 12] | |
] | |
const passedFunctions = [] | |
for (const wrapper of wrappers) { | |
const wrapperIndex = wrappers.indexOf(wrapper) | |
for (const fn of functions) { | |
const fnIndex = functions.indexOf(fn) | |
let failed = false | |
for (const [input, expected] of assertions) { | |
const result = wrapper(fn, ...input) | |
if (result !== expected) { | |
console.log(wrapperIndex + ':' + fnIndex + ' failed: fn(', ...input.map(e => [',', e]).flat().slice(1), ') returned', result, 'expected', expected) | |
failed = true | |
break | |
} | |
} | |
if (!failed) passedFunctions.push([ wrapper, fn ]) | |
} | |
} | |
// If some function passed the above test, print the entire Atachin'chi mapping and the functions | |
if (passedFunctions.length) { | |
for (let i = 1; i <= 662; i++) { | |
console.log(i, ...passedFunctions.map(fn => fn[0](fn[1], i, 330, 662))) | |
} | |
console.log('passedFunctions:', passedFunctions.map(e => e.map(e => e.toString()))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment