Acrostic polyglot programming

7

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

Pubby

Posted 2011-12-29T00:33:01.840

Reputation: 1 239

Question was closed 2017-04-14T22:03:35.947

Wow, that looks hard. – PhiNotPi – 2011-12-29T00:59:46.923

Answers

4

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.

captncraig

Posted 2011-12-29T00:33:01.840

Reputation: 4 373

4

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

saeedn

Posted 2011-12-29T00:33:01.840

Reputation: 1 241

Each horizontal line must have 2 non-whitespace characters. Add Jibberish. – captncraig – 2011-12-29T21:56:32.730

4

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<>

J B

Posted 2011-12-29T00:33:01.840

Reputation: 9 638

1I guess that's an interesting program as HQ9+ programs go... ;) – mellamokb – 2011-12-29T14:18:24.863

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 – 2011-12-29T14:58:23.450

@cemper93 I beg your pardon, but just exactly what rule is being abused here? – J B – 2011-12-29T22:26:38.167

2I think HQ9+ by its very nature is rule abuse. +1 – captncraig – 2011-12-30T15:11:50.813

Well, I guess strictly speaking you abuse the lack of a rule regarding the vertical code's length ;) – cemper93 – 2011-12-30T21:11:19.090