63
\$\begingroup\$

Super simple challenge today, or is it?

I feel like we've heard a fair bit about double speak recently, well let's define it in a codable way...

Double speak is when each and every character in a string of text is immediately repeated. For example:

"DDoouubbllee  ssppeeaakk!!"

The Rules

  • Write code which accepts one argument, a string.
  • It will modify this string, duplicating every character.
  • Then it will return the double speak version of the string.
  • It's code golf, try to achieve this in the smallest number of bytes.
  • Please include a link to an online interpreter for your code.
  • Input strings will only contain characters in the printable ASCII range. Reference: http://www.asciitable.com/mobile/

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

var QUESTION_ID=188988;
var OVERRIDE_USER=53748;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=asc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=asc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, [Other information] N bytes

where N is the size of your submission. Other information may include flags set and if you've improved your score (usually a struck out number like <s>M</s>). N should be the right-most number in this heading, and everything before the first , is the name of the language you've used. The language name and the word bytes may be links.

For example:

# [><>](http://esolangs.org/wiki/Fish), <s>162</s> 121 [bytes](https://esolangs.org/wiki/Fish#Instructions)
\$\endgroup\$
  • 1
    \$\begingroup\$ It will modify this string. Are you intentionally requiring pass-by-reference and modify in-place? And then return a copy or reference to that modified string? If so, languages like asm or C would need to accept an explicit-length string (pointer + length) where the length is either the current string length (with the buffer being twice that size), or it's the total size and you need to duplicate the low half. Thus you need to start from the end and work backwards, or allocate scratch space and then copy back. But there are answers in C and 8086 asm that totally violate all that. \$\endgroup\$ – Peter Cordes Aug 3 '19 at 1:49
  • 3
    \$\begingroup\$ @PeterCordes I do not care if it modifies the same object or builds a new one. \$\endgroup\$ – AJFaraday Aug 3 '19 at 5:08
  • 2
    \$\begingroup\$ I'd suggest wording it as "modify (or produce a modified copy) of the string" to explicitly allow answers that do or don't modify in-place. Simplifying the wording to "return a string that's twice as long, with each character repeated" would be nice but then it's not clear if void foo(char *c, size_t len) is legal that takes one input/output buffer and a length, and doesn't have any return value, just a side-effect on the object it has a pointer to. \$\endgroup\$ – Peter Cordes Aug 3 '19 at 5:16
  • \$\begingroup\$ Can the string be empty? \$\endgroup\$ – cschultz2048 Aug 6 '19 at 19:58
  • 1
    \$\begingroup\$ @cschultz2048 it says the string will only contain printable ascii characters, so that implies that they’ll always be populated. I’d expect that any code for this challenge would leave an empty string empty... anyway, I don’t think it’s a test case that I’d use for this. \$\endgroup\$ – AJFaraday Aug 6 '19 at 22:36

145 Answers 145

1 2 3 4 5
1
\$\begingroup\$

Brain-Flak, 26 bytes

{(({}<>))<>}<>{({}<>)<>}<>

Pretty simple, and my first Brain-Flak answer :D

(Note: this requires the -a and -ac flags for ascii I/O)

How it works

{  Begins a loop that will run for every character of input
(({}<>))   Pops the top element of the stack and pushes two copies of it to the second stack
<>  Go back to the first stack
}   End loop
<>   Go to the second stack
{({}<>)<>}   Reverse the second stack and puts it onto the first
<>  Go to the first stack do it outputs it

Try it Online!

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

C (clang), 60 50 bytes

gets(s);while(s[(int)i])putchar(s[(int)(i+=0.5)]);

Try it online!

Saved 10 bytes Thanks to Peter Cordes

