This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for case in range(input()): | |
print "Case #%d:" % (case+1) | |
r,c,m = map(int, raw_input().split()) | |
flip = r>c | |
if flip: c,r = r,c | |
rem = r*c-m | |
if r==1 or rem==1: | |
res = () | |
elif r>1 and rem in {2,3,5,7} or (r==2 and rem%2): | |
print "Impossible" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sudoku solver for Udacity CS258. | |
def get_groups(): | |
q = lambda f:[[f(i,j) for j in range(9)] for i in range(9)] | |
return q(lambda i,j:(i,j)) + q(lambda i,j:(j,i)) + q(lambda i,j:(i/3*3+j/3,i%3*3+j%3)) | |
# I think this is more readable than the one-liner: | |
# >> return [l for i in range(9) for l in zip(*[[(i,j),(j,i),(i/3*3+j/3,i%3*3+j%3)] for j in range(9)])] | |
def check_sudoku(grid): | |
if len(grid) != 9: return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"":d; | |
[]:VAR; | |
{|2>~2base(;{" \t"=}%n+}:LB; | |
{|~F}:N;{..abs<\2base+{" \t"=}%+"\n"+}:F; | |
{n%{{1<"#"=!}1$!!*},{"|"%~}%{ | |
:|' '/0=.58,48>-\,1>{'-'-}*"PUSH"or:I;[ | |
["PUSH"{" "N}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a response to http://swizec.com/blog/strangest-line-of-python-you-have-ever-seen | |
# Since the only input in golfscript is stdin, we'll assume the strings to test are on the last line of stdin, separated by spaces. | |
# 82B -- The first implementation avoids making assumptions about the data, prints one line for each input. Formatted as e.g. `ab YES' | |
n%)" ":s/\:|;{s|(s/(;3$1/{:c;{s+c+2|>\`{?)}+,~}%{.-1%s?~)>}%}/\0=s/&!"YNEOS">2%n}/ | |
# 71B -- Simplifying the output and printing just the matching strings saves 11B. Formatted as e.g. `["ab" "abb"]' | |
n%)" ":s/\:a;{a(s/(;@1/{:c;{s+c+2a>\`{?)}+,~}%{.-1%s?~)>}%}/\0=s/&!!},p |