Middle three digits: Difference between revisions

Added Uiua solution
m (→‎{{header|Wren}}: Minor tidy)
(Added Uiua solution)
 
(One intermediate revision by one other user not shown)
Line 2,702:
if(len<3)
{
InvalidArgumentException.new:("n must have 3 digits or more").raise()
}
else if(len.isEven())
{
InvalidArgumentException.new:("n must have an odd number of digits").raise()
};
Line 2,717:
{
new int[]{123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0}
.forEach::(n)
{
console.printLine("middleThreeDigits(",n,"):",middleThreeDigits(n) \\ on::(e => e.Message))
}
}</syntaxhighlight>
Line 6,215:
A flashing 9.999999999 99 appears on the screen indicating an error.
 
=={{header|Uiua}}==
{{Works with |Uiua|0.12.0-dev.1}}
Uses `assert` and `try` to handle the exceptions.
<syntaxhighlight lang="uiua">
[123 12345 1234567 987654321 10001 ¯10001 ¯123 ¯100 100 ¯12345
1 2 ¯1 ¯10 2002 ¯2002 0]
Mid ← (
⍤("too short")≥3.⧻.°□°⋕⌵
⍤("even length")≠0◿2.
↘¯⟜↘⌊÷2-3
)
⍉⊟⟜≡⍚⍣(Mid|⊂"Error: "◌) # Convert each
≡(&p$"_\t->\t_"°⊟) # Display
</syntaxhighlight>
{{out}}
<pre>
123 -> 123
12345 -> 234
1234567 -> 345
987654321 -> 654
10001 -> 000
-10001 -> 000
-123 -> 123
-100 -> 100
100 -> 100
-12345 -> 234
1 -> Error: too short
2 -> Error: too short
-1 -> Error: too short
-10 -> Error: too short
2002 -> Error: even length
-2002 -> Error: even length
0 -> Error: too short
</pre>
=={{header|UNIX Shell}}==
{{works with|Bourne Again Shell}}
159

edits