## Euler Lisp

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.

### Design Choices

• Lisp1
• Lexical Scoping
• Strict Evaluation
• fst and rst instead of car and cdr, this way caddr can be written as frrst

### Code Example

(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
• 67

### Solved in > 60s

• 14

Github: l3kn/rust_lisp

## Raytracer

CPU Raytracer written in the crystal language.

### Features

• Distance Estimated Objects
• Cube map background images
• Stochastic progressive photon mapping
• Surface-area-heuristic BVHs

Github: l3kn/raytracer

## StumpyPNG

Crystal library for reading and writing png files, with support for Adam7 interlacing and all kinds of color types.

Github: stumpycr/stumpy_png

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")


## StumpyGIF

Crystal library for creating (animated) gif files.

Github: stumpycr/stumpy_gif

## Scheme Compiler

Self-hosting compiler from a clojure inspired scheme dialect to LLVM IR code.

Github: l3kn/lisp-compiler-llvm

(defn range (from to)
(if (eq? from to)
(list from)
(cons from
(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))


## Isometric Renderer

Render voxel grids as isometric images.

• Combine voxels of the same type to speed up rendering

Github: l3kn/hacky_isometric

## Croco

Agend based simulation framework, inspired by StarLOGO.

Github: l3kn/croco