This file contains hidden or 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 fib-iter (a b p q n) | |
| (cond ((zerop n) b) | |
| ((evenp n) (fib-iter a | |
| b | |
| (+ (* p p) (* q q)) | |
| (+ (* 2 p q) (* q q)) | |
| (/ n 2))) | |
| (t (fib-iter (+ (* b q) (* a q) (* a p)) | |
| (+ (* b p) (* a q)) | |
| p |
This file contains hidden or 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 num->bits (n) | |
| (declare (type integer n)) | |
| (the bit-vector | |
| (if (zerop n) | |
| #*0 | |
| (loop | |
| with len fixnum = (1+ (floor (log n 2))) | |
| with res bit-vector = (make-array len :element-type 'bit) | |
| for i fixnum below len | |
| for curr integer = n then (ash curr -1) |
This file contains hidden or 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 rand-test () | |
| (= 1 (gcd (random most-positive-fixnum) | |
| (random most-positive-fixnum)))) | |
| (defun estimate-pi (attempts) | |
| (loop repeat attempts | |
| counting (rand-test) into success | |
| finally (return (sqrt (/ 6 (/ success attempts)))))) | |
| (estimate-pi 1000000) |
This file contains hidden or 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
| (defmacro if-let ((name val) t-branch nil-branch) | |
| `(let ((,name ,val)) | |
| (if ,name ,t-branch ,nil-branch))) | |
| (defstruct h-tree | |
| content | |
| weight | |
| left | |
| right) |
This file contains hidden or 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
| (defpackage :paip2 | |
| (:use :common-lisp | |
| :util) | |
| (:export :sentence | |
| :compose | |
| :mappend | |
| :*simple-grammar* | |
| :*grammar* | |
| :generate | |
| :generate-tree)) |
This file contains hidden or 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
| import java.io.IOException; | |
| import java.net.URI; | |
| import java.nio.file.Paths; | |
| import java.net.http.*; | |
| import java.nio.file.*; | |
| class App { | |
| public static void main(String[] args) throws IOException, InterruptedException { | |
This file contains hidden or 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
| (defn mul [num-str m] | |
| (let [[acc v] (reduce (fn [[acc v] ch] | |
| (let [n (+ v (* m (Integer/parseInt (str ch))))] | |
| [(conj acc (rem n 10)) | |
| (quot n 10)])) | |
| [nil 0] | |
| (reverse num-str))] | |
| (apply str (if (zero? v) acc (conj acc v))))) | |
| (mul "9876545679" 7) |
NewerOlder