Just repeat yourself

65

6

Write a program that outputs

Do not repeat yourself!

Your program code must respect the following constraints :

  • its length must be an even number
  • each character that is in position 2n (where n is an integer > 0) must be equal to the character in position 2n-1. The second character of the program is equal to the first, the fourth is equal to the third, etc.

Newlines count as characters!

This is code-golf, so the shortest code wins!

Examples

HHeellllooWWoorrlldd is a valid program

123 or AAABBB or HHeello are incorrect

Verification

You can use this CJam script to verify that your source code is valid. Simply paste your code into the "Input" box and run the script.

Arnaud

Posted 2015-09-24T02:34:14.430

Reputation: 8 231

51

Fun fact: If the problem had triplets instead, DDDooo nnnooottt rrreeepppeeeaaattt yyyooouuurrrssseeelllfff!!! would be a valid answer in Trigger

– Sp3000 – 2015-09-24T02:39:25.300

14I thought this might be too restrictive, but the flurry of answers proves me wrong. Nice question! – trichoplax – 2015-09-24T07:14:12.720

It would take a pretty serious stretch to satisfy these requirements in Haskell. All binding forms, all forms of conditional expression, all ways to enter characters and strings, and all ways to produce output are eliminated. – dfeuer – 2015-09-24T17:14:54.193

1Could someone add a scoring snippet? I like having those, and I wish every question had them. – mbomb007 – 2015-09-25T22:01:57.853

All the current answers are esoteric langs. I wonder if this is possible in a normal lang? – DankMemes – 2015-09-27T20:45:12.157

@trichoplax Too restrictive for: Python, ///, 0815, C, possibly others too... – Erik the Outgolfer – 2016-09-08T15:43:29.620

Anyone have an idea on how to get any other string other than '', "" or `` in JavaScript with this methodology? I'm still working on this... – WallyWest – 2016-09-21T21:10:10.467

@Trigger Along a similar vein, if the rule was to repeat words, not letters, then Chicken could be the go-to language.

– Engineer Toast – 2017-03-02T13:51:45.853

Answers

51

Hexagony, 166 126 124 bytes

\\;;;;33rr''22DD..));;;;;;oo;;}}eeoo\\@@nn;;;;ee;;;;aass&&;;uuoo;;;;..\\\\;;ttee..pp;;tt;;;;..rr;;''ll..'';;;;..;;}}ff..}}yy

Inserting the implicit no-ops and whitespace, this corresponds to the following source code:

       \ \ ; ; ; ; 3
      3 r r ' ' 2 2 D
     D . . ) ) ; ; ; ;
    ; ; o o ; ; } } e e
   o o \ \ @ @ n n ; ; ;
  ; e e ; ; ; ; a a s s &
 & ; ; u u o o ; ; ; ; . .
  \ \ \ \ ; ; t t e e . .
   p p ; ; t t ; ; ; ; .
    . r r ; ; ' ' l l .
     . ' ' ; ; ; ; . .
      ; ; } } f f . .
       } } y y . . .

I'm sure it's possible to shorten this even more, and maybe even solve it in side-length 6, but it's getting tricky...

How it works

enter image description here

Diagram generated with Timwi's Hexagony Colorer.

The code is completely linear. The \ right at the start redirects the IP into a diagonal, such that we don't need to worry about the doubled characters at all. The coloured paths are executed in the order orange/red, blue/grey, green, purple (when there are two paths of the same colour, the left-hand path is executed first, before wrapping around to the right-hand one).

If we ignore no-ops, mirrors and commands which are overridden by others, the linear code comes down to this:

D;o;&32;}n;o;t;';}r;e;p;e;a;t;';}y;o;u;r;s;e;l;f;');@

Letters in Hexagony just set the current memory edge's value to the letter's character code. ; prints the current memory edge as a character. We use & to reset the memory edge to 0 and print a space with 32;. } moves to a different edge, so that we can remember the 32 for further spaces. The rest of the code just prints letters on the new edge, and occasionally moves back and forth with ';} to print a space. At the end we move to the space edge again with ', increment the value to 33 with ) and print the exclamation mark. @ terminates the program.

Martin Ender

Posted 2015-09-24T02:34:14.430

Reputation: 184 808

4This is really impressive!!! – WizardOfMenlo – 2015-09-24T18:34:13.883

How did you reach the conclusion that it’s possible in size 6 or even 5? I see size 7 as even only barely fitting. – Timwi – 2015-09-24T19:22:10.767

@Timwi 5 was probably a bit overambitious, but with the exception of a single ;, there is absolutely no reuse between character pairs in the code yet. The current code is pretty much the first thing that came to my mind, so I'm thinking if one tried hard enough, it should be possible to find a much more complicated solution which reuses the semicolons and maybe even some letters, to fit this into side length 6. – Martin Ender – 2015-09-25T14:22:48.703

