euler/004.bruijn

Problem description

# TODO: This has serious performance problems

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

# palindrome? S.number→string → [S.eq? S.<~>0 0]

palindrome? [y [[[&[[>?2 (4 (3 ⋅ (+10) + 0) 1) (3 =? 5)]] (quot-rem 0 (+10))]]] (+0) 0]

# combs [[S.concat-map [S.map (mul 0) ({ 0 → 1 })] ({ ((+10) ** --1) → 0 })] --((+10) ** 0)]

solve [[y [[[0 =? 3 1 rec]]] empty ((+10) ** --1)] ((+10) ** 0)] → lmax
	rec 2 (comb ++ 1) ++0
		comb y [[[0 =? 6 1 (2 ([palindrome? 0 (0 : 2) 2] (3 ⋅ 0)) ++0)]]] empty 0

:test ((solve (+2)) =? (+9009)) ([[1]])

main [solve (+3)]