/
Facility.jl
49 lines (44 loc) · 1.08 KB
/
Facility.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function distribute(f)
function fs(dict :: Dict, xs...)
for i in values(dict)
fs(i, xs...)
end
end
function fs(arr :: Array, xs...)
for i in arr
fs(i, xs...)
end
end
function fs(xs...)
f(xs...)
end
fs
end
function _inject(sym :: Symbol, dict :: Dict)
dict[string(sym)] = eval(sym)
end
inject = distribute(_inject)
function combination{T}(xs :: Array{T, 1})
if length(xs) < 2
[]
elseif length(xs) == 2
Array{Tuple{T, T}, 1}([(xs[1], xs[2])])
else
Array{Tuple{T, T}, 1}([[(xs[1], x) for x in xs[2:end]]..., combination(xs[2:end])...])
end
end
function combination(xs)
if length(xs) < 2
[]
elseif length(xs) == 2
[(xs[1], xs[2])]
else
[[(xs[1], x) for x in xs[2:end]]..., combination(xs[2:end])...]
end
end
function pair_computation(func :: Function, xs)
function compute(x)
print(string("Result for pair ", x[1], " and ", x[2], " is ", func(x[1], x[2]), ".\n"))
end
foreach(compute, combination(xs))
end