Skip to content

Instantly share code, notes, and snippets.

View jkramer's full-sized avatar

Jonas Kramer jkramer

View GitHub Profile
@jkramer
jkramer / Mojo-UserAgent-OAuth.pm
Last active January 5, 2016 14:16
Two-legged OAuth for Mojo::UserAgent
package Mojo::UserAgent::OAuth;
use Mojo::Base -base;
use Mojo::URL;
use Net::OAuth;
our $VERSION = 0.01;
@jkramer
jkramer / 6210001000.p6
Last active January 6, 2016 11:05
A program that prints the number 6210001000 really fast.
#!/usr/bin/env perl6
my Int @digits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
loop {
my $changed = False;
for [0..9] -> $digit {
my $count = @digits.grep($digit).elems;
@jkramer
jkramer / mime.hs
Created January 11, 2016 14:02
CodinGame - MIME Type
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
@jkramer
jkramer / thor.hs
Created January 11, 2016 14:04
CodinGame - Thor
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 / temps.hs
Last active January 11, 2016 14:06
CodinGame - Temperatures
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 / chasm.hs
Created January 11, 2016 15:26
CodinGame - Chasm
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 / virus.hs
Last active January 12, 2016 11:20
CodinGame - Virus
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 / horse.hs
Created January 12, 2016 11:55
CodinGame - Horse Race
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 / initphase.hs
Created January 12, 2016 12:58
CodinGame - APU: Init Phase
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 / blurgh.p6
Created August 3, 2016 21:58
Blurgh Example
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}));
}