This file contains hidden or 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
import Control.Monad | |
import Data.Array | |
import Data.Char | |
import Data.Functor | |
import Data.List | |
import Data.Maybe | |
import Text.Printf | |
-- For storing the (steps of) the input path | |
data Step = TurnL | TurnR | Move deriving Show |
This file contains hidden or 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 Equations | |
class Container | |
def initialize(things) | |
@things = things | |
end | |
def width | |
[1, @things.reduce(0) { |s, t| s + t.width }].max | |
end |
This file contains hidden or 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
import Control.Arrow | |
import Control.Monad | |
import Data.Bool | |
import Data.Char | |
isSwCon = flip elem "bcdfghjklmnpqrstvwxz" . toLower | |
encodeC = uncurry (:) . (id &&& ('o':) . (:[]) . toLower) | |
main = interact $ foldMap $ (join $ bool (:[]) encodeC . isSwCon) |
This file contains hidden or 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
o_swamp = Array.new(10) { gets.strip.chars } | |
swamp = o_swamp.map {|r| r.clone} | |
start=(0..9).map {|y| (0..9).map {|x| [x, y]}}.flatten(1).select{|(x, y)| swamp[y][x]=='@'}.first | |
(puts "No starting location."; exit) if start == nil | |
(0..9).map {|y| (0..9).map {|x| | |
swamp[y][x] = 'N' if (x >= 9 || y >= 9 || [0, 1].product([0, 1]).any? {|(i, j)| | |
swamp[y + j][x + i] == 'O' })}} | |
queue = {start => []} | |
visited = [start] | |
until queue.empty? |
This file contains hidden or 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
#!/bin/bash | |
# mapwacom script | |
MAPWACOM=$(basename $0) | |
EXIT_CODE_BAD_DEVICE=82 | |
EXIT_CODE_NO_SUCH_DEVICE=80 | |
EXIT_CODE_NO_SUCH_SCREEN=81 | |
EXIT_CODE_MISSING_DEPS=83 | |
EXIT_CODE_USAGE=64 |
This file contains hidden or 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
import Control.Monad | |
import Data.Array | |
import Data.Char | |
import Data.List | |
import Data.Ord | |
import System.Environment | |
import System.IO | |
type GridLine = Array Int Char | |
type Grid = Array Int GridLine |
This file contains hidden or 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
#!/usr/bin/env ruby | |
class Checker | |
def initialize(words) | |
@words = words.map {|w| w.chomp.downcase}.select {|w| w.length > 1 || ['a', 'i'].include?(w)} | |
end | |
def resolve_part(sentence, accumulator) | |
if sentence.length > 0 | |
sentence = sentence.downcase.gsub(/[^a-z]/, '') |
This file contains hidden or 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
aardvark | |
aardwolf | |
aaron | |
aback | |
abacus | |
abaft | |
abalone | |
abandon | |
abandoned | |
abandonment |
This file contains hidden or 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
# Python code to generate an animation showing compound interest taking place with | |
# increasingly smaller terms. You will require matplotlib to run this code. | |
# You'll also require ImageMagick installed to generate the .gif animation. | |
# You can find this at http://usn.pw/blog/maths/2015/04/09/compound-interest | |
import matplotlib.pyplot as mp | |
import matplotlib.animation as ma | |
def gen_data(steps): | |
"""Creates the data to be plotted in this animation frame.""" |
This file contains hidden or 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
import Data.Char | |
import Data.List | |
import Control.Monad | |
squareFactor :: Int -> Int | |
squareFactor x = let desc n = n : desc (n - 1) | |
isqrt n = ceiling $ sqrt $ fromIntegral x | |
fact n m = n `mod` m == 0 | |
f1 = head $ filter (fact x) $ desc $ isqrt x | |
in x `div` f1 |