# Logo Pack LAPACK

This is the logo for LAPACK, a widely used software library for numerical linear algebra.

Your task is to print the logo (color and matrix brackets not required) as this exact string. Trailing newline is allowed.

L  A  P  A  C  K
L -A  P -A  C -K
L  A  P  A -C -K
L -A  P -A -C  K
L  A -P -A  C  K
L -A -P  A  C -K

• What's the winning criterion? Commented Jul 2, 2020 at 20:33
– qwr
Commented Jul 2, 2020 at 20:38
• @Shaggy no, this is kolmogorov-complexity
– qwr
Commented Jul 2, 2020 at 21:21
• @Bubbler It's not quite the top 6*6 of the standard 8*8 Hadamard matrix -- you'd need to switch around some rows or some columns. It's the tensor (block) product of the 2*2 Hadamard matrix with a 3*3 matrix that looks like the 3*3 Fourier matrix, but with +1 and -1 replacing the complex values. One way to get the whether the (i,j) entry is negated is as (i|j)/6^i*j%2: TIO
– xnor
Commented Jul 3, 2020 at 2:02
• math.stackexchange.com/questions/465519/… I have a bounty here for what the logo is
– qwr
Commented Jul 3, 2020 at 21:09

# Python 2, 69 bytes

print"L %sA %sP %sA %sC %sK\n"*6%tuple('     - - -   --- -'+'-  -'*3)


Try it online!

Kind-of a boring solution. Makes a string template for the output with slots to put in minuses, then inserts in hardcoded string of minuses and spaces for those slots. I didn't find a way to compress or generate this length-30 binary sequence shorter than hardcoding it. The only optimization the code uses is that the sequence ends in 3 copies of '- -'. The output includes a trailing newline which the challenge allows.

The template could also use %2s in place of  %s which would allow also putting in empty string for the spaces, but I don't see how to use this.

# Python 2, 91 bytes

i=0


Try it online!

I know most previous answers already beat this, but it's my first golf and I quite enjoyed the result :-)!

Edit: Thanks very much to @xnor for the tip with '\n'*(c=='K') all the tips!

• A nice first golf! A pattern you might find useful as a special case of the selector [x,y][b] where x is empty is just y*b.
– xnor
Commented Jul 3, 2020 at 2:16
• It looks though that your output doesn't match the spacing for alignment from the challenge. You could fix this by including a space in the alternative case to -, which probably actually allows you to make things shorter.
– xnor
Commented Jul 3, 2020 at 2:19
• Thank you @xnor! The x=y*b is awesome. I've corrected the code and lowered the size ;)! Commented Jul 3, 2020 at 3:22
• Nice improvement! On second look, the challenge though doesn't allow leading spaces, which looks tricky to deal with for a solution like yours. You'd need to avoid the prefix on the L or do something different.
– xnor
Commented Jul 3, 2020 at 3:32
• Oh, I didn't notice the spaces, thank you again! I fixed it in the simple way, but tomorrow I'll try to think in a better solution. Thanks for all the help! Commented Jul 3, 2020 at 5:01

# x86-16 machine code, IBM PC DOS, 5448 49 bytes

Binary:

00000000: b106 be25 01ad cd29 84e4 740e b020 cd29  ...%...)..t.. .)
00000010: d2ec 7302 b02d cd29 ebeb b00d cd29 b00a  ..s..-.).....)..
00000020: cd29 e2de c34c 1541 0350 1641 0c43 194b  .)...L.A.P.A.C.K
00000030: 00                                       .


Build and test using xxd -r on your favorite DOS VM.

Listing:

B1 06       MOV  CL, 6              ; loop 6 rows
ROWLOOP:
BE 0121     MOV  SI, OFFSET LS      ; letter string into SI
COLLOOP:
AD          LODSW                   ; letter into AL, dash pattern into AH
CD 29       INT  29H                ; write to screen
84 E4       TEST AH, AH             ; is AH = 0?
74 0E       JZ   END_NL             ; if so break loop, write NL
B0 20       MOV  AL, ' '            ; space char into AL
CD 29       INT  29H                ; write to screen
D2 EC       SHR  AH, CL             ; shift dash bit into CF
73 02       JNC  NO_DASH            ; is a dash?
B0 2D       MOV  AL, '-'            ; dash char in AL
NO_DASH:
CD 29       INT  29H                ; write to screen
EB EB       JMP  COLLOOP            ; loop until end of string
END_NL:
B0 0D       MOV  AL, 0DH            ; CR char
CD 29       INT  29H                ; write to screen
B0 0A       MOV  AL, 0AH            ; LF char
CD 29       INT  29H                ; write to screen
E2 DE       LOOP ROWLOOP            ; loop until end of rows

