McNuggets problem

Liste des GroupesRevenir à cl lisp 
Sujet : McNuggets problem
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 06. Aug 2024, 00:54:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8rl80$15ceb$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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



Date Sujet#  Auteur
6 Aug 24 o McNuggets problem1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal