Skip to content

Instantly share code, notes, and snippets.

View itarato's full-sized avatar

Peter Arato itarato

  • Montreal, Canada
View GitHub Profile
@itarato
itarato / math_dice.py
Created January 2, 2015 22:37
Math dice problem
import sys
import random
def solve(A, total, current, solution):
if total == 0:
print(' + '.join([str(i) for i in solution]) + ' = ' + str(sum(solution)))
return
if current >= len(A):
@itarato
itarato / ch196hard.py
Created January 11, 2015 22:03
r/DailyProgrammer 196 hard
OP_LEFT_FIRST = 0
OP_LEFT_SECOND = 1
OP_ORDER = {'.': -1, '<': 0, '>': 0, '+': 1, '-': 1, '*': 2, '/': 2, '%': 2, '^': 3, '&': 3, '|': 3}
def solve(test):
items = []
ops = []
for elem in test['eq']:
if is_num(elem):
@itarato
itarato / ch197e.hs
Created January 14, 2015 18:49
Challenge 197 easy
validISBN x y
| x > 9 = validISBN (reduce (fromIntegral x)) (extra (fromIntegral x) y)
| otherwise = elevens (fromIntegral x) y
reduce x = round(x) `mod` (tens x)
lvl x = floor $ logBase 10 x
extra x y = y + ((round(x) `div` (tens x)) * ((lvl x) + 1))
@itarato
itarato / en2hu.py
Created January 19, 2015 12:47
Translate EN -> HU
import sys
import urllib2
import re
import HTMLParser
def lookup(word_en, limit = 10):
url = 'http://szotar.sztaki.hu/search?fromlang=eng&tolang=hun&searchWord=' + word_en + '&langcode=hu&u=0&langprefix=&searchMode=WORD_PREFIX&viewMode=full&ignoreAccents=0'
result = urllib2.urlopen(url)
h = HTMLParser.HTMLParser()
@itarato
itarato / repocrawler.go
Created January 20, 2015 16:47
Special GitHub repo crawler
// The script requires your GitHub token.
// It fetches the teams for a given organisation.
// Then goes through one team's repos.
// Config file format:
// {
// "personalToken": "TOKEN_FROM_GITHUB",
// "orgName": "SELECTED_ORG_NAME",
// "teamName": "SELECTED_TEAM_NAME"
// }
@itarato
itarato / tester.php
Last active August 29, 2015 14:14
Drupal playground module.
<?php
/**
* @file
*
* SANDBOX.
*/
/**
* Implements hook_boot().
*/
@itarato
itarato / fbch1.go
Created February 8, 2015 19:25
Facebook Hacker Cup 2015 Qualification Round 1/3
package main
import (
"log"
)
func solve(digits []uint, cmp func(uint, uint) bool) []uint {
currentPos := 0
replacePos := 0
foundPos := -1
@itarato
itarato / TemplateFactory.java
Created February 14, 2015 22:46
Trying to find a way for a factory that accepts an interface as an input.
import java.lang.reflect.Method;
public class Main {
public static void main(String[] args) {
AnimalParam ap = new AnimalParam("A");
AnimalFactory<Animal, AnimalParam> af = new AnimalFactory<Animal, AnimalParam>();
Animal a = af.create(Animal.class, AnimalParam.class, ap);
System.out.println(a);
BirdParam bp = new BirdParam("B", "C");
@itarato
itarato / crop.py
Created March 20, 2015 09:00
CH206INT - Crop
import math
crop = []
width = 0
height = 0
diameter = 0
total_cache = []
offset_cache = []
@itarato
itarato / diet.py
Created March 22, 2015 12:47
Diet. FB, ch, mid.
found = False
def solve(results, parts, sums, idx):
global found
if found:
return True
if sums == results:
found = True