-5
\$\begingroup\$

This question already has an answer here:

We already have a base conversion question, but not one with negative bases (nope, this doesn't count).

(Corresponding wiki article.)

You will receive a number (may be negative) and a base (must be negative), and your task is to convert the number into the base.

The base will only be from -10 to -2.

Specs

  • You may receive the number in any positive base, including unary.
  • You may choose receive the magnitude of the base instead (10 instead of -10).
  • The input can be taken in any reasonable format.

Scoring

This is , shortest solution in bytes wins.

Testcases

input        output
8163, -10    12243
-8163, -10   9977
17, -3       212
\$\endgroup\$

marked as duplicate by Downgoat, DJMcMayhem, Mego, rink.attendant.6, Alex A. code-golf Apr 27 '16 at 5:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ It is not a duplicate because I could use Retina to do your linked challenge but I would not be able to trivially modify that algorithm to fit this challenge. \$\endgroup\$ – Leaky Nun Apr 27 '16 at 3:19
  • 2
    \$\begingroup\$ That may be true for Retina, but for most answers I can simply replace all -2s with int(input) and 2s with -int(input) \$\endgroup\$ – Downgoat Apr 27 '16 at 3:22
0
\$\begingroup\$

Jelly, 1 byte

b

Jelly supports negative bases with its base conversion builtin.

Try it online!

(bV at two bytes if the output must be a single integer.)

\$\endgroup\$
  • \$\begingroup\$ Outputting a number as an array? Is that an accepted output format for numbers? \$\endgroup\$ – Downgoat Apr 27 '16 at 2:59
  • \$\begingroup\$ @Downgoat The challenge does not give a specific output format. \$\endgroup\$ – Doorknob Apr 27 '16 at 3:01
  • \$\begingroup\$ but an array of value [1,2,3] is not equivalent (or I don't think it can be) directly cast to the integer value of 123. If a challenge is to output a string. I wouldn't output a char array (unless that's a string in my language), I would output a string. See this loophole \$\endgroup\$ – Downgoat Apr 27 '16 at 3:03

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