40
\$\begingroup\$

Based on this challenge.

In the rhythm game osu!, the difficulty modifier "Double-time" actually only increases the speed by 50%.

Your task, is to write a program that outputs a positive even integer (higher than 0), and when each byte/character (your choice which) in your source code is duplicated, it should output the number multiplied by 1.5.

For example if your source code is ABC and that outputs 6, then AABBCC should output 9.

Following the original challenge's rules:

Rules

  • You must build a full program.
  • The initial source must be at least 1 byte long.
  • Both the integers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).
  • Your program must not take input (or have an unused, empty input) and must not throw any error (compiler warnings are not considered errors).
  • Outputting the integers with trailing / leading spaces is allowed.
  • You may not assume a newline between copies of your source.
  • This is , so the fewest bytes in each language wins!
  • Default Loopholes apply.

I imagine this will be far less trivial than the original challenge, but hopefully we'll see some creative and unique answers!

\$\endgroup\$
12
  • \$\begingroup\$ @Fatalize write a program that outputs a positive even integer Yes it will. Every even number can be multiplied by 1.5 to result in a whole integer \$\endgroup\$
    – Mayube
    Jul 17, 2017 at 8:28
  • 1
    \$\begingroup\$ It seems like a dupe to me. \$\endgroup\$ Jul 17, 2017 at 8:35
  • \$\begingroup\$ @EriktheOutgolfer Very similar but I'm sure this one is going to be a lot harder (unless I'm missing something obvious). \$\endgroup\$ Jul 17, 2017 at 8:37
  • 9
    \$\begingroup\$ Duplicating characters may make trivial languages unrunnable. I wonder if there is a solution in a not single-character-command-styled or expression-based language. \$\endgroup\$
    – Keyu Gan
    Jul 17, 2017 at 10:35
  • 3
    \$\begingroup\$ @TheLethalCoder Maybe the biggest obstacle is full program. It is hard to imagine a duplicated program still have a valid entry point / function. \$\endgroup\$
    – Keyu Gan
    Jul 17, 2017 at 14:52

29 Answers 29

22
\$\begingroup\$

Pylons, 7 5 4 bytes

Picked a random language on TIO used it

46vt

Explanation:

Try it Online!

46    # Stack is [4, 6]

v     # Reverse the stack [6, 4]

t     # take top of stack 4

Doubled:

4466   # Stack is [4, 4, 6, 6]

vv     # Reverse the stack twice so it's the same [4, 4, 6, 6]

tt     # take top of stack 6 and again which is 6 again

Saved 2 bytes thanks to officialaimm

Saved 1 bytes thanks to Veedrac

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Hey, 4/6vt works as well... \$\endgroup\$
    – 0xffcourse
    Jul 17, 2017 at 11:25
  • 19
    \$\begingroup\$ I wholeheartedly approve of the strategy of picking a random TIO language and learning it for a challenge \$\endgroup\$
    – Mayube
    Jul 17, 2017 at 11:25
  • \$\begingroup\$ @officialaimm you are right, thanks. \$\endgroup\$
    – LiefdeWen
    Jul 17, 2017 at 11:28
  • 1
    \$\begingroup\$ 4/6 <- 4 divided by nothing -> 4 ; and then 6. 44//66 <- 4 divided by 4 -> 1 ; nothing divided by nothing -> nothing ; and then 6 and 6. Maybe. Well done though. \$\endgroup\$ Jul 17, 2017 at 12:12
  • 1
    \$\begingroup\$ Wouldn't 46vt do the same? \$\endgroup\$
    – Veedrac
    Jul 17, 2017 at 17:20
21
\$\begingroup\$

Jelly, 2 bytes

!‘

Try it online!

Explanation:

!‘ Implicit 0
!  Factorial
 ‘ Increment

Doubled version:

!!‘‘

Try it online!

Explanation:

!!‘‘ Implicit 0
!    Factorial
 !   Factorial
  ‘  Increment
   ‘ Increment
\$\endgroup\$
2
  • \$\begingroup\$ If you do it a third time it goes from 3 -> 4, not 3->4.5?? \$\endgroup\$
    – tuskiomi
    Jul 17, 2017 at 16:19
  • 1
    \$\begingroup\$ @tuskiomi No because it's not expected to do so. \$\endgroup\$ Jul 17, 2017 at 16:21
15
\$\begingroup\$

LibreOffice Calc, 8 bytes

=A2+3
19

Save it as *.csv and open it in LibreOffice Calc. You will get 22 in A1.


Double them:

==AA22++33

1199

You will get 33 in A1

