Skip to content

Instantly share code, notes, and snippets.

View skalahonza's full-sized avatar

Jan Skála skalahonza

View GitHub Profile
@skalahonza
skalahonza / chocolate.cpp
Last active May 17, 2018 20:13
Try to break chocolate into black and white pieces using minimal ammount of breakings
//TASK: https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=chocolate
#include <iostream>
#include <vector>
using namespace std;
#ifdef WIN32
int getchar_unlocked() { return getchar(); }
@skalahonza
skalahonza / alg02exam.cpp
Last active May 17, 2018 20:15
Dynamics programing, find ideal route between cinemas to see the most movies https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=cinemas
//TASK: https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=cinemas
#include <iostream>
#include <cstdio>
#include <vector>
#define arr std::vector
using namespace std;
#define min(a, b) ((a)<(b)?(a):(b))
@skalahonza
skalahonza / KeyNodes.cpp
Last active May 17, 2018 20:15
Find ideal path between improtant noes in cyclic graph https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=keyservers
//TASK: https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=keyservers
#include <vector>
#include <cstdio>
#include <stack>
#include <cstdlib>
#ifdef WIN32
int getchar_unlocked() { return getchar(); }
// TASK: https://cw.felk.cvut.cz/courses/a4b33alg/task.php?task=videocard
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
#if defined(WIN32) && !defined(UNIX)
@skalahonza
skalahonza / nim.hs
Created May 17, 2018 20:19
NIM game (5,4,3,2,1)
-- board type definition for game board
type Board = [Int]
initBoard :: Board
initBoard = [5,4,3,2,1]
-- player tpye definition
data Player = P1 | P2 deriving Show
nextP :: Player -> Player
nextP P1 = P2
nextP P2 = P1
@skalahonza
skalahonza / hanoi.rkt
Created May 23, 2018 11:29
Hanoi tower solver for three towers, return list of tupples (actsions) --> (from, to)
; list of actions
; - n počet disků
; move tower to c
; last stage to 2
(define (hanoi n a b c)
(cond
((eq? n 1) (list(cons a b))) ; jedno patro dám rovnou na b
(#t (append (hanoi (- n 1) a c b) (list(cons a b))
@skalahonza
skalahonza / map.rkt
Last active May 23, 2018 11:30
Trivia map implementation in scheme (really stupid and slow)
(define first car)
(define second cadr)
(define rest cdr)
(define (third list) (car (cddr list)))
(define fourth cadddr)
(define initmap '())
(define test
(list (list 'a 1) (list 'b 3))
@skalahonza
skalahonza / map.hs
Created May 23, 2018 11:32
Map implementation in Haskell (trivia stupid and slow)
type KeyVal a b = (a, b)
type Map a b = [KeyVal a b]
test = initmap ["a","b","c"] [1,2,3]
myZip (k:ks) (v:vs) = [(k,v)] ++ myZip ks vs
myZip [] [] = []
get_key (a, b) = a
get_val (a, b) = b
@skalahonza
skalahonza / queue.rkt
Created June 6, 2018 16:37
Queue implementation in scheme using 2 stacks.
(define first car)
(define second cadr)
(define rest cdr)
(define (third list) (car (cddr list)))
(define fourth cadddr)
(define (push v st)
(cons v st))
@skalahonza
skalahonza / queue.hs
Created June 6, 2018 16:37
Queue implementation in haskell using 2 stacks.
module QueueStacks where
type Stack v = [v]
push :: v -> Stack v -> Stack v
push value stack = value:stack
pop :: Stack v -> Stack v
pop [] = []
pop (_:newStack) = newStack