Skip to content

Commit

Permalink
more coding
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram Cohen authored and prozacchiwawa committed Sep 18, 2024
1 parent a85b46e commit bb70f95
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 41 deletions.
12 changes: 7 additions & 5 deletions assert.clinc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(
(defmacro assert items
(if (r items)
(list if (f items) (c assert (r items)) (q . (x)))
(f items)
(defun assert_ (items)
(if (r items)
(qq (if (unquote (f items)) (unquote (assert_ (r items))) (x)))
(f items)
)
)
)

(defmac assert items (assert_ items))
)
2 changes: 1 addition & 1 deletion calpoker_generate.clinc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
(defun pull_out_cards (selections cards count)
(if (not cards)
(assert
(= count 4)
(= count 5)
0
)
(logand selections 1)
Expand Down
2 changes: 1 addition & 1 deletion krunk_generate.clinc
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@

; format of dictionary is (lower_dictionary word high_dictionary) or (low high signature)
(defun find_exclusion_proof (word @dictionary (first second third))
(if (= (type first) atom)
(if (not (l first))
(if (logand (>= word first) (<= word second))
dictionary
0
Expand Down
67 changes: 36 additions & 31 deletions last.clinc
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
(
(defun last_inner ((next . remainder))
(if remainder
(last_inner remainder)
next
)
(defun prefix (L P)
(if L
(c (f L) (prefix (r L) P))
P
)
)

(defmacro last ARGS
(defun snoc (L agg)
(if L
(if (r L)
(snoc (r L) (c (f L) agg))
(c (f L) agg)
)
(c () ())
)
)
(defun last_inner ((next . remainder))
(if remainder
(last_inner remainder)
next
)
)

(defun snoc (L agg)
(if L
(if (r L)
(snoc (r L) (c (f L) agg))
(c (f L) agg)
)
(c () ())
)
)

(defun echo myargs
myargs
)

(defun prefix (L P)
(if L
(c (f L) (prefix (r L) P))
P
)
)
(defmac last ARGS

(if ARGS
(if (r ARGS)
(assign
(final . rest) (snoc ARGS ())
reversed (prefix rest (list final))
(qq (last_inner (unquote (c list reversed))))
)
(qq (last_inner (unquote (f ARGS))))
)
(x "Last takes at least one argument")
(if ARGS
(if (r ARGS)
(assign
(final . rest) (snoc ARGS ())
reversed (prefix rest (echo final))
(qq (last_inner (unquote (c (q . echo) reversed))))
)
(qq (last_inner (unquote (f ARGS))))
)
(x "Last takes at least one argument")
)
)
)
4 changes: 2 additions & 2 deletions onehandcalc.clinc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
; A more general function would return a list of lists of ascending sizes
; to be merged
(defun atomsort ((@ firstpos (first @ secondpos (second @ thirdpos (third . remaining)))))
(if firstpos
(if (print 'firstpos' firstpos)
(if secondpos
(if thirdpos
(assign-lambda
Expand Down Expand Up @@ -77,7 +77,7 @@
)
)
(defun check_flush ((rank1 . suit1) (rank2 . suit2) (rank3 . suit3) (rank4 . suit4) (rank5 . suit5))
(logand (= suit1 suit2) (= suit2 suit3) (= suit3 suit4) (= suit4 suit5))
(logand (= suit1 suit2) (= suit1 suit3) (= suit1 suit4) (= suit1 suit5))
)
; returns the high card of a straight or 0 if there isn't any
(defun straight_high (count1 count2 count3 count4 count5 card1 card2 card3 card4 card5)
Expand Down
1 change: 0 additions & 1 deletion spacehandcalc.clinc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
; returned list is hand type followed by cards in descending order
; all sorting is done highest to lowest
(
(include *standard-cl-22*)
(include sort.clinc)
(include deep_compare.clinc)
(include filtermap.clinc)
Expand Down
37 changes: 37 additions & 0 deletions test_onehandcalc.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

(mod ()
(include *standard-cl-23*)
(include print.clinc)
(include assert.clinc)
(include deep_compare.clinc)
(include reverse.clinc)
(include prepend.clinc)
(include map.clinc)
(include range.clinc)
(include permutations.clinc)
(include last.clinc)
(include busy.clinc)
(include onehandcalc.clinc)

(defun try_list (mylist newlist)
(assert (deep= (print 'result' (atomsort (print 'about to sort' newlist))) mylist) 0)
)

(defun try_permuted_list (mylist)
(busy (lambda ((& mylist) newlist) (try_list mylist newlist))
(permutations mylist)
0
)
)
(last
(try_list 0 0)
(try_list (range 15) (range 15))
(try_list (range 15) (reverse (range 15)))
(try_permuted_list (list -1 -1 0 0 2))
(busy (lambda (i) (try_permuted_list (range i)))
(range 4)
0
)
1
)
)

0 comments on commit bb70f95

Please sign in to comment.