I’m trying to work through some Project Euler math problems using my own Lisp interpreter.
In some cases it is pretty hard to make the code run in less the 60s,
so for now, some more math functions
prime?, factorization, modular exponentiation)
are implemented in rust
until I the interpreter is fast enough to implement them in Lisp.
- Lexical Scoping
- Strict Evaluation
cdr, this way
caddrcan be written as
(defn parse-byte (b) (- b 48)) (defn is-number (b) (and (>= b 48) (<= b 57))) (def numbers (map parse-byte (filter is-number (string-bytes input)))) (println (apply max (map product (chunks 13 numbers))))
(defn transpose (lst) (map (fn (i) (map (curry nth i) lst)) (range 0 (dec (length (fst lst)))))) (defn diagonals (rows) (zip (fst rows) (rst (frst rows)) (rrst (frrst rows)) (rrrst (frrrst rows))))
Solved in < 60s
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- 11, 12, 13, 15, 16, 17, 18, 19
- 20, 25
Solved in > 60s
CPU Raytracer written in the crystal language.
- Distance Estimated Objects
- Cube map background images
- Stochastic progressive photon mapping
- Surface-area-heuristic BVHs
Crystal library for reading and writing png files, with support for Adam7 interlacing and all kinds of color types.
include StumpyPNG canvas = Canvas.new(256, 256) (0...255).each do |x| (0...255).each do |y| # RGBA.from_rgb_n(values, bit_depth) is an internal helper method # that creates an RGBA object from a rgb triplet with a given bit depth color = RGBA.from_rgb_n(x, y, 255, 8) canvas[x, y] = color end endIf you get StumpyPNG.write(canvas, "rainbow.png")
Crystal library for creating (animated) gif files.
Self-hosting compiler from a clojure inspired scheme dialect to LLVM IR code.
(defn range (from to) (if (eq? from to) (list from) (cons from (range (fxadd1 from) to)))) (defn fizzbuzz (n) (cond ((eq? (fxrem n 15) 0) (puts "FizzBuzz")) ((eq? (fxrem n 3) 0) (puts "Fizz")) ((eq? (fxrem n 5) 0) (puts "Buzz")) (else (inspect n)))) (for-each fizzbuzz (range 1 100))
Render voxel grids as isometric images.
- Combine voxels of the same type to speed up rendering
Agend based simulation framework, inspired by StarLOGO.