Alphabet Spiral

6

2

You are to write a program or function that outputs this exact text:

OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB

May also be lowercase and trailing spaces and newlines are allowed.

Standard loopholes are disallowed

This is , so smallest byte count wins.

DanTheMan

Posted 2016-08-13T17:22:29.997

Reputation: 3 140

Can the lines have trailing spaces? – Dennis – 2016-08-13T18:23:22.650

@Dennis Yes, I will edit the question to clarify that. – DanTheMan – 2016-08-13T18:26:56.930

1

in case you wonder about the ascii codes of the spiral: http://puu.sh/qAitG/dd89c615cf.png

– downrep_nation – 2016-08-13T22:03:22.977

3This output seems far too “complex” (in the Kolmogorov sense, i.e. devoid of pattern). Golf-y languages can hope to compress it, or in the case of MATL, hope to have a spiral built-in — but IMO it’s a bad sign if the best approach to a [tag:kolmogorov-complexity] challenge is ever “just print the output as a string literal” (see Python). – Lynn – 2016-08-13T22:15:17.870

2@Lynn Feel free to downvote if you think it's a bad question. That's what it's there for. I'll keep that in mind for next time though. – DanTheMan – 2016-08-13T22:28:44.670

So I did; I was just explaining my vote. ^^ – Lynn – 2016-08-13T22:29:43.453

Strongly related. – Lynn – 2016-08-13T22:33:00.953

Answers

16

MATL, 28 26 bytes

1Y2tIL)P0v7lYLP2:JTF-JQ&()

Try it online!

Explanation

1Y2     % Push string 'AB...Z'
tIL)    % Duplicate, remove last: gives 'AB...Y'
P       % Flip: gives 'YX...A'
0       % Push 0. Char 0 is treated as space
v       % Concatenate into a column vector of char
7lYL    % 7x7 numeric array: clockwise spiral of numbers from 1 to 49
P       % Flip vertically to make it anti-clockwise
2:      % Push [1 2]. Will be attached vertically after the last col
JqJh    % Index "[end-1, end]", to be used as row index
JQ      % Index "end+1", to be used as column index
&(      % Assign [1 2] to those positions. The rest of the new col will contain 0
)       % Index into the char vector. Indexing is modular and 1-based, so 0 as an
        % index refers to the last value of the char vector, which is char 0, or
        % equivalently space. So the 0 values in the numeric array give spaces.
        % Implicitly display

Luis Mendo

Posted 2016-08-13T17:22:29.997

Reputation: 87 464

I have no idea how this works. Well done! – DanTheMan – 2016-08-13T17:49:43.820

@DanTheMan I just added an explanation... I hope that helps! – Luis Mendo – 2016-08-13T17:50:15.640

I feel like the only language that could programmatically beat this is charcoal. – Magic Octopus Urn – 2017-04-11T14:46:38.827

5

Python 2, 69 bytes

print'''OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB'''

Just do it...

cdlane

Posted 2016-08-13T17:22:29.997

Reputation: 351

5how boring. im afraid this would beat the actual answer in python tho.. – downrep_nation – 2016-08-13T21:45:25.037

2

Bubblegum, 47 bytes

A hex dump, courtesy of xxd:

00000000: 520a adf6 2e08 7444 c41e c8ff 4096 ca2d  R.....tD....@..-
00000010: 8832 2297 8cd7 1bb1 fe10 43ce 39cc 8e5f  .2".......C.9.._
00000020: 31f7 3d63 432e d3f3 3873 ecf7 7641 a3    1.=cC...8s..vA.

(This is just the spiral, “compressed”.)

Try it online.

Lynn

Posted 2016-08-13T17:22:29.997

Reputation: 55 648

1

Fourier, 143 141 bytes

Not a particularly interesting answer except that it stores newlines (ASCII code 10) as the variable T... Uses isaacg's golfing program.

79a^a^a^a^a^a^a10a~T78a81avavavava86aTa77a82a69avava76a87aTa76a83a70a65a^a75a88aTa75a84a71a^a^a^a89a10a74a85a^a^a^a^a^a65aTa73avavavavavavava

Try it online

Try it online!

Beta Decay

Posted 2016-08-13T17:22:29.997

Reputation: 21 478

1

Python 3, 72 bytes

print('OPQRSTU\nNQPONMV\nMREDCLW\nLSFABKX\nKTGHIJY\nJUVWXYZA\nIHGFEDCB')

Not exactly interesting, but it still works!

techydesigner

Posted 2016-08-13T17:22:29.997

Reputation: 105