\$\endgroup\$
1
  • 1
    \$\begingroup\$ clever language choice! \$\endgroup\$
    – Giuseppe
    Jul 18, 2017 at 2:34
11
\$\begingroup\$

MATL, 3 bytes

TnQ

Try it online! Or doubled version.

Explanation

In MATL a scalar value (number, char, logical value) is the same as a 1×1 array containing that value.

Normal version:

T    % Push true
n    % Number of elements of true: gives 1
Q    % Add 1: gives 2

Doubled version:

TT   % Push [true, true]
n    % Number of elements of [true, true]: gives 2
n    % Number of elements of 2: gives 1
Q    % Add 1: gives 2
Q    % Add 1: gives 3
\$\endgroup\$
2
  • 7
    \$\begingroup\$ TnQ for the answer... :D [We sometimes use tnq as a short-form for thank-you] \$\endgroup\$
    – 0xffcourse
    Jul 17, 2017 at 11:30
  • 8
    \$\begingroup\$ @officialaimm :) [we sometimes use that to get the first n elements from an array...] \$\endgroup\$
    – Luis Mendo
    Jul 17, 2017 at 13:39
11
\$\begingroup\$

vim, 5

i1<esc>X<C-a>

Without doubling:

i1<esc>  insert the literal text "1"
X        delete backwards - a no-op, since there's only one character
<C-a>    increment, giving 2

With doubling:

ii11<esc>   insert the literal text "i11"
<esc>       escape in normal mode does nothing
XX          since the cursor is on the last character, delete "i1"
<C-a><C-a>  increment twice, giving 3
\$\endgroup\$
10
\$\begingroup\$

Not sure if this answer is valid. Just post here in case some one may got ideas from here.

Node.js with -p flag, 7 bytes

By Alex Varga:

3/3*22

33//33**2222

Node.js with -p flag, 11 bytes

Old one:

3*2*0/1+22

33**22**00//11++2222

Output 22 and 33.

\$\endgroup\$
7
  • \$\begingroup\$ How is it supposed to do 33? TIO doesn't seem able to do it. It locks on 00. \$\endgroup\$ Jul 17, 2017 at 12:07
  • 1
    \$\begingroup\$ How about: 3/3*22 \$\endgroup\$
    – Alex Varga
    Jul 17, 2017 at 21:21
  • \$\begingroup\$ @AlexVarga so sweet. \$\endgroup\$
    – tsh
    Jul 18, 2017 at 1:17
  • \$\begingroup\$ @V.Courtois you are using strict mode \$\endgroup\$
    – tsh
    Jul 18, 2017 at 1:18
  • 1
    \$\begingroup\$ @EdmundReed need -p flag to output expression value \$\endgroup\$
    – tsh
    Jul 18, 2017 at 5:29
10
\$\begingroup\$

Python 2 REPL, 11 bytes

(3/1)*(2/1)

This simply evaluates to 3*2=6. Duplicated, it is

((33//11))**((22//11))

which evaluates to 3**2, which is 3 to the power of 2, or 9.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the site. This python does not produce any output and thus is not a valid answer. However if you change your answer to be a Python REPL, this does produce output and thus is a valid answer. You will either have to delete this answer or change the language from python 2 to python 2 repl. \$\endgroup\$
    – Wheat Wizard
    Jul 18, 2017 at 3:57
  • \$\begingroup\$ @WheatWizard Thanks, and thanks for helping! Did I do this properly? \$\endgroup\$ Jul 18, 2017 at 21:16
8
\$\begingroup\$

APL, 7 bytes

⊃⍕⌊3×⍟2

Prints 2.

⊃⊃⍕⍕⌊⌊33××⍟⍟22

Prints 3.

Try it online!

Waaat?

Single:

3×⍟2         → 2.079441542  ⍝  3 * ln 2
⌊2.079441542 → 2            ⍝  floor
⊃⍕           → '2'          ⍝  format and take first character

Double:

⍟⍟22          → 1.128508398  ⍝  ln ln 22
×1.128508398  → 1            ⍝ signum
33×1          → 33           ⍝  33 * 1
⌊⌊33          → 33           ⍝  floor
⊃⊃⍕⍕          → '3'          ⍝  format and take first character
\$\endgroup\$
5
  • \$\begingroup\$ Could you please align the comments vertically? Or do we have different settings or something causing it on my end to loop like this? \$\endgroup\$ Jul 17, 2017 at 11:44
  • 1
    \$\begingroup\$ @KevinCruijssen I think that's your browser font, but browsers doesn't render APL as monospaced anyways. that mine prntscr.com/fwp0l0 \$\endgroup\$
    – Uriel
    Jul 17, 2017 at 11:47
  • \$\begingroup\$ Ah well, it's still readable and a great answer regardless. :) \$\endgroup\$ Jul 17, 2017 at 12:00
  • \$\begingroup\$ It renders as monospace for me. Probably just depends on the font (prnt.sc/fwrnz1). The comments are definitely not aligned though :P \$\endgroup\$
    – 2xsaiko
    Jul 17, 2017 at 15:02
  • \$\begingroup\$ @therealfarfetchd thanks, I've updated the last 3 rows \$\endgroup\$
    – Uriel
    Jul 17, 2017 at 15:13
5
\$\begingroup\$

Actually, 3 bytes

1u*

Try it online!

Explanation:

1u* Errors are ignored
1   Push 1
 u  Increment
  * Multiply

Doubled version:

11uu**

Try it online!

Explanation:

11uu** Errors are ignored
1      Push 1
 1     Push 1
  u    Increment
   u   Increment
    *  Multiply
     * Multiply
\$\endgroup\$
5
\$\begingroup\$

CJam, 4 bytes

],))