LS  DB  'L',15H,'A',3H,'P',16H,'A',0CH,'C',19H,'K',0


How?

The "letter string" data contains two bytes for each letter - the high byte is the letter and the low byte is a bitmap describing if that letter should be followed by a dash for each row. The rows are indexed 6 to 1 starting from the top, where the bit in the corresponding order represents whether or not there's a dash.

Examples:

Row 5, Col 0: Data 'L', 0x15 (010101)

The fifth bit is a 1 indicating that for the fifth row after the L there is a dash after.

Row 2, Col 3: Data 'A', 0xC (001100)

The second bit is a 0 indicating that for the fifth row after the A there is not a dash after.

Or looking at it a different way, the odd bytes [ 0x15, 0x3, 0x16, 0xC, 0x19, 0x0 ] form the bitmap of the dashes (only rotated and flipped):

0x15    010101
0x3     000011
0x16    010110
0xC     001100
0x19    011001
0x0     000000


Runtime:

A standalone IBM PC DOS COM executable. Output to console.

# JavaScript (ES6),  74 72  71 bytes

_=>L A P A C K
.repeat(i=6).replace(/ /g,c=>c+' -'[863064083>>++i&1])


Try it online!

### How?

We build a string consisting of the pattern "L A P A C K\n" repeated 6 times and match all spaces. We replace each of them with either " " or " -" depending on the result of a test on a bit mask.

In binary, the constant 863064083 is:

  bit 31                  bit 7  bit 0
v                       v      v
00110011011100010101000000010011
\___/\___/\___/\___/\___/  \___/
row:  4    3    2    1    0      5


Because we start with i=6 and pre-increment i at each iteration, the first row is encoded by the bits 7 to 11 (0-indexed).

As stated in the ECMAScript specification, bitwise shifts are processed modulo 32. So there's a wrap-around when i exceeds 31 and the last row can safely be encoded by the bits 0 to 4.

### Alternate version

For 69 bytes, we could do:

_=>LAPACK
.repeat(i=6).replace(/\B/g,c=>' '+' -'[863064083>>++i&1])


Try it online!

But the corresponding output includes 2 trailing spaces on the last row1. Because the challenge looks very strict about leading and trailing whitespace, this is probably invalid. ¯\_(ツ)_/¯

1: Now, would you have noticed them if I didn't tell ya?! :-p

# Charcoal, 29 27 bytes

Ｅ?*<)3&✂⭆⍘℅ι- ⁺ ⁺λ§LAPACKμ²


Try it online! Link is to verbose version of code. Edit: Saved 2 bytes by appropriating @KevinCruijssen's custom base conversion idea. Explanation:

 ?*<)3&                     Literal string of code points
Ｅ                           Map over characters
ι                Current character
℅                 Take the ordinal
⍘  -               Convert to custom base -
⭆                   Map over characters and join
λ          Current character
⁺           Concatenated with
LAPACK   Literal string LAPACK
§         Indexed by
μ  Inner index
⁺             Prefixed with a space
✂                   ² Slice off the leading spaces


# APL+WIN, 58 bytes

n←96⍴¯2↓∊'LAPACK',¨⊂'  '⋄n[⎕av⍳'ì↑⍋+.28;EHRU^']←'-'⋄6 16⍴n


Explanation:

'LAPACK',¨⊂'  ' concatenate 2 spaces to each letter in LAPACK

96⍴¯2↓∊ convert to a vector, drop last 2 spaces and replicate to form a 96 element vector

⎕av⍳'ì↑⍋+.28;EHRU^' convert characters to ascii code point integers

n[.....]←'-' use integers as index positions to assign - character

6 16⍴n reshape vector as a 6 16 matrix


# Ruby, 63 bytes

puts"L%sA%sP%sA%sC%sK
"*6%(0..29).map{|i|'  -'[644276896[i],2]}


Try it online!

Builds the output string by successive substitution from an array of prefixes. For each letter other than L, the appropriate two-character prefix (either   or  -) is selected by using the binary digits of 644276896 (100110011001101110001010100000 in binary) to index into the three-character string  -.

