65
\$\begingroup\$

Introduction

Bad news guys - you got detention. Your English teacher doesn't understand this site and wants you to "stop doing math on your digital dohickeys, this is English class!"

She sentenced you to write her favorite saying on the blackboard 25 times, which will give a total of 100 lines on the blackboard.

The eighteen-hundreds were a time for rum.
The nineteen-hundreds were a time for fun.
The two-thousands are a time to run
a civilized classroom.

Lucky for you, you are an avid reader (not to mention an expert code-golfer)! You have a read about a trick that might possibly get you off easy.

foxtrot

(Foxtrot by Bill Amend)

Unfortunately for Jason, it didn't work out. But you have a better idea! Since your English teacher thinks you're doing math, if you leave all the numbers out of your program it just might work! You also want to keep your program as short as possible because you are a lazy student and don't want to write a lot on the board.

Write a program that complies with the following rules:

  • Your program must print the 4 above lines 25 times. The lines must be outputted in that order, repeating. Total exactly 100 lines of output (a trailing newline at the very end or a leading newline at the very beginning is okay).
  • You cannot use the characters 0123456789. Your teacher gets confused by math and will call you out!
  • You can use any imports and external libraries without counting the imports. Your English teacher doesn't know about programming. Jason could have saved a lot of work by not writing #include <stdio.h> and you don't want to make his same mistakes!
  • Score your program by byte count. Lowest score wins!
\$\endgroup\$
9
  • 2
    \$\begingroup\$ If the text would've read "1900s", writing the output would've been slightly more tricky. \$\endgroup\$
    – Ingo Bürk
    Oct 23, 2014 at 14:50
  • 30
    \$\begingroup\$ to the comix: he's not printing \n's, and the loop from 1 is pretty awkward (like against C nature)... \$\endgroup\$
    – V-X
    Oct 23, 2014 at 15:41
  • 12
    \$\begingroup\$ @V-X Bill Amend is a long-time Pascal die-hard, and whenever he writes C that becomes pretty apparent. \$\endgroup\$
    – fluffy
    Oct 23, 2014 at 18:09
  • 5
    \$\begingroup\$ This sounds very much like one of my old English teachers. \$\endgroup\$
    – Kaz Wolfe
    Oct 25, 2014 at 16:58
  • 2
    \$\begingroup\$ Banning + would have made sense here, but maybe that would have been too difficult. \$\endgroup\$
    – Pharap
    Oct 28, 2014 at 9:38

63 Answers 63

76
\$\begingroup\$

JavaScript (ES6) 164

B='teen-hundreds were a time',alert(B.replace(/./g,
"The eigh"+B+" for rum.\nThe nine"+B+" for fun.\nThe two-thousands are a time to run\na civilized classroom.\n"))

Test In FireFox/FireBug console.

\$\endgroup\$
17
  • 19
    \$\begingroup\$ This is genius! \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 17:09
  • 1
    \$\begingroup\$ Yup, replacing each character by the larger string. Making 25 copies of the larger string. \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 17:49
  • 1
    \$\begingroup\$ @Optimizer That is genius :) \$\endgroup\$ Oct 23, 2014 at 17:49
  • 3
    \$\begingroup\$ @Malvolio In fact the repeated section is 30 characters. And I could show a huge sequence of attempts, adding and cutting words and replacing replaces before finding this simple solution. \$\endgroup\$
    – edc65
    Oct 24, 2014 at 12:13
  • 1
    \$\begingroup\$ @IsmaelMiguel I think you mean any ES6 browser. Problem: at time this challenge was posted, template strings were not implemented in any browser: Firefox was the first - rel 34, dec first 2014 - then Chrome, march 2015. But even without template strings your scoure would be 153, better than mine. You should post it as an answer. \$\endgroup\$
    – edc65
    Sep 27, 2015 at 20:03
34
\$\begingroup\$

Python : 188 173 160 153

a="teen-hundreds were a time"
print"The eigh%s for rum.\nThe nine%s for fun.\nThe two-thousands are a time to run\na civilized classroom.\n"%(a,a)*len(a)

I don't python much, but this seems pretty short to me.

Edit: So I was wrong, it wasn't short at all! Thanks for the assistance in comments :D

\$\endgroup\$
19
  • 1
    \$\begingroup\$ You could lose the newline and indent on the for loop to save a couple of bytes. \$\endgroup\$
    – Holloway
    Oct 23, 2014 at 15:39
  • 1
    \$\begingroup\$ @Geobits, I make that 157 \$\endgroup\$
    – Holloway
    Oct 23, 2014 at 16:11
  • 1
    \$\begingroup\$ @Geobits are you running on a windows machine? The line encodings in windows are frequently \r\n instead of just \n. That might be why it's showing 157 bytes for us, but 160 for you. \$\endgroup\$
    – Rob Watts
    Oct 23, 2014 at 17:49
  • 2
    \$\begingroup\$ This is 160 only. You are probably skipping the three \ in \n due to escaping ... \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 17:51
  • 1
    \$\begingroup\$ You can move the value for b into the print: % has higher precedence than *. \$\endgroup\$ Oct 23, 2014 at 19:22
