93
\$\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\$
9
  • 5
    \$\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\$ Commented Aug 3, 2019 at 1:49
  • 6
    \$\begingroup\$ @PeterCordes I do not care if it modifies the same object or builds a new one. \$\endgroup\$
    – AJFaraday
    Commented Aug 3, 2019 at 5:08
  • 4
    \$\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\$ Commented Aug 3, 2019 at 5:16
  • 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
    Commented Aug 6, 2019 at 22:36
  • \$\begingroup\$ Does this answer your question? Stretching Words Because when you make the two operands in any submission to that challenge equal, programs will obey the behavior described in this challenge. An example of this behavior is here. \$\endgroup\$
    – user85052
    Commented Jan 2, 2020 at 12:29

254 Answers 254

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

Scala, 37 bytes

def^(s:String)=s.flatMap(x=>Seq(x,x))

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Wow, a nice one with clever use of Seq ; I was about to make one with replace but this one is like 10b shorter \$\endgroup\$ Commented Aug 6, 2019 at 6:43
  • 2
    \$\begingroup\$ According to other code golf solutions in Java, Kotlin and C#, it seems to be accepted to provide just a Lambda without binding it to a name. Thus, like Kotlin's it one can make use of Scala's _, for example, _.flatMap(x=>Seq(x,x)), using only 22 chars. TIO. Of course, this is just a counting trick, which does still follow your nice approach. \$\endgroup\$ Commented Aug 7, 2019 at 21:09
  • \$\begingroup\$ @cubic lettuce, I think those answers do not fully comply with the rules. Some time ago I got this useful recommendation codegolf.stackexchange.com/questions/174521/…. I would not bother with such "counting tricks"... unless it makes a scala solution shorter than any other. :) \$\endgroup\$
    – Dr Y Wit
    Commented Aug 12, 2019 at 13:37
  • \$\begingroup\$ ... the comment you linked links further to codegolf.stackexchange.com/questions/3885/… , where the accepted answer suggests to use Scala's _ where possible, however, without answering the question whether this is acceptable for the outermost function definition :) \$\endgroup\$ Commented Aug 13, 2019 at 14:39
5
\$\begingroup\$

Labyrinth, 12 bytes

",)@
" (
..:

Try it online!

I have just discovered this language so this answer may be notably improved...

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nicely done, my first thought was the same (only "," instead of "",), I've managed an eleven now - could there be a ten or better? \$\endgroup\$ Commented Jul 31, 2019 at 17:53
5
\$\begingroup\$

Stax, 2 bytes

c\

Run and debug it at staxlang.xyz!

Copy. Zip. Implicit print.

\$\endgroup\$
5
\$\begingroup\$

R, 50 33 bytes

-17 bytes thanks to Giuseppe

function(a)gsub('(.)','\\1\\1',a)

Try it online!

\$\endgroup\$
6
  • 1
    \$\begingroup\$ gsub('(.)','\\1\\1',a)? \$\endgroup\$
    – Giuseppe
    Commented Jul 31, 2019 at 15:40
  • \$\begingroup\$ I don't only check CG.SE two seconds after you post, I check all the time, haha, I should probably cut back a little. \$\endgroup\$
    – Giuseppe
    Commented Jul 31, 2019 at 15:41
  • \$\begingroup\$ @Giuseppe No idea how that works, but it does. \$\endgroup\$
    – Robert S.
    Commented Jul 31, 2019 at 15:42
  • 1
    \$\begingroup\$ Oh, well gsub does regular expression replacement -- replaces a single character match (.) in capture group 1 with two copies of capture group 1 \\1\\1, for all possible matches, as opposed to sub which only does one. \$\endgroup\$
    – Giuseppe
    Commented Jul 31, 2019 at 15:43
  • \$\begingroup\$ @Giuseppe Should this be submitted as your own answer since it is a completely different solution than what I came up with? \$\endgroup\$
    – Robert S.
    Commented Jul 31, 2019 at 15:45
5
\$\begingroup\$

Retina, 4 bytes


$<&

Try it online!

Matches the empty string (i.e. the position before/after each character) and inserts the string between this and the previous match (which is always exactly the previous character; except for the first match where it does nothing).