# 05AB1E, 31 bytes

•x—o—Õ•₃вε„ -Åв’la•Î’u.ι2ôJðý¦,


Try it online.

Explanation:

•x—o—Õ•     # Push compressed integer 251957282837
₃в   # Convert it to base-95 as list: [32,53,35,54,44,57]
ε           # Foreach over the integers:
„ -Åв      #  Convert it to custom base-" -",
#  which basically means to convert it to base-2 and index it into " -"
’la•Î’     #  Push dictionary string "lapack"
u    #  Uppercase it: "LAPACK"
.ι         #  Interleave the characters in the two strings
2ô       #  Split it into pairs of characters
J      #  Join each pair together
ðý    #  Join the list by spaces
¦   #  Remove the first character in front of the "L"
,  #  And output it with trailing newline


See this 05AB1E tip of mine (sections How to use the dictionary?, How to compress large integers?, and How to compress integer lists?) to understand why ’la•Î’ is "lapack"; •x—o—Õ• is 251957282837; and •x—o—Õ•₃в is [32,53,35,54,44,57].

([32,53,35,54,44,57] is [100000,110101,100011,110110,101100,111001] in binary.)

• Oh of course, custom base conversion, I was so close... thanks for the 2 byte saving on my answer.
– Neil
Commented Jul 3, 2020 at 14:15
• @Neil Yw I guess. ;) PS: your current TIO is broken. Commented Jul 3, 2020 at 14:43
• Yeah, I forgot to update the link when I golfed, and then I'd been editing trying another approach, so I didn't have the right code to hand. Should be fixed for real now...
– Neil
Commented Jul 3, 2020 at 18:38

# Perl 5, 57 bytes

$"=" { ,-}";say+(<"@{[L,A,P,A,C,K]}\n">)[0,21,3,22,12,25]  Try it online! ## Explanation First $" (which is a magic variable that is used as a field separator when lists are interpolated into strings - default is " ") is set to  { ,-}. Then say is called which is a newline-terminated print function, passing in the listed indexes (0, 21, 3, 22, 12, 25) from the result of the glob (<...> is shorthand for calling glob) <"@{[L,A,P,A,C,K]}\n">. This glob expands to:

L { ,-}A { ,-}P { ,-}A { ,-}C { ,-}K


Which, due to the { ,-}s, will generate a list containing all permutations of the string with either   or - before every letter (except the leading L). The chosen indices are the ones we need for the logo.

# Retina, 62 bytes

This is way too long. The markdown parser breaks terribly if I use the TIO's post snippet generator, so there's an extra leading newline in the snippet below: there is actually only 1 leading newline!


bbcccbc-cc-b--b-- c
b

