Skip to content

Instantly share code, notes, and snippets.

Dierk König Dierk

Block or report user

Report or block Dierk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Dierk
Dierk / Advent9.groovy
Created Dec 9, 2017
Advent of Groovy code, day 9
View Advent9.groovy
// 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(/\[,/,'[')
@Dierk
Dierk / Advent8.groovy
Created Dec 8, 2017
Advent of Groovy code, day 8
View Advent8.groovy
// 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) }
@Dierk
Dierk / Advent6.fr
Last active Dec 8, 2017
Advent of Frege code, day 6
View Advent6.fr
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
@Dierk
Dierk / Advent3.fr
Created Dec 4, 2017
Advent of Frege code, day 3
View Advent3.fr
module Advent3 where
{-
http://adventofcode.com/2017/day/3
-}
import Data.List
data Direction = Right | Up | Down | Left
derive Show Direction
@Dierk
Dierk / Advent2.fr
Created Dec 3, 2017
Advent of Frege code, day 2
View Advent2.fr
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
@Dierk
Dierk / Advent1.groovy
Created Dec 2, 2017
Advent of Groovy code, 2017, day 1
View Advent1.groovy
// 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
}
@Dierk
Dierk / Leak.fr
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)
@Dierk
Dierk / Balanced.purs
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
@Dierk
Dierk / Either.groovy
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<A,B> {
public <C> C match (Function <A,C> leftCase, Function <B,C> rightCase)
}
You can’t perform that action at this time.