Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lisp change machine

Name: Anonymous 2015-09-19 12:52

dynamic programming mixed with HOFs. originally an exam question. brain on fire for an undergrad fuckwit like myself

(define (change amt coins)
(cond
((= amt 0) '(()))
((or (<= amt 0) (null? coins)) '())
(else
(fold-right (lambda (a b) (append a b))
'()
(map
(lambda (n)
(map
(lambda (u)
(append (list n) u))
(change (- amt n)
(filter (lambda (k) (>= k n)) coins))))
coins)))))

;; -----------------------------------------------------------------------

(define (display-nl u)
(display u)
(newline))

(define display-elements
(lambda (u)
(map display-nl u)))

(define (demo r k)
(display-nl '-----------------------------)
(display r) (display ';;) (display k) (newline)
(display-nl '=============================)
(display-elements (change r k))
(display-nl '-----------------------------)
(newline))

;; -----------------------------------------------------------------------

(newline)

(demo 5 '(1 2 5))
(demo 13 '(1 3 5 7))
$ ./lisp <change.lisp

Loaded `prefix.txt'

-----------------------------
5;;(1 2 5)
=============================
(1 1 1 1 1)
(1 1 1 2)
(1 2 2)
(5)
-----------------------------

-----------------------------
13;;(1 3 5 7)
=============================
(1 1 1 1 1 1 1 1 1 1 1 1 1)
(1 1 1 1 1 1 1 1 1 1 3)
(1 1 1 1 1 1 1 1 5)
(1 1 1 1 1 1 1 3 3)
(1 1 1 1 1 1 7)
(1 1 1 1 1 3 5)
(1 1 1 1 3 3 3)
(1 1 1 3 7)
(1 1 1 5 5)
(1 1 3 3 5)
(1 3 3 3 3)
(1 5 7)
(3 3 7)
(3 5 5)
-----------------------------

Name: Anonymous 2015-09-24 5:53

>>36
I don't know of any bigger waste of my time than to master any language according to that definition. To me, mastering the BNF description (of certain kinds of languages) is as good as mastering the language. Implementation quirks should either be standardized or removed from the language.

Name: Anonymous 2015-09-24 6:35

>>41
To me, mastering the BNF description (of certain kinds of languages) is as good as mastering the language

You're insane.

Name: Anonymous 2015-09-24 8:42

>>42
he probably means that most languages of the same type are only syntax-change from each other. this is sadly often the case.

Name: OP 2015-09-24 13:05

>>42

The C grammar fits in like 2-3 pages IIRC in the K&R book. it's not *that* bad

Name: snakey the teenage poop 2015-09-25 12:44

>>1
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr
c-c-cdr c-c-cdr c-c-cdr cdr cdr

Name: snakey the teenage poop 2015-09-25 12:45

>>41
I SAY WE STANDARDISE DA STANDARD, LET THE FAT CATS GET WHAT'S COMING TO THEM, YA FUCKIN STAK BOI RETOID

Name: Anonymous 2015-09-25 18:45

Lisp change machine? that's called a hammock my friend. Rich Hickey showed us the way. We need to join him and change lisp, and with it, the world.

Name: Anonymous 2015-09-26 0:09

>>47
kek

Name: Anonymous 2015-09-26 10:11

>>48
/polecat kebabs/

Name: Anonymous 2015-09-28 3:42

>>47
I made a change machine in Haskell with the Obama monad.

Name: Anonymous 2015-09-28 10:42

>>50
Well you failed, because it didn't give me the rest of my money back.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List