c
-
L.{6}
.
$0X YX\LAPACK .L L  The first 2 lines replace the empty string with bbccc... c, the next 4 lines decode it into spaces and dashes by simple substitutions (b -> 3 spaces, c ->  -), the next line splits it into 6 lines of length 6 (producing a 6x6 sign matrix), the next two lines replace each character c by cX , the next line cyclically transliterates all Xs into LAPACKs, and the last 2 lines remove leading whitespace. Try it online! • Changed the code block to a fenced code block. Looks like it's now correct, preserving one leading newline and a line with three blanks. Strangely, the three blanks weren't preserved in preview. Commented Jul 3, 2020 at 4:21 # C (gcc), 92 91 84 83 bytes Saved 7 bytes thanks to the man himself Arnauld!!! Saved a byte thanks to ceilingcat!!! f(i){for(i=30;i--;i%5||puts("K"))printf("%c %c","CAPAL"[i%5]," -"[22141337>>i&1]);}  Try it online! • 84 bytes Commented Jul 3, 2020 at 10:53 • @Arnauld That's lovely - thanks! :-) Commented Jul 3, 2020 at 12:29 # Python 3, 107 bytes s='LAPACK';e=enumerate for i,_ in e(s):print(*[' -'[(j%2+i%2==2)^(i//2+j//2==3)]*(j!=0)+k for j,k in e(s)])  Try it online! How it works: blue squares are in the form $$\\begin{pmatrix}1&1\\1&-1\end{pmatrix}\$$ hence j%2+i%2==2 and red squares (when i//2+j//2==3) are in the opposite form $$\\begin{pmatrix}-1&-1\\-1&1\end{pmatrix}\$$ thus we simply xor the expressions with ^. $$\\$$ $$\begin{array}{rr|rr|rr} \color{blue}{\mathrm{L}}& \color{blue}{\mathrm{A}}& \color{blue}{\mathrm{P}}& \color{blue}{\mathrm{A}}& \color{blue}{\mathrm{C}}& \color{blue}{\mathrm{K}}\\ \color{blue}{\mathrm{L}}& \color{blue}{\mathrm{-A}}& \color{blue}{\mathrm{P}}& \color{blue}{\mathrm{-A}}& \color{blue}{\mathrm{C}}& \color{blue}{\mathrm{-K}}\\ \hline \color{blue}{\mathrm{L}}& \color{blue}{\mathrm{A}}& \color{blue}{\mathrm{P}}& \color{blue}{\mathrm{A}}& \color{red}{\mathrm{-C}}& \color{red}{\mathrm{-K}}\\ \color{blue}{\mathrm{L}}& \color{blue}{\mathrm{-A}}& \color{blue}{\mathrm{P}}& \color{blue}{\mathrm{-A}}& \color{red}{\mathrm{-C}}& \color{red}{\mathrm{K}}\\ \hline \color{blue}{\mathrm{L}}& \color{blue}{\mathrm{A}}& \color{red}{\mathrm{-P}}& \color{red}{\mathrm{-A}}& \color{blue}{\mathrm{C}}& \color{blue}{\mathrm{K}}\\ \color{blue}{\mathrm{L}}& \color{blue}{\mathrm{-A}}& \color{red}{\mathrm{-P}}& \color{red}{\mathrm{A}}& \color{blue}{\mathrm{C}}& \color{blue}{\mathrm{-K}} \end{array}$$ $$\\$$ Other techniques used: print(*[x]) instead of print(' '.join(x)), s*(j==0) instead of s if j else '', [falsy,truthy][expr] instead of truthy if expr else falsy, where the former list is just a string ' -', the rest is pretty straightforward. # APL (Dyalog), 37 bytes ' -'[(6⍴2)⊤⎕A⍳'AVDWMZ'],¨6 6⍴'LAPACK'  Try it online! • ⎕IO←0. We encode the dashes matrix by • encoding dashes as 1s (and spaces as 0s) • converting each column from binary to a decimal number (0 21 3 22 12 25) • indexing into the alphabet (AVDWMZ). We decode it the same way: • ⎕A⍳ - retrieves index into alphabet • (6⍴2)⊤ converts to binary columns • ' -'[...] - 1 becomes dash. Then we generate the LAPACK matrix with 6 6⍴'LAPACK', and concatenate each pair with ,¨. # ///, 83 bytes /$/ -//#/A@//!/
L //@/  /L@#P@#C@K!-#P$#C$K! #P@A$C$K!-#P$A$C@K! A$P$#C@K!-A$P@#C$K


Try it online!

# R + magrittr, 312 bytes

library(magrittr)

A <- matrix(c(1,1,1,-1),nrow = 2)
B <- matrix(c(1,1,1,1,1,-1,1,-1,1),nrow = 3)
kronecker(B,A) %>%
apply(1, function(x) {paste0(x,strsplit("LAPACK","")[[1]]) %>%
gsub("-1","-",.) %>%  gsub("1"," ",.)})  %>%
apply(2,function(x){paste0(x, collapse = " ")})  %>%
cat(sep = "\n")


Try it online!

This gives on my console:

 L  A  P  A  C  K
L -A  P -A  C -K
L  A  P  A -C -K
L -A  P -A -C  K
L  A -P -A  C  K
L -A -P  A  C -K


With the function kronecker() we construct a block matrix by replicating A by B coefficients.

A is a 2x2:

> A
[,1] [,2]
[1,]    1    1
[2,]    1   -1


which are the signs that we want to replicate in 3x3 blocks multiplied by the coefficients in B:

