Skip to content

Instantly share code, notes, and snippets.

View bergwerf's full-sized avatar

Herman Bergwerf bergwerf

View GitHub Profile
@bergwerf
bergwerf / isect.v
Created March 2, 2020 23:27
Spread and fan intersections, which I removed from my intuitionistic math Coq library.
(* Spread and fan prefix intersections. *)
From intuitionism Require Import lib set seq bcp spr fan.
(* Finite sequence comparison. *)
Section FiniteCompare.
(* Check if two sequences have a shared prefix. *)
Fixpoint fcompare (s t : fseq) :=
match s, t with
@bergwerf
bergwerf / collatz.v
Created February 28, 2020 22:35
Collatz Conjecture in Coq
(* The Collatz conjecture, to illustrate reckless statements. *)
Section Collatz.
(* Collatz mapping. *)
Definition collatz_map n := if even n then div2 n else n*3+1.
(* Collatz sequence starting with n. *)
Fixpoint collatz_seq n i :=
match i with
@bergwerf
bergwerf / ordered_set.go
Created February 15, 2020 23:00
Golang ordered sets using container/list
package main
import "container/list"
// ListUnion merges the second list into the first list while retaining order.
func ListUnion(dst *list.List, src *list.List) {
for e1, e2 := src.Front(), dst.Front(); e2 != nil; {
if e1 == nil {
dst.PushBack(e2.Value)
e2.Next()
@bergwerf
bergwerf / lambda.pl
Last active January 28, 2020 23:20
Lambda calculus alpha equivalence and beta reduction in Prolog (basic attempt, not complete)
%%%%%%%%%%%%%%%
% Sets and maps
%%%%%%%%%%%%%%%
% Sets: http://kti.ms.mff.cuni.cz/~bartak/prolog/sets.html
% Maps: sets of pairs.
list([]).
list([_|_]).
@bergwerf
bergwerf / fix.py
Created November 2, 2019 00:39
Attempt at Dart 2.0 Three.js interop with js_facade_gen
#!/usr/bin/env python3
'''
Get ./js_facade_gen, and ./three.js
Comment out ./three.js/src/renderers/shaders/UniformsUtils.d.ts to avoid errors
Navigate to js_facade_gen
Under Zsh, run: node index.js --base-path=../three.js --destination=../dart-threejs ../three.js/src/**/*.ts
Navigate to ../dart-threejs
Add pubspec.yaml with package:js
Run this script twice to add the needed Dart SDK imports
@bergwerf
bergwerf / query_location_strategy.dart
Created February 13, 2019 16:20
QueryLocationStrategy Angular Dart
import 'dart:html' show UrlSearchParams, EventListener;
import 'package:angular/angular.dart' show Provider, Injectable;
import 'package:angular_router/src/router/router_impl.dart' show RouterImpl;
import 'package:angular_router/angular_router.dart'
show Router, Location, LocationStrategy;
import 'package:angular_router/angular_router.dart'
show PlatformLocation, BrowserPlatformLocation;
@bergwerf
bergwerf / cached_iterator.dart
Created January 20, 2019 00:28
Cached iterator
/// Proxy iterator for [origin] that caches the result so that it can be
/// iterated again using [rewind]. Multiple rewinded copies of this iterator
/// share the [sharedCache] so it doesn't matter which one reads from [origin].
class CachedIterator<T> implements Iterator<T> {
var _i = -1;
var _terminated = false;
final Iterator<T> origin;
final List<T> sharedCache;
CachedIterator(this.origin, [List<T> cache])
@bergwerf
bergwerf / turing-1tape-add.txt
Last active April 9, 2021 05:17
Add two binary numbers on a single tape Turing machine (http://morphett.info/turing/turing.html)
; Turing 1-tape addition calculator
; The answer is first written in reverse binary
; Example input: 11011000+00011111=
; Find equals sign
0 * * r 0
0 = = r init-carry
; Write initial carry bit
init-carry _ 0 l init-carry
; This program counts the number of a characters in a string
; and appends it in reverse binary to the end of the tape
; Go to nil state
0 * * * nil
; Counting program
nil a x r odd
even a x r odd
odd a a r even
@bergwerf
bergwerf / sequence.js
Created September 30, 2018 18:07
Shortest JS to generate '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
// This:
s='';for(i=47;i<83;)s+=String.fromCharCode(++i>57?i+7:i)
// Is the same as this:
s='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'