To get to size 6, you’d have to save 36 characters compared to size 7. Even if you use the 6 unused slots you have at the moment, you’d still have to save 30. You can reuse every ; only once because you cannot traverse them horizontally. There are only 23 ;s in your code, and only 6 character repetitions (2×o, 1×t, 1×r, 2×e), giving only 29. Personally, this more than convinces me that size 6 is impossible... – Timwi – 2015-09-25T14:40:28.250

44

GolfScript, 130 84 76 bytes

22..!!..00)){{DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff}}``%%>><<[[33]]++

Try it online in Web GolfScript.

How it works

The GolfScript interpreter starts by placing an empty string on the stack.

22 # Push 22.
.. # Push two copies.
!! # Negate the last copy twice. Pushes 1.
.. # Push two copies.
00 # Push 0.
)) # Increment twice. Pushes 2.

   # STACK: "" 22 22 1 1 1 2

{{DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff}}

`` # Push a string representation of the string representation of the block.

   # This pushes "{{DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff}}" (with quotes).

%% # Take every second element of that string, then every element of the result.
>> # Discard the first element of the result. Repeat.
<< # Truncate the result to length 22. Repeat.
[[ # Begin a two-dimensional array.
33 # Push 33, the character code of '!'.
]] # End the two-dimensional array.
++ # Concatenate the empty string, the 22-character string and the array [[33]].

Concatenating an array with a string flattens, so the result is the desired output.

Dennis

Posted 2015-09-24T02:34:14.430

Reputation: 196 637

38

Unary, ~1.86 × 10222

Simple brainfuck -> unary answer. Very sub-optimal ;).

The program consists of an even number of 0’s; specifically:

1859184544332157890058930014286871430407663071311497107104094967305277041316183368068453689248902193437218996388375178680482526116349347828767066983174362041491257725282304432256118059236484741485455046352611468332836658716

of them.

Original brainfuck code:

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

Maltysen

Posted 2015-09-24T02:34:14.430

Reputation: 25 023

3Neither of the code blocks you've provided satisfy the double-up rule. What am I missing? – doppelgreener – 2015-09-24T07:43:46.627

26@doppelgreener: The first block of "code" is simply a large number. Specifically, the number of 1s in the Unary program that outputs the requested string. The second code block is the BF program that was used to produce it. As the Unary program is completely made of 1s, it trivially satisfies the repetition requirement. – El'endia Starman – 2015-09-24T07:53:32.520

8Also the number of zeroes is (luckily?) an even number :-) – Arnaud – 2015-09-24T08:36:26.497

1I’ve taken the liberty to edit the answer so that the number doesn’t look like it’s supposed to be the code. – Timwi – 2015-09-25T02:10:33.633

Technically it's Golunar and not Unary ;)

– Kametrixom – 2015-09-26T23:08:31.207

2@Kametrixom it is a Golunar description of the Unary program. The Golunar program as written doesn't fulfill the conditions. – Paŭlo Ebermann – 2015-09-27T16:16:38.607

Mmmh... is this a valid answer? For this type of challenges, shouldn't the code proposed in a solution be testable? Isn't it a loophole to provide a theoretical solution knowing well that the actual implementation is impossible? – drolex – 2017-03-02T11:52:54.283

@drolex answers that are impossible to run are completely fine as long as you can show why they would work unless specified by the OP – Maltysen – 2017-03-02T12:26:01.833

34

Ruby - 2100 1428 1032 820 670 bytes

This assumes the output can be a return value from a function (it wasn't specified that the output needs to be to STDOUT)

Code:

((((((((((((((((((((((((((((((((((((((((((((((""<<66++11**00++11**00))<<99++11++11**00))<<((55>>11**00))++((11>>11**00))))<<99++11))<<99++11++11**00))<<99++((33>>11**00))++11**00))<<((55>>11**00))++((11>>11**00))))<<99++11++((11**00<<11**00<<11**00))))<<99++11**00++11**00))<<99++11++11**00++11**00))<<99++11**00++11**00))<<88++((11>>11**00))++((11**00<<11**00<<11**00))))<<99++((33>>11**00))++11**00))<<((55>>11**00))++((11>>11**00))))<<99++22))<<99++11++11**00))<<99++((33>>11**00))++11**00++11**00))<<99++11++((11**00<<11**00<<11**00))))<<99++((33>>11**00))))<<99++11**00++11**00))<<99++((11>>11**00))++((11**00<<11**00<<11**00))))<<99++11**00++11**00++11**00))<<33))

The trick is to build the string from an empty string "" using the append operation << and the ASCII codes of the characters.

To get the numbers for the ASCII codes I'm trying to decompose the number into values I can easily generate. For example ASCII 90 is just 88+1+1, which is:

  • 88 is okay on it's own
  • 11**00 is 11^0, which is simply 1

Fortunately both ++ and -- would mean add in ruby, so I can write 90 as 88++11**00++11**00

There are some tricks to get to some numbers easier than just adding 1s, here is the code I'm using to generate the above (which includes all mappings I'm using):

