-4
\$\begingroup\$

Write a function or program that outputs the following lines <input> time:

Hello World. Dlrow Olleh. Hwlrod Eoll.
Big Brown Fox. Xof Nworb Gib. Bbfgox Iro.

EDIT: It's "B rown F ox" not "brown fox".

This is so the program with the shortest bytecount wins!

\$\endgroup\$
12
  • \$\begingroup\$ Can we ignore the capitalization? \$\endgroup\$
    – fR0DDY
    Feb 20, 2011 at 12:13
  • 4
    \$\begingroup\$ I think in most languages the code to mix up the characters is larger than embedding the strings directly. \$\endgroup\$
    – Joey
    Feb 20, 2011 at 12:55
  • 7
    \$\begingroup\$ I can't even work out what algorithm is applied to get the third sentence. \$\endgroup\$ Feb 20, 2011 at 15:18
  • \$\begingroup\$ @Peter: The first word is the odd characters of the original words, the second one is the even characters. \$\endgroup\$
    – Eelvex
    Feb 20, 2011 at 15:52
  • 1
    \$\begingroup\$ Bbfgox Iro isn't even a permutation.................... \$\endgroup\$ Mar 15, 2018 at 12:38

9 Answers 9

5
\$\begingroup\$

vim - 82 strokes

oHello World. Dlrow Olleh. Hwlrod Eoll.
Big brown fox. Xof Nworb Gib. Bbfgox Iro.<ESC>

Type the number of repeats you want before entering this.

\$\endgroup\$
2
\$\begingroup\$

Python 110 105 Characters

exec"print'Hello World. Dlrow Olleh. Hwlrod Eoll.\\nBig brown fox. Xof Nworb Gib. Bbfgox Iro.';"*input()
\$\endgroup\$
1
  • \$\begingroup\$ you can take off 5 characters by using one print and \\n to end the line \$\endgroup\$
    – Doug T.
    Feb 20, 2011 at 14:58
1
\$\begingroup\$

Ruby - 84 chars

"Hello World. Dlrow Olleh. Hwlrod Eoll.
Big brown fox. Xof Nworb Gib. Bbfgox Iro."*n
\$\endgroup\$
1
\$\begingroup\$

JavaScript - 100 characters

while(n--)print('Hello World. Dlrow Olleh. Hwlrod Eoll.\nBig brown fox. Xof Nworb Gib. Bbfgox Iro.')
\$\endgroup\$
1
\$\begingroup\$

D: 127 Characters

auto f(int n){return join(repeat("Hello World. Dlrow Olleh. Hwlrod Eoll.\nBig brown fox. Xof Nworb Gib. Bbfgox Iro.",n),"\n");}

More Legibly:

auto f(int n)
{
    return join(repeat("Hello World. Dlrow Olleh. Hwlrod Eoll.\nBig brown fox. Xof Nworb Gib. Bbfgox Iro.", n), "\n");
}
\$\endgroup\$
1
\$\begingroup\$

PowerShell: 95

"Hello World. Dlrow Olleh. Hwlrod Eoll.`nBig Brown Fox. Xof Nworb Gib. Bbfgox Iro.`n"*(read-host)

Read-Host prompts the user for input, then the string is multiplied by that value and printed. This will have an extra newline at the end, but I don't see that as a constraint in the challenge.

\$\endgroup\$
1
\$\begingroup\$

Whitespace, 761 724 bytes

