Skip to content

Instantly share code, notes, and snippets.

View arikrak's full-sized avatar

Ariel arikrak

View GitHub Profile
<>;for(<>){$s=0;$s+=(-1)**$_/(2*$_+1)for(0..$_-1);print"$s\n"}
#adr2370's solution to Leibniz Challenge
#https://github.com/adr2370/HackerRankBackToSchool/blob/master/Leibniz.py
#78 characters
for _ in [1]*input():print'%.15f'%sum((-1.)**i/(2*i+1)for i in range(input()))
/**
* Bead Ornaments - HackerRank Spring 2013 Hackathon
* Java bitmask DP solution
* Author: Jerry Ma (2013)
*
* Note that this solution uses BigInteger, which in some cases can add an unacceptable amount of overhead.
* This solution uses recursion with memoization to store the results for previously calculated states.
*/
import java.math.*;
@arikrak
arikrak / gist:4415743
Created December 30, 2012 22:39
Aleksander's solution to Sudoku code golf.
g=[1..9]
x=[(i,j)|i<-g,j<-g]
main=interact$(\s->unlines[unwords[show$s(i,j)!!0|j<-g]|i<-g]).head.s.i
s r=foldr(\p l->[m(p,n)r|r<-l,n<-r p])r x
e a b=div(a-1)3==div(b-1)3
m(p@(i,j),n)s q@(x,y)|p==q=[n]|x==i||y==j||e x i&&e y j=filter(/=n)$s q|True=s q
i s=[foldr m(\_->g)[w|w<-zip x$map read$words s,snd w>0]]
r=range
def f(s):
x=s.find('0')
if not~x:print s;exit()
[c in[(x-y)%18*(x/18^y/18)*(x/54^y/54|x%18/6^y%18/6)or s[y]for y in r(0,162,2)]or f(s[:x]+c+s[x+1:])for c in'123456789']
f('\n'.join(raw_input()for x in r(9)))
#Andy's final solution to Sudoku CodeGolf
r=range
t=r(9)
a=r(81)
def s(x):
if x<0:return 1
while(x
and
n[x]):x-=1
for l in t:
//Constantin’s shortened solution to Sudoku CodeGolf
#include<iostream>
#define O std::cout<<
#define F(i) for(int i=-1;++i<9;)
#define H G[i][j]
#define R return 0
#define Y ]==d+1
#define P F(i){F(j)
int G[9][9];
int s(){