90
\$\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\$
10
  • 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\$ Aug 3, 2019 at 1:49
  • 5
    \$\begingroup\$ @PeterCordes I do not care if it modifies the same object or builds a new one. \$\endgroup\$
    – AJFaraday
    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\$ Aug 3, 2019 at 5:16
  • \$\begingroup\$ Can the string be empty? \$\endgroup\$ Aug 6, 2019 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, 2019 at 22:36

235 Answers 235

1
4 5 6
7
8
2
\$\begingroup\$

A0A0, 165 150 142 bytes

A0A0
A0C3G1G1A0
A0I1A6V0P0G6C6A0
A0A1G-3G-3A0
G-3

A0A0
C3G1G1A0C3G1G1A0

A0A1G-3G-3A0
G-3
A0A0
C3G1G1A0C3G1G1A0
G-10A0G-10A0
A0A1G-3G-3A0
G-3

The program consists of three loops right after one another. The first loop does the following:

I1A6V0P0G6C6
I1           ; take character input, store in V0
  A6         ; append this line to the line six below
    V0       ; operand, holds input
      P0     ; prints input
        G6   ; jumps to six lines below
          C6 ; removes all instructions on the six lines below

We duplicate the operand and print instructions a little lower, so we can print it twice. We then jump to there and the last C6 is to get rid of any other instructions that we didn't need afterwards.

The second loop is empty and is constructed from the first loop. The loop is also partially executed so we can enter the loop at the same place each time. This loop will print the character a second time. Because there is a nice G6 instruction inside the copied instructions that will also be executed, we use that as a way to escape from the infinite loop. This is because six lines below is yet another loop.

G-10G1G1
G-10     ; jumps 10 lines up, back to the first loop
    G1   ; no-op
      G1 ; no-op

This is a simple infinite loop (also partially executed) that takes us back to the first loop. It's padded with no-ops, since the loops needs at least three instructions. Because the first loop contains a C6, any redundant instructions in the second loop will be removed once we get back to the first loop.

Edit: Optimized by 15 bytes. I misunderstood the default loop template I make use of in the code. I was under the impression that the amount of G1 and G-3 instructions on line 2 and 4 of the loop resp. needed to match the amount of instructions inside the loop. This is not the case, you only need two of them (although more also work, as long as each line has an equal amount of them). This change removes these extra instructions.

Edit 2: Optimized by 8 bytes. Because of edit one, it turns out that there's actually no minimum of three instructions in the loop. This allows us to drop four instructions (not two, since the loop at the bottom is partially evaluated), totalling eight bytes.

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

Python 3, 44 43 41 37 25 24 Bytes

I have refactored it a ton and came to this answer:

print(*[x*2 for x in input()],sep="")

Try it online!

then from there I got to lambda i:[x*2 for x in i]

The TIO doesn't work properly due to it being a function but here it is anyways: The TIO now works thanks to des54321 for their advice:

Try it online!

Here's my other implementation of this challenge with greatly appreciated help from the comments:

print("".join(map(lambda x:x*2,input())))

Try it online!


End result as of 26/05/2022 thanks to everybody's changes lambda i:[x*2for x in i]

Try it online!

Description

It works by separating the script using pythons map function to grab every character in the inputted string then multiplying them by 2 and joining them back together after it is converted to a map using an empty string then joining every element to it.

Thanks to pxeger for suggesting to remove unnecessary spaces, to Wheat Wizard ♦ for suggesting to remove the quotes from the input, to des54321's advice of using f=\ in the header to fix TIO with lambda functions and Nobody's help detecting the unnecessary space in the lambda.

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! Be sure to check out our Tips for Golfing in Python page for ways you may be able to golf your code! For example, you can remove the space after the comma. \$\endgroup\$
    – pxeger
    Mar 31, 2022 at 7:46
  • 1
    \$\begingroup\$ Welcome to the site! You can also remove the "" from input since it defaults to an empty prompt when nothing is provided. \$\endgroup\$
    – Wheat Wizard
    Mar 31, 2022 at 9:53
  • \$\begingroup\$ btw you can make the TIO link for the lambda solution work properly by putting `f=` in the header, like this \$\endgroup\$
    – des54321
    Apr 4, 2022 at 4:03
  • \$\begingroup\$ Well you can refactor it into lambda i:[x*2for x in i]. \$\endgroup\$ May 19, 2022 at 11:54
  • \$\begingroup\$ @NobodyNeedsNames That isn't a valid output format - char lists are allowed, but to get a result you have to join that by the empty string. \$\endgroup\$
    – emanresu A
    Jul 13, 2022 at 21:35
