Skip to content

Instantly share code, notes, and snippets.

View coyotebush's full-sized avatar

Corey Ford coyotebush

View GitHub Profile
doCase n = do
s <- getLine
putStrLn $ "Case #" ++ show n ++ ": "
main = do
n <- getLine
mapM_ doCase [1..read n]
@coyotebush
coyotebush / BalancedSmileys.hs
Last active December 11, 2015 22:29
My solutions to the 2013 Facebook Hacker Cup qualification round.
balanced :: Int -> Int -> String -> Bool
balanced hi _ _ | hi < 0 = False
balanced hi lo xs | lo < 0 = balanced hi 0 xs
balanced _ lo "" = lo == 0
balanced hi lo ('(':xs) = balanced (hi + 1) (lo + 1) xs
balanced hi lo (')':xs) = balanced (hi - 1) (lo - 1) xs
balanced hi lo (':':'(':xs) = balanced (hi + 1) lo xs
balanced hi lo (':':')':xs) = balanced hi (lo - 1) xs
balanced hi lo (_:xs) = balanced hi lo xs
host unix?
hostname %h.csc.calpoly.edu
user cjford
#!/usr/bin/runhaskell
import Control.Applicative
import Data.List
import Data.Maybe
import qualified Data.Set as S
type Board = [[Char]]
type Point = (Int, Int)
data Direction = N | S | E | W deriving (Eq, Ord)
#include <iostream>
#include <list>
#include <sstream>
using namespace std;
int to_val(char face) {
switch (face) {
case 'A': return 14;
case 'K': return 13;
#!/bin/sh
while [ -d ../.svn ]; do cd ..; done
svn update
#!/usr/bin/python
def incnums(mx, amt, nums):
if len(nums) == 0:
nums.append(-1)
(q, r) = divmod(nums[-1] + amt, mx + 1)
nums.pop()
if q > 0:
incnums(mx, q, nums)
nums.append(r)
/* Fetch data from GitHub Archive using Google's BigQuery */
select actor, repository_language, count(repository_language) as pushes
from [githubarchive:github.timeline]
where type='PushEvent'
and repository_language != ''
and PARSE_UTC_USEC(created_at) >= PARSE_UTC_USEC('2012-01-01 00:00:00')
and PARSE_UTC_USEC(created_at) < PARSE_UTC_USEC('2013-01-01 00:00:00')
group by actor, repository_language;
SELECT actor, repository_owner, repository_name, repository_language, count(repository_name) AS pushes
FROM [publicdata:samples.github_timeline]
WHERE type='PushEvent'
AND repository_url IN
(SELECT repository_url FROM
(SELECT repository_url, MAX(repository_watchers)
FROM [publicdata:samples.github_timeline]
GROUP BY repository_url
HAVING MAX(repository_watchers) > 1000))
AND PARSE_UTC_USEC(created_at) >= PARSE_UTC_USEC('2012-01-01 00:00:00')
SELECT user, top_repos.repository_url, repository_language, SUM(weight) as weight FROM
(SELECT repository_url, MAX(repository_watchers)
FROM [publicdata:samples.github_timeline]
GROUP BY repository_url
HAVING MAX(repository_watchers) > 1000) AS top_repos
JOIN EACH
(SELECT user, repository_url, repository_language, weight FROM
(SELECT actor AS user, repository_url, repository_language,
INTEGER(COUNT(repository_url)) AS weight
FROM [publicdata:samples.github_timeline]