Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tom-galvin on github.
  • I am tomgalvin (https://keybase.io/tomgalvin) on keybase.
  • I have a public key ASAcaRoM2dchScU13kI0r1BUPTcwtzx7W0nKKtSIb209ugo

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am Quackmatic on github.
* I am tomgalvin (https://keybase.io/tomgalvin) on keybase.
* I have a public key whose fingerprint is 1F76 2A3A 6E30 69E8 1347 87C8 C8CA CDEE 4376 AB7D
To claim this, I am signing this object:
import java.util.ArrayList;
/**
* Utility class for nonexistent string manipulation libraries in the
* LeJOS JVM implementation. These are only re-implemented here, because
* they are not present in the {@link String} class in LeJOS, and we cannot
* use extension methods in Java as you can in C#.
*
* @author Tom Galvin
*/
@tom-galvin
tom-galvin / c-delannoy.fs
Last active December 28, 2015 19:00
Moving Up in life.. and to the Right
open System
/// Returns a tuple of the first two elements of an array.
let head2 (a : 'a array) = a.[0], a.[1]
/// Reads a line from standard input, and verifies it is of the given length.
let readln length =
let line = Console.ReadLine() in
if line.Length = length then line else sprintf "Invalid line length: %s" line |> failwith
@tom-galvin
tom-galvin / c-spiral.cs
Created August 10, 2015 13:09
DailyProgrammer Challenge #227e Solution (Square Spirals)
using System;
using System.Linq;
namespace ChallengeSpiral
{
class Program
{
static long ToPoint(long x, long y, long s)
{
if(x <= y)
@tom-galvin
tom-galvin / c-go.hs
Created June 23, 2015 20:41
DailyProgrammer Challenge #220i Solution (It's Go time!)
import Control.Monad
import Data.Array
import Data.Char
import Data.List
import Data.Ord
data Cell = Player | Opponent | None | Oob deriving Eq
data Color = Black | White deriving Eq
type Grid = Array Int (Array Int Cell)
@tom-galvin
tom-galvin / 18-12.txt
Created May 18, 2015 12:32
18-sad cycle for 12
191114254310527751, 153363044411515149, 150207915385632828, 205879249247448225, 339482799082532022, 487945001088186328, 241900553922889638, 504436360265747128, 21583741903634855, 187864988563815914, 392100563873560657, 171681986126627738, 209429311833794865, 488046629763545050, 188068176421788502, 93535823073834302, 187759546352928746, 341318010238725514, 37664978613144898, 357794180121541528, 189391841430479115, 487945138138408596, 373984674514307481, 191114323803796890, 488042746346540547, 39496786227195997, 773579819506232907, 474921148918686076, 357794179346962695, 605576229460320924, 302130131283867726, 39488745678590089, 525707654302319824, 171479003265348177, 174728201066113539, 171572865107746466, 24942059561544313, 300302550295735745, 153370605861410635, 19959005950932762, 752214594519316123, 301930826454954868, 354443422363845607, 19853906562850439, 486527336409674897, 341412009907497760, 455270913187509969, 621762840048924028, 205969570496171139, 603846186798844836, 242201488202264341, 361306322425
@tom-galvin
tom-galvin / c-stepstring.hs
Last active August 29, 2015 14:20
DailyProgrammer Challenge #213h Solution (Stepstring Discrepancy)
import Control.Arrow
import Data.Char
import Data.List
import Data.Ord
import Text.Printf
(c0, c1) = ('a', 'b')
accum s = 0 : accumR 0 s where
accumR _ [] = []
@tom-galvin
tom-galvin / c-typist.rb
Created May 5, 2015 12:57
DailyProgrammer Challenge #213i Solution (The Lazy Typist)
class Keyboard
def initialize(rows)
@keys, @spaces, @shifts = {}, [], []
rows.each.with_index do |row, j|
row.each_char.with_index do |c, i|
unless c == '.'
@keys[c] = [] unless @keys[c]
@keys[c] << [i, j]
end
end
@tom-galvin
tom-galvin / c-unhappy.hs
Created May 2, 2015 22:27
DailyProgrammer Challenge Solution (Sad Cycles)
import Control.Applicative
import Data.Char
import Data.List
iterateU f (x:xs) | x `elem` xs = x : (reverse $ takeWhile (/= x) xs)
| otherwise = iterateU f $ f x : x : xs
main = do power <- read <$> getLine
num <- getLine
putStrLn $ intercalate ", " $