This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule World do | |
defp prev_height(p1, p2) do | |
cond do | |
p1 == 0 -> p2 | |
p2 == 0 -> p1 | |
true -> if Dice.success?(0.7), do: p1, else: p2 | |
end | |
end | |
def inc([]) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PascalTriangle do | |
def gen(0), do: [[1]] | |
def gen(n) do | |
gen(n - 1) ++ [gen_line(n)] | |
end | |
defp gen_line(n, line \\ [1]) | |
defp gen_line(0, list), do: list | |
defp gen_line(n, list) do | |
new_list = Enum.zip([0] ++ list, list ++ [0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PascalTriangle do | |
def gen(n) do | |
gen(n, [[1]]) |> Enum.reverse() | |
end | |
defp gen(0, triangle), do: triangle | |
defp gen(n, [prev | _rest] = triangle) do | |
line = Enum.zip([0] ++ prev, prev ++ [0]) | |
|> Enum.map(fn {a, b} -> a + b end) | |
gen(n - 1, [line | triangle]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule My1 do | |
def reverse([]), do: [] | |
def reverse([x | xs]) do | |
reverse(xs) ++ [x] | |
end | |
end | |
defmodule My2 do | |
def reverse(xs), do: reverse(xs, []) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Room { | |
int length; | |
int height; | |
int width; | |
public: | |
void input() { | |
std::cout << "Length, height and width for room: "; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Dice do | |
def roll(chance \\ 0.5) do | |
:rand.uniform < chance | |
end | |
end | |
defmodule Genetic do | |
@type gene :: boolean | |
@type genotype :: list(gene) | |
@type population :: list(genotype) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {makeDOMDriver, div, input, p} from '@cycle/dom'; | |
//========================================================= | |
// LIB | |
// Either monad | |
const pure = | |
value => | |
({ ok: true, value }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
function ttys_with_suspended { | |
ps ax -o tty,state | grep '\sT' | sed -e 's/\(.*[0-9]\).*/\1/' | sort | uniq -d | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (ul, li, text) | |
fizzBuzz list = | |
let | |
fizz ( i, r ) = | |
if i % 3 == 0 then | |
( i, r ++ "Fizz" ) | |
else | |
( i, r ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Result exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (onInput) | |
main = | |
Html.beginnerProgram | |
{ model = model | |
, view = view |