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
def interest_calc(initial_amount, interest, monthly_addition, months) do | |
Stream.unfold(initial_amount, fn x -> | |
month_end_principle = x + monthly_addition | |
new_principle = month_end_principle * (1 + (interest/12)) | |
{new_principle, new_principle} | |
end) |> Enum.take(months) | |
end |
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
# provides a stream of primes below n | |
# where range is a list from 2 to n | |
Stream.unfold(range,fn [head|tail] -> {head, tail |> Enum.filter(fn x -> rem(x,head) != 0 end)}; [] -> nil end) | |
# Parallelized version ~20% speed increase | |
def eliminate_factors(workers, prime_number) do | |
Enum.map(workers, fn worker -> | |
send(worker, {:factor, prime_number}) | |
end) | |
Enum.map(workers, fn worker -> |
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
def fibonacci_stream do | |
Stream.unfold( [1], fn | |
[prev, curr] -> | |
next = prev + curr | |
{next, [curr, next]} | |
([1]) -> | |
{1, [1,1]} | |
end) | |
end | |
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
<section class="slide" id="declarative"> | |
<h2>Declarative</h2> | |
<blockquote>A programming paradigm that expresses the logic of a computation without describing its control flow</blockquote> | |
<section class="slide"><center><h3>Lets make a list of numbers 1-5</h3></center></section> | |
<section class="slide"> | |
<h3>Declarative</h3> | |
<pre class="prettyprint"><code> | |
let x = take 5 [1..] | |
</code></pre> | |
<h3>Imperative</h3> |
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 Token | |
import Text.Regex.Posix | |
import Data.List | |
lexer :: String -> [Token] | |
lexer input lineNumber | |
| input =~ endline :: Bool = | |
let token = input =~ endline :: String | |
in lexer (delete (contents token) input) lineNumber + 1 | |
|input =~ whitespace :: Bool = |
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
function parseGetResponse(response){ | |
var splitUrl = response.split("?")[1].split("&"); | |
var variables = {}; | |
for(var i=0; i<splitUrl.length; i += 1){ | |
var broken = splitUrl[i].split("="); | |
var key=broken[0]; | |
var value = broken[1]; | |
variables[key] = value; | |
} | |
return variables; |
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
if($a123 > 3) | |
{ | |
$a123=0; | |
} | |
if($a123 == 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
function get_random_id() | |
{ | |
$random = ''; | |
for ($i = 1; $i <= 8; $i++) | |
{ | |
$random.= mt_rand(0, 9); | |
} | |
return $random; |
NewerOlder