\$\endgroup\$
  • \$\begingroup\$ This snippet depends on declarations and initializers (like float i = -0.5) outside the block you're counting. You need to count all the bytes of your code for a whole function or block that can be used on its own without dependencies on other parts of the source code. e.g. a whole function + any global variables it uses. \$\endgroup\$ – Peter Cordes Aug 3 '19 at 2:49
  • \$\begingroup\$ Interesting idea, though, to use float increments to half-step. putchar would be shorter than printf("%c", and also !=0 is implicit in while(s[(int]i]). I think ISO C guarantees that \0 has integer value 0, and I'm sure that it's guaranteed to be the only "false" character value so a strlen like while(*s++) is a safe. \$\endgroup\$ – Peter Cordes Aug 3 '19 at 2:51
  • \$\begingroup\$ Congratulations on your first answer! I remember when I first started, it was a bit complicated to figure out what should be counted and what shouldn't be counted (I'm still not sure sometimes). From this meta post, a function is also a valid submission, in which case we can abuse a bunch of things in C to get this 51-byte answer. It's not pretty though \$\endgroup\$ – maxb Aug 6 '19 at 9:16
  • \$\begingroup\$ Thanks guys for the comments, still learning so please forgive any mistakes and thanks for the ideas Peter would definitely try implementing them. \$\endgroup\$ – Loki Aug 7 '19 at 11:25
  • 1
    \$\begingroup\$ Building on @maxb 41 bytes \$\endgroup\$ – ceilingcat Aug 19 '19 at 5:32
1
\$\begingroup\$

Q'Nial7, 28 bytes

d is OP N{link cols mix N N}

result:

     d 'Double Speak!'
DDoouubbllee  SSppeeaakk!!

Explanation, using detailed picture mode:

     set "decor                 %turn on decoration of atoms and empty arrays,
                                %gives a picture that distinguishes all atoms                                  
"decor                                                                          
     set "diagram                                                               
"diagram                        %set default display mode to diagram,
                                %give full boxed picture of results                                 
     N:='Double Speak!'         %define string N                                       
