8
\$\begingroup\$

Background

The monkeys need your help again organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options as they appear in your insta-monkey collection. Each tower has three unique upgrade "paths", called "top", "middle", and "bottom", each having a tier represented by a number between 0 and 5 inclusive (0 meaning no upgrade). Up to two paths may be chosen for upgrading, that is contain an upgrade tier 1 or greater. Additionally, only one "main" path can contain a tier 3 or greater, with the other upgrade path (if it exists) becoming the "crosspath".

Original question: Bloons TD 6 Upgrade Paths

Task

Output in some reasonable format all valid upgrade path triples in the given order (the triples themselves are ordered). Triples can be represented in any reasonable way, such as 025 or 0-2-5. The triples must be distinguishable from each other in some way, so a flat list of numbers without triple delimiters is not allowed.

Here is the list of all 64 possible triples, as they appear in-game for your insta-monkey collection. The 5th tier (main path) monkeys are listed first, then 4th tier, etc. descending. For each main path position (top, middle, or bottom), the second tier crosspaths are listed, with the crosspath having the leftmost position listed first. Then the first tier crosspaths are listed, then no crosspath. For tier 1 and tier 0 monkeys, the same logic is followed, except duplicates are not listed.

5-2-0
5-0-2
5-1-0
5-0-1
5-0-0
2-5-0
0-5-2
1-5-0
0-5-1
0-5-0
2-0-5
0-2-5
1-0-5
0-1-5
0-0-5
4-2-0
4-0-2
4-1-0
4-0-1
4-0-0
2-4-0
0-4-2
1-4-0
0-4-1
0-4-0
2-0-4
0-2-4
1-0-4
0-1-4
0-0-4
3-2-0
3-0-2
3-1-0
3-0-1
3-0-0
2-3-0
0-3-2
1-3-0
0-3-1
0-3-0
2-0-3
0-2-3
1-0-3
0-1-3
0-0-3
2-2-0
2-0-2
2-1-0
2-0-1
2-0-0
0-2-2
1-2-0
0-2-1
0-2-0
1-0-2
0-1-2
0-0-2
1-1-0
1-0-1
1-0-0
0-1-1
0-1-0
0-0-1
0-0-0
\$\endgroup\$
3
  • \$\begingroup\$ What is the sorting that defines that order? \$\endgroup\$
    – Tbw
    Dec 29, 2023 at 22:04
  • \$\begingroup\$ @Tbw added some info on the sorting. But it is up to you to find a clever way to encode this in a program. \$\endgroup\$
    – qwr
    Dec 29, 2023 at 22:11
  • 1
    \$\begingroup\$ I expect to see at least one base-6 solution. \$\endgroup\$
    – qwr
    Dec 29, 2023 at 22:30

7 Answers 7

6
\$\begingroup\$

Jelly, 18 bytes

6p3’Ż€Œ!€ẎQMNṭṀƲÞṚ

A niladic link taking no arguments and returning a list of triples.

Explanation

6p3                | Cartesian product of 1..6 and 1..3
   ’               | Subtract 1
    Ż€             | Prefix each with zero
      Œ!€          | Permutations of each
         Ẏ         | Join outer lists
          Q        | Uniquify
           MNṭṀƲÞ  | Sort by negated maximal indices tagged onto maximum
                 Ṛ | Reverse
\$\endgroup\$
3
\$\begingroup\$

Retina 0.8.2, 97 bytes


520$*¶

00$.`
.*(...)
$1,$1
%O^`\G\d
(.)(..,.*?\1(.)*)
$1$#3$2
O^`
.+,

G`0
A`[3-5].*[3-5]|[6-9]

Try it online! Link includes footer that prettifies the output. Explanation: Based on my answer to the linked question.


520$*¶

00$.`
.*(...)
$1,$1

List all the integers from 0 to 520 inclusive, padded to 3 digits, with each integer duplicated, the duplicates separated with a comma.

