The challenge is to write an acrostic piece of code.

When read normally (horizontally), the code should take an input string and remove all but the first character on each line. For example, the input:

float
or and
ord
 line
bool var
auto
real

Output:

foo bar

In addition to this, the code also must contain valid code when run vertically. Such that applying the horizontal code on itself yields a new piece of valid code in a different language.

Rules/Restrictions:

  • Each horizontal line must contain at least 2 non-whitespace characters
  • The vertical code cannot use newlines.
  • The vertical code must be in a different language from the horizontal language, preferably something entirely different
  • The code does not have to be a complete program (doesn't need main function, etc)

What the vertical code does is up to you, although the goal is to have it do something interesting. Having it do nothing is not interesting.

Easy Mode:

  • You may use the same language both horizontally and vertically
  • No restrictions on language choice

Hard mode:

  • No comments
  • Both codes should compile and run (main function, etc)
  • Horizontal code contains exactly 1 word per line

closed as off-topic by Rohan Jhunjhunwala, Steadybox, Post Left Garf Hunter, Martin Ender Apr 14 '17 at 22:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – Rohan Jhunjhunwala, Steadybox, Post Left Garf Hunter, Martin Ender
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Wow, that looks hard. – PhiNotPi Dec 29 '11 at 0:59
up vote 4 down vote accepted

Brainfuck -> Ruby

e,
v[
a.
l>
"+
a[
=-<,----------
[>
i+
=<
0[-]
]>
*]
3,
e]
4[
;g
"4
+d
$)
<^
.%
b$
y@
ta
el
sD
.{
m[
a}
p]
{.
|d
bA
|:)
{y
?T
.K
,s
"+
pG
up
th
c}
 P
a$
[v
iF
]o
"d
,8
?t
,=
,h
"3
ay
[&
i*
]H
=s
gj
e9
t,
c<
"D
,d
?`
[q
,z
")
wT
hx
ie
lz
eW
 >
a$
[^
i!
];
>Y
0q
"#
,T
?X
]A
,b
"J
e$
n#
ds
"K
,$
?}
<?
,.
"e
iJ
-W
=k
1B
"&
,J
?g
>.
,>
"/
i@
+/
=s
1v
"E
,)
?.
+8
,v
"7
aS
[b
i$
]#
+5
=m
1w
"3
,*
?u
-f
,Z
"I
aW
[U
i%
]3
-v
=T
1E
":
}G
[;
b2
]@
};
*/
"+
;M
"B]

Horizontal is this little gem:

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

And Vertical is this:

eval"a=[i=0]*3e4;"+$<.bytes.map{|b|{?.,"putc a[i]",?,,"a[i]=getc",?[,"while a[i]>0",?],"end",?<,"i-=1",?>,"i+=1",?+,"a[i]+=1",?-,"a[i]-=1"}[b]}*";"

Which is a brainfuck interpreter stolen from this question. It qualifies for all of the hard mode criteria except the no comments bit, which I don't think is really fair to apply to brainfuck, or pretty much nothing but BF->BF would be possible.

Horizontal program runs till EOF(0) is read. Assumes newline at end of file.

Perl -> HQ9+

Any verbose target language results in huge and unreadable code (IMHO), so in the interest of the reader I'll keep it short:

+print/(^.)/for<>
  • 1
    I guess that's an interesting program as HQ9+ programs go... ;) – mellamokb Dec 29 '11 at 14:18
  • 1
    @mellamokb a very insightful remark. By increasing the accumulator (which undoubtedly is also an "interesting" HQ9+ program) instead of greeting the world, I can spare a character! Thanks a lot! – J B Dec 29 '11 at 14:58
  • @cemper93 I beg your pardon, but just exactly what rule is being abused here? – J B Dec 29 '11 at 22:26
  • 2
    I think HQ9+ by its very nature is rule abuse. +1 – captncraig Dec 30 '11 at 15:11
  • Well, I guess strictly speaking you abuse the lack of a rule regarding the vertical code's length ;) – cemper93 Dec 30 '11 at 21:11

Befunge-93 (main program) -> C (vertical program)

 >~:25*-v
m^>>>>v,_@
a^^...~
i^^...:
n^^...2 
(^^...5
i^^...*
,^^...-
j^^<<<_$v
)^<<<<<<<
{|
f|
o|
r|
(|
i|
=|
0|
;|
i|
<|
6|
4|
;|
i|
+|
+|
)|
{|
f|
o|
r|
(|
j|
=|
0|
;|
j|
<|
6|
4|
;|
j|
+|
+|
)|
p|
u|
t|
c|
h|
a|
r|
(|
i|
&|
j|
?|
3|
2|
:|
4|
6|
)|
;|
p|
u|
t|
c|
h|
a|
r|
(|
1|
0|
)|
;|
}|
}|

The main program is a Befunge-93 code which does the task and ends by reading a blank line. The vertical program is in C which prints a Sierpinski triangle of depth 4 with '.' characters.

main(i,j){for(i=0;i<64;i++){for(j=0;j<64;j++)putchar(i&j?32:46);putchar(10);}}

I think I met all rules and restrictions and all items in hard mode. I'm not sure if I didn't use comments. Because comment definition in Befunge is not the same as other languages.

EDITED: added some pipe characters which are vertical condition command in befunge to meet first rule (2 non-whitespace characters in each line) as pointed out by @CMP

  • Each horizontal line must have 2 non-whitespace characters. Add Jibberish. – captncraig Dec 29 '11 at 21:56

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