DEV Community

Discussion on: Square a number: awful answers only

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

Bash

Using curl to make a request to some API I found on google

#!/bin/sh

curl "https://api.mathjs.org/v4/?expr=$1%5E2"
Enter fullscreen mode Exit fullscreen mode

Terra

Take N as an argument, then compile an executable named square_of_<N> that prints the square of N

local stdio = terralib.includec("stdio.h")

local function squarer(n)
  return terra()
    stdio.printf("%i\n", n * n)
  end
end

local n = tonumber(... or 0)

terralib.saveobj("square_of_"..tostring(n), { main = squarer(n) })
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rafaacioly profile image
Rafael Acioly

I laughed at the curl solution I'm not gonna lie