Tell me more ×
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.

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
share|improve this question
Wow, that looks hard. – PhiNotPi Dec 29 '11 at 0:59

3 Answers

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.

share|improve this answer

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<>
share|improve this answer
I guess that's an interesting program as HQ9+ programs go... ;) – mellamokb Dec 29 '11 at 14:18
@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
1  
+1 for rule abuse – cemper93 Dec 29 '11 at 19:50
@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 – CMP Dec 30 '11 at 15:11
show 1 more comment

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

share|improve this answer
Each horizontal line must have 2 non-whitespace characters. Add Jibberish. – CMP Dec 29 '11 at 21:56
@CMP edited, thanks – saeedn Dec 30 '11 at 9:49

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.