Make me an alphabet tree

14

2

Intro

In most fonts all of the uppercase alphabet characters besides BDO have single lines approximately touching some of the four corners of the character's bounding rectangle: ACEFGHIJKLMNPQRSTUVWXYZ.

For example, the two legs of an A "touch" the bottom left and bottom right corners of the character. Likewise, C touches its top and bottom right corners (it is a bit curved but it's close enough). L only touches it's top left and bottom right corners with single lines. The bottom left corner of L is a vertex, not the end of a single line.

Here is a table of what characters touch which corners according to the Stack Exchange font I (and hopefully you) see. 1 is for upper left, 2 is for upper right, 3 lower left, 4 lower right.

A: 3 4
C: 2 4
E: 2 4
F: 2 3
G: 2
H: 1 2 3 4
I: 1 2 3 4
J: 1 3
K: 1 2 3 4
L: 1 4
M: 3 4
N: 2 3
P: 3
Q: 4
R: 3 4
S: 2 3
T: 1 2
U: 1 2
V: 1 2
W: 1 2
X: 1 2 3 4
Y: 1 2
Z: 1 4

Setup

Pretend like these corner touching lines extend in the direction of the corner that they touch so that arrangements of these characters on a grid can be "connected".

For example, all the characters in

 A
C X

are connected because the bottom left of A and top right of C connect, and the bottom right of A and top left of X connect.

However,

CAX

has no connections because connections only occur diagonally from one character to the next.

Challenge

Write the shortest program possible (in bytes) that outputs all of the characters in ACEFGHIJKLMNPQRSTUVWXYZ in one big fully connected tree, according to the rules above. Each character must appear exactly once. Use spaces for empty space.

Example

Everything in this 23-letter tree can be reached from anything else via the diagonal connections defined above:

  Q
 A J   R
C U   S Y
 I M N
E H X
 F L T
G   Z K P
     V W

Notes

  • You may hardcode your solution.
  • Your output should only contain ACEFGHIJKLMNPQRSTUVWXYZ, spaces, and newlines. BDO will not be used.
  • Leading/trailing spaces are fine as long as all the connections are properly positioned.
  • The output grid should not be larger than 30 by 30 characters (including newlines and spaces).
  • Only corner connections are considered. The bottom of Y does not connect to anything. You must use the corner connections from the table above.
  • Not all connectable corners need to connect to something. Connectable and non-connectable corners may border each other.
  • Output to stdout. There is no input.
  • Including a connectivity graph made with slashes as Peter Taylor has done is a helpful touch but not required.

Update:
githubhagocyte has made an alphabet tree validity checker over on Github.

Calvin's Hobbies

Posted 2014-08-07T09:52:27.607

Reputation: 84 000

You may hardcode your solution? – edc65 – 2014-08-07T10:48:16.833

2@edc65 You may hardcode your solution. – Calvin's Hobbies – 2014-08-07T10:53:56.190

7Funny how those 2 phrases only have 1 different character :P – Teun Pronk – 2014-08-07T10:57:51.177

Wny not accept a graph as an output? That way, the connections are prominent. – DavidC – 2014-08-07T11:42:42.957

@githubphagocyte I don't see why not. – Calvin's Hobbies – 2014-08-07T12:24:41.977

1@githubphagocyte, that would be better as an addendum to the question than as an answer, given that it's not an answer. – Peter Taylor – 2014-08-07T13:59:05.347

@githubphagocyte You could give me a link to the code and I'll edit it in with credit to you. – Calvin's Hobbies – 2014-08-07T14:05:52.273

@githubphagocyte, if it's short, edit it in. If it's not, put it somewhere like gist.github.com and edit in a link. – Peter Taylor – 2014-08-07T14:10:06.847

B and D should both touch top and bottom left hand side shouldn't they? They look like it on my screen – Tom Tanner – 2014-08-07T15:13:42.097

@TomTanner Only the endpoints of single lines count, not vertices. – Calvin's Hobbies – 2014-08-07T15:58:00.183

1Nice golf, @Calvin'sHobbies. This one's a lot of fun to see the answers for. – Jordan – 2014-08-07T17:44:37.100

xkcd 1442 makes me wonder if Randall Munroe reads your questions as inspiration. – trichoplax – 2014-11-16T20:38:04.667

Answers

1

Pyth, 32

jd"QAPMFRLZ\nUINKSHXJ\n\0GTCVEWY

Output:

Q A P M F R L Z 
 U I N K S H X J 
  G T C V E W Y

Connections, thanks to @githubphagocyte's checker:

Q   A   P   M   F   R   L   Z   
 \ / \ /   / \ /   / \   \   \  
  U   I   N   K   S   H   X   J   
     / \ /   / \ /   / \ / \ /    
    G   T   C   V   E   W   Y 

Combines @grc's null byte trick and Pyth's extremely short syntax. Made my own grid for the hell of it.

Explanation:

j is python's string join. d is space. \0 is the escape sequence for the null byte. It is a NOP when printed, so the third line has exactly two spaces in front. Also, note that strings can be EOL-terminated in Pyth, as well as quote-terminated.

isaacg

Posted 2014-08-07T09:52:27.607

Reputation: 39 268

12

GolfScript (41 chars)

'QZENRPMALHIFKSXJTUVWYGC'8/{' '*n' '+:n}/

Online demo

Connectivity graph:

Q   Z   E   N   R   P   M   A
 \   \   \ /   / \ /   / \ / \
  L   H   I   F   K   S   X   J
   \ / \ / \ /   / \ /   /   /
    T   U   V   W   Y   G   C

Peter Taylor

Posted 2014-08-07T09:52:27.607

Reputation: 41 901

11

Python, 49

print' '.join('  MQRCNAF\n XZHLKSIP\n\0GJWVUYET')

Example:

>>> print' '.join('  MQRCNAF\n XZHLKSIP\n\0GJWVUYET')
    M Q R C N A F 
   X Z H L K S I P 
  G J W V U Y E T

I think it connects up properly now, but I may have missed something again.

grc

Posted 2014-08-07T09:52:27.607

Reputation: 18 565

F4 looks connected to G1, which is invalid – Tymric – 2014-08-07T11:28:49.160

@Timmy But F2 is connected to A3. It all looks connected to me. – Calvin's Hobbies – 2014-08-07T11:33:53.550

@Calvin'sHobbies I think I misunderstood the requirements. Is it allowed to have adjacent corners that aren't connected? – Tymric – 2014-08-07T11:55:53.263

2@Timmy Sure. Those pairs of corners just don't count as connected, but the two letters may be connected in another way. – Calvin's Hobbies – 2014-08-07T11:57:36.377

9

Marbelous 164 158 143

used bmarks' tree since it almost perfectly optimized for Marbelous. Code in this case is just the ascci codes for all characters (including spaces and newlines) from left to right, delimited by spaces.

43 20 46 20 50 20 4D 20 51 20 52 20 45 20 41 14 20 58 20 48 20 4e 20 4C 20 4B 20 5A 20 49 20 53 14 47 20 59 20 56 20 20 20 55 20 4A 20 54 20 57

Output:

 C F P M Q R E A 
  X H N L K Z I S 
 G Y V   U J T W

A better Marbelous approach 135 129

This one outputs the same tree with one extra space before and after each line, it works by feeding the literals into a subroutine that prints a space before printing the literal. And just printing a space if the literal is a space (20 HEX)

57
54
4A
55
20
56
59
47
14
53
49
5A
4B
4C
4E
48
58
20
14
41
45
52
51
4D
50
46
43
Sp
Sp:
20 I0
.. =V

overactor

Posted 2014-08-07T09:52:27.607

Reputation: 3 500

This answer will get down to 96 when spaces between cells are no longer required for Marbelous source code, which will be the case later today. – overactor – 2014-08-07T15:16:30.160

1Using languages or language features which postdate the question is considered cheating. – Peter Taylor – 2014-08-07T16:41:02.497

4@PeterTaylor For now this answer only uses features that were implemented when the question was asked. – overactor – 2014-08-07T17:31:48.397

7

BrainF*ck 669

Made this one for giggles. Outputs the exact same as the example.
Will provide another solution later. Can't think of a clever way to do this in Lua so I'll just stick to this one :)

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

