Middle three digits: Difference between revisions
Content deleted Content added
m →Composition of pure functions: Updated one primitive ('tabulated') |
No edit summary |
||
Line 3,170:
-2002:*** error: number of digits must be odd ***
0:*** error: number of digits must not be smaller than 3 ***
</pre>
=={{header|MiniScript}}==
<lang MiniScript>middle3 = function(num)
negative = false
if num < 0 then
negative = true
num = num * -1
end if
str = "" + num
if str.len > 2 and str.len % 2 then
mid = (str.len + 1) / 2 - 1
return str[mid-1] + str[mid] + str[mid+1]
else
return "No result possible"
end if
end function
print middle3(123)
print middle3(12345)
print middle3(1234567)
print middle3(987654321)
print middle3(10001)
print middle3(-10001)
print middle3(-123)
print middle3(-100)
print middle3(100)
print middle3(-12345)
print middle3(1)
print middle3(2)
print middle3(-1)
print middle3(-10)
print middle3(2002)
print middle3(-2002)
print middle3(0)
</lang>
{{out}}
<pre>
123
234
345
654
000
000
123
100
100
234
No result possible
No result possible
No result possible
No result possible
No result possible
No result possible
No result possible
</pre>
|