%O^`\G\d

Sort the first duplicate of each integer in descending order of digit.

(.)(..,.*?\1(.)*)
$1$#3$2

For each integer, after the largest digit in the sorted digits, insert another digit that is the number of digits appearing after the first occurrence of that digit in the original integer.

O^`

Sort the integers in reverse by this sort key.

.+,

Delete the sort key.

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.

\$\endgroup\$
2
\$\begingroup\$

Python 3, 119 bytes

t=(0,1,2)
print(*{(*(x*(i==j)+y*(i==k)for i in t),):0for x in(5,4,3,2,1,0)for j in t for y in(2,1,0)for k in t if j-k})

A full program that takes no input and prints the ordered upgrade paths as Python tuples with a space separator.

Try it online!

How?

Go through from a "big choice" of five through to zero placing this digit left-right, placing a "small choice" of two through to zero in each of the other positions in turn, each time placing a zero in the remaining position, then deduplicate the results while maintaining order.

  t=(0,1,2)                                # create "indices" tuple t = (0,1,2)
  for x in(5,4,3,2,1,0)                    # for "big choice" x=5..0
    for j in t                             # for index j (where we want to try to place x)
      for y in(2,1,0)                      # for "small choice" y=2..0
        for k in t                         # for index k (where we want to try to place y)
          if j-k                           # if these indices differ
            for i in t                     # go through the indices, i
              x*(i==j)+y*(i==k)            # and assign a value (x, y or 0)
           (                   )           # each triple (across i) as a generator
         (*                     ,)         # ...splat to a tuple
        {                         :0 ...}  # ...as the keys of a dictionary (to deduplicate keys)
 print(*                                 ) # ...splat to print function

Perhaps the print(*{...}) could be print({...}) it will then print the dict representation, which is in order of its keys (the upgrade path triples), but will also show the dummy values : 0 along with each key.

\$\endgroup\$
1
\$\begingroup\$

Charcoal, 57 bytes

≔EΦEφ﹪%03dι∧№ι0∧›6⌈ι›²ΣEι‹2λ⟦⌈ι±⌕ι⌈ι⁻ΣιΣ⌈ιι⟧θW⁻θυ⊞υ⌈ιEυ⊟ι

Try it online! Link is to verbose version of code. Explanation: Based on my answer to the linked question.

≔EΦEφ﹪%03dι∧№ι0∧›6⌈ι›²ΣEι‹2λ⟦⌈ι±⌕ι⌈ι⁻ΣιΣ⌈ιι⟧θ

Generate all the valid triples, but then create a sort key of the maximum digit, the negated index of that digit in the triple, the other non-zero digit if any, and the triple.

W⁻θυ⊞υ⌈ι

Sort the triples in descending order by the keys.

Eυ⊟ι

Output just the triples. (This could be Eυ⪫⊟ι- to prettify the output at a cost of 2 bytes.)

\$\endgroup\$
1
\$\begingroup\$

Haskell, 154 bytes

import Data.List
x=unlines[intersperse '-'s|s<-reverse$sortOn(\x->(maximum$zip x[1,0..],sort x))$mapM id$['0'..'5']<$[1..3],elem '0's,sum[1|x<-s,x>'2']<2]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

R, 114 bytes

r=rowSums
a=apply
(b=(x=expand.grid(0:5,0:5,0:5))[r(x>2)<2&r(x>0)<3,])[order(-a(b,1,max),a(b,1,which.max),-r(b)),]

Attempt This Online!

A full program that prints a data frame with the relevant triples in rows. It also prints some redundant row and column names - hopefully that’s permissible.

The footer verifies that the data frame is correct when compared to the canonical answer.

\$\endgroup\$
1
\$\begingroup\$

Python 3.8 (pre-release), 234 bytes

from itertools import*
s,r=sorted,range;[print('-'.join(map(str,p)))for p in s(set(chain.from_iterable(permutations(list(x)+[0])for x in s(product(r(6),r(3))))),key=lambda x:(max(x),-x.index(max(x)),sum(x),x,-x.index(s(x)[1])))[::-1]]

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.