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!"
51
Fun fact: If the problem had triplets instead,
– Sp3000 – 2015-09-24T02:39:25.300DDDooo nnnooottt rrreeepppeeeaaattt yyyooouuurrrssseeelllfff!!!
would be a valid answer in Trigger14I 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