Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
using Combinatorics
n = 4
m = 3
for i in combinations(0:n,m)
println(i')
end

View file

@ -0,0 +1,27 @@
##############################
# COMBINATIONS OF 3 OUT OF 5 #
##############################
# Set n and m
m = 5
n = 3
# Prepare the boundary of the calculation. Only m - n numbers are changing in each position.
max_n = m - n
#Prepare an array for result
result = zeros(Int64, n)
function combinations(pos, val) # n, max_n and result are visible in the function
for i = val:max_n # from current value to the boundary
result[pos] = pos + i # fill the position of result
if pos < n # if combination isn't complete,
combinations(pos+1, i) # go to the next position
else
println(result) # combination is complete, print it
end
end
end
combinations(1, 0)
end

View file

@ -0,0 +1,20 @@
using Base.Iterators
function bitmask(u, max_size)
res = BitArray(undef, max_size)
res.chunks[1] = u%UInt64
res
end
function combinations(input_collection::Vector{T}, choice_size::Int)::Vector{Vector{T}} where T
num_elements = length(input_collection)
size_filter(x) = Iterators.filter(y -> count_ones(y) == choice_size, x)
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) |>
size_filter |>
bitmask_map |>
getindex_map |>
collect
end