• McNuggets problem

    From B. Pym@21:1/5 to All on Mon Aug 5 22:54:59 2024
    rosettacode.org/wiki/McNuggets_problem

    Calculate (from 0 up to a limit of 100) the largest
    non-McNuggets number (a number n which cannot be expressed
    with 6x + 9y + 20z = n where x, y and z are natural numbers).

    Output:

    43


    newLISP

    (define (cartesian-product lists)
    (if (null? lists)
    '(())
    (let (subproduct (cartesian-product (rest lists)))
    (apply append
    (map
    (fn (x) (map (fn (xs) (cons x xs)) subproduct))
    (first lists))))))

    (define (nug? x)
    (let (top 100)
    (exists
    (fn (combo) (= x (apply + combo)))
    (cartesian-product
    (list (sequence 0 top 6)
    (sequence 0 top 9)
    (sequence 0 top 20))))))

    (exists (fn (n) (not (nug? n))) (sequence 100 0))
    ===>
    43

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)