Skip to content

Instantly share code, notes, and snippets.

@dps
dps / gist:4189760
Created December 2, 2012 16:52
Python code to convert seconds since epoch to ISO format (for kml, xml datetime etc)
dt = datetime.datetime.utcfromtimestamp(seconds_since_epoch)
iso_format = dt.isoformat() + 'Z'
@dps
dps / parse.py
Created December 2, 2012 17:46
Alternate version of parse.py to do some sensible filtering of input data
#!/bin/python
"""
parse.py is a simple Python script which converts a feature file written by the Driver GUI
application (part of NNRCCar) into octave matrix files suitable for training the neural network.
This script expects to find the input file nnrccar.features in the current directory. It outputs
files y.dat and X.dat which are expected input to the octave script nnrcar.m
"""
if __name__ == '__main__':
@dps
dps / S.java
Last active December 10, 2015 08:28
class S{public static void main(String...a){int i=a[0].indexOf(48),j;char
k=48,c[]=a[0].toCharArray();if(i<0)System.out.print(c);else
for(;++k<58;){for(j=81;j-->0&&((j-i)%9*(j/9^i/9)*(j/27^i/27|j%9/3^i%9/3)
|c[j]^k)!=0;);c[i]=k;if(j<0)main("".valueOf(c));}}}
@dps
dps / K
Last active December 10, 2015 08:28
ShortestSudokuSolver in K
p:+{(=x)x}'p,,3/:_(p:,/'+:\9#'!9)%3
1@,/$*{$[&/x;,x;,/.z.s'@[x;i;:;]'&27=x[,/p i:x?0]?!10]}@.:'*.z.x;
@dps
dps / sudoku.c
Last active December 10, 2015 08:28
ShortestSudokuSolver in C written by Oli Charlesworth & Joel Hockey
main(int j,char**V){char*R=V[1],i=0,k=48,x;for(;*R>k;*++R||puts(R-i))++i;
for(;++k<58;*R=1)for(j=81;j--&&R[x=j-i]^k|x%9*(j/9-i/9)*
(j/27^i/27|j%9/3^i%9/3);)!j&&main(*R=k,V);}
#include<stdio.h>
int main(int j,char**V){char*R=V[1],i=0,k=48;for(;*R>k;*++R||
puts(R-i))++i;for(;++k<58;*R&&main(*R=k,V),*R=1)for(j=81;j
--;)*R*=R[j-i]-k||i/9^j/9&&i%9^j%9&&i/27^j/27|i%9/3^j%9/3;}
def r(a){def i=a.indexOf(48);if(i<0)print a else(('1'..'9')-(0..80).collect{
j->g={(int)it(i)==(int)it(j)};g{it/9}|g{it%9}|g{it/27}&g{it%9/3}?a[j]:'0'})
.each{i==0?r(it+a[i+1..-1]):r(a[0..<i]+it+a[i+1..-1])}}
z""a=a
z('0':b)t=foldr(++)""[z b$t++[x]|x<-['1'..'9'],notElem x
d]where{d=[h$m`mod`9+i*9|i<-a]++[h$m-j 9+i|i<-a]++[h$i*9`mod`26+m-j 3-j
27+j 9|i<-a];j=mod m;m=length t;h=(!!)$t++'0':b;a=[0..8]}
z(c:b)a=z b$a++[c]
main=do
a<-getLine
putStr$z a""
open String let rec s p=try let rec(%)=(mod)and i=index p '0'and b
j=i<>j&(i/9=j/9||i%9=j%9||i/27=j/27&i%9/3=j%9/3)&p.[i]=p.[j]||j<80&b(j+1)in
iter(fun c->p.[i]<-c;b 0||()=s p;())"948721536";p.[i]<-'0'with
_->print_string p;;s(read_line())
$_=$`.$_.$'.<>;split//;${/[@_[map{$i-($i="@-")%9+$_,9*$_+$i%
9,9*$_%26+$i-$i%27+$i%9-$i%3}0..8]]/o||do$0}for/0/||print..9