Skip to content

Instantly share code, notes, and snippets.

$(document).ready(function()
{
}
);
'''
The algorithm works as follows:
It simply checks all positions, with positions being marked with None (unknown) x (part of a ship) or o (no ship)
Because the description says that ships can't touch (including diagonally) you know for sure that if a position
has the part of a ship that the positions diagonal to it don't, like so:
o.o
.x.
o.o
@bouk
bouk / gist:3939072
Created October 23, 2012 14:31
Blah
# encoding: UTF-8
TodoItem = Struct.new(:done, :contents)
todos = []
if File.exists? 'list.td'
File.open('list.td') do |f|
todos = f.read.split("\n")
todos.map! { |item|
new_item = TodoItem.new
new_item.done, new_item.contents = item.split("|")
new_item
@bouk
bouk / gist:3939575
Created October 23, 2012 15:47
Proper todo list!
# encoding: UTF-8
module BoukeTodoApp
class TodoList
def initialize(filename)
@items = []
@filename = filename
self.load
end
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Needs program filename argument"
exit 1
fi
executable=`mktemp`
echo "Testing $1"
echo
@bouk
bouk / gist:4178208
Created November 30, 2012 20:06
Letterpress cheater
#include <string>
#include <algorithm>
#include <list>
#include <cstring>
#include <fstream>
#include <iostream>
#include <cctype>
#include <vector>
#include <set>
@bouk
bouk / gist:4178408
Created November 30, 2012 20:34
result
9,12d8
< celt
< celts
< ceres
< cerf
15,17d10
< cf
< ci
< cipro
23d15
77a78,79
> coke
> cokes
84a87
> collier
89a93
> colt
157a162
> cote
186a192
@bouk
bouk / bf.py
Created January 5, 2013 11:57
Brainfuck to C
mapping = {
'>': '++p;',
'<': '--p;',
'+': '++*p;',
'-': '--*p;',
'.': 'putchar(*p);',
',': '*p=getchar();',
'[': 'while (*p) {',
']': '}'
}
@bouk
bouk / dijkstra.hs
Created January 6, 2013 14:17
Dijkstra's algorithm implemented in Haskell. Example input: 5 7 0 1 2 0 2 7 0 3 6 1 4 6 1 2 3 2 4 5 3 4 1
import Data.List (insert)
fst3 (x,_,_) = x
snd3 (_,x,_) = x
trd3 (_,_,x) = x
toTuple2Int :: String -> (Int, Int)
toTuple2Int s = (read $ takeWhile (/=' ') s :: Int, read $ dropWhile (==' ') $ dropWhile (/=' ') s :: Int)
toTupleTuple2Int :: String -> (Int, (Int, Int))