Last active
November 2, 2023 12:23
-
-
Save Hugoberry/10da47bd381918d303c5db903afe5886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Source = {"B", "F", "T"}, | |
n = List.Count(Source), | |
combinations = Number.Power(2,n)-1, | |
CreateCombination = (mask as number) as list => | |
List.Select(List.Transform(List.Positions(Source), (position) => | |
if Number.BitwiseAnd(mask, Number.Power(2, position)) <> 0 then Source{position} else null), | |
each _ <> null), | |
AllCombinations = List.Transform({1..combinations}, CreateCombination) | |
in | |
List.Transform(AllCombinations,Text.Combine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Source = {"A", "B", "C"}, | |
// Function to generate combinations | |
fnCombinations = (list, k) => | |
let | |
comb = if k = 0 then {{}} else | |
if List.Count(list) = 0 then {} else | |
List.Combine({@fnCombinations(List.Skip(list, 1), k), | |
List.Transform(@fnCombinations(List.Skip(list, 1), k - 1), | |
each List.Combine({{List.First(list)}, _}))}) | |
in comb, | |
// Generate combinations for each k | |
CombineAll = List.Transform(List.Combine(List.Transform({1..List.Count(Source)}, each fnCombinations(Source, _))),Text.Combine) | |
in | |
CombineAll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Source = {"B", "F", "T"}, | |
AllCombinations = List.Transform( | |
{1 .. (Number.Power(2, List.Count(Source)) - 1)}, | |
(number) => | |
List.Select( | |
List.Transform( | |
List.Positions(Source), | |
(pos) => | |
if Number.BitwiseAnd(number, Number.Power(2, pos)) <> 0 then Source{pos} else null | |
), | |
(value) => value <> null | |
) | |
), | |
AllCombinationsAsText = List.Transform(AllCombinations, Text.Combine) | |
in | |
AllCombinationsAsText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment