Skip to content

Instantly share code, notes, and snippets.

View st0le's full-sized avatar

Gaurav Kamath st0le

View GitHub Profile
@st0le
st0le / Lazer-Maze.md
Last active February 1, 2016 20:45
Facebook Hacker Cup - Lazer Maze

#Laser Maze

###55 points

Standard mazes lose their mystery as one grows older. But throw in some lasers, and suddenly you've got yourself a recipe for cross-generational appeal. The object in any maze is to find your way from your starting point to some goal. In a Laser Maze you must additionally contend with laser turrets.

A laser turret is a stationary pillar that both blocks your movement and fires lasers from one side. Every time you take a step (either up, down, left, or right), every laser turret in the maze then rotates 90 degrees clockwise, and then shoots a momentary laser blast in the direction that it is facing. Needless to say, if you find yourself in the path of one of these lasers, you won't be around long enough to find a way out. A wall is a stationary pillar that blocks your movement, but does not fire lasers.

Lasers are powerful, but they do not pass through walls or laser turrets. The laser turrets respond to your movements, so you can't stand still and wait for the turrets to turn. If

import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

#New Year's Resolution

###30 points

Alex's New Year's resolution for 2015 is to eat healthier foods. He's done some research and has found out that calories come from three main sources, called macronutrients: protein, carbohydrates, and fat. Alex wants to get the right balance of protein, carbohydrates, and fat to have a balanced diet. For each available food, Alex can only choose to eat it or not eat it. He can't eat a certain food more than once, and he can't eat a fractional amount of a food.

###Input

Input begins with an integer T, the number of test cases. For each test case, the first line consists of three space-separated integers: GP, GC, and GF, which represent the amount of protein, carbohydrates, and fat that Alex wants to eat. The next line has the number of foods for that test case, an integer N. The next N lines each consist of three space-separated integers: P, C, and F, which represent the amount of protein, carbohydrates, and fat in that food, respectively.

import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
new Solution().go();
}
@st0le
st0le / Cooking-The-Book.md
Last active August 29, 2015 14:13
Easy problem of FB Hacker Cup - 2015

#Cooking the Books

###15 points

Every business can make use of a good accountant and, if they're not big on following the law, sometimes a bad one. Bad accountants try to make more money for their employers by fudging numbers without getting caught.

Sometimes a bad accountant wants to make a number larger, and sometimes smaller. It is widely known that tax auditors will fail to notice two digits being swapped in any given number, but any discrepancy more egregious will certainly be caught. It's also painfully obvious when a number has fewer digits than it ought to, so a bad accountant will never swap the first digit of a number with a 0.

Given a number, how small or large can it be made without being found out?

@st0le
st0le / Inversion Count - Merge Sort
Created August 30, 2014 05:12
Inversion Count - Merge Sort
def inversionCount_2(A):
def inversionCount_2(A,l,r):
if l >= r: return 0
m = (l + r) / 2
# recurse and store inversion counts for the halfs
invCount = inversionCount_2(A,l,m) + inversionCount_2(A,m + 1,r)
merged = []
i,j = l,m + 1
while i <= m and j <= r:
if A[i] < A[j]:
@st0le
st0le / Naive Inversion Count
Created August 30, 2014 05:06
Inversion Count - Using Naive Algorithm
def inversionCount_1(A):
c = 0
for i in xrange(len(A)):
for j in xrange(i + 1,len(A)):
if A[i] > A[j]:
c += 1
return c
@st0le
st0le / gist:b77c4fb3bfd412ba42fe
Last active August 29, 2015 14:03
Add to linked list
private Node Add(Node a, Node b)
{
Node c = null, answer = null;
int carry = 0;
while (a != null && b != null)
{
carry += a.digit + b.digit;
if (c == null)
answer = c = new Node(carry % 10, null);
else
@st0le
st0le / NonTransitiveComparator
Created June 6, 2014 22:25
Finding Minimum with a Non-Transitive Comparator
using System;
namespace SharpFoo
{
class Program
{
private Random rnd = new Random();
static void Main(string[] args)
{