Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Power-set/Julia/power-set-1.julia
Normal file
7
Task/Power-set/Julia/power-set-1.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function powerset(x::Vector{T})::Vector{Vector{T}} where T
|
||||
result = Vector{T}[[]]
|
||||
for elem in x, j in eachindex(result)
|
||||
push!(result, [result[j] ; elem])
|
||||
end
|
||||
result
|
||||
end
|
||||
18
Task/Power-set/Julia/power-set-2.julia
Normal file
18
Task/Power-set/Julia/power-set-2.julia
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Base.Iterators
|
||||
|
||||
function bitmask(u, max_size)
|
||||
res = BitArray(undef, max_size)
|
||||
res.chunks[1] = u%UInt64
|
||||
res
|
||||
end
|
||||
|
||||
function powerset(input_collection::Vector{T})::Vector{Vector{T}} where T
|
||||
num_elements = length(input_collection)
|
||||
bitmask_map(x) = Iterators.map(y -> bitmask(y, num_elements), x)
|
||||
getindex_map(x) = Iterators.map(y -> input_collection[y], x)
|
||||
|
||||
UnitRange(0, (2^num_elements)-1) |>
|
||||
bitmask_map |>
|
||||
getindex_map |>
|
||||
collect
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue