Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Created August 9, 2014 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedeemon/44b33b07380ff4cb5fa2 to your computer and use it in GitHub Desktop.
Save thedeemon/44b33b07380ff4cb5fa2 to your computer and use it in GitHub Desktop.
Aug'14 FP(FP) contest entry of thedeemon
module main;
import std.stdio, std.range, std.algorithm, std.string, std.typecons;
enum W = 3;
enum H = 5;
char[W][H][10] symbols = [["111", "101", "101", "101", "111"], ["110", "010", "010", "010", "111"],
["111", "001", "111", "100", "111"], ["111", "001", "111", "001", "111"], ["101", "101", "111", "001", "001"],
["111", "100", "111", "001", "111"], ["111", "100", "111", "101", "111"], ["111", "001", "011", "010", "010"],
["111", "101", "111", "101", "111"], ["111", "101", "111", "001", "111"]];
class MatrixReader { // range of ranges of (line, pos, range of strings); holds just H lines in memory
File f;
string[H] lines;
int curline;
this(string fname) {
f = File(fname, "r");
foreach(i; 0..H) lines[i] = f.readln.strip;
}
auto front() { return iota(lines[0].length-W+1).map!(x => tuple(curline, x, iota(H).map!(y => lines[y][x .. x+W]))); }
bool empty() { return lines[H-1].length==0; }
void popFront() {
delete lines[0];
foreach(i; 0..H-1) lines[i] = lines[i+1];
lines[H-1] = f.readln.strip;
curline++;
}
}
int whatDigit(R)(R r) {
foreach(i; 0..10)
if (equal(r.save, symbols[i][])) return i;
return -1;
}
void main(string[] argv) {
foreach(t; new MatrixReader("matrix.txt").joiner.map!(t => tuple(t[0], t[1], whatDigit(t[2]))).filter!(t => t[2] >= 0))
writeln("line: ", t[0], " col: ", t[1], " digit: ", t[2]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment