This file contains 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
// Perceptron | |
// see https://towardsdatascience.com/perceptron-learning-algorithm-d5db0deab975 | |
def weights = [0, 0, 0] // b, xCoeff, yCoeff such that classifier will become b + xCoeff * x + yCoeff * y == 0 | |
def data = [ | |
[1, 0, 0, false], // bias (start with 1), x, y, classification value | |
[1, 1, 0, true], // here: training the "or" function. Expected: [-1, 1, 1] | |
[1, 1, 1, true], | |
[1, 0, 1, true] | |
] |
This file contains 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
// see challenge here: http://adventofcode.com/2017/day/9 | |
String input = /your input here/ | |
String collapseEscape = input.replaceAll(/!./,'') | |
String collapseGarbage = collapseEscape.replaceAll(/<.*?>/,'') | |
String listString = collapseGarbage.tr('{}','[]') | |
String normCode = listString.replaceAll(/\[,/,'[') |
This file contains 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
// http://adventofcode.com/2017/day/8 | |
def input = '''b inc 5 if a > 1 | |
a inc 1 if b < 5 | |
c dec -10 if a >= 1 | |
c inc -20 if c == 10''' | |
regs =[:].withDefault{0} | |
inc = { String key, Integer x -> regs[key] += x } | |
dec = { String key, Integer x -> inc(key, -x) } |
This file contains 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 Advent6 where | |
{- | |
http://adventofcode.com/2017/day/6 | |
-} | |
import Data.List | |
mapAtIndex :: (a->a) -> Int -> [a] -> [a] | |
mapAtIndex f n xs = take n xs ++ rest (drop n xs) where |
This file contains 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 Advent3 where | |
{- | |
http://adventofcode.com/2017/day/3 | |
-} | |
import Data.List | |
data Direction = Right | Up | Down | Left | |
derive Show Direction |
This file contains 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 Advent2 where | |
{- | |
http://adventofcode.com/2017/day/2 | |
-} | |
-- the core of the checksum logic | |
checkSum xss = sum (map lineCS xss) where | |
lineCS xs = maximum xs - minimum xs |
This file contains 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
// http://adventofcode.com/2017/day/1 | |
def captcha(list) { | |
def last = list[-1] | |
def clean = list.findAll { e -> | |
if (e == last) { | |
last = e; true | |
} else { | |
last = e ; false | |
} |
This file contains 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
-- Leak example from http://homepages.inf.ed.ac.uk/wadler/papers/leak/leak.ps | |
-- convenience | |
parseStr :: String -> (String, String) | |
parseStr = packedPair . parse . unpacked where | |
packedPair (x,y) = (packed x, packed y) | |
parse :: [Char] -> ([Char], [Char]) | |
parse [] = ([], []) | |
parse (' ': cs) = ([], cs) |
This file contains 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 Balanced where | |
import Prelude (Unit, discard, ($), (+), (-), (>=), (<=), (&&), (==), negate) | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE, logShow) | |
import Data.Foldable (traverse_, foldMap) | |
import Control.Monad.State (State, execState) | |
import Control.Monad.State.Class (modify) | |
import Data.String (toCharArray) |
This file contains 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 FizzBuzz | |
import Data.Vect | |
Rule : Type | |
Rule = (n: Int) -> (old: List String) -> (List String) | |
everyNthRule : (every: Int) -> (replacement: String) -> Rule | |
everyNthRule every replacement n old = | |
if (mod n every == 0) then old ++ [replacement] else old |
NewerOlder