Skip to main content
1 of 8
dwana
  • 551
  • 4
  • 8

Calculate power of 2

The puzzle

Write a function p(n) that returns n^2

with n >-1

Rules

You can't use * or / (or power or square root operator if the language has one)

You can't use a loop or loop like constructions

You can't use POW or SQRT functions

Example

Function p(n)
Dim r()
ReDim r(n)
p = Len(Join(r, Space(n)))
End Function

So be creative and (ab)use some functions/features ^^

*edit removed wrong tag and editted rule

dwana
  • 551
  • 4
  • 8