Instantly share code, notes, and snippets.

Dierk KönigDierk

• Sort options
Created Dec 9, 2017
Advent of Groovy code, day 9
 // 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(/\[,/,'[')
Created Dec 8, 2017
Advent of Groovy code, day 8
 // 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) }
Last active Dec 8, 2017
Advent of Frege code, day 6
 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
Created Dec 4, 2017
Advent of Frege code, day 3
 module Advent3 where {- http://adventofcode.com/2017/day/3 -} import Data.List data Direction = Right | Up | Down | Left derive Show Direction
Created Dec 3, 2017
Advent of Frege code, day 2
 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
Created Dec 2, 2017
Advent of Groovy code, 2017, day 1
 // 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 }
Created Sep 16, 2017
example of a possible space leak in lazy languages like Frege when running on a platform like JVM
View Leak.fr
 -- 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)
Created Sep 14, 2017
The balanced parentheses kata with two solutions in purescript
View Balanced.purs
 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)
View FizzBuzz.idr
 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
Created Jan 20, 2017
Either type in Groovy as a special implementation of the generic sum type (works the same in Java)
View Either.groovy
 // Either type in Groovy as a special implementation of the generic sum type // see: Phil Wadler at LambdaWorld 2016: youtu.be/V10hzjgoklA import java.util.function.* import groovy.transform.* interface Either { public C match (Function leftCase, Function rightCase) }
You can’t perform that action at this time.