Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

share|improve this question
    
You may hardcode your solution? –  edc65 Aug 7 at 10:48
2  
@edc65 You may hardcode your solution. –  Calvin's Hobbies Aug 7 at 10:53
4  
Funny how those 2 phrases only have 1 different character :P –  Teun Pronk Aug 7 at 10:57
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 Aug 7 at 13:59
1  
Nice golf, @Calvin'sHobbies. This one's a lot of fun to see the answers for. –  Jordan Aug 7 at 17:44

11 Answers 11

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
share|improve this answer

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.

share|improve this answer
    
F4 looks connected to G1, which is invalid –  Timmy Aug 7 at 11:28
    
@Timmy But F2 is connected to A3. It all looks connected to me. –  Calvin's Hobbies Aug 7 at 11:33
    
@Calvin'sHobbies I think I misunderstood the requirements. Is it allowed to have adjacent corners that aren't connected? –  Timmy Aug 7 at 11:55
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 Aug 7 at 11:57

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
share|improve this answer
    
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 Aug 7 at 15:16
1  
Using languages or language features which postdate the question is considered cheating. –  Peter Taylor Aug 7 at 16:41
4  
@PeterTaylor For now this answer only uses features that were implemented when the question was asked. –  overactor Aug 7 at 17:31

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
share|improve this answer
2  
No matter how crazy the codegolf challenge, there's almost always a brainfuck answer. Gotta love it +1 –  Pharap Aug 7 at 12:34
    
@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 Aug 7 at 14:38
    
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 Aug 7 at 14:51
2  
Must 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 Aug 7 at 14:54

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
share|improve this answer
    
+1 for the optimal packing! –  DigitalTrauma Aug 10 at 14:56

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
share|improve this answer

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
$
share|improve this answer

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
share|improve this answer

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')
share|improve this answer
    
make it shorter with alert instead of console.log –  Mark Gabriel Aug 7 at 15:07
2  
@MarkGabriel I'd like to make it shorter in some smarter way. Alert has not the right font to display ascii art. –  edc65 Aug 7 at 15:20
1  
I see. Forgot about alert's formatting being different. :) –  Mark Gabriel Aug 8 at 0:28

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
share|improve this answer
    
You have no diagonal connections at all in your output –  edc65 Aug 11 at 7:11
    
@MartinBüttner - thank you, it cost me a byte to fix. –  Victory Aug 11 at 22:33
    
The problem with this (and many other) response is that the output is shorter than the code (see core1024 php) –  edc65 Aug 11 at 22:43

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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