d = "Do not repeat yourself!"

d.each_char do |c|
  print "(("
end

print '""'

VALUES = [
  [0,'00'],
  [1,'11**00'],
  [4,'((11**00<<11**00<<11**00))'],
  [5,'((11>>11**00))'],
  [11,'11'],
  [16,'((33>>11**00))'],
  [22,'22'],
  [27,'((55>>11**00))'],
  [33,'33'],
  [38,'((77>>11**00))'],
  [44,'44'],
  [49,'((99>>11**00))'],
  [55,'55'],
  [66,'66'],
  [77,'77'],
  [88,'88'],
  [99,'99']
].reverse

d.each_char do |c|
  print "<<"
  num = c.ord
  while num != 0
    convert = VALUES.find{|val|val.first<=num}
    print convert.last
    num -= convert.first
    print "++" unless num == 0
  end
  print "))"
end

I'm still thinking about other tricks to decrease the characters required to get to a number.

Note that if you use the -rpp flag, and add pp to the start of the code like so:

pp((((((((((((((((((((((((((((((((((((((((((((((""<<66++11**00++11**00))<<99++11++11**00))<<((55>>11**00))++((11>>11**00))))<<99++11))<<99++11++11**00))<<99++((33>>11**00))++11**00))<<((55>>11**00))++((11>>11**00))))<<99++11++((11**00<<11**00<<11**00))))<<99++11**00++11**00))<<99++11++11**00++11**00))<<99++11**00++11**00))<<88++((11>>11**00))++((11**00<<11**00<<11**00))))<<99++((33>>11**00))++11**00))<<((55>>11**00))++((11>>11**00))))<<99++22))<<99++11++11**00))<<99++((33>>11**00))++11**00++11**00))<<99++11++((11**00<<11**00<<11**00))))<<99++((33>>11**00))))<<99++11**00++11**00))<<99++((11>>11**00))++((11**00<<11**00<<11**00))))<<99++11**00++11**00++11**00))<<33))

then for extra 2+4 bytes this can function as a fully complete program, but it will print an extra " before and after the required string:

Example:

$ ruby -rpp golf.rb
"Do not repeat yourself!"

SztupY

Posted 2015-09-24T02:34:14.430

Reputation: 3 639

Could you clarify why this is not fully compliant? It looks perfect to me, and even the pp gem is a double letter... – trichoplax – 2016-09-09T09:16:26.067

3@trichoplax: it's in the post: 1. additional " characters in output and 2. the need of the -rpp flag (which is not like --rrpp) – SztupY – 2016-09-09T09:56:32.620

1This answer is cool but answers that do not meet the specifications are subject to deletion. – Post Rock Garf Hunter – 2017-03-01T14:53:25.990

@WheatWizard if you think it's more worth to delete this answer than to keep it, feel free to flag it for deletion – SztupY – 2017-03-01T15:23:35.583

1@SztupY To be absolutely clear, it is site policy to delete responses that do not follow the rules of the challenge. – Mike Bufardeci – 2017-03-01T16:12:31.763

@MikeBufardeci which were enacted months after this answer was posted – SztupY – 2017-03-01T17:49:13.203

@MikeBufardeci as far as I know there is also the consensus about "output can be a function return" which the solution can satisfy without breaking any rules – SztupY – 2017-03-02T11:39:47.180

@SztupY While there is a list of default I/O methods, they are just defaults. If a challenge specifies what the I/O methods need to be then you need to follow the challenge rules.

– Mike Bufardeci – 2017-03-02T14:42:34.017

@MikeBufardeci this one didn't specify STDOUT, just that it has to be outputted, so I still don't see where the submission fails – SztupY – 2017-03-02T14:47:57.463

Let us continue this discussion in chat.

– Mike Bufardeci – 2017-03-02T15:00:37.923

23

><>, 174 bytes

vv

77

99

**

00

77

bb

**

pp

""

!!

ff

ll

ee

ss

rr

uu

oo

yy



tt

aa

ee

pp

ee

rr



tt

oo

nn



oo

DD

""

~~

oo

ll

11

==

;;

00

66

bb

**

..

Thankfully, in a sense the restriction doesn't apply vertically. However, the biggest problem is that we need to double every newline.

