rosetta/special_factorials.bruijn

Problem description

:import std/Combinator .
:import std/List .
:import std/Math .

factorial [∏ (+1) → 0 | [0]]

superfactorial [∏ (+1) → 0 | factorial]

hyperfactorial [∏ (+1) → 0 | [0 ** 0]]

alternating-factorial y [[=?0 0 ((factorial 0) - (1 --0))]]

exponential-factorial y [[=?0 0 (0 ** (1 --0))]]

:test ((factorial (+4)) =? (+24)) ([[1]])
:test ((superfactorial (+4)) =? (+288)) ([[1]])
:test ((hyperfactorial (+4)) =? (+27648)) ([[1]])
:test ((alternating-factorial (+3)) =? (+5)) ([[1]])
:test ((exponential-factorial (+4)) =? (+262144)) ([[1]])

invfac y [[[compare-case 1 (2 ++1 0) (-1) 0 (∏ (+0) → --1 | ++‣)]]] (+0)

:test ((invfac (+1)) =? (+0)) ([[1]])
:test ((invfac (+2)) =? (+2)) ([[1]])
:test ((invfac (+6)) =? (+3)) ([[1]])
:test ((invfac (+24)) =? (+4)) ([[1]])
:test ((invfac (+120)) =? (+5)) ([[1]])
:test ((invfac (+720)) =? (+6)) ([[1]])
:test ((invfac (+5040)) =? (+7)) ([[1]])
:test ((invfac (+40320)) =? (+8)) ([[1]])
:test ((invfac (+362880)) =? (+9)) ([[1]])
:test ((invfac (+3628800)) =? (+10)) ([[1]])
:test ((invfac (+119)) =? (-1)) ([[1]])

seq-a [((superfactorial 0) : ((hyperfactorial 0) : {}(alternating-factorial 0)))] <$> (iterate ++‣ (+0))

seq-b exponential-factorial <$> (iterate ++‣ (+0))

# return first 10/4 elements of both sequences
main [(take (+10) seq-a) : {}(take (+5) seq-b)]