11
\$\begingroup\$

Given two integers, which may be negative, zero, or positive, \$a\$ and \$b\$ (taken in any reasonable format, including inputting a plain complex number), convert it to \$a + bi\$ where \$i\$ is the imaginary number (square root of negative one). Then, raise it to the power of a third (positive integer) input variable, \$c\$ as to \$(a + bi)^c\$. You should then end up with something like \$d + ei\$. You must then output, or return, \$d\$ and \$e\$ in any reasonable format (including outputting a plain complex number).

Input and output may be taken or outputted in any order.

Examples:

5, 2, 2 -> 21, 20
1, 4, 2 -> -15, 8
-5, 0, 1 -> -5, 0
caird coinheringaahing
50.9k11 gold badges133 silver badges364 bronze badges
asked Oct 14, 2017 at 7:43
\$\endgroup\$
6
  • \$\begingroup\$ If we use de Moivre's formula, is floating point imprecison allowed? \$\endgroup\$ Commented Oct 14, 2017 at 12:03
  • \$\begingroup\$ @Giuseppe Yes, that's okay. \$\endgroup\$ Commented Oct 14, 2017 at 13:12
  • 4
    \$\begingroup\$ FWIW I think the change to the rules (allowing a fully flexible I/O) made a fairly interesting challenge pretty dull. \$\endgroup\$ Commented Oct 15, 2017 at 20:50
  • \$\begingroup\$ @JonathanAllan at least for languages with native complex number support -- which are quite many :( \$\endgroup\$ Commented Oct 17, 2017 at 11:22
  • \$\begingroup\$ @JonathanAllan I can't please everyone :( \$\endgroup\$ Commented Oct 17, 2017 at 12:08

23 Answers 23

8
\$\begingroup\$

Mathematica, 17 bytes

ReIm[(#+#2I)^#3]&

Try it online!

-8 bytes from alephalpha

but........ rules have changed...... so

Mathematica, 5 bytes

Power
answered Oct 14, 2017 at 8:06
\$\endgroup\$
4
  • 5
    \$\begingroup\$ {Re@#,Im@#}& -> ReIm \$\endgroup\$ Commented Oct 14, 2017 at 8:24
  • 1
    \$\begingroup\$ 17 bytes. You can simply remove @#&. \$\endgroup\$ Commented Oct 14, 2017 at 8:31
  • \$\begingroup\$ haha, yes, my mistake \$\endgroup\$ Commented Oct 14, 2017 at 8:33
  • \$\begingroup\$ You can now do #^#2& or just Power. \$\endgroup\$ Commented Oct 15, 2017 at 12:25
7
\$\begingroup\$

Python 3, 3 bytes

pow

Try it online!

Input and output as complex numbers.


Python 3, 47 bytes

def f(a,b,c):n=(a+b*1j)**c;return n.real,n.imag

Try it online!

Input and output as integers


Python 2, (削除) 62 (削除ここまで) 60 bytes

-2 bytes thanks to @Leonhard

a,b,c=input();d=1;e=0
exec'd,e=a*d-b*e,a*e+b*d;'*c
print d,e

Try it online!

does not use complex number type

answered Oct 14, 2017 at 7:52
\$\endgroup\$
0
5
\$\begingroup\$

Javascript (ES6), (削除) 51 (削除ここまで) 50 bytes

a=>b=>g=c=>c?([x,y]=g(c-1),[x*a-b*y,a*y+b*x]):"10"
  • Takes input in currying form: f(a)(b)(c)
  • Returns the result as an array: [d, e]

Explanation

a=>b=>g=c=> // Input in currying syntax
 c?( // If `c` != 0:
 [x,y]=g(c-1), // Set [x, y] to the result of f(a)(b)(c-1)
 [x*a-b*y,a*y+b*x] // Return (a + bi) * (x + yi)
 ): // Else: (when c = 0)
 "10" // Return [1, 0] (to end the recursion)

f=a=>b=>g=c=>c?([x,y]=g(c-1),[x*a-b*y,a*y+b*x]):"10"
<div oninput="o.innerText=f(a.value)(b.value)(c.value)"><input id=a type=number value=0><input id=b type=number value=0><input id=c type=number value=1 min=1><pre id=o>

answered Oct 14, 2017 at 8:18
\$\endgroup\$
4
\$\begingroup\$

Pari/GP, 36 bytes

f(a,b,c)=divrem((a+b*x)^c%(x^2+1),x)

Try it online!


Pari/GP, 36 bytes

f(a,b,c)=[real(d=(a+b*I)^c),imag(d)]

Try it online!

answered Oct 14, 2017 at 11:41
\$\endgroup\$
4
\$\begingroup\$

Jelly, 1 byte

*

Try it online!

Thanks to Mr. Xcoder for alerting me of rule updates (-6 as a result).
Thanks to someone for alerting me of rule updates (-2 as a result).

First argument: (a+bj)
Second argument: c
Returns: (d+ej)

answered Oct 14, 2017 at 8:01
\$\endgroup\$
6
  • \$\begingroup\$ 8 bytes \$\endgroup\$ Commented Oct 14, 2017 at 8:43
  • \$\begingroup\$ 7 bytes \$\endgroup\$ Commented Oct 14, 2017 at 12:03
  • \$\begingroup\$ In fact Jonathan's 3 byter would suffice; ḅı*, as the rules have changed and you are now allowed to output a plain complex number. \$\endgroup\$ Commented Oct 15, 2017 at 5:10
  • \$\begingroup\$ @Mr.Xcoder was sleeping when that happened \$\endgroup\$ Commented Oct 15, 2017 at 7:54
  • 1
    \$\begingroup\$ It seems like a * onebyter is ok now as you can take input as a complex \$\endgroup\$ Commented Oct 15, 2017 at 11:29
3
\$\begingroup\$

Actually, 1 byte

n

Try it online!

Note that the rules have changed and complex numbers are valid I/O types (unfortunately this turns the post into a "perform this exponentiation" challenge). Original answer below.

Actually, 3 bytes

Çn╫

Try it online!

Returns the values separated by a newline. Takes the inputs in reverse order and returns the results in reverse order (See the tio link).

Çn╫ - Full program. Reversed inputs.
Ç - Return a+bi.
 n - Exponentiation.
 ╫ - Pushes the real and imaginary parts of a.
answered Oct 14, 2017 at 8:26
\$\endgroup\$
3
\$\begingroup\$

R, 3 bytes

This is becoming boring. If input and output is allowed as a complex number, there is a builtin for a power function.

`^`

For example:

> (5+2i)^2
[1] 21+20i
> (1+4i)^2
[1] -15+8i
> (-5+0i)^1
[1] -5+0i

or

> `^`(5+2i,2)
[1] 21+20i
> `^`(1+4i,2)
[1] -15+8i
> `^`(-5+0i,1)
[1] -5+0i
answered Oct 14, 2017 at 13:23
\$\endgroup\$
0
2
\$\begingroup\$

05AB1E, (削除) 20 (削除ここまで) (削除) 19 (削除ここまで) (削除) 17 (削除ここまで) 16 bytes

‚UTSsFXâP`(‚RŠ‚+

Try it online! Takes three separate inputs in the order b, a, c and outputs an array [d, e]. Edit: Saved 2 bytes thanks to @Datboi. Saved 1 byte thanks to @Adnan. Explanation:

‚ Join a and b into a pair
 U Store in variable X
 T Push 10 to the stack
 S Split into the pair [d, e] = [1, 0]
 s Swap with c
 F Repeat the rest of the program c times
 X Get [a, b]
 â Cartesian product with [d, e]
 P Multiply each pair together [da, db, ea, eb]
 ` Push each product as a separate stack entry
 ( Negate eb
 ‚ Join with ea into a pair [ea, -eb]
 R Reverse the pair [-eb, ea]
 Š Push under da and db
 ‚ Join them into a pair [da, db]
 + Add the two pairs [da-eb, db+ea]
answered Oct 14, 2017 at 10:18
\$\endgroup\$
7
  • \$\begingroup\$ Input and output may be taken or outputted in any order. - That means that you can take the first two inputs in reverse order. \$\endgroup\$ Commented Oct 14, 2017 at 10:27
  • \$\begingroup\$ @Mr.Xcoder Thanks, I hadn't noticed that. \$\endgroup\$ Commented Oct 14, 2017 at 10:33
  • \$\begingroup\$ I'm not sure if it matters or not, but calculating the number can also be done with 'jì+³m. \$\endgroup\$ Commented Oct 14, 2017 at 10:53
  • \$\begingroup\$ You can replace 1 0‚ with TS for -2 bytes :) \$\endgroup\$ Commented Oct 14, 2017 at 22:32
  • \$\begingroup\$ And P automatically vectorizes, so you don't need the . \$\endgroup\$ Commented Oct 15, 2017 at 8:18
2
\$\begingroup\$

C# (.NET Core), (削除) 62 (削除ここまで) 38 bytes

a=>c=>System.Numerics.Complex.Pow(a,c)

Try it online!

answered Oct 14, 2017 at 9:44
\$\endgroup\$
1
  • \$\begingroup\$ You should include the .Real and .Imaginary` in your answer.. According to the rule "You must then output, or return, d and e in any reasonable format (not including outputting a plain complex number)" you're not allowed to just output the Complex number. \$\endgroup\$ Commented Oct 14, 2017 at 14:02
2
\$\begingroup\$

Pyth, (削除) 5 (削除ここまで) (削除) 12 (削除ここまで) (削除) 5 (削除ここまで) 2 bytes

^E

Takes in c first, followed by a+bj.

(削除) 7 bytes of boilerplate because apparently output as an imaginary number is disallowed. (削除ここまで) It's been re-allowed! Hurrah! And with taking in a complex number being a reasonable input, we can cut out an additional 3 bytes!

Previous solutions:

^.jEE

When complex numbers were not reasonable inputs.

m,edsd]^.jEE

When complex numbers were not reasonable outputs.

Test Suite.

answered Oct 14, 2017 at 7:51
\$\endgroup\$
0
2
\$\begingroup\$

05AB1E, 1 byte

m

Try it online!

Input: c\n(a+bj)
Output: (d+ej)

answered Oct 14, 2017 at 8:33
\$\endgroup\$
2
  • \$\begingroup\$ Same tip as Neil, 'jì+³m is a different way to calculate the number. \$\endgroup\$ Commented Oct 14, 2017 at 10:58
  • \$\begingroup\$ @Adnan at least for me it does matter indeed :p \$\endgroup\$ Commented Oct 14, 2017 at 12:35
2
\$\begingroup\$

J, (削除) 10 (削除ここまで), (削除) 7 (削除ここまで), 1 byte(削除) s (削除ここまで)

^

Takes c as the right argument and the complex number ajb (how you represent a + bi in J) as the left argument.

Try it online!

Other Solutions

7 bytes

Takes the complex number input as a list.

^~j./@]

10 bytes

This outputted the a + bi in the list a b.

+.@^~j./@]

I wanted to try something cute like ^~&.(j./) but the inverse of j./ is obviously not defined. Actually, ^~&.(+.inv) works and you can make that ^&.(+.inv) which is also 10 bytes if you reverse the order in which you take the args.

answered Oct 14, 2017 at 18:53
\$\endgroup\$
0
2
\$\begingroup\$

TI-BASIC, (削除) 25 (削除ここまで) (削除) 22 (削除ここまで) 8 bytes

Takes the complex number and the exponent as input, and stores output in Ans as a complex number. Drastic drop in bytes due to loosened restrictions on input/output.

Prompt C,E
C^E
answered Oct 14, 2017 at 11:03
\$\endgroup\$
3
  • \$\begingroup\$ You can save 2 bytes with imag({iAns,Ans in the last line (by i I mean the complex number i). \$\endgroup\$ Commented Oct 14, 2017 at 20:57
  • 1
    \$\begingroup\$ And I guess then one more byte by just combining the two lines into imag({i,1}(A+Bi)^C. \$\endgroup\$ Commented Oct 14, 2017 at 21:01
  • 1
    \$\begingroup\$ Rules have changed, now you can take input and return complex numbers, if that is of any help. \$\endgroup\$ Commented Oct 15, 2017 at 12:11
2
\$\begingroup\$

6502 machine code subroutine, (削除) 199 (削除ここまで) (削除) 187 (削除ここまで) 185 bytes

A2 03 B5 FB 95 26 CA 10 F9 88 D0 01 60 A5 26 85 61 A5 27 85 62 A5 FB 85 63 A5
FC 85 64 A9 20 85 6F D0 36 18 A5 6D 65 65 85 28 A5 6E 65 66 85 29 A5 4B 85 26
A5 4C 85 27 50 CF 38 A5 6D E5 65 85 4B A5 6E E5 66 85 4C A5 28 85 61 A5 29 85
62 A5 FB 85 63 A5 FC 85 64 06 6F A9 00 85 65 85 66 A2 10 46 62 66 61 90 0D A5
63 18 65 65 85 65 A5 64 65 66 85 66 06 63 26 64 CA 10 E6 A9 FF 24 6F 70 B9 30
02 F0 9E A5 65 85 6D A5 66 85 6E 24 6F 30 14 A5 28 85 61 A5 29 85 62 A5 FD 85
63 A5 FE 85 64 06 6F D0 B4 A5 26 85 61 A5 27 85 62 A5 FD 85 63 A5 FE 85 64 06
6F B0 A0
  • -12 bytes with improved "spaghetti" structure
  • -2 bytes changing the register to pass the exponent, so we can make use of zeropage addressing mode in the initial copy loop

This is position-independent code, just put it somewhere in RAM and call it with a jsr instruction.

The routine takes the (complex) base as two 16bit signed integers (2's complement, little-endian) in $fb/$fc (real) and $fd/$fe (imaginary), and the exponent as an unsigned 8bit integer in the Y register.

The result is returned in 26ドル/27ドル (real) and 28ドル/29ドル (imaginary).


Explanation

This is still an interesting challenge on the 6502 CPU as there are no instructions for even multiplying. The approach is straight forward, implementing a complex multiplication and executing it as often as required by the exponent. Golfing is done by avoiding subroutines, instead creating kind of a "branch spaghetti", so the code for doing a simple 16bit multiplication that's needed multiple times is reused with the lowest possible overhead. Here's the commented disassembly:

 .cexp:
A2 03 LDX #03ドル ; copy argument ...
 .copyloop:
B5 FB LDA $FB,X
95 26 STA 26,ドルX
CA DEX
10 F9 BPL .copyloop ; ... to result
 .exploop:
88 DEY ; decrement exponent
D0 01 BNE .mult ; zero reached -> done
60 RTS
 .mult: ; multiply (complex) result by argument
A5 26 LDA 26ドル ; prepare to multiply real components
85 61 STA 61ドル ; (a*c)
A5 27 LDA 27ドル
85 62 STA 62ドル
A5 FB LDA $FB
85 63 STA 63ドル
A5 FC LDA $FC
85 64 STA 64ドル
A9 20 LDA #20ドル ; marker for where to continue
85 6F STA 6ドルF
D0 36 BNE .mult16 ; branch to 16bit multiplication
 .mult5:
18 CLC ; calculate sum (a*d) + (b*c)
A5 6D LDA 6ドルD
65 65 ADC 65ドル
85 28 STA 28ドル ; and store to imaginary component of result
A5 6E LDA 6ドルE
65 66 ADC 66ドル
85 29 STA 29ドル
A5 4B LDA 4ドルB ; load temporary result (a*c) - (b*d)
85 26 STA 26ドル ; and store to real component of result
A5 4C LDA 4ドルC
85 27 STA 27ドル
50 CF BVC .exploop ; next exponentiation step
 .mult3:
38 SEC ; calculate difference (a*c) - (b*d)
A5 6D LDA 6ドルD
E5 65 SBC 65ドル
85 4B STA 4ドルB ; and store to temporary location
A5 6E LDA 6ドルE
E5 66 SBC 66ドル
85 4C STA 4ドルC
A5 28 LDA 28ドル ; prepare to multiply real component of result
85 61 STA 61ドル ; with imaginary component of argument
A5 29 LDA 29ドル ; (a*d)
85 62 STA 62ドル
A5 FB LDA $FB
85 63 STA 63ドル
A5 FC LDA $FC
85 64 STA 64ドル
06 6F ASL 6ドルF ; advance "continue marker"
 .mult16:
A9 00 LDA #00ドル ; initialize 16bit multiplication
85 65 STA 65ドル ; result with 0
85 66 STA 66ドル
A2 10 LDX #10ドル ; bit counter (16)
 .m16_loop:
46 62 LSR 62ドル ; shift arg1 right
66 61 ROR 61ドル
90 0D BCC .m16_noadd ; no carry -> nothing to add
A5 63 LDA 63ドル ; add arg2 ...
18 CLC
65 65 ADC 65ドル
85 65 STA 65ドル
A5 64 LDA 64ドル
65 66 ADC 66ドル
85 66 STA 66ドル ; ... to result
 .m16_noadd:
06 63 ASL 63ドル ; shift arg2 left
26 64 ROL 64ドル
CA DEX ; decrement number of bits to go
10 E6 BPL .m16_loop
A9 FF LDA #$FF ; check marker for where to continue
24 6F BIT 6ドルF
70 B9 BVS .mult3
30 02 BMI .saveres ; have to save result to temp in 2 cases
F0 9E BEQ .mult5
 .saveres:
A5 65 LDA 65ドル ; save result to temporary
85 6D STA 6ドルD
A5 66 LDA 66ドル
85 6E STA 6ドルE
24 6F BIT 6ドルF ; check "continue marker" again
30 14 BMI .mult4
 .mult2:
A5 28 LDA 28ドル ; prepare to multiply imaginary components
85 61 STA 61ドル ; (b*d)
A5 29 LDA 29ドル
85 62 STA 62ドル
A5 FD LDA $FD
85 63 STA 63ドル
A5 FE LDA $FE
85 64 STA 64ドル
06 6F ASL 6ドルF ; advance "continue marker"
D0 B4 BNE .mult16 ; branch to 16bit multiplication
 .mult4:
A5 26 LDA 26ドル ; prepare to multiply imaginary component of
85 61 STA 61ドル ; result with real component of argument
A5 27 LDA 27ドル ; (b*c)
85 62 STA 62ドル
A5 FD LDA $FD
85 63 STA 63ドル
A5 FE LDA $FE
85 64 STA 64ドル
06 6F ASL 6ドルF ; advance "continue marker"
B0 A0 BCS .mult16 ; branch to 16bit multiplication

Example program using it (C64, assembly source in ca65-syntax):

.import cexp
CEXP_A = $fb
CEXP_AL = $fb
CEXP_AH = $fc
CEXP_B = $fd
CEXP_BL = $fd
CEXP_BH = $fe
CEXP_RA = 26ドル
CEXP_RAL = 26ドル
CEXP_RAH = 27ドル
CEXP_RB = 28ドル
CEXP_RBL = 28ドル
CEXP_RBH = 29ドル
.segment "LDADDR"
 .word $c000
.segment "MAIN"
 jsr $aefd ; consume comma
 jsr $ad8a ; evaluate number
 jsr $b1aa ; convert to 16bit int
 sty CEXP_AL ; store as first argument
 sta CEXP_AH
 jsr $aefd ; ...
 jsr $ad8a
 jsr $b1aa
 sty CEXP_BL ; store as second argument
 sta CEXP_BH
 jsr $b79b ; read 8bit unsigned into X
 txa ; and transfer
 tay ; to Y
 jsr cexp ; call our function
 lda CEXP_RAH ; read result (real part)
 ldy CEXP_RAL
 jsr numout ; output
 ldx CEXP_RBH ; read result (imaginary part)
 bmi noplus
 lda #'+' ; output a `+` if it's not negative
 jsr $ffd2
noplus: txa
 ldy CEXP_RBL
 jsr numout ; output (imaginary part)
 lda #'i'
 jsr $ffd2 ; output `i`
 lda #0ドルd ; and newline
 jmp $ffd2
numout:
 jsr $b391 ; convert to floating point
 jsr $bddd ; format floating point as string
 ldy #01ドル
numout_loop: lda $ff,y ; output loop
 bne numout_print ; until 0 terminator found
 rts
numout_print: cmp #' ' ; skip space characters in output
 beq numout_next
 jsr $ffd2
numout_next: iny
 bne numout_loop

Online demo

Usage: sys49152,[a],[b],[c], e.g. sys49152,5,2,2 (Output: 21+20i)

answered Oct 16, 2017 at 16:40
\$\endgroup\$
1
\$\begingroup\$

Dyalog APL, 10 bytes

⎕*⍨⊣+ ̄11しろまる

Try it online!

a is left argument, b is right argument, and c via input prompt.

Returns a complex number in the format dJe.

answered Oct 14, 2017 at 17:36
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Rules have changed, now you can take input and return complex numbers, if that's of any help. \$\endgroup\$ Commented Oct 15, 2017 at 12:13
  • \$\begingroup\$ Now, you can input and output complex numbers directly (according to rules). So the answer is simply the * function (or, taking input from stdin and outputting to stdout, we have: ⎕*⎕). \$\endgroup\$ Commented Oct 12, 2021 at 11:34
1
\$\begingroup\$

MATL, 1 byte

^

Inputs are a+jb, c.

Try it online!

Old version: non-complex input and output, 8 bytes

J*+i^&Zj

Input order is b,a, c.

Try it online!

Explanation

J Push imaginary unit
 * Multiply by implicit input b
 + Add implicit input a
 i Take input c
 ^ Power
 &Zj Push real and imaginary parts. Implicitly display
answered Oct 14, 2017 at 15:15
\$\endgroup\$
4
  • \$\begingroup\$ Multiply by implicit input b - Add implicit input b. Did you mean a in either of those? \$\endgroup\$ Commented Oct 14, 2017 at 17:13
  • \$\begingroup\$ @Mr.Xcoder Yes, thanks. Corrected \$\endgroup\$ Commented Oct 15, 2017 at 2:42
  • \$\begingroup\$ You can take input in the form of a complex number now, and output in the form of a complex number. You can probably cut out a lot of boilerplate from this answer because of that. \$\endgroup\$ Commented Oct 15, 2017 at 11:48
  • \$\begingroup\$ @StevenHewitt Thanks! Edited now \$\endgroup\$ Commented Oct 15, 2017 at 12:36
1
\$\begingroup\$

C (gcc), 34 bytes

#define f(a,b,c)cpow((a)+1i*(b),c)

Try it online!

answered Oct 15, 2017 at 13:56
\$\endgroup\$
1
\$\begingroup\$

Casio-Basic, 6 bytes

a^b

Change to the rules to allow input and output as complex numbers made this significantly shorter.

3 bytes for the function, +3 to enter a,b in the parameters box.

answered Oct 14, 2017 at 11:38
\$\endgroup\$
0
0
\$\begingroup\$

8th, 38 bytes

Code

c:new dup >r ( r@ c:* ) rot n:1- times

SED (Stack Effect Diagram) is: c a b -- (a + bi) ^ c

Warning: a + bi is left on r-stack, but this doesn't affect subsequent computations.

Ungolfed version with comments

needs math/complex
: f \ c a b -- (a + bi) ^ c
 c:new \ create a complex number from a and b
 dup \ duplicate a + bi
 >r \ store a + bi on r-stack
 ( r@ c:* ) rot n:1- times \ raise ( a + bi ) to c
;

Example and usage

: app:main
 \ rdrop is not strictly required
 2 5 2 f . cr rdrop
 2 1 4 f . cr rdrop 
 1 -5 0 f . cr rdrop 
 bye
;

Output of the previous code

c:1:data:{"real":21,"imag":20}
c:1:data:{"real":-15,"imag":8}
c:2:data:{"real":-5,"imag":0}
answered Oct 15, 2017 at 12:14
\$\endgroup\$
0
\$\begingroup\$

Octave / MATLAB, 6 bytes

@power

Anonymous function that inputs two numbers and outputs their power.

Try it online!

Old version: non-complex input and output, 30 bytes

@(a,b,c)real((a+j*b)^c./[1 j])

Anonymous function that inputs three numbers and outputs an array of two numbers.

Try it online!

answered Oct 14, 2017 at 15:08
\$\endgroup\$
0
0
\$\begingroup\$

Perl 6, (削除) 29 26 20 19 (削除ここまで) 11 bytes

{$_=($^a+$^b*i)**$^c;.re,.im}

Try it

{(($^a+$^b*i)**$^c).reals}

Try it

((*+* *i)** *).reals

Try it

((*+* *i)***).reals

Try it

With the change of output restrictions it can be further reduced:

(*+* *i)***

Try it

The *** part is parsed as ** * because the ** infix operator is longer than the * infix operator.

Expanded:

# __________________ 1st parameter
# / _______________ 2nd parameter
# / / ______ 3rd parameter
# / / /
# V V V
( * + * * i) ** *
# ^ ^^
# \ \________ exponentiation
# \_____________ multiplication
answered Oct 14, 2017 at 15:17
\$\endgroup\$
1
  • \$\begingroup\$ You can now do (*+* *i)***. \$\endgroup\$ Commented Oct 15, 2017 at 12:19
0
\$\begingroup\$

R, 25 bytes

simplest - since outputting complex is allowed.

function(a,b,c)(a+b*1i)^c
ovs
61.2k3 gold badges49 silver badges164 bronze badges
answered Oct 15, 2017 at 12:36
\$\endgroup\$
1
  • \$\begingroup\$ you can simplify your code by just taking a complex number z as input - then function body is simply z^c. \$\endgroup\$ Commented Oct 12, 2021 at 11:36
0
\$\begingroup\$

Ruby, 9 bytes

Returns an anonymous function that takes a complex number and integer and returns a complex number.

proc &:**

This is equivalent to ->x,y{x**y} (11 bytes).

Attempt This Online!

answered Dec 6, 2022 at 17:27
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.