> B
[,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1   -1
[3,]    1   -1    1


Then we explode LAPACK with strsplit() and prepend 1 or -1. With gsub() we substitute 1 and -1. Then, we collapse the strings and print out to the console.

• Welcome to the site! This is a code golf challenge, so you should aim to minimise the number of bytes/characters in your code. For example, there are a number of spaces I'm sure can be removed, as well as some other stuff (not to familiar with R). You should be able to test your code here, which also allows users who don't have R installed to verify your code. Finally, I'ed edited your answer slightly to fit the standard answer format. Commented Jul 3, 2020 at 15:01
• B%x%A is a nifty shortcut for kronecker(B,A), and it's generally shorter to just nest all your calls together rather than using the pipe syntax. Commented Jul 3, 2020 at 16:00
• 112 bytes -- still your method, just heavily golfed. Commented Jul 3, 2020 at 16:22
• @Giuseppe unfortunately the challenge doesn't allow leading spaces. I struggled with that on my code hahahah Commented Jul 3, 2020 at 20:16
• @yyyyyyyan fair enough, 125 bytes -- didn't really read the spec and was focused on golfing the existing answer. Commented Jul 3, 2020 at 20:39

# Japt-R, 30 bytes

Happy to be beating 05AB1E after quite a bit of work on this but still feel I could do much better. Originally based on Neil's Charcoal solution.

"?*<)3&"¬®csSi-)í"LAPACK")ò ¸x


Test it

# PowerShell, 62 57 bytes

Port of the Arnauld's alternative answer. Very nice! Delicious! Thanks.

We avoid the problem with 2 trailing spaces on the last row because we use the array of strings, not the string with repeated LAPACK\n.

,'LAPACK'*6-replace'\B',{' '+' -'[(214811968-shr++$i)%2]}  Try it online! # PowerShell, 71 bytes port of C (gcc) answer. Thanks @Noodle9 and @Arnauld. -join(29..0|%{'CAPAL'[$_%5];' ';' -'[(22141337-shr$_)%2];'K '*!($_%5)})


Try it online!

# PowerShell, 94 77 bytes

-17 bytes thanks to mazzy

-join("L  A  P  A  C  K
"*6|% t*y|%{"$_-"[++$i+12-in' &,:=BHKYVdgp'[0..12]]})


Try it online!

Just checking for the indexes we need saves 9 bytes over just writing out the block. However, if we represent the indexes using their char values, we save loads more. We add 12 to the current iteration to get everything into the printable ASCII range. ' &,:=BHKYVdgp'[0..12] converts our index string into an index array so we can use -in.

• Commented Jul 9, 2020 at 20:17

# Io, 125 bytes

"      - - -    -- - --   --   --  - "foreach(x,i,("LAPACK"exSlice(x%6,x%6+1).." ".. i asCharacter .. if(x%6>4,"
",""))print)


Try it online!

# Python 2, 132 bytes

s,a,i="0"*19+bin(0x208200090824009002402)[2:],list("L  A  P  A  C  K\n"*6),0
for c in s:
if(int(c)):a[i]="-"
i+=1
print "".join(a)


Try it online!

Yes, I realise this is longer than a simple print statement, but I spent too long trying to get this to work and I liked the approach (for larger matrices, this method would become much more efficient). There must be at least a few ways to shave a couple bytes off this answer

# brainfuck, 356 bytes

++++++++[>+++++>++++++++>++++>+++++++++>+<<<<<-]>+++++>+>>++++>++<.<..<.>..>++++.<..<.>..<++.>..>-----.>.<+.<.<<.>--.>..>++++.<.<<.>.>..<++.>.<<.>>>-----.>.<+.<..<--.>..>++++.<..<.>.<<.>++.>.<<.>>>-----.>.<+.<.<<.>--.>..>++++.<.<<.>.>.<<.>++.>..>-----.>.<+.<..<--.>.<<.>>>++++.<.<<.>.>..<++.>..>-----.>.<+.<.<<.>--.>.<<.>>>++++.<..<.>..<++.>.<<.>>>-----.>.


Try it online!

There is the version, line by line (The 1st one is used to store the different chars)

++++++++[>+++++>++++++++>++++>+++++++++>+<<<<<-]>+++++>+>>++++>++
<.<..<.>..>++++.<..<.>..<++.>..>-----.>.
<+.<.<<.>--.>..>++++.<.<<.>.>..<++.>.<<.>>>-----.>.
<+.<..<--.>..>++++.<..<.>.<<.>++.>.<<.>>>-----.>.
<+.<.<<.>--.>..>++++.<.<<.>.>.<<.>++.>..>-----.>.
<+.<..<--.>.<<.>>>++++.<.<<.>.>..<++.>..>-----.>.
<+.<.<<.>--.>.<<.>>>++++.<..<.>..<++.>.<<.>>>-----.>.
`