Instantly share code, notes, and snippets.

# voila

• Sort options
Created Jul 6, 2019
Change recursive to iterative
View change.js
 /* How many different ways can we make change of \$ 1.00, given half-dollars, quarters, dimes, nickels, and pennies? More generally, can we write a procedure to compute the number of ways to change any given amount of money? This problem has a simple solution as a recursive procedure. Suppose we think of the types of coins available as arranged in some order. Then the following relation holds: The number of ways to change amount a using n kinds of coins equals the number of ways to change amount a using all but the first kind of coin, plus the number of ways to change amount a - d using all n kinds of coins, where d is the denomination of the first kind of coin.
Created Jul 3, 2019
Factorial recursive to iterative
View fact.js
 let fact0 = (n) => { if (n > 0) { return n * fact0(n - 1); } else return 1; } console.log(fact0(5, (x) => x)) let fact1 = (n, k) => {
Last active Jul 3, 2019
Hanoi Tower recursive to iterative
View hanoi.js
 // recursive const hanoi0 = (n, a, b, c) => { if (n > 0) { hanoi0(n - 1, a, c, b); console.log(`\${a} ==> \${c}`); hanoi0(n - 1, b, a, c); } } hanoi0(3, "a", "b", "c");
Created Jul 3, 2019
Water Jugs puzzle with QuickCheck/PropEr
View erlang_shell.txt
 1> c("jug_statem.erl"). {ok,jug_statem} 2> jug_statem:test(100). .................................................................................................... OK: Passed 100 test(s). 18% {jug_statem,fill_big,0} 17% {jug_statem,big_to_small,0}
Created Jul 3, 2019
Water Jugs puzzle with Python-Z3
View jugs.py
 from z3 import * Jug, (Big, Small) = EnumSort( 'Jug', ['Big', 'Small']) Act, (FillBig, FillSmall, EmptyBig, EmptySmall, BigToSmall, SmallToBig) = EnumSort( 'Act', ['FillBig', 'FillSmall', 'EmptyBig', 'EmptySmall', 'BigToSmall', 'SmallToBig']) #m = 10 for n in range(5, 10): print("n = {}".format(n))
Created Jul 3, 2019
Water Jugs puzzle in Z3
View jugs.z3
 (declare-const n Int) (declare-datatypes () ((Jug Big Small))) (declare-datatypes () ((Act FillBig FillSmall EmptyBig EmptySmall BigToSmall SmallToBig))) (declare-fun vol (Jug Int) Int) (declare-fun act (Int) Act) (assert (= n 6)) (assert (= (act 0) EmptyBig)) (assert (= (vol Big 0) 0)) (assert (= (vol Small 0) 0))
Created Jul 3, 2019
Water Jugs puzzle in Alloy
View jugs.als
 /* Impose an ordering on the State. */ open util/ordering[State] open util/integer /* Stores the jugs level */ sig State { small, big:Int } /* initial state */ fact { first.small = 0 && first.big = 0 }
Created May 1, 2019
View keybase.md

### Keybase proof

I hereby claim:

• I am voila on github.
• I am th3rac25 (https://keybase.io/th3rac25) on keybase.
• I have a public key ASCeC9hVEe0BrGoScMK4IAb0V3F8O40tgBLXc6nyxW-_hAo

To claim this, I am signing this object:

Created Dec 18, 2013
View okasaki2.3.ml
 open Printf module type Ord = sig type t val lt : t -> t -> bool val lte : t -> t -> bool val eq : t -> t -> bool end
Created Dec 18, 2013
View okasaki2.4.ml
 open Printf module type Ord = sig type t val lt : t -> t -> bool val lte : t -> t -> bool val eq : t -> t -> bool val succ : t -> t end
You can’t perform that action at this time.