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 sys | |
tshirt = [ | |
0b01001001, 0b01101110, 0b01100110, 0b01101001, | |
0b01101110, 0b01101001, 0b01110100, 0b01100101, | |
0b00100000, 0b01000011, 0b01100001, 0b01101101, | |
0b01110000, 0b01110101, 0b01110011, 0b00100000, | |
0b01001001, 0b00100000, | |
0b01110111, 0b01110010, | |
0b01101001, 0b01110100, |
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
pairs = lambda xs: zip(xs, xs[1:]) | |
print pairs([1,2,3,4,5,6]) # [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] | |
sorted = lambda xs: all([x<=y for (x, y) in pairs(xs)]) | |
print sorted([1,2,3,4,5,6,7]) # True | |
print sorted([1,2,3,4,5,9,7]) # False |
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
// Resources: | |
// https://github.com/diafygi/webcrypto-examples | |
// https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey | |
// http://blog.engelke.com/tag/webcrypto/ | |
// Tested in Firefox Developer Edition | |
function strToArrayBuffer(str) { | |
var buf = new ArrayBuffer(str.length * 2); | |
var bufView = new Uint16Array(buf); | |
for (var i = 0, strLen = str.length; i < strLen; i++) { |
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
-module(first). | |
-export([double/1,treble/1,square/1,mult/2,area/3]). | |
mult(X, Y) -> | |
X*Y. | |
double(X) -> | |
mult(2, X). | |
% Area of a triangle (Heron's formula) |
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
-module(patterns). | |
-export([all_tests/0]). | |
% all_tests invokes all tests (xor, maxThree, howManyEquals) | |
all_tests() -> | |
all_xor_tests(), | |
test_max_three(), | |
test_how_many(). | |
% all_xor_tests invokes all XOR tests. |
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
-module(fib). | |
-export([fib/1]). | |
% Fibonacci direct recursion implementation | |
fib(0) -> | |
0; | |
fib(1) -> | |
1; | |
fib(N) when N>0 -> | |
fib(N-1) + fib(N-2). |
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
-module(recursion). | |
-export([test/0,fib/1,loop/1,sum/1,max/1,perfect/1]). | |
% Typical loop in Erlang | |
loop(N) when N>0 -> | |
io:format("~p~n", [N]), | |
loop(N-1); | |
loop(_) -> % implies N = 0 | |
io:format("bye~n"). |
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
-module(product). | |
-export([all_tests/0,test_sum/0,test_prod/0,test_maximum/0,sum/1,sumT/1,prod/1, | |
prodT/1,maximum/1,maximumT/1]). | |
%% sum implementation with direct recursion (per the video) | |
sum([]) -> 0; | |
sum([X|Xs]) -> X + sum(Xs). | |
%% sum implementation with tail recursion (per the video) | |
sumT(Xs) -> sumT(Xs, 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
-module(transform). | |
-export([double/1,evens/1,median/1,modes/1,sort/1,counters/2]). | |
%% ---------------------------------------------------------------------------- | |
%% Double | |
double([]) -> []; | |
double([X|Xs]) -> [2*X | double(Xs)]. | |
%% ---------------------------------------------------------------------------- | |
%% Evens |
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
-module(more_lists). | |
-export([reverse/1,take/2,take2/2,test_take/0,test_take2/0]). | |
%% Take with direct recursion | |
-spec take(integer(), [T]) -> [T]. | |
take(_, []) -> []; % handles case where N > length(Xs) | |
take(0, _) -> []; | |
take(N, [X|Xs]) when N > 0 -> [X | take(N-1, Xs)]. | |
test_take() -> |
OlderNewer