1
\$\begingroup\$

Write some code...

Write a program that takes no input and outputs an integer n which is a multiple of 3. So n=3k, where k is a positive integer.
Double the last character of your code.
Your code should then output k.

Examples

Here is my program hui#2(21+4)//lm, which outputs 81. Because of that, hui#2(21+4)//lmm should output 27.
or
If p8$w2*8 outputs 9, p8$w2*88 should output 3.

Rules

This is , shortest answer in bytes wins!

\$\endgroup\$
  • 3
    \$\begingroup\$ Can it output 9.0 and 3.0? (Taking square roots, so it automatically turns into a float. :P) \$\endgroup\$ – totallyhuman Aug 27 '17 at 1:02
  • 5
    \$\begingroup\$ This is a less interesting version of double the source, double the output. And that wasn't terribly interesting to begin with. \$\endgroup\$ – Wheat Wizard Aug 27 '17 at 3:26
  • 3
    \$\begingroup\$ I've downvoted this as, even by my standards, this is far too trivial, solvable with basic subtraction or square rooting, as illustrated by a lot of the solutions so far. \$\endgroup\$ – Shaggy Aug 27 '17 at 8:04
  • 5
    \$\begingroup\$ @BillSteihn You don't understand - this is code golf. The goal is to find the shortest answer, not to be creative. The answer that Shaggy provided is a trivial way of achieving your answer, and will be the shortest way to solve this challenge in most languages. \$\endgroup\$ – clismique Aug 27 '17 at 9:20
  • 4
    \$\begingroup\$ As @QwerpDerp said, this is code golf; creativity is, for the most part, not conducive to a healthy byte count. \$\endgroup\$ – Shaggy Aug 27 '17 at 17:09

33 Answers 33

0
\$\begingroup\$

Ruby, 5 bytes

3/0b1

Division by one or three, written in binary.

\$\endgroup\$
  • 2
    \$\begingroup\$ This appears to be a code snippet and not a function or full program. \$\endgroup\$ – LyricLy Aug 29 '17 at 5:31
0
\$\begingroup\$

RProgN 2, 2 bytes

6›

6› takes 6 and shifts it right. 110 -> 11 which gives 3. 6›› shifts 6 twice, which gives 110 -> 1, or 1.

Try it online!

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

Forth (gforth), 10 bytes

Feels cheap to just overwrite the 33 numeric literal, but it's the shortest way I know of to make this work in forth

: 33 1 ; 3

Try it online!

outputs 3

: 33 1 ; 33

Try it online!

outputs 1

Explanation

: 33 1 ;  \ defines a new word 33 that puts a 1 on the stack.
          \ In forth explicit word definitions are parsed before numeric literals
\$\endgroup\$
  • 1
    \$\begingroup\$ This is in the wrong direction. You should output 3 for the first program and 1 for the second. \$\endgroup\$ – Weijun Zhou Feb 7 '18 at 18:39
  • \$\begingroup\$ @WeijunZhou Good catch, thanks for pointing that out \$\endgroup\$ – reffu Feb 7 '18 at 18:51

Your Answer

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