Output

  Q
 A J   R
C U   S Y
 I M N
E H X
 F L T
G   Z K P
     V W

Teun Pronk

Posted 2014-08-07T09:52:27.607

Reputation: 2 599

2No matter how crazy the codegolf challenge, there's almost always a brainfuck answer. Gotta love it +1 – Pharap – 2014-08-07T12:34:47.277

@AndoDaan Nope it wouldn't. I didn't use that though. I made my own brainf*ck like I always do. I did use that a lot and learned most of the tricks I always use when writing BF so I wouldn't be surprised if it looks simular. – Teun Pronk – 2014-08-07T14:38:42.613

Not simular, identical. Both 669 bytes in length. Both using the same character by character method(no optimization at all), and also both identical with where all the plussy, miney and other thingy symbols go. – AndoDaan – 2014-08-07T14:51:13.323

2Must be a coincidence then. I participate for the fun of the challenge and I don't see the fun of generating a BF. The only way that even could be fun a little bit is when you wrote the generator yourself. – Teun Pronk – 2014-08-07T14:54:34.340

6

PHP 46

This was more like puzzle solving rather than programming, so my answer is more like puzzle solution rather than code. However it's a valid PHP program, so I'm submitting it.

C A Q S R P M J
 X Z I F K N H
G T U V W Y E L