29
\$\begingroup\$

CJam, 151 140 135 132 130 128 bytes (Tweetable)

"TeighYrum.TnineYfun.Ttwo-thousands are a time to run
a civilized classroom.""YT"["teen-hundreds were a time for ""
The "]erAF+*

Try it here

I am able to shorten this down to 110 bytes by converting this to unicode, but since that is not beating the other unicode solution, I would rather not put it :)

\$\endgroup\$
5
  • 23
    \$\begingroup\$ Hey, what's that :D emoticon doing there?! Are you texting your friends during detention? Go to the principal's office! \$\endgroup\$
    – Doorknob
    Oct 23, 2014 at 21:11
  • 2
    \$\begingroup\$ @Doorknob :D :P \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 21:16
  • \$\begingroup\$ Maybe you could make T alias to .\nThe , then remove the extra line that this produces from the start of the output string (my cjam-fu isn't good enough to figure out whether you can easily do that) \$\endgroup\$
    – user16402
    Oct 24, 2014 at 7:21
  • \$\begingroup\$ @professorfish that ends up consuming more bytes than it saves. mothereff.in/…*%28Y%2F%28%40\ \$\endgroup\$
    – Optimizer
    Oct 24, 2014 at 7:48
  • \$\begingroup\$ Nitpicking: Using the upper 128 bytes of an ASCII-compatible code page has nothing to do with Unicode. \$\endgroup\$
    – Dennis
    Oct 25, 2014 at 16:39
24
\$\begingroup\$

PHP, 0 bytes


You can use any imports and external libraries without counting the imports.

To run this code, you must import a library called data://text/plain,<?php...classroom.\n"; with this:

<?php require_once 'data://text/plain,<?php
  for($i=ord("z");$i>ord("a");$i--)
    echo "The eighteen-hundreds were a time for rum.
The nineteen-hundreds were a time for fun.
The two-thousands are a time to run
a civilized classroom.
";'; ?>

And you must have allow_url_include enabled in your php.ini.

No more numbers or extensions, thanks to Dennis.

\$\endgroup\$
2
  • 9
    \$\begingroup\$ My first instinct was to yell something about loopholes, but since this answer is actually self-contained, I think this is a clever way of using PHP to exploit a loophole that has been created deliberately for Python answers. Since you're already cheating, you could just use require_once "data://text/plain,The eighteen-hundreds...";, which doesn't require sh, doesn't use numbers and is still 0 bytes. \$\endgroup\$
    – Dennis
    Oct 24, 2014 at 16:36
  • 10
    \$\begingroup\$ I'll upvote this for creativity but I won't accept this one. \$\endgroup\$
    – hmatt1
    Oct 25, 2014 at 16:52
14
\$\begingroup\$

Ruby, 185 180 176 bytes

EDIT: String interpolation, thanks @britishtea

It's my first golf ever, and I'm not much of a Rubist (but I certainly love Ruby). Anyway, this is it (shortened, Doorknob's suggestion).

t=' were a time for '
s="The eighteen-hundreds#{t}rum.
The nineteen-hundreds#{t}fun.
The two-thousands are a time to run
a civilized classroom."
s.split.size.next.times{puts s}
\$\endgroup\$
6
  • 1
    \$\begingroup\$ You can golf this down further by replacing some of the repeating words / word-groups with String interpolation. \$\endgroup\$
    – britishtea
    Oct 23, 2014 at 16:35
  • 3
    \$\begingroup\$ +1 for noticing there are (almost) 25 words in the string \$\endgroup\$ Oct 23, 2014 at 21:52
  • 2
    \$\begingroup\$ s.split.size.next saves 5 characters (you don't need to specify the space to split on). \$\endgroup\$
    – Doorknob
    Oct 23, 2014 at 23:50
  • \$\begingroup\$ I don't know Ruby, but wouldn't (s.split.size+1).times be 1 byte shorter? \$\endgroup\$
    – seequ
    Oct 25, 2014 at 20:54
  • 1
    \$\begingroup\$ @Sieg not allowed to use numbers! \$\endgroup\$
    – rjdown
    Oct 26, 2014 at 2:31
13
\$\begingroup\$

Java 249 231 230 222

My first answer! Why not start off using the language I know so well.

class c{public static void main(String[]g){for(int a='!';a++<':';out.println("The eighxrum.\nThe ninexfun.\nThe two-thousands are a time to run\na civilized classroom.".replaceAll("x","teen-hundreds were a time for ")));}}

Ungolfed

import static java.lang.System.*;
class c
{
    public static void main(String[]g)
    {
        for(int a='!';a++<':';out.println("The eighxrum.\nThe ninexfun.\nThe two-thousands are a time to run\na civilized classroom.".replaceAll("x","teen-hundreds were a time for ")));
    }
}
\$\endgroup\$
7
  • 9
    \$\begingroup\$ Welcome! You can get rid of the public for your class and shorten args to a single character. You could also do a++<':' instead of incrementing it separately. Since the OP isn't counting imports, you can save a bit more with import static java.lang.System.*;, then you don't need to write System. later (where it counts). Doing that I got it down to around 230. You might want to take a look at the Java tips page if you haven't already. \$\endgroup\$
    – Geobits
    Oct 23, 2014 at 15:35
  • \$\begingroup\$ @Optimizer Thanks! I just didn't see the strikeout above. \$\endgroup\$
    – Luminous
    Oct 23, 2014 at 15:58
  • \$\begingroup\$ @Luminous NP :) \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 16:01
  • \$\begingroup\$ @Geobits Thank you! Apparently, you can also stick code right into the loop itself. Didn't add or remove anything, but I think it looks more golfed that way. \$\endgroup\$
    – Luminous
    Oct 23, 2014 at 16:02
  • 4
    \$\begingroup\$ Loop abuse is pretty common. If you had multiple statements in the body, you could put one on the outside and the rest inside to save a single character (since you need a semicolon outside anyway). A lot of golfs end up being one big loop that way. Also, "looks more golfed" is a totally valid reason to do anything even if it doesn't save :P \$\endgroup\$
    – Geobits
    Oct 23, 2014 at 16:05
11
\$\begingroup\$

C 171

a='a';b="teen-hundreds were a time for ";main(){for(;a++<'z';)printf("The eigh%srum.\nThe nine%sfun.\nThe two-thousands are a time to run\na civilized classroom.\n",b,b);}

At first, I tried the simplistic version (189 bytes), which was better than the other C solution...

main(a){for(a='a';a<'z';++a)printf("The eighteen-hundreds were a time for rum.\nThe nineteen-hundreds were a time for fun.\nThe two-thousands are a time to run\na civilized classroom.\n");}

which I later optimized a bit...

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Huh, that's nifty. I didn't realise static variables with string literals assigned to them implicitly have type char *. \$\endgroup\$
    – FireFly
    Oct 23, 2014 at 19:38
  • \$\begingroup\$ @FireFly GCC compiles fine on the a presumably because it defaults to int, which can accept a char value. It doesn't like b unless I call it a char[] though. V-X, what compiler are you using? \$\endgroup\$ Oct 23, 2014 at 20:17
  • \$\begingroup\$ b is int too but it holds the pointer to the string literal. It's completely ok in GCC (I have on my machine 4.8.2). \$\endgroup\$
    – V-X
    Oct 24, 2014 at 6:51
  • 1
    \$\begingroup\$ for(a='a';++a<'z';) \$\endgroup\$
    – seequ
    Oct 25, 2014 at 20:59
9
\$\begingroup\$

CJam, 109 107 106 104 103 bytes

0000000: 22 0c 20 4f 18 41 e4 d8 a5 f3 95 cf 5e 2b cb 1c  ". O.A......^+..
0000010: 44 64 2f bf 28 23 e2 47 4e 4e 77 73 fc 43 09 a2  Dd/.(#.GNNws.C..
0000020: 09 0b fb 18 29 e8 e8 49 5d fc 00 da b8 70 b6 3e  ....)..I]....p.>
0000030: 0c 24 d7 5a 5b 28 1c 45 2e 90 63 86 04 5c 3e 95  .$.Z[(.E..c..\>.
0000040: 4b ae 66 22 48 48 2a 62 46 47 2b 62 22 54 0a 20  K.f"HH*bFG+b"T. 
0000050: 2d 2e 22 27 7b 2c 57 25 7c 66 3d 7b 28 2f 29 2a  -."'{,W%|f={(/)*
0000060: 7d 5a 2a 43 44 2b 2a                             }Z*CD+*

The above is a reversible xxd dump.

Testing

You can generate and execute the above code by running this in the online interpreter:

"bxyyeighxrum.yninexfun.ytwo-thousands abto run
a civilized classroom.y
The xteen-hundreds webfor bre a time ""T
 -."'{,W%|f#31bHH*b:c`'\2*/'\*"HH*bFG+b""T
 -."`"'{,W%|f={(/)*}Z*CD+*"]:+~

To see the generated code (without executing it), remove the final ~.

To count the number of bytes (one character is one byte in ISO-8859-1), replace the final ~ with a ,.

Printable version (122 bytes)

"bxyyeighxrum.yninexfun.ytwo-thousands abto run
a civilized classroom.y
The xteen-hundreds webfor bre a time "{(/)*}Z*CD+*

After pushing the string (S), the following gets executed:

{    }Z*        " Repeat 3 times:     ";
 (              "     Q := S.shift()  ";
  /             "     T := S.split(Q) ";
   )            "     R := T.pop()    ";
    *           "     S := T.join(R)  ";
        CD+*    " S *= 12 + 13        ";

Moar golfing

After pushing the unprintable string (U), the following gets executed:

HH*b                        " U := U.base(17 * 17) ";
    FG+b                    " U := U.base(15 + 16) ";
        "T\n -."            " P := 'T\n -.'        ";
                '{,W%|      " P |= 'zyx...\0'      ";
                      f=    " U[i] -> P[U[i]]      ";

This pushes the string of the printable version. The rest of the code works as before.

\$\endgroup\$
10
  • \$\begingroup\$ Using the code, I get this generated code which is 144 bytes. Am I doing something wrong ? \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 22:49
  • \$\begingroup\$ UTF-8 encoding would result in a higher byte count, yes. With ISO-8859-1, the byte count is 109. You can replace ~ with , to verify. \$\endgroup\$
    – Dennis
    Oct 23, 2014 at 22:53
  • 2
    \$\begingroup\$ I got the exact result Optimizer did, but adding the ]:+~ made it work. Why don't you just add that to your code? \$\endgroup\$
    – Luminous
    Oct 24, 2014 at 3:12
  • 1
    \$\begingroup\$ @user23013: The Java interpreter respects $LANG for I/O. Internally, CJam just has 16-bit chars. \$\endgroup\$
    – Dennis
    Oct 24, 2014 at 11:37
  • 3
    \$\begingroup\$ You actually do not have to unicode-ize your solution as without compression itself it is only 124 bytes, beating all others. \$\endgroup\$
    – Optimizer
    Oct 24, 2014 at 21:23
9
\$\begingroup\$

JavaScript, ES6, 174 172 154 bytes

Using @edc65's replace trick. Thanks!

alert((d="teen-hundreds were a time").replace(/./g,`The eigh${d} for rum.
The nine${d} for fun.
two-thousands are a time to run
a civilized classroom.
`))

Works only in latest Firefox (34 and above) due to use of template strings.

\$\endgroup\$
2
  • \$\begingroup\$ @Nijikokun You know that will cause 30 repetitions instead of 25, right ? \$\endgroup\$
    – Optimizer
    Oct 24, 2014 at 20:45
  • \$\begingroup\$ I am guessing that ff 34 is beta or something since I am on latest (just checked) and it is 33 and it does not work on there \$\endgroup\$
    – Sammaye
    Oct 28, 2014 at 16:12
8
\$\begingroup\$

BrainFuck (1,597 characters)

+++++++++++++++++++++++++[>->-[--->+<]>-.[---->+++++<]>-.---.--[--->+<]>-.+[->+++<]>++.++++.--.+.++++++++++++.+++[->+++<]>..+++++++++.[----->++<]>+.[->++++++++<]>.[--->+<]>---.-------.----------.++++++++++++++.-------------.-.--[--->+<]>---.+[---->+<]>+++.--[->++++<]>-.[->+++<]>.+++++++++++++.-------------.--[--->+<]>-.[->+++<]>+.-[->+++<]>.---[->++++<]>.-----------.++++.--------.--[--->+<]>-.++[->+++<]>.+++++++++.+++.[-->+++++<]>+++.---[----->++<]>.+++.--------.+[----->++<]>++.>++++++++++.>-[--->+<]>-.[---->+++++<]>-.---.--[--->+<]>-.+[----->+<]>+.-----.+++++.---------.[--->+<]>---.+++[->+++<]>..+++++++++.[----->++<]>+.[->++++++++<]>.[--->+<]>---.-------.----------.++++++++++++++.-------------.-.--[--->+<]>---.+[---->+<]>+++.--[->++++<]>-.[->+++<]>.+++++++++++++.-------------.--[--->+<]>-.[->+++<]>+.-[->+++<]>.---[->++++<]>.-----------.++++.--------.--[--->+<]>-.++[->+++<]>.+++++++++.+++.[-->+++++<]>+++.++[->+++<]>.-[--->+<]>--.-------.[----->++<]>++.>++++++++++.>-[--->+<]>-.[---->+++++<]>-.---.--[--->+<]>-.---[->++++<]>.+++.--------.[->+++++<]>++.+[--->++<]>.------------.+++++++.++++++.--.++[->+++<]>++.+++++++++++++.----------.--[--->+<]>---.+[---->+<]>+++.[->+++<]>+.--[--->+<]>---.-------------.--[--->+<]>-.[->+++<]>+.-[->+++<]>.---[->++++<]>.-----------.++++.--------.--[--->+<]>-.---[->++++<]>.-----.[--->+<]>-----.---[----->++<]>.+++.-------.>++++++++++.--[--->++++<]>+.-[->+++<]>.+[->+++<]>.++++++.[->++++++<]>.[------>+<]>.+++.---.-[--->+<]>++.---[->+++<]>.-.-[--->+<]>-.+[->+++<]>.+++++++++.-----------.--[--->+<]>--..-.---..--.+[----->++<]>++.>++++++++++.[[-]<+]<-]

This can still be golfed further, if anyone is interested.

You can test this out and confirm that it gives the correct output while meeting all of the rules.

\$\endgroup\$
2
  • 5
    \$\begingroup\$ What's this? I told you to write sentences, not random squiggles! There aren't even any words in here! \$\endgroup\$
    – Riking
    Oct 25, 2014 at 21:27
  • 5
    \$\begingroup\$ Ummm.. I think the goal is to use the fewest characters. You sure won the "anti-goal" :-) \$\endgroup\$ Oct 27, 2014 at 12:01
