June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,23 @@
using Combinatorics
function solve(n::Vector{<:AbstractString}, pred::Vector{<:Function})
rst = Vector{typeof(n)}(0)
for candidate in permutations(n)
if all(p(candidate) for p in predicates)
push!(rst, candidate)
end
end
return rst
end
Names = ["Baker", "Cooper", "Fletcher", "Miller", "Smith"]
predicates = [
(s) -> last(s) != "Baker",
(s) -> first(s) != "Cooper",
(s) -> first(s) != "Fletcher" && last(s) != "Fletcher",
(s) -> findfirst(s, "Miller") > findfirst(s, "Cooper"),
(s) -> abs(findfirst(s, "Smith") - findfirst(s, "Fletcher")) != 1,
(s) -> abs(findfirst(s, "Cooper") - findfirst(s, "Fletcher")) != 1]
solutions = solve(Names, predicates)
foreach(x -> println(join(x, ", ")), solutions)