The code that runs roughly goes like this:

v            Redirect instruction pointer to move downwards
79*07b*p     Place a ? on row 77 before the first ;
"..."        Push "Do not repeat yourself!" backwards, riffled between spaces

[main loop]
~o           Pop a space and output a char
l1=?;        If there is only the final space left, halt
06b*.        Jump back to the start of the loop

Note that the program has no double spaces — when in string mode, ><> pushes spaces for empty cells. Conversely, however, this means that a solution using g (read single cell from source code) would be trickier, since what spaces are in the program become NULs when read.

(Note: This can be 50 bytes shorter if it terminates with an error, but I like it this way.)

Sp3000

Posted 2015-09-24T02:34:14.430

Reputation: 58 729

1The right tool for the job... – Erik the Outgolfer – 2016-09-08T15:39:06.910

20

Sclipting, 186 146 bytes

끄끄닶닶긂긂닦닦닶닶덇덇긂긂댧댧뉖뉖댇댇뉖뉖눖눖덇덇긂긂뎗뎗닶닶덗덗댧댧댷댷뉖뉖닆닆뉦뉦긒긒

껢껢鎵鎵❶❶合合虛虛替替標標現現併併一一終終

To be clear, there are three lines of code, the middle of which is empty, because the newline needs to be duplicated. The byte count is based on UTF-16 encoding.

Explanation

The block of Korean characters at the start pushes the string "DDDof� \"\u0002nf�of�twG \"\u0002rw'efVpw\aefVaf\u0016twG \"\u0002yw�of�uwWrw'sw7efVlf�fff!\"\u0012". You will notice that every third character is a character we want; the rest is gibberish. Here’s why:

In Sclipting, two Korean characters encode three bytes. Thus, each Korean character effectively encodes 12 bits. To get a string starting with D, the first 8 bits have to be 0x44; the rest don’t matter, but since we have to repeat every character, the 12th to 20th bits are also going to be 0x44. Thus, we will have a value of the form 0x44n44n for some n, which decomposes into the three bytes 0x44 0xn4 0x4n.

For the o, which is 0x6F, we get the bytes 0x6F 0xn6 0xFn.

Since I’m lazy, I started by encoding "DDDooo nnnooottt (etc.)" and then replaced every other character with the previous, which is why I get 0x444444 = "DDD" for the D and 0x6F66F6 = "of�" for the o. The is there because 0xF6 by itself is invalid UTF-8 encoding.

Now, back to the program. The rest of the program proceeds as follows:

껢껢 — pushes the string ".\"�"

鎵鎵 — removes the last character twice, leaving us with "."

❶❶ — two duplicates. Stack now: [".", ".", "."]

合合 — concatenate twice. Stack now: ["..."]

Now, what I want to do next is use "..." as a regular expression so that I can match three characters from the original string at a time, using the 替...終 loop construct. However, since every instruction is duplicated, I need to have two such regular-expression loops nested inside each other, and if the stack underruns I get a runtime error. Therefore,

虛虛 — push the empty string twice

and then start the loops. This way, the outer loop iterates only once because it matches the regular expression "" against the string "", which yields a single match. The inner loop runs once for every match of "..." against the big string. The body of the loop is:

標標 — push two marks onto the stack. Stack now: [mark mark]

現現 — push two copies of the current regex match. Stack now: [mark mark "DDD" "DDD"]

併併 — concatenate up to the first mark. Stack now: ["DDDDDD"]

一一 — take first character of that string, and then (redundantly) the first character of that. Stack now has the character we want.

The inner loop ends here, so every match of the regular expression is replaced with the first character of that match. This leaves the desired string on the stack.

Then the outer loop ends, at which point the desired string is taken off the stack and the only match of "" in the string "" is replaced with it, leaving the desired string once again on the stack.

Timwi

Posted 2015-09-24T02:34:14.430

Reputation: 12 158

3Umm... why didn't you use code format here? Is it the chinese characters? – Erik the Outgolfer – 2016-09-08T15:39:48.530

@EriktheOutgolfer I was wondering the same thing (and they are Korean characters, not Chinese). – Kevin Cruijssen – 2017-03-02T12:16:45.350

@KevinCruijssen I think there are some Chinese characters in there too. In fact, spec says that it uses Hangul for data and Chinese for instructions. – Erik the Outgolfer – 2017-03-02T12:34:20.357

@EriktheOutgolfer Ah, you're indeed right. I should have rtfm.. :) – Kevin Cruijssen – 2017-03-02T12:40:09.350

12

Labyrinth, 528 bytes