\$\endgroup\$
5
\$\begingroup\$

Labyrinth, 11 bytes

,:
"~~."
 @

Try it online!

How?

, - takes a byte from STDIN and pushes its ordinal onto the stack (0-255)
  -                                    unless EOF which pushes -1
: - duplicates the top of the stack [TOS]
~ - bitwise NOT TOS (-1 becomes 0, n becomes -n-1)
  -   4-neighbours: if TOS=0 go forward to @
  -                 if TOS<0 go left to ~
  -                 if TOS>0 go right to " (never the case)
@ - exits the program, otherwise...
~ - bitwise NOT TOS (undoes the effect of the previous ~)
. - print and discard TOS (mod 256) as an ASCII character
" - no-op
  -   We've hit a wall, turn around!
. - print and discard TOS (mod 256) as an ASCII character
~ - bitwise NOT TOS (stack starts with an infinite supply of 0s, so now TOS=-1) 
~ - bitwise NOT TOS (and now TOS=0 again)
  -   4-neighbours, but TOS=0 takes us forward to "
" - no-op
  -   ...and we're back at the starting ,
  -      facing right, with infinite 0s on the stack - just like the start
\$\endgroup\$
5
\$\begingroup\$

Turing Machine But Way Worse, 475 bytes

0 0 0 1 1 0 0 
1 0 1 1 1 0 0
0 1 0 1 2 0 0
1 1 1 1 a 0 0
0 2 0 1 3 0 0
1 2 1 1 b 0 0
0 3 0 1 4 0 0
1 3 1 1 c 0 0
0 4 0 1 5 0 0
1 4 1 1 d 0 0
0 5 0 1 6 0 0
1 5 1 1 e 0 0
0 6 0 1 7 0 0
1 6 1 1 f 0 0
0 7 0 1 g 0 0
1 7 1 1 g 0 0
0 a 0 1 b 0 0
1 a 1 1 b 0 0
0 b 0 1 c 0 0
1 b 1 1 c 0 0
0 c 0 1 d 0 0
1 c 1 1 d 0 0
0 d 0 1 e 0 0
1 d 1 1 e 0 0
0 e 0 1 f 0 0
1 e 1 1 f 0 0
0 f 0 0 h 1 0
1 f 1 0 h 1 0
0 h 0 1 i 1 0
1 h 1 1 i 1 0
0 i 0 1 0 0 0
1 i 1 1 0 0 0
0 g 0 1 g 0 1
1 g 1 1 g 0 1

Trivial modification of this answer

Try it online!

\$\endgroup\$
5
\$\begingroup\$

GolfScript, 7 6 4 bytes

{.}%

[Try it online!][TIO-jyx60w31]

my first golfscript program! Other people's explanations on here were super helpful for me to refer to so I'll type mine out even though its pretty short

{ }        code block
 .         copy the top item of the stack
   %       array map

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ doesn't this beat other golfscript answers? nicely done \$\endgroup\$ Commented Aug 6, 2019 at 6:46
5
\$\begingroup\$

Leaf Lang, 86 bytes

Note: The interpreter does not have a stable release. If I introduce a breaking change I will update this post :)

import"string.lf"argv reverse splitString 0=0=while:o:o:o:o:o o print o print 0=0=stop

Explaination:

0                  - push 0 to the top of stack
import "string.lf" - import stdlib's string.lf
argv               - add all of argv in order to the stack
reverse            - reverse string on top of stack (part of string.lf)
splitString        - split a string into chars (part of string.lf)
0 = 0 =            - this checks to see if the top value of the stack is a zero
while              - runs while the top value on the stack is true (1)
:o:o:o:o           - the language has pop as a keyword but :o is 1 char less and can be put side by side.
:o                 - grab the first letter on top of the stack and store in o
o                  - push the value in o on top of the stack
print              - print top value on stack with no newline
o                  - push the value in o on top of the stack
print              - print top value on stack with no newline
0 = 0 =            - check if the next value on the stack is not a zero
stop               - required to end while loop

Degolfed:

import "string.lf"

# [0, 'o', 'l', 'l', 'e', 'h']
0 argv reverse splitString

0 = 0 = while pop pop pop pop
    : current_char
    current_char print current_char print
    0 = 0 =
