7
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ Wow, that looks hard. \$\endgroup\$
    – PhiNotPi
    Commented Dec 29, 2011 at 0:59
  • \$\begingroup\$ I think the main reason this should remain closed - after a conversion to being a golf, is that the second piece of code can do "anything" which isn't very clear. \$\endgroup\$ Commented Apr 12, 2020 at 15:44

3 Answers 3

4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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<>
\$\endgroup\$
5
  • 1
    \$\begingroup\$ I guess that's an interesting program as HQ9+ programs go... ;) \$\endgroup\$
    – mellamokb
    Commented Dec 29, 2011 at 14:18
  • 1
    \$\begingroup\$ @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! \$\endgroup\$
    – J B
    Commented Dec 29, 2011 at 14:58
  • \$\begingroup\$ @cemper93 I beg your pardon, but just exactly what rule is being abused here? \$\endgroup\$
    – J B
    Commented Dec 29, 2011 at 22:26
  • 2
    \$\begingroup\$ I think HQ9+ by its very nature is rule abuse. +1 \$\endgroup\$
    – captncraig
    Commented Dec 30, 2011 at 15:11
  • \$\begingroup\$ Well, I guess strictly speaking you abuse the lack of a rule regarding the vertical code's length ;) \$\endgroup\$
    – cemper93
    Commented Dec 30, 2011 at 21:11
4
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ Each horizontal line must have 2 non-whitespace characters. Add Jibberish. \$\endgroup\$
    – captncraig
    Commented Dec 29, 2011 at 21:56

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