Skip to content

Instantly share code, notes, and snippets.

@maksverver
maksverver / A.py
Created November 25, 2013 01:13
Facebook Hacker Cup 2014 Qualification Round solutions
#!/usr/bin/env python3
for case in range(int(input())):
N = int(input())
grid = [ input() for _ in range(N) ]
black = [ (r,c) for r in range(N) for c in range(N) if grid[r][c] == '#' ]
(r1,c1),(r2,c2) = black[0], black[-1]
size = r2 - r1 + 1
rect = [ (r1+i,c1+j) for i in range(size) for j in range(size) ]
print('Case #{}: {}'.format(case + 1, "YES" if rect == black else "NO"))
@maksverver
maksverver / A.py
Created December 8, 2013 18:00
Facebook Hacker Cup Round 1 solutions
from sys import stdin
for case in range(1, int(stdin.readline()) + 1):
L, N = stdin.readline().split()
N = int(N)
b = len(L)
n = 1
while b**n < N:
N -= b**n
n += 1
@maksverver
maksverver / random.in
Created May 4, 2014 16:57
Code Jam 2014 Round 1B - Problem B: New Lottery Game - random test data
100
141976667 113579661 391170920
451206059 627065946 749652418
676768891 736358526 311938017
982606110 301318993 547385207
162257290 810753529 528568774
125567510 312214706 921252360
338180051 673570368 438642619
435874729 155125087 572058812
315528113 500802098 91451398
#!/usr/bin/env python3
N = 22
e = 0
for p in sum([[1/N, i/N] for i in range(1,N)], []):
e = (1 + e*p)/p
print(e)
#!/usr/bin/env python3
import numpy as np
N = 22 # number of prisoners
M = 2 # number of switches
def state(n,m):
# n is the number of uncounted prisoners
# m is the value of the counter
@maksverver
maksverver / A.c
Last active August 29, 2015 14:13
Facebook Hacker Cup 2015 Round 1 Solutions
#include <stdio.h>
#define MAX 10000000
static int P[MAX+1];
int main() {
for (int i = 2; i <= MAX; ++i) {
if (!P[i]) for (int j = i; j <= MAX; j += i) P[j]++;
}
#include <algorithm>
#include <assert.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <utility>
#include <iostream>
using namespace std;
typedef unsigned long long uint64;
#include <assert.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <utility>
#include <iostream>
using namespace std;
typedef unsigned long long uint64;
Score: 110
4 0 4 3
0 5 5 0 4
4 5 0 5 5 0
3 0 5 5 0 5 4
4 5 0 5 5 0
0 5 5 0 4
4 0 4 3
Score: 110
#include <stdio.h>
#include <string.h>
/* Tiles are labeled clockwise starting from the top.
Colors are r(ed), y(ellow), g(reen), b(lue).
Uppercase for head, lowercase for butt. */
char tiles[9][4] = {
"yrGB",
"RbyG",
"BrbG",