DEV Community

Rishit Khandelwal
Rishit Khandelwal

Posted on

whats the worst program you can make for squaring a number.

Try making a ultimate slow program to square a number, or share a program you have made previously.
The slower the better.
But each iteration should do something, dont loop for ever and then print the square like this:

function square(x) {
  while(true) {}
  console.log(x*x)
}
Enter fullscreen mode Exit fullscreen mode

Ok, now comment your slow program in the comments ;)

Join orbits community now: https://discord.gg/9hB4VJcw97

Top comments (4)

Collapse
 
ncpa0cpl profile image
ncpa0cpl • Edited
const square = (n: number) => {
  n = Math.abs(n);
  while(true) {
    const result = Math.random() * Number.MAX_SAFE_INTEGER;
    if(result % n === 0) {
      let c = result;
      let d = 0;
      while(true) {
        c -= n;
        d++;
        if(c === 0) break;
      }
      if(d === n) return result;
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

DISCLAIMER
This for all I know may crash the browser tab it's running in.

Collapse
 
miguelmj profile image
MiguelMJ
int square(int x){
  int result = 0;
  for(int i=0; i < x; i++){
    int acc = 0;
    for(int j = 0; j < x; j++){
      acc = acc+1;
    }
    for(int k = acc; k > 0; k--){
      result = result+1;
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This is the stupidest way I could think of, maybe even a little far-fetched 😂

Collapse
 
agtoever profile image
agtoever

Just add 1s and create a new object for a*b times. Python implementation.

Try it online!

Collapse
 
rishitkhandelwal profile image
Rishit Khandelwal

Could be even slower than that. 🤓