Skip to content

Instantly share code, notes, and snippets.

@jarble
Created February 1, 2024 21:56
Show Gist options
  • Save jarble/f8a9d0f99c106837401bbb9b22b1ecb2 to your computer and use it in GitHub Desktop.
Save jarble/f8a9d0f99c106837401bbb9b22b1ecb2 to your computer and use it in GitHub Desktop.
Inverse of factorial function in MiniZinc
function int:factorial(int:t) =
if t = 0 then 1 else t * factorial(t-1) endif;
function int: factorial_inverse(int:n, int:factorial) =
if factorial == factorial(n) then n else factorial_inverse(n+1,factorial) endif;
function int:factorial_inverse(int:n) =
factorial_inverse(0,n);
int:a = factorial_inverse(720);
solve satisfy;
output [show(a)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment