This question already has an answer here:

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!

marked as duplicate by Magic Octopus Urn, Kevin Cruijssen code-golf Mar 15 at 13:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

Ruby - 84 chars

"Hello World. Dlrow Olleh. Hwlrod Eoll.
Big brown fox. Xof Nworb Gib. Bbfgox Iro."*n

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.

Python 110 105 Characters

exec"print'Hello World. Dlrow Olleh. Hwlrod Eoll.\\nBig brown fox. Xof Nworb Gib. Bbfgox Iro.';"*input()
  • you can take off 5 characters by using one print and \\n to end the line – Doug T. Feb 20 '11 at 14:58
  • @doug-t Thanks a lot. – fR0DDY Feb 20 '11 at 17:34

JavaScript - 100 characters

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

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");
}

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.

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

Game Maker Language, 107

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

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
  • 1
    Bleh, why bump a challenge like this? – Magic Octopus Urn Mar 15 at 12:50
  • @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..) – Kevin Cruijssen Mar 15 at 13:01
  • @MagicOctopusUrn I've dupe-hammered it. – Kevin Cruijssen Mar 15 at 13:12
  • 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. – Magic Octopus Urn Mar 15 at 13:19
  • "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. – Kevin Cruijssen Mar 15 at 13:58

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