11
\$\begingroup\$

Behold! The Crystal Maze™ Time Matrix!

      0   1   2   3   4   5   6   7   8   9  10
  1   0   5  10  15  20  25  30  35  40  45  50
  2   0  10  20  30  40  50  60  70  80  90 100
  3   0  15  30  45  60  75  90 105 120 135 150
  4   0  20  40  60  80 100 120 140 160 180 200
  5   0  25  50  75 100 125 150 175 200 225 250

Obviously, this is self explanatory to anyone who knows The Crystal Maze™️, but here's a quick run-down for anyone else:

  • In The Crystal Maze™, team members attempt a series of games where they can win Crystals.
  • Crystals represent time in the final game, 5 seconds for every crystal.
  • They can also fail these games in a way which gets a team member locked in, so they are not able to participate in the final game.
  • Before the final game, they have the option to buy the team members back with crystals, giving them less time but more people.

The Matrix shows you the number of crystals along the top, and the number of team members on the left. The body of the matrix is filled with "people seconds". Its purpose is to decide if selling a crystal will increase your "people seconds" or not.

The game

  • Generate the precise textual output of The Crystal Maze™ Matrix.
    • The crystals, along the top, will range from 0 to 10.
    • Team members will range from 1 to 5.
    • All columns will be exactly 3 characters wide and right-justified.
    • Columns are separated with a space.
    • A single value will show (crystals × team members × 5).
  • Use any language capable of producing this textual output.
  • It's code golf, so attempt to do so in the fewest bytes.
  • Please include a link to an online interpreter such as TIO.
\$\endgroup\$
5
  • \$\begingroup\$ "The precise textual output" - So yes, a string with this precise content. \$\endgroup\$
    – AJFaraday
    Jul 21, 2023 at 11:32
  • 1
    \$\begingroup\$ Must the leading/trailing space of each line be exactly as shown (two leading and zero trailing spaces on each line, fitting with the column width of three) or is that part of it flexible at all? Are we allowed a trailing empty line? (Probably a good idea to allow this one.) Are we allowed a trailing line (or lines?) containing some spaces (and if so how many)? Same question for a leading line(s)...? \$\endgroup\$ Jul 21, 2023 at 11:37
  • 1
    \$\begingroup\$ @JonathanAllan Good catch, I've corrected my example \$\endgroup\$
    – AJFaraday
    Jul 21, 2023 at 13:09
  • \$\begingroup\$ Are the 2 leading spaces now required? \$\endgroup\$
    – Arnauld
    Jul 21, 2023 at 13:12
  • \$\begingroup\$ I think so, it's 3 characters wide and right-justified, same as the other columns \$\endgroup\$
    – AJFaraday
    Jul 21, 2023 at 13:13

22 Answers 22

8
\$\begingroup\$

R, 60 bytes

write(format(rbind(c("",1:5),0:10%o%c(1,1:5*5)),j="r"),1,12)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ write is cool! I wish I've thought about it - I tried with prmatrix and best I could get was 67 bytes... \$\endgroup\$
    – pajonk
    Jul 21, 2023 at 18:45
  • \$\begingroup\$ @pajonk I've never seen prmatrix before, definitely a function for me to file away for future use! \$\endgroup\$
    – Giuseppe
    Jul 23, 2023 at 0:50
7
\$\begingroup\$

Excel (ms365), 145, 122 bytes

enter image description here

Formula in A1:

=LET(x,ROW(1:6)-1,y,COLUMN(A:K)-1,TEXTJOIN(HSTACK(IF(y+1," "),CHAR(10)),,RIGHT("  "&HSTACK(IF(x,x," "),IF(x,y*5*x,y)),3)))

This can be 117 bytes if we would swap CHAR(10) out for a literal Alt+Enter:

