Skip to content

Instantly share code, notes, and snippets.

View AKST's full-sized avatar

Angus AKST

View GitHub Profile
@AKST
AKST / ReverseBinary_update.py
Last active December 16, 2015 12:09
Reverse Binary with stdin
def reverse_bin (num):
reversed = 0
while num != 0:
reversed = (reversed << 1) | (num & 1)
num >>= 1
return reversed
if __name__ == "__main__":
print(reverse_bin(int(input())))
@AKST
AKST / fun_with_functions.js
Last active December 19, 2015 07:19
Fun with js functions. Just decided in implement my own version of map, filter, foldl, along with a few helper functions.
Array.prototype.forEach = function (fun) {
for (var i = 0; i < this.length; i++) {
fun(this[i]);
}
};
Array.prototype.foldl = function (acc, fun) {
this.forEach(function (elem) {
acc = fun(elem, acc);
});
import Data.Monoid ((<>))
import Data.Maybe (fromMaybe)
makeXzzer :: Int -> String -> (Int -> Maybe String)
makeXzzer deviser msg =
\x -> if x `mod` deviser == 0
then Just msg
else Nothing
fizzer :: Int -> Maybe String
@AKST
AKST / Preferencial Voting System Sim.py
Last active December 21, 2015 10:09
Preferencial voting system simulator based on the australian voting system.
from copy import deepcopy
from random import shuffle
PARTIES = [
"LNP", "ALP", "GRN", "ASP", "BKAP",
"ON", "WLP", "PAP", "FF", "CD"
]
# functions
@AKST
AKST / PascalsTriangle.scala
Last active December 23, 2015 08:29
Recursively Generate Pascals Triangle
import scala.annotation.tailrec
object PascalsTriangle {
type Triangle = Map[(Int, Int), Int]
type TriangleResult = (Triangle, Int, Int) => Triangle
def generateTriangle(colMax: Int, rowMax: Int, generateResult: TriangleResult): Triangle = {
@tailrec
def recLoop(triangle: Triangle, colIt: Int, rowIt: Int): Triangle =
@AKST
AKST / fib.hs
Created September 22, 2013 09:14
A tail recrusive implementation of the fibonacci squence
fib :: (Eq a, Num a, Num b) => a -> b
fib n = impl n 1 0
where
impl 0 _ b = b
impl n a b = impl (n - 1) (a + b) a
@AKST
AKST / max.scm
Last active December 23, 2015 19:29
Just a simple implementation of the max function in scheme.
;; original function from a while back
(define (max . lst)
(let (
(x (car lst))
(xs (cdr lst)))
(if (null? xs)
x
(let ((xs_max (apply max xs)))
(if (> x xs_max)
x
@AKST
AKST / TreeFilter.hs
Last active December 24, 2015 17:59
data Tree a = Node a (Tree a) (Tree a) | Empty
tFilter :: (Ord a) => (a -> Bool) -> Tree a -> Tree a
tFilter f tree = impl f tree Empty
where
impl f Empty acc = acc
impl f (Node x l r) acc =
impl f l $
impl f r $
package object example {
/**
* Tranverse a seqence of booleans (which it interprets as seqence of bits),
* and these booleans are transfromed into a binary value. Eg.
*
* scala> boolsToBin(List(true, true, false, true))
* resXX: Int = 11
*/
def boolsToBin(bs: Seq[Boolean]): Int = {
@AKST
AKST / wikitextToHtml.py
Last active August 29, 2015 13:56
Transforms Wikitext into basic html mainly (p & h2 tags), removes citations & meta data. Source available under apache 2 license.
# Copyright 2014 Angus Thomsen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,