Skip to content

Instantly share code, notes, and snippets.

View soegaard's full-sized avatar

Jens Axel Søgaard soegaard

View GitHub Profile
@camoy
camoy / README.md
Last active January 24, 2022 07:35
Miller-Rabin liars

Primality tests like the Fermat test and the Miller-Rabin test rely on so-called "witnesses." In the case of Fermat, if a^{p-1} = 1 (mod p), for some a, then p is probably prime. The a is called a Fermat witness. However, if a composite passes the test for a given a, then a is called a Fermat liar. The same principle holds for Miller-Rabin, although the equation is slightly more complicated.

Which numbers are the most honest? Which ones are the most lying? Run racket main.rkt to produce a bunch of heat maps that show the most honest (dark) and most lying (bright) numbers. This one shows for the numbers 2 to 1024:

Miller-Rabin liars

#lang racket
(require math/array)
;; https://en.wikipedia.org/wiki/Conway's_Game_of_Life
;; These are the game rules for a single CELL which can be 1 (alive) or 0
;; dead. NEIGHBOR-COUNT is the number of live neighbors the cell has.
(define (game-rules cell neighbor-count)
(cond
;; Any live cell with fewer than two live neighbours dies, as if by
;; underpopulation.
@Bracktus
Bracktus / rounders.rkt
Created January 3, 2022 17:18
A small ball game
#lang sketching
(require racket/list)
(class Player Object
(init-field x y x-vel y-vel attached)
(super-new)
;direction is whether we're rotating clockwise or anti clockwise around the ball.
;either -1 or 1
(define-values (direction) (values 1))
@sschwarzer
sschwarzer / racket_tips.md
Last active October 16, 2022 18:00
Racket tips and tricks

Racket tips and tricks

These are extracted from discussions I triggered on the Racket Slack. Thanks to everyone who participated in the discussion threads! :-)

Conversion to boolean

Use (and value #t) to convert a value to its boolean equivalent.

Entering a module in the Racket REPL

@alex-hhh
alex-hhh / world-map.rkt
Last active August 20, 2019 03:01
World Map, standard-fish competition 2019
#lang racket
(require json racket/draw math/base)
(define (lat-lon->map-point coordinates)
(match-define (list lon lat _ ...) coordinates)
(define-values (x y) (values (degrees->radians lon) (asinh (tan (degrees->radians lat)))))
(list (/ (+ 1 (/ x pi)) 2) (/ (- 1 (/ y pi)) 2)))
(define (draw-polygon dc polygons)
(define path
@beatfactor
beatfactor / install_nginx_macos_source.md
Last active June 27, 2024 10:13
Install Nginx on Mac OS from source (without brew)

Install Nginx on Mac OS from source

no Homebrew required

1. Download Nginx

$ cd /usr/local/src
$ curl -OL http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -xvzf nginx-1.12.2.tar.gz && rm nginx-1.12.2.tar.gz
@sliminality
sliminality / Default (OSX).sublime-keymap
Last active October 8, 2023 04:47
Racket and Sublime Text 3
{
// Evaluate file in the open SublimeREPL.
// Depends on you creating the Packages/User/EvalInREPL.sublime-macro file.
{ "keys": ["super+r"], "command": "run_macro_file", "args": { "file": "Packages/User/EvalInREPL.sublime-macro" },
"context": [
{ "key": "selector", "operator": "equal", "operand": "source.elm" }
]
},
// Reindent selection on tab
@staltz
staltz / introrx.md
Last active July 4, 2024 10:11
The introduction to Reactive Programming you've been missing
@1wErt3r
1wErt3r / SMBDIS.ASM
Created November 9, 2012 22:27
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no