This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; L-99: Ninety-Nine Lisp Problems | |
;; Problem 9: Pack consecutive duplicates of list elements into sublists. | |
; If a list contains repeated elements they should be placed in separate sublists. | |
; | |
; Example: | |
; | |
; * (pack '(a a a a b c c a a d e e e e)) | |
; ((A A A A) (B) (C C) (A A) (D) (E E E E)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Original Version from Atabey Kaygun, Conjugate Partitions | |
; http://kaygun.tumblr.com/post/145269023094/conjugate-partitions | |
; Derived versions: Rainer Joswig, [email protected], 2016 | |
; version 1 using LOOP | |
(defun dual (xs &aux k n r) | |
(loop while xs do | |
(setf k (reduce #'min xs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun make-vars (vars &aux syms) | |
(values (loop for var in vars | |
if (eq var NIL) | |
collect (let ((sym (gensym "ignore"))) (push sym syms) sym) | |
else collect var) | |
syms)) | |
(defmacro multiple-value-bind-some (vars form &body body) | |
(multiple-value-bind (vars syms) (make-vars vars) | |
`(multiple-value-bind ,vars ,form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; http://xen.garden/wp/?p=25 | |
; Common Lisp version by Rainer Joswig, [email protected], 2016 | |
(defun create-symbol (prefix suffix) | |
(intern (format nil "~a-~a" prefix suffix) | |
(symbol-package suffix))) | |
(defun make-get-set (name | |
&aux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Hi and welcome to team Gilded Rose. As you know, we are a small inn | |
; with a prime location in a prominent city ran by a friendly | |
; innkeeper named Allison. We also buy and sell only the finest goods. | |
; Unfortunately, our goods are constantly degrading in quality as they | |
; approach their sell by date. We have a system in place that updates | |
; our inventory for us. It was developed by a no-nonsense type named | |
; Leeroy, who has moved on to new adventures. Your task is to add the | |
; new feature to our system so that we can begin selling a new | |
; category of items. | |
; First an introduction to our system: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun diamond (letter) | |
(labels ((letter-value (letter) | |
(- (char-code (char-downcase letter)) | |
(char-code #\a))) | |
(pad-char (char n) | |
(loop repeat n do (write-char #\space)) | |
(write-char char)) | |
(write-letter-line (letter front back) | |
(pad-char letter front) | |
(unless (zerop back) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; John McCarthy. Puzzle Solving Program in LISP. Memo 20, Artificial Intelligence Project | |
; ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-020.pdf | |
; 1960 | |
; Common Lisp translation: 2016, Rainer Joswig, [email protected] | |
; basically the code is unchanged, but using s-expression syntax | |
(defparameter pzl | |
'((a1 (a2 a5) 7.5) | |
(a2 (a1 a5 a9 a3) 3.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; page 13, Ralf Hinze, Einführung in die funktionale Programmierung mit Miranda | |
#| | |
take' 0 x = [] | |
take' (n+1) [] = [] | |
take' (n+1) (a:x) = a : take' n x | |
; The ugly Scheme version in the book | |
(define take |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun split-with (pred list) | |
"splits the LIST at the first NIL result of PRED" | |
(values (loop while (and (not (null list)) | |
(funcall pred (first list))) | |
collect (pop list)) | |
list)) | |
(defun map-while (predicate function list) | |
(loop with e | |
while (not (null list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://www.reddit.com/r/dailyprogrammer/comments/3irzsi/20150828_challenge_229_hard_divisible_by_7/ | |
(defun lucky7s (n &aux | |
(nx0 (floor (+ n 2) 3)) | |
(ny0 (floor (+ n 1) 3)) | |
(nz0 (floor n 3)) | |
(cache (make-hash-table :test 'equal))) | |
(labels ((nt (k m &aux (n 0) (t0 0) nsub tsub) | |
(cond ((zerop m) | |
(values (if (zerop k) 1 0) 0)) |