Update the same in Perl. Length still remains 46:

print"CAQSRPMJ
 XZIFKNH
GTUVWYEL"=~s/\S/$& /rg

core1024

Posted 2014-08-07T09:52:27.607

Reputation: 1 811

4

HTML, 55

code

<pre>C F P M Q R E A
 X H N L K Z I S
G Y V   U J T W

output:

C F P M Q R E A
 X H N L K Z I S
G Y V   U J T W

xem

Posted 2014-08-07T09:52:27.607

Reputation: 5 523

3

Bash+coreutils, 46

sed 's/\S/ &/g'<<<"CAQSRPMJ
 XZIFKNH
GTUVWYEL"

Now shamelessly borrowing @core1024 optimal tree:

Output:

$ ./alphatree.sh
 C A Q S R P M J
  X Z I F K N H
 G T U V W Y E L
$

Digital Trauma

Posted 2014-08-07T09:52:27.607

Reputation: 64 644

2

STATA 63

Edit: now my own solution. Should be all the letters.

di 'C F P M Q R E A' di ' X H N L K Z I S' di 'G Y V   U J T W'

 C F P M Q R E A 
  X H N L K Z I S 
 G Y V   U J T W

bmarks

Posted 2014-08-07T09:52:27.607

Reputation: 2 114

1

Javascript 83

I'll begin with hardcoding YOUR solution

console.log('  Q\n A J   R\nC U   S Y\n I M N\nE H X\n F L T\nG   Z K P\n     V W')

edc65

Posted 2014-08-07T09:52:27.607

Reputation: 31 086

make it shorter with alert instead of console.log – Zaenille – 2014-08-07T15:07:18.673

2@MarkGabriel I'd like to make it shorter in some smarter way. Alert has not the right font to display ascii art. – edc65 – 2014-08-07T15:20:14.380

1I see. Forgot about alert's formatting being different. :) – Zaenille – 2014-08-08T00:28:05.320

1

PHP, 69

<?php echo preg_replace("/(\w)/",'\1 ',"CAQSRPMJ
 XZIFKNH
GTUVWYEL");

gives

C A Q S R P M J 
 X Z I F K N H 
G T U V W Y E L

Victory

Posted 2014-08-07T09:52:27.607

Reputation: 21

You can shave two bytes by replacing your regex with "/\w/",'\0 ' – ATaco – 2016-11-07T02:30:14.813

You have no diagonal connections at all in your output – edc65 – 2014-08-11T07:11:56.147

@MartinBüttner - thank you, it cost me a byte to fix. – Victory – 2014-08-11T22:33:28.757

The problem with this (and many other) response is that the output is shorter than the code (see core1024 php) – edc65 – 2014-08-11T22:43:01.787