Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #242: Software uses US measurements, but the OS is in metric...


comp / comp.lang.lisp / McNuggets problem

SubjectAuthor
o McNuggets problemB. Pym

1
Subject: McNuggets problem
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 22:54 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: McNuggets problem
Date: Mon, 5 Aug 2024 22:54:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <v8rl80$15ceb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 06 Aug 2024 00:54:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="51ec0738d78fae23c740e6e73e04a0c7";
logging-data="1225163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h9b/ZeuQDopgnpJnvILoU"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:EjVmBXtoy6ndMHRllFJw9g7noQo=
View all headers

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

1

rocksolid light 0.9.8
clearnet tor