stop
```
\$\endgroup\$
4
\$\begingroup\$

Whitespace, 33 bytes

[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   S _Read_STDIN_as_integer][T T   T   _Retrieve][S N
S _Duplicate_input][T   N
S S _Output_as_character][T N
S S _Output_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Start LOOP:
  Character c = STDIN as character
  Print c
  Print c
  Go to next iteration of LOOP
\$\endgroup\$
2
  • \$\begingroup\$ This language is Bizzare! \$\endgroup\$
    – AJFaraday
    Commented Aug 2, 2019 at 10:27
  • 1
    \$\begingroup\$ @AJFaraday :D It's perfect for some source-code and polyglot tagged challenges, though. ;) And this answer is quite straight-forward tbh. You can take a look at some of my other answers in Whitespace for harder examples. \$\endgroup\$ Commented Aug 2, 2019 at 10:42
4
\$\begingroup\$

Brain-Flak, 48 bytes

([]){{}({}<>)<>([])}{}<>([]){{}(({}<>))<>([])}<>

Try it online!

This code has two main sections. The first just reverses the string:

([]){{}({}<>)<>([])}{}<>

The second is nearly identical, it reverses the string and doubles the characters in place

([]){{}(({}<>))<>([])}{}<>

The reason we need to reverse things is that we need to touch every element of the strings in order to make the output. Since Brain-Flak uses a stack model touching each character means popping all of the elements and pushing them. Because of the FIFO manner of a stack this means each time this is done you reverse the string. The reversing issue is not present in Brain-Flueue below.

Brain-Flueue, 28 bytes

([]<>){({}[()])<>(({}))<>}<>

Try it online!

Since queues are first in last out all we need to do in Brain-Flueue is iterate through the entire string doubling every character in place. However this does make it harder to iterate through the entire stack. In Brain-Flak we could just go until the stack height is zero however with a queue, pushing something puts it on the bottom of the queue essentially losing it. Instead we use the second queue to keep track of the number of operations we need. This makes are main loop look like:

([]<>){({}[()])<>...<>}<>

With the contents being the meager

(({}))

Just for fun, both of these answers could get a lot shorter if there were no null bytes in the input (ascii value zero)

Brain-Flak, 26 bytes

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

Try it online!

Brain-Flueue, 14 bytes

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

Try it online!

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

Befunge-93, 8 bytes

~:1+%:,,

Try it online!

For each character in input, outputs c%(c+1) as a character twice. This makes the program calculate -1%0 on EOF (-1), which terminates it.

\$\endgroup\$
4
\$\begingroup\$

Husk, 3 bytes

ṁR2

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ The solution I came up with was ṁ´e \$\endgroup\$
    – Jo King
    Commented Oct 2, 2020 at 18:23
  • 1
    \$\begingroup\$ Ṙ2 is -1 byte. \$\endgroup\$
    – Razetime
    Commented May 16, 2021 at 8:37
4
\$\begingroup\$

Flobnar, 11 bytes

\\@
|~
,e
:

Try it online!

This feels golfable.

\$\endgroup\$
1
  • \$\begingroup\$ upvoted for name alone \$\endgroup\$
    – Jonah
    Commented Aug 1, 2019 at 2:10
4
\$\begingroup\$

!@#$%^&*()_+, 12 bytes

*^(_^_!@@*^)

Try it online! If programs could terminate with an error, *(!@@*) works for 7 bytes.

Explanation

*^(_^_!@@*^)
*^                 take input, add 1
  (        )       loop until top of stack is 0
   _^_             subtract 1
      !            duplicate
       @@          output twice
         *^        take input, add 1
\$\endgroup\$
2
  • 1
    \$\begingroup\$ How do you pronounce !@#$%^&*()_+ ?? 😛 \$\endgroup\$
    – roblogic
    Commented Aug 1, 2019 at 20:45
  • 3
    \$\begingroup\$ @roblogic There are two canonical pronunciations. (1) "ek-nid-puc-ay-al-rulp" (2) "dang" \$\endgroup\$ Commented Aug 1, 2019 at 20:49
4
\$\begingroup\$

C (gcc), 62 41 bytes

f(char*a){for(;putchar(putchar(*a++)););}

Try it online!

This takes in input as the first arg, and outputs a NULL-terminated string to stdout. Not sure if the NULLs are a big deal. If you read the string properly, you'll stop after the first one ;)

Original without using a footer

\$\endgroup\$
4
\$\begingroup\$

C# (Visual C# Interactive Compiler), 26 bytes

s=>s.SelectMany(c=>c+""+c)

Try it online!

\$\endgroup\$
8
  • 1
    \$\begingroup\$ You could just use s=>s.Select(c=>c+""+c) instead to save 4 bytes \$\endgroup\$ Commented Aug 1, 2019 at 2:52
  • 1
    \$\begingroup\$ I considered that, but the signature would be kind of strange, since it is converting from IEnumerable<char> to IEnumerable<string> and other answers had avoided this. \$\endgroup\$
    – dana
    Commented Aug 1, 2019 at 3:10
  • \$\begingroup\$ Wait, this answer is actually wrong right now.. The output is a list of 2-char strings, which is neither a string nor list of chars/single-char strings. I.e. "abc" results in ["aa","bb","cc"]. The additional join in the print makes it aabbcc, but that should then be counted towards the byte-count. If ["aa","bb","cc"] would have been an acceptable output, I would have a few 1-byter solutions for my 05AB1E answer.. \$\endgroup\$ Commented Aug 1, 2019 at 10:05
  • 2
    \$\begingroup\$ @KevinCruijssen - the output is a list of characters. If you use Select you get a list of 2-character strings. SelectMany flattens each element and connects them. The output is a long list of characters. \$\endgroup\$
    – dana
    Commented Aug 1, 2019 at 12:10
  • 1
    \$\begingroup\$ @dana Ah ok, thanks for explaining. Then your code is indeed correct, but ZacFaragher's suggestion would give the incorrect result. Based on your response to him I thought the problem was outputting a list of single-char strings instead of actual chars, in which case you could also use single-char strings as IEnumerable<string> as both in- AND output. Didn't knew SelectMany would flatten in the process. In that case my initial upvote remains (couldn't retract it earlier anyway ;p). \$\endgroup\$ Commented Aug 1, 2019 at 12:15
4
\$\begingroup\$

Pepe, 19 bytes

REEerEErReEeReEeree

Try it online!

Explanation:

REEe # Input as str -> (R)
rEE # Create loop labelled 0 -> (r)
  rReEe # Output as char -> (R)
        # r flag: don't pop
  ReEe # Output as char and pop -> (R)
ree # Loop while (R) != 0
\$\endgroup\$
4
\$\begingroup\$

Perl 6, 13 11 bytes

{S:g{.}x=2}

Try it online!

Anonymous code block that takes a string and returns a string by replacing each character with twice of itself.

\$\endgroup\$
4
\$\begingroup\$

Forth (gforth), 39 bytes

: f bounds ?do i 1 type i 1 type loop ;

Try it online!

Beats NieDzejkob's submission by one byte. If we don't care empty strings, we can safely remove the ? in ?do, making it 38 bytes.

A function that takes a string in the standard representation (addr, length), and prints the result to the console.

How it works

gforth documentation about bounds

: f ( addr len -- )
  bounds ?do        \ Iterate through char addresses..
    i 1 type        \   Print one char at the address
    i 1 type        \   One more time
  loop ;            \ End loop
\$\endgroup\$
4
\$\begingroup\$

Wolfram Language (Mathematica), 13 11 bytes

-2 thanks to LegionMammal978

#~Riffle~#&

Try it online!

Takes and returns an array of characters.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I believe the more straightforward #~Riffle~#& would be a valid 11-byte solution (taking and returning a character list). \$\endgroup\$ Commented Nov 3, 2019 at 14:51
4
\$\begingroup\$

JavaScript (V8), 28 bytes

a=>[...a].map(p=>p+p).join``

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Arn, 5 bytes

|{|}\

Since this is <6 bytes I can't compress it

Explained

      \ Fold with...
| Concatenation after...
  { Mapping...
    | And concatenating _ and _
  } End map

Fold's required input is automatically assumed to be _ (initialized as STDIN). Type casting automatic, output automatic.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The answer that I can't understand how it works, even after explanation! (Just like Arnauld's explanations) +1 \$\endgroup\$
    – user96495
    Commented Aug 15, 2020 at 6:29
4
\$\begingroup\$

Kotlin, 48 35 bytes

35 bytes from 48 bytes thanks to @user

{it.map{"$it$it"}.joinToString("")}

Not much to it, just that it.map() returns a CharArray so you have to joinToString() it.

Kotlin Playground Link(Would've been TIO but TIO has issues with kotlin.)

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to Code Golf! You can also use something like {it.map{"$it$it"}.joinToString("")} (lambdas are allowed according to a meta consensus). \$\endgroup\$
    – user
    Commented Feb 14, 2021 at 22:24
  • 1
    \$\begingroup\$ FYI there's already a few Kotlin solutions. (although we don't prohibit posting your own attempts) codegolf.stackexchange.com/search?q=inquestion%3A188988+Kotlin (I think there's also the graduation userscript that shows a leader board under every questions, but I don't use it myself) cc @user \$\endgroup\$
    – user202729
    Commented Feb 15, 2021 at 10:14
  • \$\begingroup\$ @user202729 Even if we did prohibit duplicate answers, this one's different from the other two, and it could be made shorter than both of them with a lambda. I do agree with you that one should check pre-existing answers first, though. \$\endgroup\$
    – user
    Commented Feb 15, 2021 at 16:23
  • 1
    \$\begingroup\$ @user Thanks for the help, I've edited that in. \$\endgroup\$
    – grian
    Commented Feb 15, 2021 at 18:48
4
\$\begingroup\$

Python 3.8, 31 bytes

for x in input():print(end=x*2)

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Excel, 43 bytes

=CONCAT(MID(A1,SEQUENCE(LEN(A1),2,,0.5),1))

Link to Spreadsheet

\$\endgroup\$
1
  • \$\begingroup\$ You can mark this as 42 bytes by removing the 0 in 0.5 - Excel will autoformat this back into your answer, but changes made by autoformatting are not counted in bytecounts \$\endgroup\$ Commented Apr 5, 2022 at 14:55
4
\$\begingroup\$

Vyxal, 1 byte

Y

Try it Online!

Yet another trivial answer. Y interleaves the input string with itself. It’s good that Vyxal can tie with Jelly and beat 05AB1E in matters of triviality.

\$\endgroup\$
1
  • \$\begingroup\$ Due to the way Y works, the s flag is unnecessary. \$\endgroup\$
    – emanresu A
    Commented Sep 12, 2021 at 10:36
4
\$\begingroup\$

Binary Pi Calculus, 5 bytes

0x37 0xA7 0xB2 0x7B 0x00

I don't know if there is an interpreter for BPC. If there is one, I'd appreciate if someone let me know.

Explanation

0x37     0xA7     0xB2     0x7B     0x00
00110111 10100111 10110010 01111011 00000000
0011011110100111101100100111101100000 000
001                                   Run the following on an infinite number of threads:
   1011110                            Read from free channel 0 into bound variable 0
          100     1100                Write bound variable 0...
             11110                    ...to free channel 1
                      100111101100    Do so again
                                  000 End the process

BPC technically does not have I/O capabilities. Instead, I use the global names 0 and 1 for STDIN and STDOUT, respectively (these numbers are, incidentally, the file descriptors for STDIN and STDOUT in most 'nix operating systems)

\$\endgroup\$
4
\$\begingroup\$

Rust, 38 bytes

|x:&str|x.find(|c|print!("{c}{c}")>())

Playground

This takes advantage of Rust's new formatting features (capturing identifers automatically) as well as the fact that () implements Ord and can be compared to itself. Basically this solution searches the string for a character that matches a predicate, but that predicate outputs the character twice and returns false.

\$\endgroup\$
4
\$\begingroup\$

Python, 31 bytes

lambda x:''.join(i*2for i in x)

This uses the shorthand for a generator comprehension. It will loop through every character in x and double it. sum won't work for str, so I took the advice from the error and used ''.join.

\$\endgroup\$
1
  • \$\begingroup\$ Nice, never even knew this existed \$\endgroup\$
    – Seggan
    Commented Jul 18, 2022 at 1:34
1
2
3 4 5
9

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.