Middle three digits: Difference between revisions

Content added Content deleted
imported>Arakov
(Added Uiua solution)
 
Line 6,215: Line 6,215:
A flashing 9.999999999 99 appears on the screen indicating an error.
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}}==
=={{header|UNIX Shell}}==
{{works with|Bourne Again Shell}}
{{works with|Bourne Again Shell}}