+--+--+--+--+--+--+--+--+--+--+--+--+--+                                        
|`D|`o|`u|`b|`l|`e|` |`S|`p|`e|`a|`k|`!|                                        
+--+--+--+--+--+--+--+--+--+--+--+--+--+                                        
     mix N N                    %nesting restructuring: create table of items
                                %from list of items, the list being N N                                       
+--+--+--+--+--+--+--+--+--+--+--+--+--+                                        
|`D|`o|`u|`b|`l|`e|` |`S|`p|`e|`a|`k|`!|                                        
+--+--+--+--+--+--+--+--+--+--+--+--+--+                                        
|`D|`o|`u|`b|`l|`e|` |`S|`p|`e|`a|`k|`!|                                        
+--+--+--+--+--+--+--+--+--+--+--+--+--+                                        
     cols mix N N               %nesting restructuring: list of columns
                                %of the table                                       
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+
||`D|`D|||`o|`o|||`u|`u|||`b|`b|||`l|`l|||`e|`e|||` |` |||`S|`S|||`p|`p|||`e|`e|
|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+|+--+--+
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------

+-------+-------+-------+                                                       
|+--+--+|+--+--+|+--+--+|                                                       
||`a|`a|||`k|`k|||`!|`!||                                                       
|+--+--+|+--+--+|+--+--+|                                                       
+-------+-------+-------+                                                       
     link cols mix N N          %construction op: items of the first item of N
                                %are followed by the items of the second item of N, etc.                                       
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 
|`D|`D|`o|`o|`u|`u|`b|`b|`l|`l|`e|`e|` |` |`S|`S|`p|`p|`e|`e|`a|`a|`k|`k|`!|`!| 
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 
\$\endgroup\$
1
\$\begingroup\$

Forget, 61 55 bytes

I created this language when I was bored one day. I released it the same day as this challenge was posted. I can guarantee this was not designed specifically for this challenge.

in;cleanse;out;out;pop;hasin;in;cleanse;out;out;pop;end

-6 bytes by terminating on EOF
There's no TIO (yet). The interpreter is available here There's a TIO now
Explanation:

in - reads a character from standard input and pushes a pointer to the stack

cleanse - unpoisons the pointer on top of the stack

out - prints the value stored at the address on top of the stack as a character

out - see above

pop - removes the value from the stack to avoid memory leaks

hasin - while characters are available on standard input...

(the body of the loop is the same as before it)

end marks the end of the loop

The only way this program can error is if the interpreter forgets the value stored at the address on the stack and the program attempts to use it.

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

Aceto: 5 bytes

,dppO

Doesn't work on TIO, because it hangs indefinitely. Buffering might prevent you from seeing the result, run with -F to immediately flush all output.

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

Go, 110 bytes

func main(){for j:=0;j<len(os.Args[1]);j++{fmt.Printf("%c%c",os.Args[1][j],os.Args[1][j])};fmt.Printf("\n");}

Try It on Jdoodle!

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

C#, 104 bytes

public class P{public static void Main(string[]a){foreach(char c in a[0])System.Console.Write(c+""+c);}}

Try Online

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

Piet, 20 codels

If you are using npiet, you might want to use the -q option to stop the interpreter from printing a prompt for each character.

Double Speak

Rundown

If STDIN contains no character, Piet's input functions will not lock or throw an error, but simply fail quietly. To know if we reached the end of the string, we therefore push a sentinel 0 to the stack to detect if nothing was read.

In pseudo code:

1. Push 1 to stack
2. Perform NOT on top of stack
3. Attempt to read character
4. Duplicate top of stack, twice.
5. Perform NOT on top of stack, twice,
   leaving a 1 if character was read, 0 otherwise.
6. Turn Direction Pointer as many steps as value on top of stack.
7. If we turn, print character, twice, and go to start
8. If we do not turn, get caught in exit block. (Bottom left corner.)
\$\endgroup\$
1
\$\begingroup\$

AsciiDots, 27 21 bytes

.>#a?**>$_a#
 \---/\/

Note that this halts in an error, which is allowed.

-6 bytes by getting rid of whitespace and not using warps.

Try it online!

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

Kipple (cipple), 28 bytes

(i>ac<0>b(a-1b+1c+1a?)b>o<c)

It's actually suprisingly difficult to duplicate stack items in Kipple

Expanation

(i>ac<0>b(a-1b+1c+1a?)b>o<c) Full program

(i                         ) Loops until the input stack is empty
 i>a                         Push the top item of the input stack to stack A
    c<a>b                    Push 0's to stack B and C
         (a-1b+1c+1a?)       A loop that basically pushes the top of stack A to stack B and C
                      b>o<c  Push the top of stack B and stack C to the output stack

Try it online!

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

MathGolf, 2 bytes

I hope this isn't a duplicate. (Great, it isn't.)

_^

Explanation

_  Duplicate the implicit input
 ^ Zip

Try it online!

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

Hexadecimal Stacking Pseudo-Assembly Language, 60 bytes

000000100000420000400000420000400000030000040000140000010000

Try it online!

000000 Label start:
100000 read character
420000 load it into register
400000 push it on the stack another time
420000 load it into register
400000 push it on the stack another time
030000 ignore next command if top of stack is non-zero
040000 end program
140000 print string
010000 go to start
\$\endgroup\$
1
\$\begingroup\$

Python 3, 31 bytes

for t in input():print(t,end=t)

a simple program of python

for t in input():

asking for the input, and doing a for loop for every char in the string.

print(t,end=t)

print the character, and then close the line with the same character.

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

Clojure, 25 bytes

(fn[s](apply str(map #(str % %)s)))
\$\endgroup\$
1
\$\begingroup\$

[sed], 13 bytes

sed 's/\(.\)/&&/g'  <<< "Double speak"

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ 1) Please use a properly formatted heading line for your answer so the leaderboard script can parse it. 2) The quotes around the code are necessary only when specified in command line due to the shell's own parsing rules, they not need to appear in the answer and even less to get counted. 3) As possible please add TIO links to your answers so people can try them out easier and see how input is supposed to get passed to the code. \$\endgroup\$ – manatwork Nov 11 '19 at 10:54
  • 2
    \$\begingroup\$ Just as information (its existence doesn't invalidate your solution), Leo Tenenbaum's sed solution is shorter. ☹ \$\endgroup\$ – manatwork Nov 11 '19 at 10:56
  • \$\begingroup\$ @manatwork: Oh sorry, I visually "grepped" through the StackExchange posts, but didn't see sed. \$\endgroup\$ – stephanmg Nov 11 '19 at 11:03
  • \$\begingroup\$ Yes, capture group is not needed, so @LeoTenenBaums's solution is better. \$\endgroup\$ – stephanmg Nov 11 '19 at 11:14
1
\$\begingroup\$

[awk], 24 bytes

awk '$0=gensub(/./,"&&","g")' <<< "Double speak"

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ I guess you accidentally pasted an older code version since you still debugged it. That would explain that \n. \$\endgroup\$ – manatwork Nov 11 '19 at 11:00
  • \$\begingroup\$ Yes, you are right. Thanks for pointing me to this. \$\endgroup\$ – stephanmg Nov 11 '19 at 11:01
  • 1
    \$\begingroup\$ You could shorten it by learning from Leo Tenenbaum's sed solution and avoid using a capture group: $0=gensub(/./,"&&","g"). \$\endgroup\$ – manatwork Nov 11 '19 at 11:03
  • \$\begingroup\$ Thanks @manatwork. I shortened it. \$\endgroup\$ – stephanmg Nov 11 '19 at 11:08
1
\$\begingroup\$

Bash, 45 bytes

while IFS= read -n1 c;do printf %s"$c$c";done 

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Yeah I removed this part. Btw. I'm not sure if it's a valid solution, because the string is not modified but a copy is printed. \$\endgroup\$ – stephanmg Nov 11 '19 at 11:45
  • \$\begingroup\$ @JoKing: You are probably right. \$\endgroup\$ – stephanmg Nov 11 '19 at 11:57
1
\$\begingroup\$

Binary Lambda Calculus, 10 bytes

8446 0016 c25b 3fdf 9ade

This program was on this page and was known as a ``stuttering'' program.

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

GolfScript, 9 bytes

Great if this hasn't been posted yet.

[{.}/]''+

Try it online!

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

@, 8 bytes

¤ōōč

Explanation

¤    Forever
   č Read a character
 ōō  Output twice
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 4 bytes

{.}%

Try it online!

Takes an input, which it treats as a list of characters, and maps . (push top item of stack to stack) over them.

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

Pip, 4 bytes

aWVa

Try it online!

The operator WV ("weave") takes two iterables and interleaves their elements. In this case, weaving the input string with itself produces the desired output.

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

Burlesque, 2 bytes

)J

Try it online!

) # Map (implicitly explode and apply to each character then concatenate)
J # Duplicate
\$\endgroup\$
0
\$\begingroup\$

Pyth, 5 bytes

sm*2d
s      Concatenate
  *2d  lambda d: d*2
 m     Mapped over
     Q Input (implicit

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 3 byter here, but theres a 2 byte solution for pyth here \$\endgroup\$ – frank Dec 2 '19 at 22:38
0
\$\begingroup\$

QBasic, 58 bytes

LINE INPUT s$
FOR i=1TO LEN(s$)*2
?MID$(s$,i/2+.1,1);
NEXT

Explanation

LINE INPUT reads all input characters until a newline into s$. We loop i from 1 up to twice the length of the string and output the i/2th character (rounded up) at each iteration. There's a slight hitch, in that QBasic rounds numbers with a fractional part of .5 up sometimes and down other times; adding a small amount like .1 is sufficient to round the halves up, while the whole numbers still get rounded back down.

\$\endgroup\$
1 2 3 4 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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