Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
(lib 'struct)
|
||||
(lib 'sql) ;; for table
|
||||
|
||||
(define T (make-table (struct meal (name poids price))))
|
||||
|
||||
(define meals
|
||||
'((🐂-beef 3.8 36)
|
||||
(🍖-pork 5.4 43)
|
||||
(🍗-ham 3.6 90)
|
||||
(🐪-greaves 2.4 45)
|
||||
(flitch 4.0 30)
|
||||
(brawn 2.5 56)
|
||||
(welt 3.7 67)
|
||||
(🐃--salami 3.0 95)
|
||||
(🐖-sausage 5.9 98)))
|
||||
|
||||
(list->table meals T)
|
||||
;; sort table according to best price/poids ratio
|
||||
(define (price/poids a b )
|
||||
(- (// (* (meal-price b) (meal-poids a)) (meal-price a) (meal-poids b)) 1))
|
||||
(table-sort T price/poids)
|
||||
|
||||
(define-syntax-rule (name i) (table-xref T i 0))
|
||||
(define-syntax-rule (poids i) (table-xref T i 1))
|
||||
|
||||
;; shop : add items in basket, in order, until W exhausted
|
||||
(define (shop W )
|
||||
(for/list ((i (table-count T)))
|
||||
#:break (<= W 0)
|
||||
(begin0
|
||||
(cons (name i) (if (<= (poids i) W) 'all W))
|
||||
(set! W (- W (poids i))))))
|
||||
|
||||
;; output
|
||||
(shop 15)
|
||||
→ ((🐃--salami . all) (🍗-ham . all) (brawn . all) (🐪-greaves . all) (welt . 3.5))
|
||||
Loading…
Add table
Add a link
Reference in a new issue