Skip to content

Instantly share code, notes, and snippets.

@tom-galvin
tom-galvin / c-reverse-maze.hs
Last active August 29, 2015 14:20
DailyProgrammer Challenge Solution (Reverse Maze Pathfinding)
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
@tom-galvin
tom-galvin / c-tex.rb
Last active August 29, 2015 14:20
DailyProgrammer Challenge Solution (TeXSCII)
module Equations
class Container
def initialize(things)
@things = things
end
def width
[1, @things.reduce(0) { |s, t| s + t.width }].max
end
@tom-galvin
tom-galvin / c212e.hs
Last active August 29, 2015 14:20
DailyProgrammer Challenge #2012e Haskell Solution (Rövarspråket)
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)
@tom-galvin
tom-galvin / c211i.rb
Last active August 29, 2015 14:19
DailyProgrammer Challenge #211i Solution (Ogre Maze)
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?
@tom-galvin
tom-galvin / mapwacom
Last active April 21, 2025 12:59
Mapwacom script
#!/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
@tom-galvin
tom-galvin / c209h.hs
Last active August 29, 2015 14:18
DailyProgrammer Challenge #209h Haskell Solution (Unpacking a Sentence in a Box)
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
@tom-galvin
tom-galvin / c209h.rb
Created April 10, 2015 15:01
DailyProgrammer Challenge #209h Solution (Unpacking a Sentence in a Box)
#!/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]/, '')
@tom-galvin
tom-galvin / words
Created April 10, 2015 14:24
A better word list
aardvark
aardwolf
aaron
aback
abacus
abaft
abalone
abandon
abandoned
abandonment
@tom-galvin
tom-galvin / plot-compound-interest.py
Last active April 28, 2022 08:46
A Python/matplotlib script to animate compound interest with an increasing number of terms
# 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."""
@tom-galvin
tom-galvin / c209i.hs
Created April 8, 2015 14:40
DailyProgrammer Challenge #209i Solution (Packing a Sentence in a Box)
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