2020: rgbctf: insert creative algo chall name - 5225225
This commit is contained in:
parent
58e78c7c3d
commit
bf6ebc4719
|
@ -0,0 +1,44 @@
|
|||
# [insert creative algo chall name]
|
||||
|
||||
writeup by [5225225](https://www.5snb.club) for [BLÅHAJ](https://blahaj.awoo.systems)
|
||||
|
||||
**Misc**
|
||||
**449 points**
|
||||
**67 solves**
|
||||
|
||||
> Find the total number of unique combinations for input values of x = 4 and n = 12
|
||||
>
|
||||
> There exists a set of values, r, with values binary increasing (2^0, 2^1, ... 2^(n-1))
|
||||
>
|
||||
> A combination is a set of x values where each value is generated by creating x subsets of r with
|
||||
> all values within a subset being summed
|
||||
>
|
||||
> The x subsets should use all values in r exactly once.
|
||||
|
||||
(full challenge text in challenge.txt)
|
||||
|
||||
## Writeup
|
||||
|
||||
This is fairly simple stuff, easily translated into python. I installed more-itertools
|
||||
(<https://more-itertools.readthedocs.io/en/stable/)> for `set_partitions`, which makes this problem
|
||||
trivial.
|
||||
|
||||
```python
|
||||
import more_itertools
|
||||
|
||||
x = 4
|
||||
n = 12
|
||||
|
||||
r = [2**i for i in range(n)]
|
||||
|
||||
parts = more_itertools.set_partitions(r, k = x)
|
||||
|
||||
summed = []
|
||||
for p in parts:
|
||||
o = set()
|
||||
for i in p:
|
||||
o.add(sum(i))
|
||||
summed.append(o)
|
||||
|
||||
print(len(summed))
|
||||
```
|
|
@ -0,0 +1,62 @@
|
|||
Find the total number of unique combinations for input values of x = 4 and n = 12
|
||||
There exists a set of values, r, with values binary increasing (2^0, 2^1, ... 2^(n-1))
|
||||
A combination is a set of x values where each value is generated by creating x subsets of r with all values within a subset being summed
|
||||
The x subsets should use all values in r exactly once.
|
||||
|
||||
Example Case:
|
||||
Input:
|
||||
x = 3
|
||||
n = 5
|
||||
|
||||
Given the input above we can create a set r that consists of the following n values
|
||||
[2^0, 2^1, 2^2, 2^3, 2^4]
|
||||
OR
|
||||
[1, 2, 4, 8, 16]
|
||||
|
||||
Each combination is formed via x subsets of the set [1, 2, 4, 8, 16]
|
||||
[16], [2,8], [1, 4]
|
||||
[1, 2, 4], [8], [16]
|
||||
[1, 4], [2, 8], [16]
|
||||
...
|
||||
|
||||
This renders sets of size x that are the sums of the elements of each set
|
||||
16, 10, 5
|
||||
7, 8, 16
|
||||
5, 10, 16
|
||||
...
|
||||
|
||||
Note: combination 1 and combination 3 are the duplicates and should not be counted twice as they both consist of 5, 10, and 16
|
||||
|
||||
All possible unique combinations for x = 3 and n = 5:
|
||||
3 8 20
|
||||
4 8 19
|
||||
1 12 18
|
||||
4 9 18
|
||||
5 8 18
|
||||
2 12 17
|
||||
4 10 17
|
||||
6 8 17
|
||||
1 14 16
|
||||
2 13 16
|
||||
3 12 16
|
||||
4 11 16
|
||||
5 10 16
|
||||
6 9 16
|
||||
7 8 16
|
||||
1 2 28
|
||||
1 4 26
|
||||
2 4 25
|
||||
1 6 24
|
||||
2 5 24
|
||||
3 4 24
|
||||
1 8 22
|
||||
2 8 21
|
||||
1 10 20
|
||||
2 9 20
|
||||
|
||||
Final Output:
|
||||
25
|
||||
(There are 25 combinations generated above)
|
||||
|
||||
*IMPORTANT*
|
||||
The answer should be formatted as rgbctf{[output value here]} with your output value replacing [output value here]
|
Loading…
Reference in New Issue