Use '''s instead of 's. – Erik the Outgolfer – 2016-09-28T12:22:30.177

@EriktheGolfer It'd be a duplicate if he did that. – mbomb007 – 2016-09-28T13:35:23.373

2@mbomb007 I don't think so, because the other one is Python 2. Python 3 is different AFAIK, but, if it would be a dupe, I don't see why it isn't a dupe like this. – Erik the Outgolfer – 2016-09-28T13:37:27.063

2@EriktheGolfer When the only difference is a pair of parentheses and the version of the language, and the method used is identical, it's a duplicate. Just because versions are slightly different, doesn't mean you can provide the exact same answer in every version of a language without it being a duplicate. – mbomb007 – 2016-09-28T18:41:42.940

1@mbomb007 As I said before, why isn't this, as it is right now, a dupe then? The method is the same, the only differences are 1) Quoting type (does not change functionality) and 2) Parentheses, because the print statement is now a function, but that doesn't change anything, except that print is out of the builtins (and enhanced). So, why isn't this still a dupe then? – Erik the Outgolfer – 2016-09-29T10:44:26.967

1

PHP, 130 bytes

for($p=30,$s=1,$r=_;$i<51;$r[$p]=chr(90-abs(25-$i++)),$p+=$s*(9-$d))if(!$n||!$c=++$c%$n)($d=8-$d)?$n++:$s=-$s;echo wordwrap($r,8);

literally draws the spiral. Run with -r

breakdown

for($p=30,$s=1,$r=_;    // initialize position to 3*9+3, $s(ign) to +1, $r(esult) to string
                        // implicit $c(ount)=$d(irection)=$i(ndex)=le($n)gth=0
    $i<51;              // loop $i from 0 to 50
    $r[$p]=chr(90-abs(25-$i++)),// 2. set current position in string to correct character
    $p+=$s*(9-$d))              // 3. move cursor
    if(!$n||!$c=++$c%$n)        // 1. if 1st iteration ($n==0) or ++$c has rotated around $n
        ($d=8-$d)                   // negate $direction (0=horizontal, 8=vertical)
            ?$n++                   // if vertical: increase length
            :$s=-$s                 // else invert sign
        ;
                        // output: wrap to lines of 8 characters
echo wordwrap($r,8);    // having left spaces avoids need to provide 3rd and 4th parameter

Easy to extend: For more alphabet, append %50 after $i++, replace 51 with the wanted number, modify 8-$d, 9-$d, $p=30 and the wordwrap width to the new dimensions.

Titus

Posted 2016-08-13T17:22:29.997

Reputation: 13 814

0

C#, 151 145 136 130 bytes

namespace a{class P{static void Main(){System.Console.Write("OPQRSTU\nNQPONMV\nMREDCLW\nLSFABKX\nKTGHIJY\nJUVWXYZA\nIHGFEDCB");}}}

Again, a boring one that does the trick.

Saved 6 bytes thanks to auhmaan.

Matt Brewerton

Posted 2016-08-13T17:22:29.997

Reputation: 101

You can save some bytes by replacing using System; ... Console.Write("...") with System.Console.Write("...") – auhmaan – 2017-04-11T15:00:13.780

You don't need a namespace. You can also compile to a Func<string> to save even more bytes: ()=>"OPQRSTU\nNQPONMV\nMREDCLW\nLSFABKX\nKTGHIJY\nJUVWXYZA\nIHGFEDCB"; – TheLethalCoder – 2017-06-01T14:46:34.583

You can save 5 bytes by using a string literal by prepending @ to the string before the quotes and then replacing the \n with literal new lines – PunPun1000 – 2017-06-01T18:35:15.100

You can save 2 more bytes by using namespace System and Console.Write instead of namespace a and System.Console.Write – Mr Scapegrace – 2017-06-02T07:37:24.220

0

Lua, 69 bytes

print([[OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB]])

At least it works!

Josh

Posted 2016-08-13T17:22:29.997

Reputation: 1 021

0

05AB1E, 46 bytes

•ûk2šÄ>¸©W$V-ÏfQ*LnHO”Ïmsqšƒ1ËUðhd@ý(™š•36B1¡»

Try it online!

Won't win by any means, but it does work.

Magic Octopus Urn

Posted 2016-08-13T17:22:29.997

Reputation: 19 422

0

JavaScript ES6, 62 bytes

a=>`OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB`

Try it

let f=a=>`OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB`;

console.log(f());

Shaggy

Posted 2016-08-13T17:22:29.997

Reputation: 24 623

0

Windows batch, 84 bytes

@for %%p in (OPQRSTU NQPONMV MREDCLW LSFABKX KTGHIJY JUVWXYZA IHGFEDCB) do @echo %%p

Simple enough for loop to loop through the strings.

stevefestl

Posted 2016-08-13T17:22:29.997

Reputation: 539

0

Japt, 54 52 bytes

`opqÏ
nqpmv
mdclw
lsfabkx
ktgjy
juvwxyza
ihgfcb

Try it online


Explanation

Simply a compressed string of the spiral in lowercase.

Shaggy

Posted 2016-08-13T17:22:29.997

Reputation: 24 623

0

Modern Pascal 2.0, 122 bytes

 Write('OPQRSTU'+#13#10+'NQPONMV'+#13#10+'MREDCLW'+#13#10+'LSFABKX'+#13#10+'KTGHIJY'+#13#10+'JUVWXYZA'+#13#10+'IHGFEDCB');

Explanation Simply embed CRLF into the string, and display it.

// Author of Modern Pascal

Ozz Nixon

Posted 2016-08-13T17:22:29.997

Reputation: 21

0

Ruby, 63 bytes

In this case, nothing I found beats the boring answer...

puts"OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB"

My best solution that didn't print the literal string only, but still has to directly hardcode some of it, is 110 bytes:

w=[*?B..?Q].reverse*''
puts [*?O..?U]*'',[?N,w[0,5],?V]*'',"MREDCLW
LSFABKX
KTGHIJY",[?J,*?U..?Z,?A]*'',w[8,8]

Value Ink

Posted 2016-08-13T17:22:29.997

Reputation: 10 608

0

///, 57 bytes

OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB

Try it online!

Just another boring answer. Move on!

Erik the Outgolfer

Posted 2016-08-13T17:22:29.997

Reputation: 38 134

Darn, I was 52561024 seconds late! – Comrade SparklePony – 2017-04-11T14:57:42.303