Skip to content

Instantly share code, notes, and snippets.

voila

  • Dunedin, NZ
Block or report user

Report or block voila

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@voila
voila / change.js
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.
@voila
voila / fact.js
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) => {
@voila
voila / hanoi.js
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");
@voila
voila / erlang_shell.txt
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}
@voila
voila / jugs.py
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))
@voila
voila / jugs.z3
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))
@voila
voila / jugs.als
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 }
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:

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
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.