[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_input_as_integer][T   T   T   _Retrieve_heap_at_0][S N
S _Duplicate][N
S S N
_Create_Label_LOOP][S N
N
_Discard_top][S S S T   N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate_input][N
T   T   T   N
_Jump_to_Label_EXIT_if_negative][S S S N
_Push_0][S S T  T   S T T   S S T   N
_Push_-89_\n][S S T T   T   S T S T N
_Push_-53_.][S S S T    T   S S N
_Push_12_o][S S S T T   T   T   N
_Push_15_r][S S T   T   T   S T S N
_Push_-26_I][S S T  T   S S S S T   T   N
_Push_-67_space][S S S T    S T S T N
_Push_21_x][S S S T T   S S N
_Push_12_o][S S S T S S N
_Push_4_g][S S S T  T   N
_Push_3_f][S S T    T   N
_Push_1_b][S S T    T   S S S S T   N
_Push_-33_B][S T    S S T   T   S N
_Copy_6th_space][S S T  T   T   S T S T N
_Push_-53_.][S S T  T   N
_Push_1_b][S S S T  T   S N
_Push_6_i][S S T    T   T   T   S S N
_Push_-28_G][S T    S S T   S S N
_Copy_4th_space][S S T  T   N
_Push_-1_b][S S S T T   T   T   N
_Push_15_r][S S S T T   S S N
_Push_12_o][S S S T S T S S N
_Push_20_w][S S T   T   S T S T N
_Push_-21_N][S T    S S T   S T N
_Copy_5th_space][S S S T    T   N
_Push_3_f][S S S T  T   S S N
_Push_12_o][S S T   T   S T T   N
_Push_-11_X][S T    S S T   T   N
_Copy_3rd_space][S S T  T   T   S T S T N
_Push_-53_.][S S S T    S T S T N
_Push_21_x][S S S T T   S S N
_Push_12_o][S S T   T   T   T   S T N
_Push_-29_F][S T    S S T   S S N
_Copy_4th_space][S S S T    S T T   N
_Push_11_n][S S S T S T S S N
_Push_20_w][S S S T T   S S N
_Push_12_o][S S S T T   T   T   N
_Push_15_r][S S T   T   S S S S T   N
_Push_-33_B][S T    S S T   S T N
_Copy_5th_space][S S S T    S S N
_Push_4_g][S S S T  T   S N
_Push_6_i][S T  S S T   T   N
_Copy_3rd_B][S S T  T   S T T   S S T   N
_Push_-89_\n][S S T T   T   S T S T N
_Push_-53_.][S S S T    S S T   N
_Push_9_l][S N
S _Duplicate_9_l][S S S T   T   S S N
_Push_12_o][S S T   T   T   T   T   S N
_Push_-30_E][S T    S S T   S S T   N
_Copy_9th_space][S S S T    N
_Push_1_d][S T  S S T   T   N
_Copy_3rd_o][S S S T    T   T   T   N
_Push_15_r][S S S T S S T   N
_Push_9_l][S S S T  S T S S N
_Push_20_w][S S T   T   T   S T T   N
_Push_-27_H][S T    S S T   T   S N
_Copy_6th_space][S S T  T   T   S T S T N
_Push_-53_.][S S S T    S T N
_Push_5_h][S S S T  S N
_Push_2_e][S S S T  S S T   N
_Push_9_l][S N
S _Duplicate_9_l][S S T T   S T S S N
_Push_-20_O][S T    S S T   T   S N
_Copy_6th_space][S S S T    S T S S N
_Push_20_w][S S S T T   S S N
_Push_12_o][S S S T T   T   T   N
_Push_15_r][S S S T S S T   N
_Push_9_l][S S T    T   T   T   T   T   N
_Push_-31_D][S T    S S T   S T N
_Copy_5th_space][S S T  T   T   S T S T N
_Push_-53_.][S S S T    N
_Push_1_d][S S S T  S S T   N
_Push_9_l][S S S T  T   T   T   N
_Push_15_r][S S S T T   S S N
_Push_12_o][S S T   T   T   S S N
_Push_-12_W][S T    S S T   T   S N
_Copy_6th_space][S S S T    T   S S N
_Push_12_o][S S S T S S T   N
_Push_9_l][S N
S _Duplicate_9_l][S S S T   S N
_Push_2_e][S S T    T   T   S T T   N
_Push_-27_H][N
S S S N_Create_Label_PRINTER
][S N
S _Duplicate][N
T   S N_Jump_to_Label_LOOP_if_0
][S S S T   T   S S S T T   N_Push_99
][T S S S _Add][T   N
S S _Print_as_character][N
S N
S N
_Jump_to_Label_PRINTER]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (containing the raw spaces, tabs and new-lines).

