C#
So I decided to get a little more... creative with my entry. The Brainfuck code is embedded into the C# as the various operators (not in comments or in hardcoded strings), while the C# code itself operates on a similar principal to the way Brainfuck prints characters (meaning there are no hardcoded strings, and C# generates each individual character as an integer then casts it to a char when printing).
I'm sure I could have made this more elegant, but it took me long enough to finish as it is.
Everything was tested on this JavaScript Brainfuck interpreter by Cal Henderson and with Visual Studo 2012's C# compiler (targeted at .NET framework v4.0).
using System;
namespace Polyglot
{
internal static class Program
{
private static void Main()
{
var a = new short[50];
short _1 = 72;
short _2 = 0;
short _3 = 0;
short _4 = 0;
short _5 = 0;
short _6 = 0;
short _7 = 97;
short _8 = 0;
short _9 = 0;
short _10 = 0;
short _11 = 0;
short _12 = 0;
short _13 = 0;
short _14 = 0;
short _15 = 0;
short _16 = 46;
short _19 = 0;
short _20 = 0;
short _21 = 0;
if( 0 >= 0 )
{
++_1;
++_1;
++_1;
++_1;
}
a[ -1 < 0 ? 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 : 0 + 1 > 1 ? 0 : 0 ] = 9001;
if( 7 < 42 )
{
++_1;
++_1;
}
Console.Write( (char)_1 );
_2 = 101;
_1 += 1 + 1 + 1 + 1 + 1;
_3 = 42 > 7 ? 110 + 9 : 1 + 1;
a[ -1 < 0 ? 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 : 0 > 0 ? 0 : 0 ] = 9001;
if( 1 < 2 )
_4 = 32;
Console.Write( (char)_2 );
++_1;
_5 = 105;
Console.Write( (char)_3 );
--_1;
_6 = 115;
Console.Write( (char)_4 );
++_1;
++_1;
++_1;
_1 += 1 + 1 + 5;
Console.Write( (char)_5 );
--_1;
--_1;
if( 42 > 41 )
{
++_1;
++_1;
++_1;
}
a[ -1 < 0 ? 0 : 10 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 > 5 ? 0 : 0 ] = 9001;
if( 42 < 9001 )
Console.Write( (char)_6 );
Console.Write( (char)_4 );
Console.Write( (char)_7 );
if( 12 > 11 && 11 > 10 )
{
_8 = 108;
_9 = _3;
}
else
{
++_1;
++_1;
++_1;
}
a[ -1 < 0 ? 1 + 1 + 1 + 1 + 1 + 1 : 1 > 2 ? 0 : 0 ] = 9001;
if( _4 < _1 )
{
++_1;
Console.Write( (char)_8 );
}
else if( _4 > _19 && _2 > _20 )
{
++_21;
++_21;
++_21;
++_21;
++_21;
_21 += (short)( _21 + 36 );
}
a[ -7 < 9 ? 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 : 4 > 8 ? 9 : 9 ] = (short)( 12 < 10 ? -_4 : _9 );
Console.Write( (char)_9 );
if( _4 > _9 )
{
++_1;
++_1;
++_1;
}
a[ -9 < 7 ? 10 - 1 - 1 - 1 - 1 : 6 > 7 ? 0 : 0 ] = _21;
if( 1 < 0 )
return;
else
{
++_1;
Console.Write( (char)_7 );
}
_10 += 5 + 4 + 1 + 2 + 8 + 9 + 1 + 91;
Console.Write( (char)_10 );
if( 10 > _4 ) ++_21; else a[ -0 < 0 ? 5 + 6 + 1 + 2 + 3 + 9 : 1 > 2 ? 0 : 9 ] = 50;
if( _21 <= _4 )
_11 = 58 + 57;
Console.Write( (char)_11 );
if( _2 <= _8 )
Console.Write( (char)_4 );
else if( 1 >= 2 )
return;
else if( 42 >= _4 )
_1 += ++_21;
else
{
a[ -99 < --_1 ? --_1 - _1 : 44 > 12 ? 9 : 7 ] = (short)( _2 < _4 ? _21 : 6 );
throw new Exception();
}
switch( _4 )
{
case 32:
var x = (char)( (short)( _4 + 66 ) );
Console.Write( x );
break;
default: break;
}
_12 += (short)( ++_12 + ( ++_1 ) + 1 + 1 + 1 );
Console.Write( (char)_12 );
_13 += (short)( 39 + 38 + 39 );
Console.Write( (char)_13 );
if( _12 < _13 )
Console.Write( (char)_13 );
if( _13 >= _4 )
{
_14 = (short)( 500 - ( - ( 50 ) ) - ( --_1 ) - 90 - ( -4 ) - 267 );
Console.Write( (char)_14 );
}
switch( _1 )
{
case 52:
_15 += (short)( ++_1 + ( ++_21 ) );
break;
default:
_15 += (short)( 15 + ( ++_1 ) + 2 );
break;
}
Console.Write( (char)_15 );
if( _16 <= 3521 && _21 < _4 )
Console.WriteLine( (char)_16 );
_16 = (short)( Int16.Parse( "54" ) % 2 );
_20 = (short)( Int16.Parse( "99" ) / ( _1 > _4 ? 3 : 0 ) );
_1 = (short)( 02.23 );
if( _16 > 9 || _20 >= 52 )
_1 += (short)( ( ++_1 ) + _21 );
a[ -0 < 0 ? -52 - ( --_20 ) : 1 > 0 ? 1 : 2 ] = (short)( _12 < _19 ? Int16.Parse( "19" ) : 44 );
_12 -= (short)f( --_19 / 19.467d );
if( _12 > _14 )
_19 += (short)( _19 + 1 + _3 + 5 );
a[ -904 < 409 ? 4 + ( ++_4 ) + 4 : 49 > 50 ? 49 : 50 ] = (short)( 50 < 99 ? _4 + 669.2452 : 0 );
if( 44 > ++_4 )
a[ -9 < 6 ? 6 + ( ++_4 ) : 9 > 2 ? 44 : 8 ] = 3;
}
private static double f( double x )
{
return x < 12 ? x + 13.22 : x < 6 ? x + 90.45 : 5555;
}
}
}
This is the original Brainfuck code I wrote for this challenge:
> +++++ +++
[ - < +++++ ++++ > ]
< ++++ .
+++++
> ++
[ - < +++++ +++++ > ]
< . ++ . -- . +++++ ++++ .
----
> +++++ +
[ - < ----- ----- > ]
< ... >>
+++++ +
[ - < +++++ > ]
< ++ . >>
+++++ +++++ ++
[ - < +++++ +++++ > ] <
- . >
+++++ +
[ - < ---- > ] <
++ . +++++ +++ .
> ++
[ - < +++++ > ]
< + . < . >>
+++
[ - < ----- > ] <
+ . +++++ ++++ . +++ .
< . > ----- ---- . +++++ +++++ + .
<< ... > . >>
++++
[ - < ---- > ] < .
--- . >
++++
[ - < ++++ > ]
< + .
> ++
[ - < +++ > ]
< + . < + .
When running the C# code through a Brainfuck interpreter, you end up with the following commands (notice the addition of the square brackets at the beginning, these are from the array declaration and don't do anything, since the cell under the memory pointer in the array will already be 0):
[] > +++++ +++
[ - < +++++ ++++ > ]
< ++++ .
+++++
> ++
[ - < +++++ +++++ > ]
< . ++ . -- . +++++ ++++ .
----
> +++++ +
[ - < ----- ----- > ]
< ... >>
+++++ +
[ - < +++++ > ]
< ++ . >>
+++++ +++++ ++
[ - < +++++ +++++ > ] <
- . >
+++++ +
[ - < ---- > ] <
++ . +++++ +++ .
> ++
[ - < +++++ > ]
< + . < . >>
+++
[ - < ----- > ] <
+ . +++++ ++++ . +++ .
< . > ----- ---- . +++++ +++++ + .
<< ... > . >>
++++
[ - < ---- > ] < .
--- . >
++++
[ - < ++++ > ]
< + .
> ++
[ - < +++ > ]
< + . < + .
Not sure
code-golf
is the best tag for this challenge. IMHOpopularity-contest
would be better. – Florent – 2014-02-25T10:10:41.630@Florent, feel free to edit, I'm new here – Thomas Ayoub – 2014-02-25T10:11:40.837
3Whose Barney? The purple dinosaur? Fred's BFF? – None – 2014-02-25T10:14:18.443
1@LowerClassOverflowian How I met Your Mother character, see edit – Thomas Ayoub – 2014-02-25T10:15:51.260
Samoth, I agree with @florent, but neither he nor I can edit as you need 1000 reputation to edit someone else's question. You can do it yourself though if you think it's a good idea. – Level River St – 2014-02-25T10:32:58.903
@steveverrill strange, on StackOverflow you can edit with 1 rep, but it have to be approved – Thomas Ayoub – 2014-02-25T10:34:37.647
Yeah, you can "suggest" with 1 rep, but the approval process the edit could take hours. It's better to do it yourself, as you have done. – Level River St – 2014-02-25T10:37:01.217
4Can someone please create the tag "bro-contest"? – Pierre Arlaud – 2014-02-25T10:53:57.423
1@Florent if the challenge is intended to be won by the shortest answer, I don't think you should retag it to a popularity contest. Samoth, in case you don't know, in a popularity contest the winner is chosen by voters - the answer with the highest vote wins. If you want your contest to be won by the answer with shortest code, please retag your question as a code-golf, and if you want it to be a popularity contest, please edit your question. – user12205 – 2014-02-25T11:11:26.823
I think reusing somebody else's Brainfuck code is poor sport for these competitions. – grovesNL – 2014-02-25T17:31:18.370
@grovesNL as it would be the exact same code, no. I could even have include it in the question – Thomas Ayoub – 2014-02-25T22:08:45.683
@Samoth: That assumes that everyone independently found the shortest way to write that string in Brainfuck, when there is no obvious shortest path to write strings. It's completely different than writing something like
echo "text"
. An extra plus sign before a loop will change the entire procedure, because of how the characters have to be created. Likewise using two loops instead of one loop could either increase or decrease the length of your code, and due to the ASCII characters, it's not obvious which will occur until you've already written it. – grovesNL – 2014-02-25T22:18:40.023