Today's challenge is deceptively simple. Square a number. Given the input of an integer, output that integer multiplied by itself.
E.g.
square(...
For further actions, you may consider blocking this person and/or reporting abuse
Compact solution that passes all tests:
You should add a to-do comment for each unimplemented number.
Definitely will add that to the to-do list!
Ohhh, boy. I needed that laugh, today. Thanks.
Came here to submit this exact version, good job!
thanks for your help
Bash
Using
curl
to make a request to some API I found on googleTerra
Take N as an argument, then compile an executable named
square_of_<N>
that prints the square of NI laughed at the curl solution I'm not gonna lie
I think I found another one, even better:
this one works by searching inside the comments to this post any solution that was written in javascript (looking if the author has selected the js highlighter), then simply
eval
s it and finally runs itsince it could be picked itself, it must be named square
this is my favorite answer
So meta π
thanks
Obviously, to square a number you first need to draw a square.
CSS
JS
Limitations
It will only work for non-negative integer values of
n
.Other than that, it's limited only by your browser's ability to render thousands upon thousands of
div
s.I was hoping I'd see something like this π
Beg for mercy.
+1 point for readability
note: using
with
should improve performances since it does not need to accessMath
each timesqrt
is usedJust keep adding 1. It will get there
How about the use of the good old two-dimensional array?!
Not a full code snippet, but I would submit something terrible like this:
We need some bloated JavaScript libraries.
Simple enough. Just create some random square images and check randomly to see if the diagonal of one equals our number, with the added bonus of a potential for an awesome looking image.
And by the Infinite Monkey Theorem, given an infinite number of monkeys running an inifinite number of square functions, we'll eventually have the worlds greatest image. What a bonus.
Using JS theres a NPM package for this: npmjs.com/package/sqr
Install it via
npm install sqr
Late, but any excuse for a cross join:
Create an x * x array of dots. Count the dots.
Just ignore the floating point error:
AFK, but the method I want to try is just a series of additions;
n^2 - (n-1)^2 == n + n-1
, so just do that in a for-loop from 1 to n.For example: