| Bytes | Lang | Time | Link |
|---|---|---|---|
| 825 | Vyxal | 240905T144253Z | pacman25 |
| 011 | Jelly | 231230T081641Z | Nick Ken |
| 135 | Python 3 | 220630T193318Z | Fmbalbue |
| 064 | Regenerate a | 220711T010709Z | thejonym |
| 071 | Python | 220710T215123Z | lynn |
| 271 | Batch | 220710T210052Z | Youserna |
| 075 | Python 3 | 220704T062213Z | the defa |
| 012 | Pyth | 220701T153443Z | math jun |
| 080 | Python 2 | 220630T190413Z | Kevin Cr |
| 067 | JavaScript V8 | 220630T174857Z | Arnauld |
| 018 | K ngn/k | 220630T180442Z | ovs |
| 106 | Rust | 220701T092135Z | mousetai |
| 062 | Ruby | 220701T055622Z | G B |
| 026 | Charcoal | 220701T001336Z | Neil |
| 050 | Retina 0.8.2 | 220701T000203Z | Neil |
| 058 | Factor + math.combinatorics | 220630T181940Z | chunes |
| 010 | Husk | 220630T211049Z | ovs |
| 011 | 05AB1E | 220630T180515Z | Kevin Cr |
Vyxal, 66 bitsv2, 8.25 bytes
⁺ŀfʀΠvṖÞfU
Bitstring:
111111011001001101001110100101101000111101101011000011001000110100
Jelly, 11 bytes
6p3’Ż€Œ!€ẎQ
A niladic link that returns the 64 triples. This is my answer to the follow-up question but with the sorting code removed.
Python 3, 161 146 141 135 bytes
from itertools import*
for u in product(*[range(6)]*3):
i,j,k=u
if 0not in u or i>2and j>2or j>2and k>2or k>2and i>2:1
else:print(u)
-5 thanks to qwr
Regenerate -a, 73 64 bytes
[345]([12]0|0[012])|[12]([1-5]0|0[0-5])|0([012][0-5]|[345][012])
Surprised nopony did this yet. Probably golfable!
EDIT: -9 thanks to math junkie for reminding me of the shorter output format. Now it's 1 byte per combination :P I still think it can be golfed further, possibly with a new approach :-)c
Python, 71 bytes
for x in range(521):max(s:='%03d'%x)<'6'!=['0','3']>sorted(s)==print(s)
I took the ['0','3']>sorted(s) idea from ovs.
Batch, 271 bytes
@!! 2>nul||cmd/q/v/c%0&&exit/b&for /l %%i in (0,1,5)do @(for /l %%j in (0,1,5)do @(for /l %%k in (0,1,5)do @(set s=%%i%%j%%k&set p=!s:0=!&if !p:~!==~ set p=0
if !p!. neq !s!. set/af=!p!/10&set/al=!p!%%10&if !f! lss !l! (if !f! leq 2 echo !s!)else if !l! leq 2 echo !s!)))
Python 3, 75 bytes
print([r for r in[(x//36,x//6%6,x%6)for x in range(216)]if[0,3]>sorted(r)])
Pyth, 12 bytes
f>,Z3ST^U6 3
Port of Kevin Cruijssen's Python answer
f>,Z3ST^U6 3
U6 Range up to 6 = [0,1,2,3,4,5]
^ 3 Cartesian product with itself 3 times = [0,1,2,3,4,5] * [0,1,2,3,4,5] * [0,1,2,3,4,5]
f Filter for elements T such that:
>,Z3ST [0,3] > sorted(T)
Python 2, 82 80 bytes
from itertools import*
print[k for k in product(*[range(6)]*3)if[0,3]>sorted(k)]
-2 bytes thanks to @ovs.
Explanation:
from itertools import*: Importitertoolsfor the cartesianproductbuiltinrange(6): Push list[0,1,2,3,4,5][^]*3: Repeat it three times:[[0,1,2,3,4,5],[0,1,2,3,4,5],[0,1,2,3,4,5]]product(*^): Use the cartesian product builtin to get all tripletsk for k in ^: Loop over these triplets^if: And filter to only keep the triple-tupletskthat are:sorted(k): When sorted and converted to an array[0,3]>^: are smaller than[0,3]
[^]: Wrap all these tuplets into an arrayprint^: And print it as result
JavaScript (V8), 75 67 bytes
Saved 8 bytes thanks to @tsh
Prints one comma-separated triplet per line.
for(i=216;i--;)[...a=[i/36%6|0,i/6%6|0,i%6]].sort()<'0,3'&&print(a)
K (ngn/k), 20 18 bytes
?,/+'!'1|3*<'+!3#3
+!3#3 All triples with values in 0 1 2.
<' Grade up each triple. This results in all permutations of 0 1 2 with some duplicates.
1|3* Multiply by 3 and take maximum with 1 to generate all permutations of 6 3 1.
+'!' For each permutation, generate all triples where the each entry is a non-negative integer less than the number in the permutation at the same index.
?,/ Flatten into a matrix with three columns and take the unique rows.
Rust, 106 bytes
for i in 0..6{for j in 0..6{for k in 0..6{let mut t=[i,j,k];t.sort();if t<[0,3,6]{print!("{i}{j}{k}
")}}}}
Actually using nested loops is barely shorter than my attempt using itertoools.
Charcoal, 26 bytes
ΦEφ﹪%03dι∧№ι0∧›6⌈ι›²ΣEι‹2λ
Try it online! Link is to verbose version of code. Explanation:
φ Predefined variable `1000`
E Map over implicit range
ι Current value
﹪%03d Formatted to 3 0-filled digits
Φ Filtered where
ι Current value
№ Contains
0 Literal string `0`
∧ Logical And
6 Literal string `6`
› Is greater than
ι Current value
⌈ Maximum character
∧ Logical And
² Literal integer `2`
› Is greater than
ι Current value
E Map over digits
2 Literal string `2`
‹ Is less than
λ Current digit
Σ Take the sum
Implicitly print
28 bytes for the prettier version:
ΦEφ⪫﹪%03dι-∧№ι0∧›6⌈ι›²ΣEι‹2λ
Try it online! Link is to verbose version of code.
Retina 0.8.2, 50 bytes
520$*¶
00$.`
.+(...)
$1
G`0
A`[3-5].*[3-5]|[6-9]
Try it online! Link includes footer that prettifies the output. Explanation:
520$*¶
00$.`
.+(...)
$1
List all the integers from 0 to 520 inclusive, padded to 3 digits.
G`0
Only keep those integers with at least one 0 digit.
A`[3-5].*[3-5]|[6-9]
Discard those with more than one digit greater than 2 or with a digit greater than 5.
Factor + math.combinatorics, 59 58 bytes
6 iota 3 selections [ natural-sort "\0"before? ] filter .
-1 byte from a tip by @ovs.
Note the string "\0" has literal control character 3 embedded as well as the 0; you can see it on TIO. This string is equivalent to the longer (but clearer) sequence { 0 3 }.
6 iota 3 selectionsGenerate all 3-selections of \$[0..5]\$:
{ { 0 0 0 } { 0 0 1 } ... { 5 5 5 } }[ natural-sort { 0 3 } before? ] filterSelect those that when sorted are less than
{ 0 3 }..Print them.
Husk, 10 bytes
uΣmPΠmŀ∫ḣ3
Similar to my K answer.
∫ḣ3 -- cumulative sums of [1..3] -> [1,3,6]
mŀ -- lowered range of each -> [[0],[0,1,2],[0,1,2,3,4,5]]
Π -- cartesian product of the three lists
mP -- for each triplet, get all permutations
Σ -- flatten into a list of triplets
u -- get the unique ones
05AB1E, 13 11 bytes
5Ý3ãʒ{₆1š‹P
-2 bytes thanks to a tip of @ovs using 136.
Outputs as a list of triplets.
Explanation:
5Ý # Push a list in the range [0,5]
3ã # Cartesian power of 3: get all triplets using these [0,1,2,3,4,5]
ʒ # Filter this list by:
{ # Sort the triplet from lowest to highest
ƵZ # Push compressed integer 136
S # Convert it to a list of digits: [1,3,6]
‹ # Check for sorted triplet [a,b,c] whether [a<1,b<3,c<6]
P # Check if all three are truthy
# (after which the filtered list of 64 triplets is output implicitly)
ƵZS could alternatively be ₆1š for the same byte-count: try it online.
₆ # Push 36
1š # Convert it to a list of digits, and prepend 1
See this 05AB1E tip of mine (section How to compress large integers?) to understand why ƵZ is 136.