Skip to content

Instantly share code, notes, and snippets.

View Anderssorby's full-sized avatar
🏢
Working from office

Anders Christiansen Sørby Anderssorby

🏢
Working from office
View GitHub Profile
@Anderssorby
Anderssorby / Collatz.fm
Created September 26, 2020 20:10
Play with the Collatz conjecture in Formality
Collatz.run: IO(Unit)
do IO {
var val_str = IO.prompt("start value:");
let start = Nat.parse_decimal(val_str);
Collatz.step(start);
}
Collatz.step(start: Nat): IO(Unit)
let next = Collatz.next(start);
do IO {
@Anderssorby
Anderssorby / formality.vim
Created September 9, 2020 20:24
A syntax file for the Formality language tweaked from Haskell syntax
" Vim syntax file
" Language: Formality
" Maintainer: Anders Christiansen Sørby <anders@sorby.xyz>
" Last Change: August 16. 2020
"
" Version: 2.0
" Url:
"
" Remove any old syntax stuff hanging around
@Anderssorby
Anderssorby / pollards_rho.py
Created July 12, 2018 06:16
Pollard's Rho algorithm
from argparse import ArgumentParser
import numpy as np
gcd_table = {}
def gcd(a, b):
while a % b != 0:
a, b = b, a % b
return b
bound = 10000
@Anderssorby
Anderssorby / numpy_mnist.py
Last active November 16, 2017 01:09
Neural network using numpy on binary data
import numpy as np
from itertools import product
from timeit import default_timer as timer
import matplotlib.pyplot as plt
# Deterministic
np.random.seed(1234)
# Data
dim = 4
;; 4clojure problem #53
(fn [s] (loop [longest [] r (sorted-set) [x n & xs :as l] s]
(cond
(nil? n) longest
(= n (inc x)) (recur (if (> (+ 2 (count r)) (count longest)) (vec (conj r x n)) longest) (conj r x n) (rest l))
:else (recur longest (sorted-set) (rest l)))))
;; Creates the nth row of pascals triangle
;; the addition way
(fn [n]
(loop [s [1]]
(if
(= n (count s)) s
(recur (into (into [1] (map + s (rest s))) [1]))
)))
;; A prime finder (not optimized)
(fn [s] (loop [i s p [] n 2]
(cond
(= 0 i) p
(every? identity (map #(not= 0 (mod n %)) p)) (recur (dec i) (conj p n) (inc n))
:else (recur i p (inc n)))))
;; An infix calculator
(defn calc [& x]
(loop [a (first x) b (second x) c (nth x 2) remainding (drop 3 x)] ;; This loop is unnecessary complex
(let [result (b a c)]
(if (empty? remainding)
result
(recur
result
(first remainding)
(second remainding)