Explanation in pseudo-code:

integer i = input_as_integer
Start LOOP
  i = i-1
  if i is negative:
    EXIT
  Call function PRINT

function PRINT
  Print "Hello World. Dlrow Olleh. Hwlrod Eoll.\n
         Big Brown Fox. Xof Nworb Gib. Bbfgox Iro.\n
         "
  Go to the next iteration of LOOP

Some things I did to golf it:

  • SNS (Duplicate) is used for repeated characters (ll)
  • 99 is subtracted from every ASCII-value, which we'll add in the PRINT function to reduce loads of bytes. In Whitespace an integer/character is formed by using SS (Stack Manipulation: Push Number) + S or T (Positive or Negative) + some T / S (Binary representation of the number where T=1 and S=0) + N. So having lower binary values and adding the 99 in the PRINT function is shorter than using the large binary values directly.
  • Since creating the number for a space is 11 bytes (SSTTSSSSTTN), I copied the spaces from the last occurrences to the top of the stack instead. For example, after the first space is created in \n.orI xogfbB, I then use STSSTTSN (copy 6th to top) instead to copy the previous space. The largest distant between two spaces is 9, and since STSSTSSTN (copy 9th to top) is still 2 bytes shorter than SSTTSSSSTTN (create space) I've done this for all spaces to save bytes.
  • I did something similar as with the copying of spaces above for every character that has a distance of 3 or less. This applies to the B in Big B and the o in od Eo (Note: The distance between both b in b. Bb is also three, but creating the number for b (SSTTN) is actually shorter than copying the 3rd value to the top of the stack (STSSTTN).)
\$\endgroup\$
0
\$\begingroup\$

Game Maker Language, 107

repeat argument0{return "Hello World. Dlrow Olleh. Hwlrod Eoll.#Big Brown Fox. Xof Nworb Gib. Bbfgox Iro."}
\$\endgroup\$
0
\$\begingroup\$

Java 8, 121 bytes

n->{for(;n-->0;System.out.println("Hello World. Dlrow Olleh. Hwlrod Eoll.\nBig Brown Fox. Xof Nworb Gib. Bbfgox Iro."));}

Explanation:

Try it online.

n->{           // Method with integer parameter and no return-type
  for(;n-->0;  //  Loop `n` times
    System.out.println("Hello World. Dlrow Olleh. Hwlrod Eoll.\n
                        Big Brown Fox. Xof Nworb Gib. Bbfgox Iro."));}
               //   And print this text + a trailing new-line that many times
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Bleh, why bump a challenge like this? \$\endgroup\$ Mar 15, 2018 at 12:50
  • \$\begingroup\$ @MagicOctopusUrn I'm just looking for old [tag:string] solutions to practice programming in Whitespace, and noticed this didn't had a Java answer yet either.. Also, golfing languages might be better suited to utilize the repeated characters in the challenge (although it's more likely they just use a text encryption for the entire text, so I understand the duplicated vote..) \$\endgroup\$ Mar 15, 2018 at 13:01
  • \$\begingroup\$ @MagicOctopusUrn I've dupe-hammered it. \$\endgroup\$ Mar 15, 2018 at 13:12
  • \$\begingroup\$ I mostly wanted to discuss: codegolf.meta.stackexchange.com/questions/8143/… but Dennis closed my meta because it already exists apparently. Odd how this predates that challenge though. Technically we should be closing the rickroll one. \$\endgroup\$ Mar 15, 2018 at 13:19
  • \$\begingroup\$ "Odd how this predates that challenge though. Technically we should be closing the rickroll one." We don't always close the newer one as a dupe. Sometimes an older one is closed instead if the newer one is much better specified (if the author of the older challenge agrees). Here is a recent example of that, with Martin's reasoning and relevant meta-post at the top. \$\endgroup\$ Mar 15, 2018 at 13:58

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