Try it normally!

Try it doubled!

Explanation

Normal:

]     e# Wrap the stack in an array: []
 ,    e# Get its length: 0
  ))  e# Increment twice: 2

Double:

]         e# Wrap the stack in an array: []
 ]        e# Wrap the stack in an array: [[]]
  ,       e# Get its length: 1
   ,      e# Get the range from 0 to n-1: [0]
    )     e# Pull out its last element: 0
     )))  e# Increment 3 times: 3
\$\endgroup\$
2
  • \$\begingroup\$ The overloads are tricky...;) \$\endgroup\$ Jul 17, 2017 at 16:41
  • \$\begingroup\$ AB], also works. \$\endgroup\$
    – geokavel
    Jul 17, 2017 at 17:03
4
\$\begingroup\$

05AB1E, 2 bytes

X>

Try it online!

Explanation:

X> Only top of stack is printed
X  Push X (default 1)
 > Increment

Doubled version:

XX>>

Try it online!

Explanation:

XX>> Only top of stack is printed
X    Push X (default 1)
 X   Push X (default 1)
  >  Increment
   > Increment
\$\endgroup\$
4
\$\begingroup\$

Neim, 2 bytes

𝐓>

Try it online!

Explanation:

𝐓> Implicit 0
𝐓  Factorial
 > Increment

Doubled version:

𝐓𝐓>>

Try it online!

𝐓𝐓>> Implicit 0
𝐓    Factorial
 𝐓   Factorial
  >  Increment
   > Increment
\$\endgroup\$
2
  • \$\begingroup\$ 4 out of the 5 answers... you're really going for it on this one! \$\endgroup\$ Jul 17, 2017 at 9:30
  • 5
    \$\begingroup\$ @TheLethalCoder At least it's not 15 yet. ;) \$\endgroup\$ Jul 17, 2017 at 9:32
3
\$\begingroup\$

Pyth, 3 bytes

he1

Try it here.

Explanation:

he1
h   Increment
 e   Last digit
  1   1

Doubled version:

hhee11

Try it here.

Explanation:

hhee11
h      Increment
 h      Increment
  e      Last digit
   e      Last digit
    11     11
\$\endgroup\$
1
  • 1
    \$\begingroup\$ one he11 of an answer \$\endgroup\$
    – Uriel
    Jul 17, 2017 at 14:33
3
\$\begingroup\$

Ruby REPL, 8 bytes

";3#";22

The REPL only prints the last value evaluated: 22.

Doubled:

"";;33##"";;22

This time 33 is the last value evaluated. The string is discarded once again, and a # starts a comment.

\$\endgroup\$
3
\$\begingroup\$

Zsh, 14 bytes

<:|echo 22
3
:

Try it online!

Getting a full program in a non-golfing language to print anything with source code duplicated like this is a challenge. Zsh is very useful for this, because files and heredocs are implicitly passed to cat. Let's take a look at the first line in both cases:

<:|echo 22            # Give the file : on stdin to cat. cat pipes to 'echo 22', which ignores stdin
<<::||eecchhoo  2222  # Start heredoc on following lines with EOF string '::', pass to cat.
                      # Since cat exits 0, 'eecchhoo 2222' is not executed

So long as 3 is not a program, the first program will only print 22. The second program will print 33 surrounded by extra newlines (due to the duplication).


If 3 is a function/program/alias, then this 18 byte solution will still work!

<:|echo 22\\c\
3
:

Try it online!

