Skip to main content
4 of 6
added 1 character in body
ovs
  • 61.2k
  • 3
  • 49
  • 164

Milky Way, 17 bytes

-3 bytes by using Olivier Grégoire's formula

^^':2;g:>/+2/! 

usage: ./mw squares.mwg -i 2612

Explanation

code explanation stack layout ^^ clear preinitialized stack [] ': push input and duplicate it [input, input] 2; push 2 and swap ToS and SoS [input, 2, input] g nth root [input, s=floor(sqrt(input))] : duplicate ToS [input, s, s] > rotate stack right [s, input, s] / divide [s, input/s] + add [s+input/s] 2/ divide by 2 [(s+input/s)/2] ! output => (s+input/s)/2 
ovs
  • 61.2k
  • 3
  • 49
  • 164