7
\$\begingroup\$

Perl - 145

I'm happy to see so many answers! Here's a Perl solution.

$s="teen-hundreds were a time for";print"The eigh$s rum.
The nine$s fun.
The two-thousands are a time to run
a civilized classroom.
"for b..z
\$\endgroup\$
0
7
\$\begingroup\$

Since she hates math so much, why not Mathematica (177)

   a = "teen-hundreds were a time for "; Do["The eigh" <> a <> "rum.
   The nine" <> a <> "fun.
   The two-thousands are a time to run a civilized classroom." // Print, {StringLength@a}]
\$\endgroup\$
0
6
\$\begingroup\$

Javascript ES6, 198 193 bytes

m=Math;alert("The eighteen-hundreds were a time for rum.\nThe nineteen-hundreds were a time for fun.\nThe two-thousands are a time to run\na civilized classroom.\n".repeat(~~(m.exp(m.PI)+m.E)))

Your teacher doesn't want any numbers, but since they are an english teacher, they've got no clue what Math.floor(Math.exp(Math.PI)+Math.E) means.

More readably:

alert("The eighteen-hundreds were a time for rum.\n\
 The nineteen-hundreds were a time for fun.\n\
 The two-thousands are a time to run\na civilized\n classroom.".repeat(Math.floor(Math.exp(Math.PI)+Math.E)))

Must be run in the latest firefox

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Missing a newline at end, so the first and last rows are appended giving 75 rows \$\endgroup\$
    – edc65
    Oct 23, 2014 at 16:00
  • \$\begingroup\$ I'll award +1 for bending the rules with XKCD's reference of e^pi, but with +e as opposed to -pi... Bravo! \$\endgroup\$ Oct 24, 2014 at 4:25
  • \$\begingroup\$ -4 bytes: with(Math)alert("long string here".repeat(exp(PI)+E|[])) \$\endgroup\$
    – nderscore
    Oct 24, 2014 at 19:59
  • \$\begingroup\$ Oh well, forget about Math: (q='aaaaa'.length)*q \$\endgroup\$
    – edc65
    Oct 24, 2014 at 23:11
  • \$\begingroup\$ Forget about @edc65 comment too! Use this:"\x18".charCodeAt()! (hardcode the arrow up and you will save a ton!) \$\endgroup\$ Oct 25, 2014 at 20:25
6
\$\begingroup\$

Javascript - 178 Bytes 176 Bytes

My first golf, thought I'd give it a shot with bit twiddling operators, didn't turn out quite as well as hoped, but oh well!

c="teen-hundreds were a time for "
b=!!c
alert(Array((b+b+b<<b+b)+b<<b).join("The eigh"+c+"rum.\nThe nine"+c+"fun.\nThe two-thousands are a time to run\na civilized classroom.\n"))

Since I'm already in detention, and obviously have troubles behaving myself... Javascript - 71 Bytes

This one will probably get me in deeper trouble, but, if I already landed myself in detention, AND I'm planning on cheating my detention, apparently I lack good judgement on how I should behave myself in class. Maybe if I can pull one over my on teacher, I can pull one over on all the other golfers out there.

b=+true;alert( Array((b+b+b<<b+b)+b<<b).join($('code')[+!b].innerHTML))

Quick! Chrome/IE 11/Firebug users, open your consoles RIGHT NOW and try it.

(Please don't hurt me too much, I thought it was funny)

\$\endgroup\$
7
  • 1
    \$\begingroup\$ The 72 is fun. The 176 is many times wrong: Array(25).join() gives 24 repetitions, and a newline at end sentence is missing. All in all 24*3=72 rows instead of 100 (lazy boy!) \$\endgroup\$
    – edc65
    Oct 23, 2014 at 22:26
  • \$\begingroup\$ AUGH, ok fixed. Now 178 and 71. \$\endgroup\$
    – Sidney
    Oct 23, 2014 at 22:42
  • 1
    \$\begingroup\$ You can save 2 bytes adding the t and a trailing space in "een-hundreds...for". \$\endgroup\$
    – Luminous
    Oct 24, 2014 at 3:19
  • \$\begingroup\$ What is the second code doing? \$\endgroup\$
    – justhalf
    Oct 24, 2014 at 3:58
  • 1
    \$\begingroup\$ @justhalf, It takes use of JQuery, a common JavaScript library that apparently the SO network utilizes. The $ is actually a function that, among many many other things, takes a lot of the work out of DOM element selection. By using $('<selector>'), which is in this case all elements with the 'code' tag, I get an object containing all elements. By using [+!b] I get the integer value of false, which is zero, so I select the 0th index, which happens to be the OP's first code block, which is in fact the teachers favorite saying. \$\endgroup\$
    – Sidney
    Oct 24, 2014 at 13:20
5
\$\begingroup\$

C# - 229 216 Bytes

Free using FTW!

using c=System.Console;
class S{static void Main(){var a="teen-hundreds were a time";for(int b=a.Length,i=b-b;i++<b;)c.Write("The eigh"+a+" for rum.\nThe nine"+a+" for fun.\nThe two-thousands are a time to run\na civilized classroom.\n");}}

Alternative, same byte count (more usingabuse, though)

using i=System.Int32;
using c=System.Console;
class S{static void Main(){var a="teen-hundreds were a time";for(int b=new i();b++<a.Length;)c.Write("The eigh"+a+" for rum.\nThe nine"+a+" for fun.\nThe two-thousands are a time to run\na civilized classroom.\n");}}
\$\endgroup\$
10
  • 4
    \$\begingroup\$ ~~ (╯°□°)╯︵ ┻━┻ \$\endgroup\$ Oct 23, 2014 at 18:46
  • \$\begingroup\$ You can add " for " to a \$\endgroup\$ Oct 23, 2014 at 19:01
  • \$\begingroup\$ @FryAmTheEggman the string is 25 characters long, he is using it to obtain the number 25 discretely. However, he can swap this method out for simply subtracting chars from each other (':'-'!' == 25), which is shorter than a.Length, and will allow for to be included as you suggest. (Alternativly, do as other answers seem to, and just loop between ! and :, funny how we all chose the same chars) \$\endgroup\$ Oct 23, 2014 at 19:47
  • \$\begingroup\$ @VisualMelon Whoops, you're totally right. \$\endgroup\$ Oct 23, 2014 at 19:57
  • 1
    \$\begingroup\$ I thought I could since usings are not even being counted, has OP clarified this? \$\endgroup\$ Oct 26, 2014 at 14:35
5
\$\begingroup\$

Befunge-93, 268 260 256 (grid size: 72x6=432)

#v"K">:!#@_v>$"enin">,,,,::-" rof emit a erew sderdnuh neet">:#,_$::!!-#
, ,,,"The "<|\!\%-"\^"::%-" #":-!!:
   -"#-"-::$_ "hgie"^v1"two-thousands are a time to run"
$_$  "nuf"v"rum"
v1-"##",,,<      >:#,_"moorssalc dezilivic a"1
_# < ^,,\-"AK."$_,#!:

This is my first time golfing, so I figured I'd try a language that hadn't already been done for this problem, since I wouldn't be adding anything otherwise. Since it's Befunge-93 compatible (fits inside an 80x25 grid and uses only Befunge-93 instructions), it should work in Befunge-98 too. Just in case, I also avoided having the pointer pass over any non-instruction characters other than space. I couldn't remember whether the specification actually defined those characters as no-ops, and I'll be having no nasal demons in MY code.

You can't really ungolf Befunge code. The key thing to note here is that Befunge pushes characters to the stack as their ASCII values, making it relatively simple to refer to numbers without literally referring to them. The "K" in the top left is 75, referring to the number of repetitions times the number of "the" clauses per repetition; I use modulus and some other craftiness on (copies of) this number to determine which path to take through the printing on each go-around. ::- is a nice idiom for zero, useful for zero-terminating strings; I use it twice here.

On occasion the pointer needs to pass through a place where I'm defining a string, hence the specific choices of characters used to get certain numbers at some points.

The nice thing about a lot of Befunge interpreters is that you can watch the pointer dart around the grid, as well as see what values are in the stack. That way you can step through and see how the program works yourself, more or less! I'd recommend using http://befungius.aurlien.net/ if you don't have your own preferred Befunge interpreter.

This can probably be pared down a bit (or a lot) more. Please give me feedback! If I need to provide a better explanation, someone let me know; I'm new to this.

Edit - shaved off a few bytes by getting rid of the unnecessary redirect to the last row when the program terminates (just putting the @ where the ^ used to be).

Another edit - shaved off some more bytes in various places, mostly with trickery. (Also added the grid size, as seems to be the trend with Befunge answers.)

\$\endgroup\$
4
  • \$\begingroup\$ Hey Kasran welcome to the codegolf stack exchange! This answers look great. Your explanation is good and you linked to a Befunge interpreter which is really helpful for weird languages not everyone has a compiler for (people commonly do things like "run this here"). \$\endgroup\$
    – hmatt1
    Oct 25, 2014 at 16:04
  • \$\begingroup\$ Befunge is a really hard language, and you have to keep the size of the code itself in your mind when writting. Your code looks great and works. But would it reduce the size if you save re a time somewhere? \$\endgroup\$ Oct 25, 2014 at 16:26
  • \$\begingroup\$ I'm not using any Funge-98-specific instructions or behaviors that I know of, but since I wrote this answer I did learn that certain behaviors of the Befungius interpreter aren't standard - namely using # at one end of a line to skip the character at the other end (in CCBI, for instance, the # just skips the infinite space in between it and the character at the other end), which breaks this program. I haven't bothered to come back and fix this submission with this in mind. \$\endgroup\$
    – Kasran
    Jan 17, 2017 at 18:42
  • \$\begingroup\$ There's a few 1 digits in there, which are not allowed \$\endgroup\$
    – Jo King
    Apr 14, 2019 at 13:36
4
\$\begingroup\$

Pyth 135 136 140

*ltG%"The eigh%srum%snine%sfun%stwo-thousands are a time to run\na civilized classroom.\n"*hhZ("teen-hundreds were a time for "".\nThe 

Note the trailing space.

Uses pretty much the same trick as @Geobits and his commenter friends in the Python answer to construct the string. Now also uses some of this answer.

This uses the built-in variable G, which contains abcdefghijklmnopqrstuvwxyz and gets one less than its length to produce the 25 outputs.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This seems to be 136 bytes rather than 135 \$\endgroup\$
    – Optimizer
    Oct 23, 2014 at 17:05
  • 1
    \$\begingroup\$ @Optimizer Sorry, I should read my own notes: I forgot the trailing space when I pasted it there myself :S \$\endgroup\$ Oct 23, 2014 at 17:18
4
\$\begingroup\$

Ruby - 152 141

puts"The eight#{e="een-hundreds were a time for "}rum.
The ninet#{e}fun.
The two-thousands are a time to run
a civilized classroom.
"*(?X-??)

http://repl.it/2Om/6

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Clever use of 1.8's character literals! You might be able to use String#* to repeat the lines 25 times instead of Integer#times. \$\endgroup\$
    – britishtea
    Oct 23, 2014 at 23:12
  • \$\begingroup\$ @britishtea - worked a treat :) \$\endgroup\$
    – Mikey
    Oct 23, 2014 at 23:18
  • 1
    \$\begingroup\$ You could shave off a few more bytes by not assigning the lines first. The space between puts and a string literal is optional (puts"hi" is legal). \$\endgroup\$
    – britishtea
    Oct 23, 2014 at 23:20
  • \$\begingroup\$ Assigning e inside the interpolation is a nice touch. \$\endgroup\$ Oct 24, 2014 at 12:26
3
\$\begingroup\$

Python, 165 bytes

h="hundreds were a time for "
t="The "
for i in h:print t+"eighteen-"+h+"rum.\n"+t+"nineteen-"+h+"fun.\n"+t+"two-thousands are a time to run\na civilized classroom."

It worked out really nicely that the length of h is 25, that was not intentional. =)

\$\endgroup\$
3
\$\begingroup\$

Python 2 - 143

A silly answer:

from this import i
a="teen-hundreds were a time for ",".\nThe "
print"The eigh%srum%snine%sfun%stwo-thousands are a time to run\na civilized classroom.\n"%(a+a)*i

Note that the full count is 162. I left out all of from this import i.

Uses similar replacements to my pyth strategy, but I couldn't resist posting this after discovering the hilariousness of importing from this :)

\$\endgroup\$
2
  • \$\begingroup\$ +1 For use of from this import i! How did you know about that? \$\endgroup\$
    – Beta Decay
    Oct 26, 2014 at 16:54
  • 1
    \$\begingroup\$ @BetaDecay I actually was bored and decided to read the zen of python, so I went to my interpreter and wrote import this. Then I thought: "What else could be in the this module?" So I called dir(this). Lo and behold, along with a dictionary, a garbled up string, and a "!" variable, there was a numeric constant... equal to 25. \$\endgroup\$ Oct 26, 2014 at 23:35
3
\$\begingroup\$

PHP (175 157 156 bytes; 152 with unix EOF):

Not the most golfed solution, but surely does the job and is smaller than some attempts.

Here is the code:

$a=a;$f='re a time';$r="teen-hundreds we$f for";while($a++<z)echo"The eigh$r rum.
The nine$r fun.
The two-thousands a$f to run
a civilized classroom.
";

Old version:

$a=a;while($a++!=z)echo"The eighteen-hundreds were a time for rum.
The nineteen-hundreds were a time for fun.
The two-thousands are a time to run
a civilized classroom.
";

This works because php cycles the chars, and we just check if it isn't z and stop.

(One curiosity is that when php reaches z, it then goes to aa.)

\$\endgroup\$
1
  • 3
    \$\begingroup\$ The general convention here is to count newlines as only one byte, unless perhaps your language is so stubborn it only accepts CRLF, which is not the case for PHP. \$\endgroup\$
    – Luna
    Oct 25, 2014 at 8:54
3
\$\begingroup\$

Python 2 - 155

Note: since control characters don't show on SE, I've replaced it with \x19.

a,b='\nThe ','teen-hundreds were a time for '
print(a+'eigh'+b+'rum.'+a+'nine'+b+'fun.'+a+'two-thousands are a time to run\na civilized classroom.')*ord('\x19')

Base 64 version:

YSxiPScKVGhlICcsJ3RlZW4taHVuZHJlZHMgd2VyZSBhIHRpbWUgZm9yICcKcHJpbnQoYSsnZWln
aCcrYisncnVtLicrYSsnbmluZScrYisnZnVuLicrYSsndHdvLXRob3VzYW5kcyBhcmUgYSB0aW1l
IHRvIHJ1bgphIGNpdmlsaXplZCBjbGFzc3Jvb20uJykqb3JkKCcZJyk=
\$\endgroup\$
6
  • \$\begingroup\$ Regarding the import, I think you could save a bit with from string import * or however it's called in Python \$\endgroup\$
    – FireFly
    Oct 23, 2014 at 17:25
  • 1
    \$\begingroup\$ You can move "teen" into b. \$\endgroup\$ Oct 23, 2014 at 18:48
  • 2
    \$\begingroup\$ You can remove the [] brackets in the first line, which implicitly creates a tuple and then unpacks it. \$\endgroup\$
    – Doorknob
    Oct 23, 2014 at 23:51
  • \$\begingroup\$ You can also move the ord('d')//len('aaaa') to before the string so you don't have to bracket it. \$\endgroup\$ Oct 24, 2014 at 0:20
  • 1
    \$\begingroup\$ @Dennis The OP's latest edit allows leading newlines. \$\endgroup\$
    – Beta Decay
    Oct 25, 2014 at 14:25
3
\$\begingroup\$

LiveScript - 181

p=(a,b)->"The #{a}teen-hundreds were a time for #b.\n"
each console.log,map (->(p \eigh \rum)+(p \nine \fun)+'The two-thousands are a time to run\na civilized classroom.'),[\A to\Y]

Required imports:

{each, map} = require 'prelude-ls'

If you want to run it under Node.js, install the LiveScript (not livescript) and prelude-ls packages from npm, replace alert with console.log and run lsc prog.ls, where prog.ls contains the program.

\$\endgroup\$
2
  • 13
    \$\begingroup\$ See rules: "You cannot use the characters 0123456789" \$\endgroup\$
    – Paul R
    Oct 23, 2014 at 16:22
  • 2
    \$\begingroup\$ Nice catch, fixed. \$\endgroup\$
    – Luna
    Oct 24, 2014 at 10:48
3
\$\begingroup\$

05AB1E, 91 bytes

AgG“TheŸ¯een-““«Ã€à€…€º€‡ “©“ê¶m.“««“The¥Šteen-“®„ˆ¦.««“The‚•-““šä€™€…€º€„‡Ð“«“a–Ìized¬¸.“»

Try it online!

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

T-SQL: 206

Makes use of a cross join on five rows to generate 25 rows selecting the phrase. The line breaks are important for the output.

with c as(SELECT\ N FROM(VALUES(\),($),($),($),($))A(B))SELECT REPLACE('The eigh$rum.
The nine$fun.
The two-thousands are a time to run
a civilized classroom.','$','teen-hundreds were a time for ')FROM c a,c b
\$\endgroup\$
2
\$\begingroup\$

Bash, 151 bytes

Pretty much a straight port of your own answer

t="teen-hundreds were a time for"
for i in {a..y};{
echo "The eigh$t rum.
The nine$t fun.
The two-thousands are a time to run
a civilized classroom."
}
\$\endgroup\$
2
\$\begingroup\$

C, 196 chars

This isn't an easy task for good ol' C. Factoring out the "The %steen-hundreds ..." pattern saves me a whole two characters.

Whitespace for clarity, include not counted.

#include <stdio.h>
main(){
  for (char*p="The %steen-hundreds were a time for %s.\n",
           *s="The two-thousands are a time to run\na civilized classroom.",
           *q=p;
       *q++ - 'a';
       puts(s))
   printf(p,"eigh","rum"), printf(p,"nine","fun");
}
\$\endgroup\$
2
\$\begingroup\$

Ruby, 145

?K.upto(?c){puts"The eigh#{x="teen-hundreds we#{t="re a time "}for "}rum.
The nine#{x}fun.
The two-thousands a#{t}to run
a civilized classroom."}

Explanation

  • Use String#upto to print the lines 25 times. The range "K".."c" is 25 characters.
  • Use basic String interpolation to shorten the lines.
\$\endgroup\$
1
  • 2
    \$\begingroup\$ #{a="The "} is actually costing you more characters! #{a} is the same length as The \$\endgroup\$
    – Mikey
    Oct 23, 2014 at 23:34
2
\$\begingroup\$

Racket 173

(let([x"teen-hundreds were a time for "])(for([z(+ #xa #xf)])(displayln(~a"The eigh"x"rum.\nThe nine"x"fun.\nThe two-thousands are a time to run\na civilized classroom."))))

Ungolfed:

(let ([x "teen-hundreds were a time for "])
  (for([z(+ #xa #xf)])
    (displayln (~a "The eigh"x"rum.\nThe nine"x"fun.\nThe two-thousands are a
     time to run\na civilized classroom."))))
\$\endgroup\$
2
\$\begingroup\$

C, 215 203 199 bytes

main(a){a<<='\xC'+'\xD';while(a>>=!!a)printf("The eighteen-hundreds were a time for rum.\nThe nineteen-hundreds were a time for fun.\nThe two-thousands are a time to run\na civilized classroom.\n");}

Ungolfed

main(a)
{
  a<<='\xC'+'\xD';
  while(a>>=!!a)
    printf("The eighteen-hundreds were a time for rum.\nThe nineteen-hundreds were a time for fun.\nThe two-thousands are a time to run\na civilized classroom.\n");
}

I used bit shifting to iterate without any number.

a<<='\xC'+'\xD' sets a to 0b1[25 zeros]

a>>=!!a shifts right one bit for each time we iterate the loop

Edit : a equals argc, so its value is already 1 when the program is run with no arguments. Changed a>>='\xB'-'\xA' to a>>=!!'\xA' which is 4 bytes shorter. Also the text was displayed only 24 times. Fixed it. Removed extra brackets in the while.

Edit 2: changed !!'\xA' to !!a. Seems to work and saves 4 bytes

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can use puts to save more bytes. \$\endgroup\$
    – Spikatrix
    Jun 2, 2015 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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