2
\$\begingroup\$

GeoGebra, 40 bytes

s="a
InputBox(s
Sum(Zip(S+S,S,Split(s,{"

Input goes in the Input Box.

Just found out about GeoGebra's parentheses/quotation marks/(other stuff I'm missing) auto-complete when pasting in code, really cool.

Try It On GeoGebra!

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

Alice, 12 9 bytes

/O./
@IZ\

Try it online!

Explanation Flattened

/        Switch to Ordinal mode
 I       Reads a string from the input
  .      Duplicates it
   \/    Does a U turn and switch line
     Z   Zip the two strings
      O  Print it
       @ Bye
\$\endgroup\$
2
\$\begingroup\$

K (ngn/k), 11 bytes

{,/{x,x}'x}

Try it online!

Quick.

Explanation:

{,/{x,x}'x}       Main program.
        'x        For each character in the string...
   {x,x}          Duplicate the character twice
 ,/               Then join each duplicated character together
\$\endgroup\$
2
\$\begingroup\$

MUMPS, 36 bytes

a(s) f %=1:1:$l(s) w $e(s,%),$e(s,%)

Try it online!

Explanation:

  • a(s) labels this line as a subroutine a with one parameter s.
  • $l is short for $length and returns the length of a string.
  • f is short for for. f %=1:1:$l(s) loops from 1 to $l(s) in steps of 1 with the variable % storing the current value.
  • $e is short for $extract. $e(s,%) gets the character of s at position % (one-indexed).
  • w is short for write and prints the expression that follows it.
\$\endgroup\$
2
\$\begingroup\$

Fig, \$\log_{256}(96)\approx\$ 0.823 bytes

Y

See the README to see how to run this

Polyglots with Vyxal and does the exact same thing: interleaving the input with itself.

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

Raku, 21 bytes

{[~] [Z~] .comb xx 2}

Try it online!

{                   }  : anonymous code block
          .comb        : yields chars of input string
                xx 2   : repeat list of chars
     [  ]              : reduction metaoperator
      Z~               : Z operator and concat operator
                       : Z is a metaoperator here that zips using ~
 [~]                   : concat zipped list of repeated chars
\$\endgroup\$
5
  • 2
    \$\begingroup\$ Funnily enough, you can remove the [Z~] simply by capitalising the first x. I also have a regex based answer \$\endgroup\$
    – Jo King
    Sep 7, 2022 at 9:09
  • \$\begingroup\$ lmao that is quite the trick. I like your regex based answer. Lakmatiol in the raku discord came up with {S:g/./$/$//}, which is 13 bytes. I was going to improve mine with it but I will leave it be. Should I continue to use Raku for the language or prefer Perl 6? \$\endgroup\$
    – south
    Sep 7, 2022 at 21:06
  • \$\begingroup\$ Perl 6 was the old name for Raku, so some older answers are mislabelled. Raku is the preferred name these days \$\endgroup\$
    – Jo King
    Sep 7, 2022 at 21:07
  • \$\begingroup\$ That was the impression I was under. Thanks \$\endgroup\$
    – south
    Sep 7, 2022 at 21:09
  • 1
    \$\begingroup\$ I was pretty happy with my 16; that 13-byte answer from the Discord is impressive. \$\endgroup\$
    – Mark Reed
    Nov 23, 2022 at 0:48
2
\$\begingroup\$

C (gcc), 57 bytes (code) + 11 bytes (flags) + N bytes (argv[1])

Note: the flag in question is -Dx=s[1][i] this code compiles with GCC and Clang

I also had a solution with shorter source code, but including the flags there are more bytes.

main(i,s)char**s;{for(i=0;x^'\0';i++)printf("%c%c",x,x);}

tricks used:
I was able to skip adding int i, char**s by adding the char**s after main is declared, saving 2 bytes. I was also able to set i=0 in the for loop to save a single byte. Using the flag -Dx=s[1][i] saved me 7 bytes.

Try it online!

\$\endgroup\$
8
  • \$\begingroup\$ We don't require counting flags in the byte count anymore. \$\endgroup\$
    – naffetS
    Sep 16, 2022 at 19:20
  • \$\begingroup\$ What's the + N bytes (argv[1])? You don't count input in the bytecount. \$\endgroup\$
    – naffetS
    Sep 16, 2022 at 19:28
  • \$\begingroup\$ @Steffan dang, I didn't know that. I have a much shorter solution then. Also, I did not realize that we did not need to include the byte count on input. I have a question, can't I make my code 1 byte with a flag containing the entire source? \$\endgroup\$
    – Breadleaf
    Sep 16, 2022 at 19:34
  • \$\begingroup\$ Technically yes, but that's disallowed as a loophole. codegolf.meta.stackexchange.com/a/5076/92689 \$\endgroup\$
    – naffetS
    Sep 16, 2022 at 19:35
  • \$\begingroup\$ codegolf.meta.stackexchange.com/a/14339/92689 \$\endgroup\$
    – naffetS
    Sep 16, 2022 at 19:35
2
\$\begingroup\$

Piet + ascii-piet, 18 bytes (3×6=18 codels)

Technically, we can create a trivial 5 codel (4 ops + 4 no-ops) answer that will never terminate. This non-trivial no-error implementation is a lot more interesting.

Piet image with codel size 25

Codel size 1: Piet image with codel size 1

rfnf Tk??k?Ttilj t

Try visual Piet online! or Try npiet online!

This improves the answer by @gastropner with 2 codels. Instead of a 5×4 image, this uses a 3×6 image. If you count the number of bytes using ascii-piet, you will find that the previous answer was 18 bytes as well and this is not an improvement but an alternative.

We use the fact that invalid instructions get ignored and got lucky that the whole program is a cycle, just like the previous answer. The main loop is a total of 10 operations, which is an improvement of 1 compared to the previous answer. This improvement was possible by moving the termination point to the right instead of bottom left. In order, the operations are:

1.  Output the top value on the stack as character,
2.  Pop the top value from the stack (0 for all but the first loop),
3.  Push 1 to the stack,
4.  Use a `not` operation to turn it into 0,
5.  Push the input character to the stack,
6.  Duplicate the input character
      (OR 0 in case there was no input character),
7.  Duplicate it again,
8.  Use a `not` operation to turn the top value into
      a 0 if there was a (non-null) character and
      a 1 if there wasn't,
9.  Exit the loop if the top value from the stack is 1,
10. Output the top value on the stack as character.

I don't think it's possible to remove popping 0 from the stack, because you need the 0 on the stack which requires steps 3 and 4. If you remove step 2, your program could technically become 9 steps total at the expense of an ever growing stack, however, loops must always use an even number of codels. With 9 operations you would thus need a 2 codel block to make up for the odd number. If you could get the program to work in 8 steps, that's probably the minimum as I believe you will necessarily need 8 operations: INC DUP DUP NOT OUTC OUTC DP+/CC+ PUSH. Using the same DUP and OUTC commands will be very difficult with so little space, but I think that would be the only option for reducing the size. Lastly, I do think you need the ninth NOT to contrast the sentinel with the input character, because you cannot check for the difference between a successful command and an ignored command without having a different truth value for both.

Note that this also fixes a small bug in the previous answer. The problem with that code is that the Codel Chooser switches between left and right for each iteration. This means that half the time, no 1 is added to the stack and then the previous value on the stack is used in the NOT operation. Then if it reaches the DP+ operation with a 1 (a quarter of the time) and this is the end of the string it will act as if this is the input character and print two <SOH> characters. This bug only occurs for strings of length 𝟤+𝟦𝑘.

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

str, 2 bytes

do

d = duplicate, o = output. Runs characterwise by default.

Try it online!

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

Rattle, 12 bytes

|I=@P[gbb>]`

Try it Online!

Explanation

|              take string as input
 I             split string into characters and store in consecutive memory slots
  =@           set top of stack to the value of the pointer (i.e. length of string)
    P          set pointer to 0
     [....]`   repeat n times where n is the top of the stack
      g        get character in storage at pointer
       bb      add character to print buffer twice
         >     shift pointer right
               [print buffer output implicitly]
\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 27 bytes

Unsurprisingly not the best JS answer.
Takes array of characters as input since it seems valid for some answers. Output is a string.

s=>s.map(b=>a+=b+b,a="")&&a

Try it online!

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

Python 3, 39 38 bytes

lambda s:(j:=''.join)(map(j,zip(s,s)))

Try it online!

Explanation:

lambda s:                              # a function which takes a string and...
                            zip(s,s)   # zips it with itself,
                      map(j,        )  # joins each tuple,
         (j:=''.join)(               ) # and joins each string together.
\$\endgroup\$
1
\$\begingroup\$

Python 2, 31 bytes

Realised I was beaten to it already.

lambda s:''.join(c*2for c in s)
\$\endgroup\$
1
\$\begingroup\$

Ruby, 16 bytes

gsub /./m,'\0\0'

Requires -p.

Try it online!

Alternatively:

gsub(/./m){$&*2}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Without a flag its: ->s{s.gsub(/./m){$&*2}} \$\endgroup\$
    – TKirishima
    Sep 7, 2022 at 14:41
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 69 bytes

	I =INPUT
S	I LEN(1) . X REM . I	:F(O)
	O =O X X	:(S)
O	OUTPUT =O
END

Try it online!

Prints with a single trailing newline.

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

kavod, 16 bytes

*>1+8?99.1-#<#0.

Try it online!

I picked up a random tarpit and decided this would be a nice challenge to solve

Explanation:

*     Take a byte of input and push to stack
>     Push to the register stack without popping from normal stack
1+    Add one to the input
8?    Go to the eighth character in the program if the top of the stack is nonzero (not EOF)
99.   Go to the 99th character in the program (terminating the program). This will be skipped over if input is not EOF
1-    Decrement TOS
#     Print with popping
<#    Get input back from register stack and print it
0.    Go back to the start of the program.
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 5 bytes

⭆S⁺ιι

Try it online! Link is to verbose version of code. Explanation:

 S      Input string
⭆       Map over characters and join
   ι    Current character
  ⁺     Plus
    ι   Current character
        Implicitly print
\$\endgroup\$
1
\$\begingroup\$

PHP, 74 bytes

function doubleSpeaker ($s) {
    return preg_replace('/(.)/', '$1$1', $s);
}

Try it online!

\$\endgroup\$
5
  • 15
    \$\begingroup\$ Welcome to CGCC! The winning criteria for this challenge is code-golf which means submissions should attempt to have the smallest amount of bytes. This submission seems to have a lot of excess whitespace and unnecessarily long variable names. Additionally, you should add the language name and score to the header of your submission. \$\endgroup\$
    – Jo King
    Jul 31, 2019 at 23:48
  • 3
    \$\begingroup\$ Just in a few seconds, your solution was lowered to 41 bytes: Try it online! Nice RegEx idea by the way. \$\endgroup\$
    – Night2
    Aug 1, 2019 at 9:23
  • 3
    \$\begingroup\$ Capturing is pointless. Try it online! \$\endgroup\$
    – manatwork
    Aug 1, 2019 at 9:30
  • 1
    \$\begingroup\$ Same idea as in my Lua answer btw, just implemented in PHP. \$\endgroup\$ Aug 1, 2019 at 9:39
  • 5
    \$\begingroup\$ Using @manatwork's update and $argn: Try it online! 36 bytes. \$\endgroup\$
    – Night2
    Aug 1, 2019 at 9:48
1
\$\begingroup\$

3var, 10 bytes

k'>|[PP'>]

Try it online!

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

4, 21 bytes

3.6000180070050050094

Try it online!

Explanation

3.          Start the program
6 00 01     Set memory cell 00 to 1 (BF +)
8 00        Start a loop while memory cell 00 is non-zero
7 00        Feed input to memory cell 00 (BF ,)
5 00 5 00   Print input 2 times ("a" -> "aa")
9           Jump to the corresponding 8       
\$\endgroup\$
1
\$\begingroup\$

SimpleTemplate, 23 bytes

This answer is for a language I wrote, which was supposed to be for templates but hasn't seen many updates.

This is the basic "split, loop, output twice", but without the splitting.

{@eachargv.0}{@echo_,_}

And now, ungolfed:

{@each argv.0 as char}
    {@echo char, char}
{@/}

And an explanation:

  • {@each argv.0 as char}
    Loops over each value in argv.0, which is the first argument given when calling the render() method.
    Due to this, you can pass an array of characters or a simple string, and it will loop through it.
    The as char is optional and the default variable name is _.
    Whitespace is optional

  • {@echo char, char}
    Outputs char. Twice.
    Whitespace is optional

  • {@/}
    Closes the scope of the {@each ... }.
    This is optional, as the language was written to keep track of how many scopes were open and automatically closes all at the end.

Pretty simple, right?

You can try it on: http://sandbox.onlinephpfunctions.com/code/d008a116a051df131edf02533182c5305cf8e834
When trying, you can go to line 906 and change the variable between $golfed and $ungolfed to try both versions.

\$\endgroup\$
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\$
5
  • \$\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\$ Aug 3, 2019 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\$ Aug 3, 2019 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, 2019 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, 2019 at 11:25
  • 1
    \$\begingroup\$ Building on @maxb 41 bytes \$\endgroup\$
    – ceilingcat
    Aug 19, 2019 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
4 5 6
7
8

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.