Data update
This commit is contained in:
parent
07c7092a52
commit
61b93a2cd1
313 changed files with 6160 additions and 346 deletions
23
Task/Middle-three-digits/BASIC256/middle-three-digits.basic
Normal file
23
Task/Middle-three-digits/BASIC256/middle-three-digits.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
function middleThreeDigits(n)
|
||||
if n < 0 then n = -n
|
||||
if n < 100 then return "" ## error code
|
||||
if n < 1000 then return string(n)
|
||||
if n < 10000 then return ""
|
||||
ns = string(n)
|
||||
if length(ns) mod 2 = 0 then return "" ## need to have an odd number of digits for there to be 3 middle
|
||||
return mid(ns, length(ns) \ 2, 3)
|
||||
end function
|
||||
|
||||
dim a = {123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -123451, 2, -1, -10, 2002, -2002, 0}
|
||||
|
||||
print "The 3 middle digits of the following numbers are : "
|
||||
print
|
||||
for i = 0 to 15
|
||||
result = middleThreeDigits(a[i])
|
||||
print a[i]; chr(9); " => ";
|
||||
if result <> "" then
|
||||
print result
|
||||
else
|
||||
print "Error: does not have 3 middle digits"
|
||||
end if
|
||||
next
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
≪ ABS DUP XPON
|
||||
IF DUP 2 < OVER 2 MOD OR THEN
|
||||
DROP2 -1
|
||||
ELSE
|
||||
2 / 1 - ALOG / IP 1000 MOD
|
||||
END
|
||||
≫
|
||||
'→M3D' STO
|
||||
|
||||
≪ { 123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345 -10 2002}
|
||||
→ tl
|
||||
≪ 1 tl SIZE FOR j
|
||||
tl j GET →M3D
|
||||
NEXT
|
||||
≫
|
||||
≫ EVAL
|
||||
29
Task/Middle-three-digits/Yabasic/middle-three-digits.basic
Normal file
29
Task/Middle-three-digits/Yabasic/middle-three-digits.basic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
sub middleThreeDigits$ (n)
|
||||
if n < 0 n = -n
|
||||
if n < 100 return "" // error code
|
||||
if n < 1000 return str$(n)
|
||||
if n < 10000 return ""
|
||||
ns$ = str$(n)
|
||||
if mod(len(ns$), 2) = 0 return "" // need to have an odd number of digits for there to be 3 middle
|
||||
return mid$(ns$, len(ns$) / 2, 3)
|
||||
end sub
|
||||
|
||||
dim a(16)
|
||||
a(0) = 123 : a(1) = 12345 : a(2) = 1234567
|
||||
a(3) = 987654321 : a(4) = 10001 : a(5) = -10001
|
||||
a(6) = -123 : a(7) = -100 : a(8) = 100
|
||||
a(9) = -123451
|
||||
a(10) = 2 : a(11) = -1 : a(12) = -10
|
||||
a(13) = 2002 : a(14) = -2002 : a(15) = 0
|
||||
|
||||
print "The 3 middle digits of the following numbers are : \n"
|
||||
|
||||
for i = 1 to 16
|
||||
result$ = middleThreeDigits$(a(i))
|
||||
print a(i), "\t => ";
|
||||
if result$ <> "" then
|
||||
print result$
|
||||
else
|
||||
print "Error: does not have 3 middle digits"
|
||||
fi
|
||||
next
|
||||
Loading…
Add table
Add a link
Reference in a new issue