66))__vv          ..33::00&&__vv          ..44__99||__vv          ..33::00&&__vv            ..99))__vv            ..99))__vv      ..44__88$$__vv          ..22__99++__vv          ..22__99$$__vv            ..22__99))$$__vv      ..33__77$$__vv            ..33__vv

      ..44__99||__^^          ..11__99++__^^          ..44__88$$__^^          ..44((__88$$__^^      ..11))__99++__^^      ..99((__^^          ..33::00&&__^^          ..44__99||__^^          ..44((__88$$__^^            ..99))__^^          ..11__99$$((__^^    ..@@

xx

The double newlines hurt, but at least this proves that it's doable!

Each character is printed one-by-one, first by forming the code point then printing a single char. The code points are formed by:

D 68  66))
o 111 44__99||
  32  33::00&&
n 110 11__99++
t 116 44__88$$
r 114 44((__88$$
e 101 99))
p 112 11))__99++
a 97  99((
y 121 22__99++
u 117 22__99$$
s 115 22__99))$$
l 108 33__77$$
f 102 11__99$$((
! 33  33

where

)(        Increment/decrement by 1 respectively
&|$       Bitwise AND/OR/XOR respectively
+         Add
:         Duplicate
_         Push zero
0-9       Pop n and push n*10+<digit>

The unusual behaviour of Labyrinth's digits is exploited in 33::00&&, which is actually

[33] -> [33 33] -> [33 33 33] -> [33 33 330] -> [33 33 3300] -> [33 32] -> [32]
     :          :             0              0               &          &

Each single char is printed with the mechanism

__vv

  ..

xx

The xx exist only to pad the grid so that it's 5 high. First the __ push two zeroes, then we hit a grid rotation operator v. We pop a zero and rotate:

__ v
  v
   .
  .
xx

and again:

__ v

  v.

xx.

We then move rightwards to the . on the third row, thus executing the print command only once.

Sp3000

Posted 2015-09-24T02:34:14.430

Reputation: 58 729

I love the trick you used to execute the print command only once. That’s extremely clever. – Timwi – 2015-09-25T05:05:32.697

11

CJam - 176 136 bytes

66))HH77++GG00++BB88++HH77++EE88++GG00++DD88++99))CC88++99))AA77++EE88++GG00++BB99++HH77++KK77++DD88++JJ77++99))AA88++II66++33]]{{cc}}//

Thanks to Sp3000 for dividing my program size by two :-)

