Skip to content

Instantly share code, notes, and snippets.

View .vimrc
"enter current millenium
set nocompatible
syntax on
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
View exercise_blanks.py
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import os
from torch.utils.data import DataLoader, TensorDataset, Dataset
import operator
import data_loader
import pickle
View test.py
from search import SearchProblem, a_star_search
class NiceProblem(SearchProblem):
def __init__(self):
self.node = (0,0)
self.expanded = 0
def get_start_state(self):
"""
Returns the start state for the search problem
View runall.py
from multiprocessing.dummy import Pool
from subprocess import check_output
NUMBER_OF_PROCESSES = 4
to_run = [
'-p tiny_set.txt -s 4 7 -z fill',
'-p tiny_set.txt -f bfs -s 4 7 -z fill',
'-p tiny_set_2.txt -f bfs -s 6 6 -z corners',
'-p tiny_set_2.txt -f ucs -s 6 6 -z corners',
View solve.hs
data List a = Node a (List a) | Empty -- Recursive
data Maze = Maze {grid::Grid, visited::Path, stack::Stack}
type Path = List Cell
--type Stack = [Cell]
type Stack = List Cell
type Grid = [[Char]]
-- Linked List --
push :: List a -> List a -> List a
push Empty ys = ys
@lironsade
lironsade / algo.py
Last active Jan 6, 2019
Important algorithms for interviews
View algo.py
def mergeSort(A):
mid = len(A) // 2
if len(A) > 1:
left = mergeSort(A[:mid])
right = mergeSort(A[mid:])
# merge
i = j = k = 0
while i < len(left) and j < len(right):
if left[i] < right[j]:
View exam2.hs
data MyList a = Empty | List (a, (MyList a)) deriving (Show, Eq)
instance Functor MyList where
fmap _ Empty = Empty
fmap f (List (x, xs)) = List (f x, fmap f xs)
flatten :: (MyList (MyList (a))) -> (MyList a)
flatten Empty = Empty
flatten (List (x, xs)) = myConcat x (flatten xs)
View test.hs
import Control.Monad.Writer
type Tower = ([Int], Char)
data Hanoi = Hanoi Tower Tower Tower deriving Show
move :: Hanoi -> Hanoi
move (Hanoi a b c) = Hanoi (init (fst a), snd a) b ((fst c) ++ [last (fst a)], snd c)
solve :: Hanoi -> Writer [String] Hanoi
solve (Hanoi a b c) = solve' (length (fst a)) (Hanoi a b c)
View testDB.py
####################################################
# Measure times of executions for DB's External Sort
# Assumptions:
# - Your ExternalMemory.jar is in /tmp
# - fileGenerator.jar in /tmp
# What does it do?
# Generates the files 250, 500, 750, 1000 in /tmp.
# They should be in about the size of their name.
# Create the "/tmp/sortemp" directory if not exists
# Measures running time of your program for each
View test.hs
data NiceTree = R | B | Node [NiceTree] deriving (Show, Eq)
exmpl = Node [Node [R, B, B], Node [B], Node [R, R], Node [B]]
eval :: NiceTree -> NiceTree
eval R = R
eval B = B
eval (Node xs)
| res == 0 = error "can't compute tie"
| res > 0 = R
You can’t perform that action at this time.