The last \ is line continuation, so the newline is discarded, effectively making the echo statement echo '22\c3'. The \c causes echo to stop printing after 22 (which also happens to suppress the newline).

\$\endgroup\$
3
\$\begingroup\$

R, 11 6 bytes

1+7*!0

Try it online!

! is negation, and ** is exponentiation (an alias for ^). Numerics get converted to booleans: 0 to FALSE, all others to TRUE. Booleans get converted to integers: FALSE to 0, TRUE to 1, so !0==1, !1==0, !!00==0 and !!11==1.

The single version thus computes \$1+7\times 1=8\$, and the double version computes \$11+77^0=12\$.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I was just trying to come up with a solution relying on * and **, but you beat me to it! \$\endgroup\$
    – Giuseppe
    Sep 10, 2019 at 19:37
  • \$\begingroup\$ @Giuseppe I'm not convinced my solution is optimal (the need for brackets around !0 is annoying). There might be something shorter with - and *, but I haven't found such a solution yet... \$\endgroup\$ Sep 10, 2019 at 21:22
2
\$\begingroup\$

Cubix, 6 bytes

O.1)W@

Prints 2.

  O
. 1 ) W
  @

Pushes 1, ) increments, W jumps left to O which outputs 2, and @ finishes the program.

Doubled up, it's obviously OO..11))WW@@, which on a cube is:

    O O
    . .
1 1 ) ) W W @ @
. . . . . . . .
    . .
    . .

It pushes 1 twice, ) increments twice, W jumps left again, which puts it at the right-hand O heading north, which outputs 3, and then the next command is @ which terminates the program.

Try it online!

Doubled online!

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

Klein, 8 6 bytes

/3+@4\

Single, Double

Explanation

For the single the program follows a pretty straightforward path. The first mirror deflects it into the second which deflects it through the 4 to the end of the program.

The double is a little more complex. Here it is:

//33++@@44\\

The first two mirrors work the same, however there is a new mirror due to the doubling which deflects the ip back to the beginning, it is caught by the duplicate of the first mirror and deflected towards the end. All that is run is the 33++ which evaluates to 6.

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

TI-Basic, 3 bytes

Single:

int(√(8

The last expression is implicitly returned/printed in TI-Basic, so this prints 2

Doubled:

int(int(√(√(88

Returns/prints 3

TI-Basic is a tokenized language; int(, √(, and 8 are each one byte in memory.

\$\endgroup\$
1
  • \$\begingroup\$ Technically the challenge spec explicitly states when each character is doubled, but I'll allow this and update the spec \$\endgroup\$
    – Mayube
    Jul 18, 2017 at 15:48
2
\$\begingroup\$

><>, 19 8 Bytes

32b*!{n;

Prints 22
Try it online!

Explanation:

32b   push literals onto the stack: [3,2,11]
*     multiply the top two values: [3,22]
!     skip the next instruction
{     (skipped)
n     pop and print the top value from the stack (22)
;     end execution

Doubled:

3322bb**!!{{nn;;

Prints 33
Try it online!

Explanation:

3322bb push literals onto the stack: [3,3,2,2,11,11]
**     multiply top values (twice): [3,3,2,242]
!      skip next instruction
!      (skipped)
{{     rotate the stack to the left (twice): [2,242,3,3]
nn     pop and print the top two values from the stack (33)
;      end execution

Old Version:
Normal:

11+!vn;
    n
    ;

Prints 2
Try it online!

Explanation:

1    push 1 on the stack: [1]
 1    push 1 on the stack: [1,1]
  +    add top two values of the stack: [2]
   !    skip the next instruction
    v    (skipped)
     n    print the top value of the stack (2)
      ;    end execution

Doubled:

1111++!!vvnn;;
        nn
        ;;

Prints 3
Try it online!

Explanation:

1111    push four 1's on the stack: [1,1,1,1]
    +    add top two values of the stack: [1,1,2]
     +    add top two values of the stack: [1,3]
      !    skip the next instruction
       !    (skipped)
        v    change direction of execution (down)
         n    print the top value of the stack (3)
          ;    end execution

\$\endgroup\$
2
  • 5
    \$\begingroup\$ I think you're supposed to duplicate the newlines too. \$\endgroup\$ Jul 17, 2017 at 16:37
  • \$\begingroup\$ @EriktheOutgolfer There aren't newlines anymore. \$\endgroup\$
    – KSmarts
    Sep 28, 2017 at 18:02
2
\$\begingroup\$

Perl 6, 14 bytes

'|d 3#';say 22

Try it online! Try it doubled!

This uses the conveniently named debug function dd to output the doubled program to STDERR. To separate the logic we encase the doubled program in quotes, which then cancel each other out when doubled, along with a comment character # to comment out the now invalid normal program.

\$\endgroup\$
1
  • \$\begingroup\$ This works as-is in 5 too (with some imports)! \$\endgroup\$ Nov 14, 2021 at 13:08
2
\$\begingroup\$

Vyxal, 2 bytes

¡›

Try it Online!

Port of the Jelly answer.

   # (implicit zero)
¡  # Factorial
 › # Incremented

Doubled (Try it Online!):

¡    # 0 factorial = 1
 ¡   # 1 factorial = 1
  ›› # Incremented twice = 3

Vyxal, 3 bytes

ðL›

Try it Online!

ð   # Space character
 L  # Length
  › # Incremented

Doubled (Try it Online!)

ðð     # Space character (one's a nop)
  LL   # Length twice (one's a nop)
    ›› # Incremented twice
\$\endgroup\$
3
  • \$\begingroup\$ why is the second space/length symbol a nop? \$\endgroup\$
    – Mayube
    Nov 12, 2021 at 21:31
  • \$\begingroup\$ @Mayube It's not really a nop, just is in the context of this program. If we push two spaces and only use one, the other's useless. ðL gets a 1, and the length of 1 is 1 so the second does nothing. \$\endgroup\$
    – emanresu A
    Nov 12, 2021 at 21:33
  • \$\begingroup\$ Ah that makes sense! \$\endgroup\$
    – Mayube
    Nov 12, 2021 at 21:33
2
\$\begingroup\$

Hexagony, 6 bytes

))$$!@

Try it online! (Try it doubled!)

Explanation

  ) )
 $ $ !
  @ .

This program does nothing too weird; it just executes each line in order:

  • )): Increment twice (memory cell = 2).
  • $$: Jump the jump; basically a no-op.
  • !: Print memory cell (2)
  • @: Stop.

   ) ) )
  ) $ $ $
 $ ! ! @ @
  . . . .
   . . .

Only the first and third lines are executed, due to Hexagony's control flow:

  • ))): Increment 3 times (memory cell = 3).
  • )$$$: This line is skipped.
  • $!: Jump over the first !, so the memory cell isn't printed twice.
  • !: Print 3.
  • @: Stop.
