Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Kramer jkramer

View GitHub Profile
View ö.p6
#!/usr/bin/env perl6
$*IN.slurp.&talk;
sub talk(Str $_) {
my @ös = |('Ö','ö') xx *;
for .lines {
for .comb.produce(&[~]) {
print "\r", @ös.shift, ' ', $_;
@jkramer
jkramer / Log::Dispatch.pm6
Last active Sep 26, 2016
Log::Dispatch for Perl 6
View Log::Dispatch.pm6
class Log::Dispatch {
enum Level <DEBUG INFO NOTICE WARNING ERROR CRITICAL ALERT EMERGENCY>;
class Output {
has Level $.level = DEBUG;
method format(Level $level, DateTime $ts, @args) {
$ts ~ ' [' ~ $level.lc ~ '] ' ~ @args>>.gist.join(' ')
}
@jkramer
jkramer / blurgh.p6
Created Aug 3, 2016
Blurgh Example
View blurgh.p6
use Blurgh;
class Blog::Post does Blurgh::Route[:('post')] {
state %posts;
state $next-post-id = 1;
# Matches "GET /post/123" (only if integer exists in %posts)
multi method get(Int:D $id where { %posts{$_}:exists }) {
$.render(:text(%posts{$id}));
}
@jkramer
jkramer / initphase.hs
Created Jan 12, 2016
CodinGame - APU: Init Phase
View initphase.hs
import Control.Monad
import Data.List
main = do
[ _, height ] <- replicateM 2 (fmap read getLine)
cells <- fmap concat (forM [0 .. height - 1] (\ y -> fmap (parseRow y) getLine))
forM cells (putStrLn . findNext cells)
where
parseRow y cells = map ((,) y . fst) $ filter ((==) '0' . snd) $ zip [0..] cells
@jkramer
jkramer / horse.hs
Created Jan 12, 2016
CodinGame - Horse Race
View horse.hs
import System.IO
import Control.Monad
import Data.List
main = do
hSetBuffering stdout NoBuffering -- DO NOT REMOVE
count <- fmap read getLine
strengths <- fmap sort (replicateM count (fmap read getLine))
@jkramer
jkramer / virus.hs
Last active Jan 12, 2016
CodinGame - Virus
View virus.hs
import Data.List
import Data.Ord
import System.IO
import Control.Monad
type Node = Int
type Gateway = Node
type Link = (Node, Node)
type Path = [Link]
@jkramer
jkramer / chasm.hs
Created Jan 11, 2016
CodinGame - Chasm
View chasm.hs
import System.IO
import Control.Monad
main = do
hSetBuffering stdout NoBuffering -- DO NOT REMOVE
[road, gap, platform] <- replicateM 3 (fmap read getLine)
forever $ do
[speed, x] <- replicateM 2 (fmap read getLine)
@jkramer
jkramer / temps.hs
Last active Jan 11, 2016
CodinGame - Temperatures
View temps.hs
import System.IO
import Data.List
import Data.Ord
main = do
hSetBuffering stdout NoBuffering
n <- fmap read getLine
if n == 0
then print 0
else getLine >>= print . head . sortOn abs . reverse . sort . map read . words
@jkramer
jkramer / thor.hs
Created Jan 11, 2016
CodinGame - Thor
View thor.hs
import System.IO
main = do
hSetBuffering stdout NoBuffering -- DO NOT REMOVE
[lightx, lighty, initialtx, initialty] <- fmap (map read . words) getLine
mapM_ (\ x -> getLine >> putStrLn x) (path initialtx initialty lightx lighty)
path x y lx ly =
zipWith (++) (direction "S" "N" (y - ly)) (direction "E" "W" (x - lx))
where
@jkramer
jkramer / mime.hs
Created Jan 11, 2016
CodinGame - MIME Type
View mime.hs
import Control.Monad
import Data.Char
import Data.Maybe
import Data.List
main = do
[n, q] <- replicateM 2 (fmap read getLine)
types <- replicateM n (fmap ((\ [x, y] -> (map toLower x, y)) . words) getLine)
replicateM q $ do
ext <- fmap (extension . map toLower) getLine