Skip to content

Instantly share code, notes, and snippets.

@xtoss
xtoss / magic_trick.py
Created April 13, 2014 02:43
Python solution for Problem A. Magic Trick - Google Code Jam 2014
# google code jam 2014
# Problem A. Problem A. Magic Trick
# https://code.google.com/codejam/contest/2974486/dashboard#s=p0
# Author: jamie.xu - https://github.com/eytoss
PROBLEM_ID = "A" # A B or C
PROBLEM_SIZE = "small"
def run():
"""I/O handler"""
@xtoss
xtoss / cookie_clicker.py
Created April 13, 2014 02:41
Python solution for Problem B. Cookie Clicker - Google Code Jam 2014
@xtoss
xtoss / deceitful_war.py
Created April 13, 2014 02:35
Python solution for Problem D. Deceitful War - Google Code Jam 2014
# Google Code Jam 2014
# Problem D. Deceitful War
# https://code.google.com/codejam/contest/2974486/dashboard#s=p3
# Author: jamie.xu - https://github.com/eytoss
import copy
PROBLEM_ID = "D" # A B or C
PROBLEM_SIZE = "large"
def run():
"""I/O handler"""
@xtoss
xtoss / minesweeper_master.py
Created April 13, 2014 02:01
Python solution for Problem C. Minesweeper Master - Google Code Jam 2014
# Google Code Jam 2014
# Problem C. Minesweeper Master
# https://code.google.com/codejam/contest/2974486/dashboard#s=p2
# Author: jamie.xu - https://github.com/eytoss
PROBLEM_ID = "C" # A B or C
PROBLEM_SIZE = "large"
# `impossible` look up tables, used as short cut
# G4[9] == 1 means 9 mines for a 4 by 4 grid is impossible
# actually in my algorithm, it might just check G3[2] depending where I put this short-cut
@xtoss
xtoss / Consonants.py
Created May 12, 2013 13:40
Python solution for google code jam 2013 Round 1C - Problem A - Consonants: https://code.google.com/codejam/contest/2437488/dashboard#s=p0
"""
Used to solve google code jam 2013 Round 1C - Problem A - Consonants
Owner: Jamie Xu - [email protected]
"""
def Consonants():
in_f = open('A-small-attempt0.in', 'r')
out_f = open('output.txt', 'w')
num_of_case = int(in_f.readline().rstrip('\n'))
for i in range(1, num_of_case+1):
solve_case(in_f, out_f, i)
@xtoss
xtoss / Pogo.py
Created May 12, 2013 13:34
Python solution for google code jam 2013 Round 1C - Problem B - Pogo: http://code.google.com/codejam/contest/2437488/dashboard#s=p1
"""
Used to solve google code jam 2013 Round 1C - Problem B - Pogo
Owner: Jamie Xu - [email protected]
"""
import math
def Pogo():
in_f = open('A-large.in', 'r')
out_f = open('output.txt', 'w')
num_of_case = int(in_f.readline().rstrip('\n'))
for i in range(1, num_of_case+1):
@xtoss
xtoss / output.txt
Created May 4, 2013 18:32
Result for Large Data Set for Google code jam 2013 Round 1B - Problem A - Osmos
Case #1: 0
Case #2: 0
Case #3: 0
Case #4: 1
Case #5: 1
Case #6: 20
Case #7: 3
Case #8: 20
Case #9: 20
Case #10: 5
@xtoss
xtoss / A-large.in
Created May 4, 2013 18:31
Large Data Set for Google code jam 2013 Round 1B - Problem A - Osmos
100
3 8
5 6 9 4 8 2 1 7
3 1
2
3 100
2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
3 100
1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
1000000 1
@xtoss
xtoss / Osmos.py
Created May 4, 2013 18:30
My solution for Google code jam 2013 Round 1B - Problem A - Osmos
"""
Used to solve google code jam 2013 Round 1B - Problem A - Osmos
Owner: Jamie Xu - [email protected]
"""
def osmos():
"""
File Handle
"""
in_f = open('A-large.in', 'r')
out_f = open('output.txt', 'w')
@xtoss
xtoss / D-small-attempt4_output.txt
Created April 14, 2013 04:14
The question stated there will always be a TOTAL_NUM_OF_KEYS in each chest description line while I was treating it as key type. This output was generated after the code fixing, which was as simple as removing the TOTAL_NUM_OF_KEYS info from chest_key_list.
Case #1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Case #2: 1 2 7 3 9 10 4 12 14 5 11 15 6 8 13
Case #3: 1 2 3 4 5
Case #4: 2 1 3 7 6 12 4 5 8 13 9 10 11 14 15 16 17 18 19 20
Case #5: 2 1
Case #6: 1
Case #7: IMPOSSIBLE
Case #8: IMPOSSIBLE
Case #9: 1 2 3 4 5
Case #10: 1 2 5 7 11 12 14 17 19 20 3 4 6 8 9 10 13 15 16 18