\$\endgroup\$
1
\$\begingroup\$

MathGolf, 2 bytes

▬)

Try it online! Try it doubled

Similar to other answers in that the first instruction produces a 1 even when doubled and the second increments it. In this case, I've used reverse exponentiation (0**0 = 0**0**0 = 1) but it also could have been any of the !£≤° instruction and perhaps even more that I missed.

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

Stax, 3 bytes

UJ^

Run and debug it

Run and debug the doubled one

U pushes -1. J squares. ^ increments.

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

Deadfish~, 12 bytes

iis(ooh)iiio

Try it online!

Try it doubled!

Explanation

iis(ooh)iiio

Set the accumulator to 2, square it, print twice to get 44, stop.

iiiiss((oooohh))iiiiiioo

Set the accumulator to 4 and square it twice to get 256.
Since Deadfish~ doesn't like the number 256, it sets the accumulator to 0 instead.
The (...) part of the code is ignored if the accumulator is 0, and then the rest of the code prints 66.

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

Perl 5 + -M5.10.0 -MData::Dump+(dd), 17 bytes

q{\};d 3#};say 22

Try it online!

Doubled

qq{{\\}};;dd  33##}};;ssaayy  2222

Try it online!

Explanation

I was hopeful to find a way to trigger a print without using an external, but I couldn't come up with anything so I settled on dd.

The trick here was to leverage Perl's flexibly delimited strings to encase the doubled code without causing a syntax error. Using {...} (or any other pairs like(), [], <>) means in the original code the end char can be escaped with a single \ which when doubled is just a backslash. Using q is easiest as qq is just as valid.

q{\};d 3#};say 22

Here we have a short string containing };d 3#, then we just say 22 which outputs 22.

qq{{\\}};;dd  33##}};;ssaayy  2222

Here we have a string containing a single \ and then we ddump out 33 and the rest of the program is commented out.


Now that I look through the other answers I see that @JoKing's answer would work as-is with my command line arguments too...

\$\endgroup\$
0
\$\begingroup\$

Japt, 2 bytes

Another "factorial+1" solution.

ÊÄ

Test it

ÊÊÄÄ

Test it

\$\endgroup\$
0
\$\begingroup\$

Octave, 1 byte

I think we all know this is a worthless answer. Gotta show Octave some love.

0

Try it online!

\$\endgroup\$

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.