Skip to content

Instantly share code, notes, and snippets.

bigrams = {
"th" : 1.52, "he" : 1.28, "in" : 0.94,
"er" : 0.94, "an" : 0.82, "re" : 0.68,
"nd" : 0.63, "at" : 0.59, "on" : 0.57,
"nt" : 0.56, "ha" : 0.56, "es" : 0.56,
"st" : 0.55, "en" : 0.55, "ed" : 0.53,
"to" : 0.52, "it" : 0.50, "ou" : 0.50,
"ea" : 0.47, "hi" : 0.46, "is" : 0.46,
"or" : 0.43, "ti" : 0.34, "as" : 0.33,
"te" : 0.27, "et" : 0.19, "ng" : 0.18,
#!/usr/bin/env python3
import socketserver
import logging
from random import randint
HOST, PORT = "", 999
import sys
def is_triangle(tri):
return all([tri[i%3] + tri[(i+1)%3] > tri[(i+2)%3] for i in range(3)])
in_str = [line.strip() for line in sys.stdin.readlines()]
in_list = [[int(side) for side in line.split()] for line in in_str]
print("part 1: ", len(list(filter(is_triangle, in_list))))
@kylethebaker
kylethebaker / assignment1.erl
Last active June 27, 2017 09:13
Function Erlang Week 1 Assignment
-module(assignment1).
-export([area/1]).
-export([perimeter/1]).
-export([enclose/1]).
-export([tail_bits/1]).
-export([direct_bits/1]).
% Define shape types
% coordinate pair
@kylethebaker
kylethebaker / functions_over_list.erl
Created June 28, 2017 01:24
Week 2 - Functions Over Lists
-module(functions_over_lists).
-export([product/1]).
-export([maximum/1]).
-export([product_fold/1]).
product(X) -> product(X, 1).
product([], Product) -> Product;
product([X | Xs], Product) -> product(Xs, X * Product).
def encode(key, pt):
"""Encodes the plaintext using key."""
return "".join([encode_single(x, y) for x, y in get_pairs(key, pt)])
def decode(key, ct):
"""Decodes the ciphertext using key."""
return "".join([decode_single(x, y) for x, y in get_pairs(key, ct)])
@kylethebaker
kylethebaker / more_functions_over_lists.erl
Created July 10, 2017 01:20
Week 2 - More functions over lists
-module(more_functions_over_lists).
-export([join/2, concat/1]).
-export([reverse/1]).
-export([member/2]).
-export([merge_sort/1, quick_sort/1, insertion_sort/1]).
-export([permutations/1]).
join([], Ys) -> Ys;
join([X | Xs], Ys) ->
@kylethebaker
kylethebaker / assignment2.erl
Last active July 10, 2017 06:18
Functional Erlang Week 2 Assignment
-module(assignment2).
-export([print_indexes/1]).
-export([get_indexes/1, get_top_n_words/2, get_alpha_indexes/1]).
-define(SPLIT_TOKENS, " .,'\"()[]{}!?-\\").
% Gets all of the indexes.
get_indexes(Filename) ->
maps:to_list(get_indexes_ranges(Filename)).
@kylethebaker
kylethebaker / returning_funs.erl
Created July 16, 2017 06:07
Week 3 - Functions as Results
-module(returning_funs).
-compile(export_all).
-type unary() :: fun((Term) -> Term).
% composes a function onto another F(G(X))
-spec compose(unary(), unary()) -> unary().
compose(F, G) ->
fun (X) -> F(G(X)) end.
@kylethebaker
kylethebaker / fibonacci.erl
Last active July 23, 2017 01:57
Erlang Fast Fibonacci
-module(fibonacci).
-export([fast_fib/1]).
-export([slow_fib/1]).
-spec slow_fib(integer()) -> integer().
-spec fast_fib(integer()) -> integer().
% Finds the Nth fibonacci number using standard recursion
% Gets unbearably slow to find around when N = 45