Explanation

  • The codes HH77++, GG00++, ... compute the integer ascii code of the characters by adding numbers (for example: `HH77++' pushes 17, 17 and 77 on the stack, then add these 3 numbers)
  • the portion of code at the end ]]{{cc}}// loops through the ascii codes and convert them to characters.

Try it here

Arnaud

Posted 2015-09-24T02:34:14.430

Reputation: 8 231

1Did you generate this with a program? At the very least, the very end can be 33cc, but I'm sure there's better ways for some of the others – Sp3000 – 2015-09-24T07:36:52.373

@Sp3000 yes, just ran a program that tried various combinations with ++. I haven't tried other operators... – Arnaud – 2015-09-24T08:05:31.523

3Another note: instead of cc everywhere, do ]]{{cc}}// at the end – Sp3000 – 2015-09-24T08:07:17.177

11

Self-modifying Brainf***, 72 bytes

Note that \x00 represents a literal NUL hex byte (empty cell). The source code is placed on the tape, left of the starting cell.

!!fflleessrruuooyy  ttaaeeppeerr  ttoonn  ooDD\0\0<<<<<<++[[<<]]<<[[..<<]]

Explanation

!!fflleessrruuooyy  ttaaeeppeerr  ttoonn  ooDD  The string on the tape for easy printing
\x00\x00                                        A separator to make printing shorter
<<<<<<++                                        Change first '.' to '0' (comment)
[[<<]]<<                                        Move to separator, then left to string
[[0.<<]]                                        Print string

Also, before making this program, I was making one using only BF characters in the source. It's possible! It's also much longer, since for an odd ASCII value, I was going to create double the value, then divide by two. Somewhat shorter would be modifying the entire source to generate odd values to start with.

mbomb007

Posted 2015-09-24T02:34:14.430

Reputation: 21 944

Won't this output DDoo nnoott rreeppeeaatt yyoouurrsseellff!! (double spaces)? I see two .s. – Erik the Outgolfer – 2016-09-29T13:47:06.633

@EriktheGolfer Time for you to read my answer. Change first '.' to '0'. I changed the explanation to show (again) that the first . is changed to a zero. – mbomb007 – 2016-09-30T13:22:04.377

7

Jelly, 66 bytes (non-competing)

““DDoo  nn““oott  rreepp““eeaatt  yyoouurrss““eellff!!””ṛṛḷḷWWQQ€€

Try it online!

Factoid

The program still works if you remove every second character.

Try it online!

How it works

““DDoo  nn““oott  rreepp““eeaatt  yyoouurrss““eellff!!”

returns an array of string. The literal begins with a , ends with a , and the strings are delimited internally by . The result is

["", "DDoo  nn", "", "oott  rreepp", "", "eeaatt  yyoouurrss", "", "eellff!!"]

The link's argument and the return value are set to this array of strings, then the remainder of the source code is executed.

<literal>”ṛṛḷḷWWQQ€€  Argument/return value: A (string array)

         ”ṛ           Yield the character 'ṛ'.
           ṛ          Select the right argument of 'ṛ' and A: A.
            ḷ         Select the left argument of A and A: A.
              W       Wrap; yield [A].
             ḷ        Select the left argument of A and [A]: A.
               W      Wrap; yield [A].
                Q     Unique; deduplicate [A]. Yields [A].
                 Q€€  Unique each each; for each string s in A, deduplicate s.

Dennis

Posted 2015-09-24T02:34:14.430

Reputation: 196 637

Why non-competing? – justhalf – 2016-09-29T05:36:43.103

1Because Jelly was created in December 2015, so it postdates this challenge by three months. – Dennis – 2016-09-29T05:59:11.790

Oops, didn't realize this is an old challenge – justhalf – 2016-09-29T14:09:42.350

5

MSM, 270 160 bytes

!!'',,ff'',,ll'',,ee'',,ss'',,rr'',,uu'',,oo'',,yy'',,  '',,tt'',,aa'',,ee'',,pp'',,ee'',,rr'',,  '',,tt'',,oo'',,nn'',,  '',,oo'',,DD'',,......................

My first MSM program!

String output in MSM is done by pushing the individual characters onto the stack and joining them into a single string via ., e.g.

!olleH.....

The number of . is one less than the number of characters. For Do not repeat yourself! we need 22 .s. Luckily this is an even number, so we have 11 doubles

......................

Putting the letters in front of it requires some more effort. The pattern

cc'',,

does the trick for each character c. It evaluates as follows

cc'',,            push c (remember: commands are taken from the left and operate on the right)
c'',,c            push c
'',,cc            quote ' and push
,,cc'             pop
,cc               pop
c                 voilà!

We need 23 such patterns starting with !!'',, and ending with DD'',, followed by the 22 join commands ..

nimi

Posted 2015-09-24T02:34:14.430

Reputation: 34 639

5

Gammaplex, 66 bytes

\\

XX""!!fflleessrruuooyy  ttaaeeppeerr  ttoonn  ooDD""XXXXrrRREE

Gammaplex is a 2D language that uses the position of the first newline as the line length, and ignore all other newlines.

jimmy23013

Posted 2015-09-24T02:34:14.430

Reputation: 34 042

5

Befunge 98, 70 66 bytes

Try it online!

After my invalid answer, here's a better one that actually fits the challenge!

2200**xx""!!fflleessrruuooyy  ttaaeeppeerr  ttoonn  ooDD��""kk,,@@

(Thanks to Martin Ender for suggesting the use of ��, character 0x17, instead of 88ff++)

Explanation:

2200          Push 2, 2, 0, and 0 onto the stack
*             Multiply 0 and 0, yielding 0
*             Multiply 2 and 0, yielding 0
              The stack is now [2, 0]
x             Pop a vector off the stack and set the instruction pointer delta to that
              The instruction pointer is now skipping over every other character, since the delta is (2, 0)
"!f ... oD�" Push the string onto the stack, with the number 23 (number of characters in the string) at the top
k,            Pop characters off the stack and print them, 23 times
@             End the program

Hactar

Posted 2015-09-24T02:34:14.430

Reputation: 646

You can save four bytes by using an unprintable character (code point 23) inside the string instead of 8f+: https://tio.run/nexus/befunge-98#@29kZGCgpVVRoaSkqJiWlpOTmlpcXFRUWpqfX1mpoFBSkpiYmlpQkJpaVATi5efn5Sko5Oe7uIiLKyllZ@voODj8/w8A

– Martin Ender – 2017-03-02T12:48:56.527

4

DC, 348 346 342 306 290 278 bytes

File dnr6.short.dc (without trailing newline):

AAzz--22222222vvPPAAAAAAAAvvPP88vvFFFFFFFFvv00++AAzz--PP11vvFFFFFFFFvv00++AAAAAAvvPP11vvEEEEEEEEvv00++OOOO//44999999vv++PP77II++OOOO//44999999vv++PPAAAAAAvv88vvFFFFFFFFvv00++PPAAzz--BBPP11vvFFFFFFFFvv00++77OOOO++++PPOOOO//44999999vv++66vvFFFFFFFFvv00++PP99zz++OO88++PPAAAAvv33PP

Run:

$ dc < dnr6.short.dc 
Do not repeat yourself!

user19214

Posted 2015-09-24T02:34:14.430

Reputation:

3

Backhand, 54 bytes

vv""!!fflleessrruuooyy  ttaaeeppeerr  ttoonn  ooDD""HH

Try it online!

Since Backhand's pointer already moving at three cells a tick, all we need to do is decrease that to 2 using v

Jo King

Posted 2015-09-24T02:34:14.430

Reputation: 38 234

That is surprisingly surprising – Want – 2020-01-25T09:18:10.847

3

BotEngine, 6x49=294

vv  PP

  !!ee

  ffee

  llee

  eeee

  ssee

  rree

  uuee

  ooee

  yyee

    ee

  ttee

  aaee

  eeee

  ppee

  eeee

  rree

    ee

  ttee

  ooee

  nnee

    ee

  ooee

  DDee

>>  ^^

SuperJedi224

Posted 2015-09-24T02:34:14.430

Reputation: 11 342

2

Alice, 74 bytes

aa00tt,,JJ""DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff!!//@@""ooYY;;tt


Try it online!

Explanation

The first catch is that we need to be able to enter the string, so we want to skip only the first ". We do this by jumping onto the first " because then the IP will move one cell before looking at the current cell again, so that it's the second " which enters string mode. But to be able to jump there, we need 10, 0 on top of the stack, in that order (second, top). This is done with aa00tt,,:

                          Stack:
aa   Push two 10s.        [... 10 10]
00   Push two 0s.         [... 10 10 0 0]
tt   Decrement twice.     [... 10 10 0 -2]
,    Rotate(-2).          [... 0 10 10]
,    Rotate(10).          [... 0 10 0]

This rotation function pops an argument. If that argument is negative, it pushes the value on top of the stack down by that many positions. If the argument is positive, it goes looking for the element that many positions below the top and pulls it up to the top. Note that in the case of Rotate(10), there aren't enough elements on the stack, but there is an implicit infinite amount of zeros at the bottom, which is why a zero ends up on top.

Now we can Jump onto the first " using these two arguments. The second " enters string mode and records all of that DDoo nnoott.... When it hits the /, the IP is redirected southeast and we enter Ordinal mode. For now on the IP bounces up and down across the three lines (two of which are empty), so it first records three more spaces on lines two and three and then we leave string mode when it hits the ". Since we're in Ordinal mode at this time, all the recorded characters are pushed as a single string to the stack (even though we recorded most of them in Cardinal mode), so we end up with this string (note the trailing spaces):

DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff!!   

Now the IP keeps bouncing up and down which means that it executes one command of every other pair, i.e. Y and t. Then the IP will hit the end of the grid on the second line and start bouncing backwards through the grid. This also switches in which pair of characters the IP hits the first line, so when going back it now executes ;, o and @. So ignoring all the spaces and implicit IP redirections, the executed code is Yt;o@ in Ordinal mode.

The Y is the "unzip" command which separates a string into the characters in alternating positions. Since each character is repeated, that really just gives us two copies of the string we're going for, although the first copy has two trailing spaces and the second has one trailing space. t splits off that trailing space and ; discards it. Finally, o prints the string and @ terminates the program.

Martin Ender

Posted 2015-09-24T02:34:14.430

Reputation: 184 808

2

05AB1E, 100 58 52 bytes

-6 bytes thanks to Kevin Cruijssen

„„€€··™™……€€––  ……¹¹‚‚  ……––‚‚))εε##θθáá}}»»……!!θθJJ

Try it online!

„„€€·              # dictionary string "g do"
     ·             # double (no effect on strings)
      ™            # title case: "G Do"
       ™           # title case again (no effect)
……€€––             # dictionary string "tools not–"
                   # spaces necessary so "–…" isn't parsed as a dictionary word
……¹¹‚‚             # dictionary string "team repeat‚"
                   # spaces necessary again
……––‚‚             # dictionary string "j yourself‚"
)                  # wrap the entire stack in an array
 )                 # and again: [["G Do", "tools not–", "team repeat‚", "j yourself‚"]]
  ε        }       # for each:
   ε      }        #  for each:
    #              #   split on spaces: ["tools", "not–"]
     #             #   and again: [["tools", "not–"]]
      θ            #   get the last element: ["tools", "not–"]
       θ           #   and again: "not–"
        á          #   keep only letters: "not"
         á         #   and again (no effect)
            »      # join the list by newlines, joining sublists by spaces:
                   # "Do not repeat yourself"
             »     # join the stack by newlines, joining lists by spaces (no effect)
……!!               # literal string "…!!"
    θ              # get the last character: "!"
     θ             # and again (no effect)
      J            # join the stack without separators: "Do not repeat yourself!"
       J           # and again (no effect)
                   # implicit output

Idempotency rules.

Grimmy

Posted 2015-09-24T02:34:14.430

Reputation: 12 521

1Nice answer, I'm impressed you were able to squeeze in the dictionary strings like that! It's unfortunately that á doesn't vectorizes on the inner strings, otherwise it could be used after the )).. Removing all á and using εεáá}} after the )) works as alternative, but unfortunately it doesn't save any bytes (but maybe you can find inspiration from it?).. And „„!! instead of ……!! work as well, since the ! builtin leaves the strings the same apparently. Ah well, I tried. xD – Kevin Cruijssen – 2019-09-04T13:00:59.420

1@KevinCruijssen I've been trying to refactor those repeated ##θθáá for a while, and for some reason I didn't consider εε}}... I tried €€, which doesn't quite work... This is now the shortest answer, thanks! – Grimmy – 2019-09-04T13:08:20.807

2

reticular, noncompeting, 62 bytes

2200**UU""DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff!!""oo;;

Try it online!

Explanation in parts:

2200**
2200    the stack looks like [2 2 0 0]
    *   [2 2 0*0]
     *  [2 2*0*0]
        [2 0]

U sets the pointer direction to (2, 0), that is, moving 2 x-units and 0 y-units, so it skips every other character, starting with the next U being skipped. Then, every other character is recorded, and it is equivalent to:

"Do not repeat yourself!"o;

which is a simple output program.

Other

This is competing for WallyWest's JavaScript bounty:

I can prove that, while numbers can be constructed under this restriction, strings cannot. Since no literals can be used, as the placement of any literal-building character would create an empty string:

""
''
``

Then, only some operator can be used; the only "paired" operators used are:

++ -- << >> ** ~~ || && !! ==

And none of these can cast numbers/others to strings. So no strings can be outputted.

Conor O'Brien

Posted 2015-09-24T02:34:14.430

Reputation: 36 228

Bounty ends in 5 days, @ConorOBrien, hope you don't mind waiting! But bounty is yours. – WallyWest – 2016-09-30T23:38:41.937

1

Stax, 70 bytes

GG11hh::zzaapp..}}..""DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff!!""

Run and debug it at staxlang.xyz!

Stax very fortunately has the builtin :: for every-nth. All I need to is push the string doubled, push 2, and run ::. Easy, right?

Wrong.

Pushing that string is tricky. The first quotation mark can be doubled by .."", which is a length-2 literal for ." followed by a meaningful quotation mark. Problem is, I see no way to terminate the string (which is necessary, or else the doubled version will be printed) without starting a new one.

The end of the program terminates string literals. If I can put this doubled literal there, perhaps there'll be a nice workaround. To jump somewhere from the end of a program, however, requires G}, so at minimum, I'm looking at this:

GG [deduplicate] }}""DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff!!""

This does... nothing. G does not begin a block, so neither will jump to the second }. Again, I need to ignore one character: ..}}. Execution jumps from the first G to the second }, continues to the end, jumps back to the second G and from there to the second }, and continues once more to the end before resuming at the start of the [deduplicate] section with the doubled string atop the stack.

Deduplication is simple. 11hh pushed eleven and halves it twice, rounding down both times and yielding two, and :: will then get us the output we need.

GG11hh::..}}..""DDoo  nnoott  rreeppeeaatt  yyoouurrsseellff!!""

Uh-oh. This prints nothing. There are two problems here: first, that ..} means the string .} will be atop the stack at the end of the program, and second, Stax's ordinary implicit output is now disabled!

The worse issue is the output. When a Stax program terminates gracefully without printing anything, the top of the stack will be implicitly printed. But we haven't printed anything...? Ah, but we have. Unterminated string literals are printed rather than pushed, and even those two empty strings (from the unmatched " at the end), despite being empty, are enough to trip this check. Any printing must be done by hand.

We'll need either pp or PP, and in this instance, ignoring the first through ..pp is unacceptable, as it will print the string .p. That means we need our desired output either alone on the stack or in the top two along with an empty string. This latter is accomplished by pushing two empty strings (zz) and rotating the top three items twice (aa) before printing.

Once that's done, we have a stack four strings tall. A fifth, .}, is then pushed before the program exits gracefully; at this point, the lack of implicit output becomes a blessing as well as a curse, as nothing extra will now be printed!

Khuldraeseth na'Barya

Posted 2015-09-24T02:34:14.430

Reputation: 2 608