-10
\$\begingroup\$

Your task is to find the square of a number without using the multiplication sign or division sign

However, to make this even trickier, no use of any addition sign or even the minus sign can be used either

e.g. / // * ** + - are not allowed

no imports are allowed either

An integer will be given in the input

Test cases:

5 -> 25

6 -> 36

10 -> 100

724 -> 524176

This is a extended version of this

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Don't post immediately \$\endgroup\$
    – Fmbalbuena
    Jan 10 at 10:19
  • \$\begingroup\$ i did make sure to check for duplicates tho hopefully there is not duplicate question but sry \$\endgroup\$
    – DialFrost
    Jan 10 at 10:20
  • 3
    \$\begingroup\$ R, 1 byte: ^. Are you sure this is a good and well-specified challenge? \$\endgroup\$
    – pajonk
    Jan 10 at 10:25

10 Answers 10

2
\$\begingroup\$

Vyxal, 1 byte

²

Try it Online!

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

05AB1E, 1 byte

n

Try it online!

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

Ruby, 18 bytes

->a{(1..a).sum{a}}

Attempt This Online!

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

Gaia, 1 byte

s

Try it online!

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

Integral, 1 byte

4

Try it Online!

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

Pip, 4 bytes

SQ:a

Attempt This Online!

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

C (gcc), 93 bytes

a(x,y){return y?a(x^y,(x&y)<<1):x;}s(x){return x?a(s((x>0?x:a(~x,2))>>1)<<2,x&1?x<<1^3:0):0;}

Try it online!

a performs addition by using bitwise operations to add and carry for each bit simultaneously and using recursion. s does the squaring: (2n)2 = 4n2 and (2n+1)2 = 4n2 + 4n + 1, with a special case for negative numbers.

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

dinoux, 1 byte

²

Try it Online!

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

2sable, 1 byte

n

Try it online!

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

Perl 5, 32 bytes

sub{map{map 0,1..$_[0]}1..$_[0]}

Try it online!

\$\endgroup\$

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