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 / mushroom.hs
Created June 1, 2015 20:30
Mushroom eater puzzle
import System.IO
import Control.Monad
solve_v1 :: [Int] -> Int
solve_v1 (a:[]) = 0
solve_v1 (a:b:c) = (if a > b then a - b else 0) + (solve_v1 (b:c))
min_dist :: [Int] -> Int
min_dist (a:[]) = 0
min_dist (a:b:c) = if a > b then max (min_dist (b:c)) (a - b) else min_dist (b:c)
@itarato
itarato / li_reg.py
Created July 18, 2015 17:51
Linear regression of my weight
import numpy as np
import matplotlib.pyplot as plt
def plot_result(O):
sample_size = 50
linX = np.linspace(np.min(npdata[:,1]), np.max(npdata[:,1]), num=sample_size)
testX = np.concatenate((np.ones((sample_size, 1)), linX.reshape((sample_size, 1))), axis=1)
y = np.dot(testX, O)
plt.plot(linX, y[:,0], 'r-')
@itarato
itarato / lin_reg_norm_eq.py
Created July 18, 2015 18:15
Linear regression with normal equation
import numpy as np
import matplotlib.pyplot as plt
def plot_result(O):
sample_size = 50
linX = np.linspace(np.min(npdata[:,1]), np.max(npdata[:,1]), num=sample_size)
testX = np.concatenate((np.ones((sample_size, 1)), linX.reshape((sample_size, 1))), axis=1)
y = np.dot(testX, O)
plt.plot(linX, y[:,0], 'r-')
@itarato
itarato / logistic_regression_2d.py
Created July 19, 2015 11:42
2D Logistic Regression
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
fin = file('logreg.txt', 'r')
npdata = np.genfromtxt(fin, delimiter=',')
posData = npdata[npdata[:,2] == 1,:]
negData = npdata[npdata[:,2] == 0,:]
@itarato
itarato / neural_network_trainer.py
Created July 25, 2015 18:17
Small neural network trainer.
import numpy as np
class NeuralNetwork:
def __init__(self, data, layer_sizes):
"""
:param data: (M)x(N+1) matrix of inout data, Y is in last column.
:param iteration: Iteration count for training.
"""
self.data = data
@itarato
itarato / ch224i.go
Last active August 29, 2015 14:25
Challenge 224 intermediate
package main
import (
"bytes"
"io/ioutil"
"log"
)
func temp(...interface{}) {}
@itarato
itarato / ch224h.go
Created July 27, 2015 08:22
Challenge 224 hard - Langford strings
package main
import (
"log"
)
var (
n int = 8
l []int = make([]int, n*2)
used map[int]bool = make(map[int]bool)
@itarato
itarato / heighway_dragon.py
Created July 28, 2015 08:03
Heighway dragon fractal
import turtle
limit = 6
frac = 0.8
def draw(size, inv = False):
if size > limit:
t.lt(90)
@itarato
itarato / LondonTime.swift
Created August 6, 2015 08:15
Easy London time menu bar item for OS-X in Swift 2.
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var statusItem:NSStatusItem!
var timer:NSTimer!
func applicationDidFinishLaunching(aNotification: NSNotification) {
let statusBar = NSStatusBar.systemStatusBar()
@itarato
itarato / Genetic.py
Created August 13, 2015 07:40
Sort of genetic algorithm for an imaginary consumption-waste cycle process
import random
import Journey
import copy
__pool_size__ = 90
__survival_limit__ = 30
__mutation_rate__ = 5