=LET(x,ROW(1:6)-1,y,COLUMN(A:K)-1,TEXTJOIN(HSTACK(IF(y+1," "),"
"),,RIGHT("  "&HSTACK(IF(x,x," "),IF(x,y*5*x,y)),3)))
\$\endgroup\$
2
  • 1
    \$\begingroup\$ =LET(a,COLUMN(A:K),b,ROW(1:5),TEXTJOIN(HSTACK(IF(a," "),CHAR(10)),,RIGHT(" "&HSTACK(VSTACK(" ",b),VSTACK(a-1,5*b*(a-1))),3))) is 126 bytes for starters, but this is very golfable, so I expect it could be lowered to 100 or so quite easily. \$\endgroup\$ Jul 22, 2023 at 5:33
  • 1
    \$\begingroup\$ @JosWoolley, thanks for the contribution. Was able to lower it a little further. \$\endgroup\$
    – JvdV
    Jul 22, 2023 at 8:54
5
\$\begingroup\$

Charcoal, 26 25 bytes

E⁶⪫E¹²◧⎇λI×⊖λ∨×⁵ι¹⎇ιIιω³ 

Try it online! Link is to verbose version of code. Explanation:

 ⁶                          Literal integer `6`
E                           Map over implicit range
    ¹²                      Literal integer `12`
   E                        Map over implicit range
       ⎇λ                   If not the first column
            λ               Current column
           ⊖                Decremented
          ×                 Multiplied by
                ι           Current row
              ×             Multiplied by
               ⁵            Literal integer `5`
             ∨              Logical Or
                 ¹          Literal integer `1`
         I                  Cast to string
                  ⎇ι        If not the first row
                    Iι      Current row as a string
                      ω     Else empty string
      ◧                ³    Left-pad to length 3
  ⪫                         Join with spaces
                            Implicitly print

23 22 bytes using the newer version of Charcoal on ATO:

E⁶⪫E¹²◧⎇λ×⊖λ∨×⁵ι¹∨ιω³ 

Attempt This Online! Link is to verbose version of code. Explanation: PadLeft stringifies its argument, allowing the removal of two instances of Cast and the subsequent simplification of Ternary to Or.

\$\endgroup\$
5
\$\begingroup\$

Pure Bash - no external utilities, 66

Thanks to @Nahuel Fouilleul for saving 10 bytes!

printf "`echo %3s{,,}{,,,}`\n" '' {0..10} $[{1..5}*{1,{0..50..5}}]

Try it online!

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

Thunno 2 N, 21 bytes

5ıTĖ×5×nƤð4ṙ;TĖðƤð4ṙƤ

Try it online!

Explanation

5ı           # Map over [1..5]:
  TĖ×        #  Multiply by [0..10]
     5×      #  And multiply by 5
       nƤ    #  Prepend the current number
         ð4ṙ #  Right-justify to length 4
;            # End map
 TĖ          # Push [0..10]
   ðƤ        # Prepend a space
     ð4ṙ     # Right-justify to length 4
        Ƥ    # Prepend this list
             # Implicit output, joined on newlines
\$\endgroup\$
4
\$\begingroup\$

Perl 5, 76 bytes

printf$"x3 .($b="%4d"x11),0..10;//,printf"
  $_$b",map$_*=5*$',0..10for 1..5

Try it online!

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

Python 3, 69 bytes

for k in b"\n":print(('%4s'*12%(k//5or'',*range(0,11*k,k)))[1:])

Try it online!

Thanks to dingledooper for -3 bytes from the bytestring hardcode. If trailing spaces are allowed:

64 bytes

for k in b"\n":print('%3s '*12%(k//5or'',*range(0,11*k,k)))

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ I think you could save a few bytes by looping over a b-string rather than a counter. \$\endgroup\$ Jul 21, 2023 at 21:48
  • \$\begingroup\$ @dingledooper Yes, too bad, I liked the 5-k%5 \$\endgroup\$
    – xnor
    Jul 21, 2023 at 21:54
4
\$\begingroup\$

Python 3, 76 bytes

print(*(' '.join(f'{i*j*5:3}'for i in range(11))for j in range(6)),sep='\n')

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Jul 23, 2023 at 15:32
  • \$\begingroup\$ @RydwolfPrograms Thank you so much :-) Just 1 question, if I have a different answer in a different programming language, should I edit this answer to include it or post a whole new different answer? \$\endgroup\$
    – Ghost
    Jul 23, 2023 at 15:38
  • 1
    \$\begingroup\$ @LightningMcQueen post a whole new different answer. \$\endgroup\$ Jul 23, 2023 at 15:40
4
\$\begingroup\$

Vyxal, 115 bitsv1, 14.375 bytes

5ƛ₀ʀ*5*J;₀ʀðppÞĠ

Try it Online!

Explained

5ƛ₀ʀ*5*J;₀ʀðppÞĠ­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁤⁢‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌­
5ƛ      ;         # ‎⁡To each number in the range [1, 5]:
  ₀ʀ*             # ‎⁢  Multiply it by the range [0, 10]
     5*           # ‎⁣  Multiply that by 5
       J          # ‎⁤  And prepend the number to the start of the list
         ₀ʀðp     # ‎⁢⁡The list [0, 10] with " " prepended
             p    # ‎⁢⁢Put that list at the start of the list of lists from before
              ÞĠ  # ‎⁢⁣Gridify, right-aligning and joining columns on spaces.
💎

Created with the help of Luminespire.

\$\endgroup\$
4
\$\begingroup\$

SQL, Will never win 267

with C AS(SELECT 10 C UNION ALL SELECT C-1FROM C WHERE C-1>=0),M AS(SELECT 5 M UNION ALL SELECT M-1FROM M WHERE M-1>0),PS as(select C,M,C*M*5 PS from C cross join M)SELECT*FROM(SELECT*FROM PS)tbl PIVOT(max(PS)FOR C IN ([0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]))P

Try it here db<>fiddle

Explained...

--List Crystals 0-10
with Crystal AS (
    SELECT 10 Crystal
UNION ALL
    SELECT Crystal-1
    FROM Crystal
    WHERE Crystal-1>=0
    )
--List Members 1-5
,Member AS (
    SELECT 5 Member
UNION ALL
    SELECT Member-1
    FROM Member
    WHERE Member-1>0
    )
--Join Crystal and Member, Calc People Seconds
,PS as
(
    select Crystal,Member,Crystal*Member*5 PS
    from Crystal
    cross join Member
)
--Pivot Maze
SELECT * FROM   
    (
    SELECT *
    FROM PS
    ) tbl 
PIVOT(
    max(PS)
    FOR Crystal IN ([0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10])
    ) pvt
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Jul 24, 2023 at 17:40
3
\$\begingroup\$

JavaScript (ES6), 74 bytes

+4 bytes for a quick and dirty fix to comply with the updated output

f=(y=5,x=11)=>x--?f(y,x)+`   ${x*y*5||x}`.slice(-4):y?f(y-1)+`
  `+y:'   '

Try it online!

Commented

f = (                    // f is a recursive function taking:
  y = 5,                 //   y = team members
  x = 11                 //   x = crystals
) =>                     //
x-- ?                    // if x is not 0 (decrement it afterwards):
  f(y, x) +              //   do a recursive call with (x, y)
  `   ${x * y * 5 || x}` //   and append x * y * 5 or x if this is 0
  .slice(-4)             //   right-justified to 4 characters
                         //   with leading spaces
:                        // else:
  y ?                    //   if y is not 0:
    f(y - 1) +           //     do a recursive call with just y-1 (which
                         //     means that x is implicitly reset to 11)
    `\n  ` +             //     followed by a line feed a 2 spaces
    y                    //     followed by y
  :                      //   else:
    '   '                //     insert the 3 top-left spaces and stop
\$\endgroup\$
3
\$\begingroup\$

Bash, 138 bytes

(echo;seq 0 10;paste -d' ' <(seq 5) <(printf %s\\n {1..5}\*{0..10}\*5|bc|xargs -n11)|tr \  \\n)|sed 's/^/printf %3s\\\\n /e'|pr -ats\  -12

Try it online!

With comments

This solution works by generating all the desired numbers, one per line, and then formatting the table with printf(1) and pr(1):

(
  # Generate the top line
  echo
  seq 0 10            

  # Intersperse 1 through 5 in-between the calculated rows using paste(1).
  # The calculation is done with a cross-product of {1..5}*{0..10}*5 piped
  # to bc(1).
  paste -d' ' \
    <(seq 5)  \
    <(\
        printf '%s\n' {1..5}\*{0..10}\*5 |
        bc                               |
        xargs -n11                       \
     ) |
  tr ' ' '\n' \
) |

# All columns should be 3 characters wide.
sed 's/^/printf "%3s\\n" /e' |

# Use pr(1) to output data across (-a), no header (-t) and with a space
# separator (-s ' ') between the 12 columns (-12).
pr -ats' ' -12
\$\endgroup\$
3
\$\begingroup\$

Retina, 67 bytes


   11*#5*$(¶_11*@
_
$>:&
#
 $:&
%`@(?<=(.).*)
 $.($1*$:&*5*
P^`\d+

Try it online! Explanation:


   11*#5*$(¶_11*@

Insert a template for the output: 11 column headers, and 5 rows, each with a header.

_
$>:&

Populate the row headers. $>:& translates as 1-indexed match index.

#
 $:&

Populate the column headers. $:& is the 0-indexed match index.

%`@(?<=(.).*)
 $.($1*$:&*5*

Populate the table body. Each row is processed independently, and each @'s match index is multiplied by the row number and by 5.

P^`\d+

Left-pad all of the numbers to the same width.

\$\endgroup\$
3
\$\begingroup\$

Jelly, 19 bytes

-r⁵×þ`ḣ7ẸƇ»×¥5AG⁶3¦

Try it online!

How?

-r⁵×þ`ḣ7ẸƇ»×¥5AG⁶3¦ - Main Link: no arguments
-r⁵                 - -1 inclusive range 10 -> [-1,0,1,2,3,4,5,6,7,8,9,10]
     `              - use as both arguments of:
    þ               -   table with:
   ×                -     multiplication
      ḣ7            - head to index seven
         Ƈ          - keep those for which:
        Ẹ           -   any?
            ¥5      - last two links as a dyad - f(M=that, 5):
           ×        -   {M} multiply {5}
          »         -   {M} maximum {that}
                      (multiplies M's positive values by 5)
              A     - absolute values
               G    - format as a grid
                  ¦ - sparse application...
                 3  - ...to indices: [3]
                ⁶   - ...action: a space character
                      (replaces the top left 5 (from -1×-1×5) with a space)
\$\endgroup\$
3
\$\begingroup\$

C (clang), 99 bytes

p(r,i){r?printf("\n%d",r):0;for(i=-1;i++<10;printf("\t%d",r>0?i*5*r:i));}f(i){for(i=0;i<6;p(i++));}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Suggest r&&printf("\n%d",r) instead of r?printf("\n%d",r):0 \$\endgroup\$
    – ceilingcat
    Jul 25, 2023 at 15:01
3
\$\begingroup\$

05AB1E, 22 bytes

5LTÝδ*5*TÝšεNš}§3j»ð2ǝ

Should have been 21 bytes without the §, but unfortunately there is a bug in 05AB1E.

Try it online.

Explanation:

5LTÝδ*           # Push a 0..10 by 1..5 multiplication table:
5L               #  Push a list in the range [1,5]
  TÝ             #  Push a list in the range [0,10]
    δ            #  Pop both lists, and apply double-vectorized:
     *           #   Multiply the values together
      5*         # Multiply each value by 5
        TÝš      # Prepend list [0,10] to this matrix
           ε  }  # Map over each row:
            Nš   #  Prepend the 0-based map-index to the list
§                # (workaround: cast every integer to a string)
 3j              # Prepend leading spaces where necessary so each string is of length 3
   »             # Join each inner list of strings with space delimiter,
                 # and then each string with newline delimiter
      ǝ          # Replace the character 
     2           # at (0-based) index 2 (which is the first '0')
    ð            # with a space
                 # (after which the result is output implicitly)
\$\endgroup\$
3
\$\begingroup\$

Ruby, 77 bytes

Improvements thanks to Dingus

q=*r=1..10;s=" "
1.upto(6){|i|puts"  #{s} "+("%4d"*10)%q
q=r.map{|j|j*5*s=i}}

Try it online!

Ruby, 82 bytes

q=r=[*1..10];s=" "
1.upto(6){|i|puts ("  #{s} "+"%4d"*10)%q
s=i;q=r.map{|j|j*i*5}}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ 77 bytes \$\endgroup\$
    – Dingus
    Jul 24, 2023 at 10:19
  • \$\begingroup\$ @Dingus Thanks! I really should have spotted the 5*s=i myself. The others were a bit trickier. \$\endgroup\$ Jul 24, 2023 at 18:45
2
\$\begingroup\$

Python, 97 bytes

[print(("%4s"*12%x)[1:])for x in[(" ",*range(11))]+[(c,*range(0,c*50+1,5*c))for c in range(1,6)]]

Attempt This Online!

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

Kotlin, 118 bytes 97 bytes

fun main() = println((0..5).joinToString("\n") { j -> (0..10).joinToString(" ") { i -> "${i * j * 5}".padStart(3) } })

Try it online!

I've removed about 21 bytes thanks to The Thonnu because I forgot to remove spaces, also I've used "%3d".format() to pad the numbers to a width of 3 characters.

fun main()=println((0..5).joinToString("\n"){j->(0..10).joinToString(" "){"%3d".format(it*j*5)}})

Try it online!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Welcome to Code Golf. Can you remove those spaces to shorten the code? \$\endgroup\$
    – The Thonnu
    Jul 23, 2023 at 15:47
  • \$\begingroup\$ Yes, thanks, we can. I've got it down to 97 bytes, @TheThonnu :-) \$\endgroup\$
    – Ghost
    Jul 23, 2023 at 15:58
  • 1
    \$\begingroup\$ Cool. Nice answer btw! \$\endgroup\$
    – The Thonnu
    Jul 23, 2023 at 16:43
  • 1
    \$\begingroup\$ The output doesn't look correct—the first column should be 1 to 5, not all zeros. \$\endgroup\$ Jul 24, 2023 at 5:20
  • \$\begingroup\$ @SuperStormer OK - I'm working on that :-) \$\endgroup\$
    – Ghost
    Jul 24, 2023 at 11:57
1
\$\begingroup\$

BQN (CBQN), 128 bytes

This is definitely sub-optimal. I don't really know what I'm doing with this language.

•Out ¯1↓⥊(1↓˘∾˘⍉(/⟜" "∘(4-≠)∾⊢)¨•Fmt¨[↕6]∾⍉[↕11]∾5××´¨1↓↕6‿11)∾˘6‿1⥊@+10

Attempt This Online!

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

Jelly, 16 bytes

⁵Żð⁶;W;Gµ5×1;×þ5

Try it online!

   ð⁶;W;Gµ          [[" "] + a] + f(a), as a grid
                    where
 ⁵Ż                 a    = [0…10]
          5×1;×þ5   f(r) = table of [1]+(5×r) times [1…5]
\$\endgroup\$
1
\$\begingroup\$

Java, 112 bytes

v->{var r="";for(int i=-1,j;i++<5;r+="\n")for(j=-2;j++<10;)r+=r.format("%4s",i<1?j<0?r:j:j<0?i:i*j*5);return r;}

Try it online.

Explanation:

v->{                      // Method with empty unused parameter and String return-type
  var r="";               //  Result-String, starting empty
  for(int i=-1,j;i++<5    //  Loop `i` in the range (-1,5]:
      ;                   //    After every iteration:
       r+="\n")           //     Append a newline to the result-String
    for(j=-2;j++<10;)     //   Inner loop `j` in the range (-2,10]:
      r+=r.format("%4s",  //    Append the following with up to 4 leading spaces to the
                          //    result-String:
          i<1?i<j?        //     If it's the first row and column:
            r             //      Append the result-String itself, which is still "" at
                          //      this point
          :               //     Else-if it's the first row, but NOT the first column:
            j             //      Append `j`
          :j<0?           //     Else-if it's the first column, but NOT the first row:
            i             //      Append `i`
          :               //     Else (it's neither the first row nor column):
            i*j*5);       //      Append `i` multiplied by `j` multiplied by 5
  return r;}              //  After the nested loops, return the result-String
\$\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.