package main import ( "fmt" "strconv" "git.mstar.dev/mstar/goutils/other" "github.com/Skarlso/cache" ) var stoneCache = cache.New[uint64]() // Doesn't work, the cache thing can't handle recursion func AdvanceBroken(val uint64, iteration int, maxIter int) cache.Cacheable[uint64] { return func() uint64 { fmt.Printf("Iteration %d with val %d\n", iteration, val) if iteration == maxIter { fmt.Println("1") return 1 } if val == 0 { fmt.Println("0") return stoneCache.WithCache( AdvanceBroken(1, iteration+1, maxIter), []any{1, iteration + 1, maxIter}, ) } if len(strconv.FormatUint(val, 10))%2 == 0 { fmt.Println("Split") str := strconv.FormatUint(val, 10) fmt.Println("format") left := other.Must(strconv.ParseUint(string([]rune(str)[:len(str)/2]), 10, 64)) right := other.Must(strconv.ParseUint(string([]rune(str)[len(str)/2:]), 10, 64)) fmt.Printf("l: %d, r: %d\n", left, right) return stoneCache.WithCache( AdvanceBroken(left, iteration+1, maxIter), []any{left, iteration + 1, maxIter}, ) + stoneCache.WithCache( AdvanceBroken(right, iteration+1, maxIter), []any{right, iteration + 1, maxIter}, ) } return stoneCache.WithCache( AdvanceBroken(val*2024, iteration+1, maxIter), []any{val * 2024, iteration + 1, maxIter}, ) } }