Skip to content

Instantly share code, notes, and snippets.

(defn tree
[arr]
(if (empty? arr)
[]
[[(tree (rest arr))]
[(tree (reverse
(rest
(reverse arr))))]]))
@mzdravkov
mzdravkov / schedule.php
Last active August 29, 2015 14:24
scheduling problem in php
<?php
$day_start = 7;
$day_end = 19;
$positions = 4;
$people = 8;
$position_hours = 8;
$work_hours = 20;
$busy = [[[3,16,19]],
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
@mzdravkov
mzdravkov / schedule3.jl
Created June 21, 2015 15:08
schedule problem 5
# our schedule is 3D array with (5 workdays, W workhours, P positions) for dimensions
day_start = 7
day_end = 19
positions = 4
people = 8
position_hours = 8
work_hours = 20
# generate random schedule of each intern's busy times
busy = ntuple(people, i -> fill((0,0,0), rand(0:7)))
@mzdravkov
mzdravkov / schedule3.jl
Created June 21, 2015 14:14
schedule problem 4
# our schedule is 3D array with (5 workdays, W workhours, P positions) for dimensions
day_start = 9
day_end = 17
day_hours = day_end - day_start
positions = 4
people = 8
position_hours = 8
work_hours = 20
new_schedule() = fill(0, 5, day_hours, positions)
@mzdravkov
mzdravkov / schedule2.jl
Created June 15, 2015 10:56
schedule problem 3
function pickrand(col)
index = rand(1:length(col))
col[index]
end
function isbusy(intern, busy, day_hours, day, hour)
for i = 1:length(busy[intern])
if busy[intern][i][1] == day && (busy[intern][i][2]-day_hours) <= hour < (busy[intern][i][3]-day_hours)
return true
end
@mzdravkov
mzdravkov / schedule2.jl
Last active August 29, 2015 14:23
schedule problem 2
function pickrand(col)
index = rand(1:length(col))
col[index]
end
function isbusy(intern, busy, day_hours, day, hour)
for i = 1:length(busy[intern])
if busy[intern][i][1] == day && (busy[intern][i][2]-day_hours) <= hour < (busy[intern][i][3]-day_hours)
return true
end
@mzdravkov
mzdravkov / schedule.jl
Last active August 29, 2015 14:22
schedule problem
# our schedule is 3D array with (5 workdays, 8 workhours, 4 positions) for dimensions
schedule = Array(Int, 5, 8, 4)
day = hour = position = 0
while true
schedule = Array(Int, 5, 8, 4)
remaining_hours = fill(20, 8)
bad_schedule = false
for day = 1:5, hour = 1:8, position = 1:4
intern = rand(1:8)
nodes = %w[1 2 3 4 5 6 7 8]
constraints = {"1" => %w[3 6],
"2" => %w[1],
"4" => %w[3],
"5" => %w[3 4],
"6" => %w[1 3]}
edges = nodes.combination(2).to_a
nodes.map { |n| constraints[n].map { |c| edges.delete([n, c].sort) } if constraints[n] }
@mzdravkov
mzdravkov / math1
Last active August 29, 2015 14:06
2003's math olympiad
Can one find 4004 positive integers such that the sum of any 2003 of them is
not divisible by 2003?
Proof?:
Suppose we have 4004 positive integers (lets call them the set W), so that 2002 of them (the set T1) are of the type n∙2003 + 1 (where n is different for each of them) and 2002 of them (the set T2) are of the type m∙2003 + 2 (where m is different for each of them).
When we choose 2003 numbers from W, there will be an even number of T1s and an odd number of T2s or an odd number of T1s and an even of T2s.
So the two cases are:
Case 1: