Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -1,38 +1,36 @@
# we define a UNION MODE so that our middle 3 digits PROC can #
# return either an integer on success or a error message if #
# the middle 3 digits couldn't be extracted #
MODE EINT = UNION( INT # success value #, STRING # error message # );
# PROC to return the middle 3 digits of an integer. #
# if this is not possible, an error message is returned #
# instead #
PROC middle 3 digits = ( INT number ) EINT:
BEGIN
# convert the absolute value of the number to a string with the #
# minumum possible number characters #
STRING digits = whole( ABS number, 0 );
INT len = UPB digits;
IF len < 3
THEN
# number has less than 3 digits #
# return an error message #
"number must have at least three digits"
ELIF ( len MOD 2 ) = 0
THEN
# the number has an even number of digits #
# return an error message #
"number must have an odd number of digits"
ELSE
# the number is suitable for extraction of the middle 3 digits #
INT first digit pos = 1 + ( ( len - 3 ) OVER 2 );
# the result is the integer value of the three digits #
( ( ( ABS digits[ first digit pos ] - ABS "0" ) * 100 )
+ ( ( ABS digits[ first digit pos + 1 ] - ABS "0" ) * 10 )
+ ( ( ABS digits[ first digit pos + 2 ] - ABS "0" ) )
)
FI
END; # middle 3 digits #
# we define a UNION MODE so that our middle 3 digits PROC can #
# return either an integer on success or a error message if #
# the middle 3 digits couldn't be extracted #
MODE EINT = UNION( INT # success value #, STRING # error message # );
# PROC to return the middle 3 digits of an integer. #
# if this is not possible, an error message is returned #
# instead #
PROC middle 3 digits = ( INT number ) EINT:
BEGIN
# convert the absolute value of the number to a string with the #
# minumum possible number characters #
STRING digits = whole( ABS number, 0 );
INT len = UPB digits;
IF len < 3
THEN
# number has less than 3 digits return an error message #
"number must have at least three digits"
ELIF len MOD 2 = 0
THEN
# the number has an even number of digits- return an error message #
"number must have an odd number of digits"
ELSE
# the number is suitable for extraction of the middle 3 digits #
INT first digit pos = 1 + ( ( len - 3 ) OVER 2 );
# the result is the integer value of the three digits #
( ( ( ABS digits[ first digit pos ] - ABS "0" ) * 100 )
+ ( ( ABS digits[ first digit pos + 1 ] - ABS "0" ) * 10 )
+ ( ( ABS digits[ first digit pos + 2 ] - ABS "0" ) )
)
FI
END; # middle 3 digits #
main: (
# test the middle 3 digits PROC #
[]INT test values = ( 123, 12345, 1234567, 987654321
, 10001, -10001, -123, -100
@ -60,4 +58,4 @@ main: (
ESAC;
print( ( newline ) )
OD
)
END