RosettaCodeData/Task/Mayan-numerals/FutureBasic/mayan-numerals.basic

118 lines
2.6 KiB
Plaintext

//
// Mayan numbers cartouche
//
// FutureBasic 7.0.34 July 2025 R.W
CFStringRef cartouche (7) // array for cartouche
// This is how the cartouche layout will
// be. It consists of 8 printed lines.
cartouche(0)= @"║ Θ ║" // the number 0
cartouche(1)= @"║ ● ║" // the number 1
cartouche(2)= @"║ ● ● ║" // the number 2
cartouche(3)= @"║ ● ● ● ║" // the number 3
cartouche(4)= @"║ ● ● ● ● ║" // the number 4
cartouche(5)= @"║━━━━━━━━━║" // the number 5
cartouche(6)= @"╔═════════╗" // top line
cartouche(7)= @"╚═════════╝" // bottom line
//
// Converts decimal number to vigesimal
//
// On entry: n is a decimal number
// On exit: result as a string of vigesimal
// separated by space
//
local fn decToVigesimal(n as long) as CFStringRef
CFStringRef result
result = @"": if n == 0 then result = @" 0"
while n > 0
result = concat(str(n % 20),result)
n = fix (n/20)
wend
end fn = result
//
// Converts vigesimal to a Mayan cartouche
//
// On entry: n is a vigesimal string separated by spaces
// On exit: Mayan cartouche drawn (horizontally)
//
local fn VigesimalToMayan(n as CFStringRef)
Int m, x, y, idx, al, ov
boolean done = _False
CFStringRef disg (6,15)
CFStringRef vn
CFArrayRef myArray
myArray = fn StringComponentsSeparatedByString(n,@" ")
al = len(myArray) - 1
vn = @""
for m = 1 to al
done = _False
vn = myArray [m]
idx = intval(vn)
ov = idx
disg (0,m) = cartouche(6)
for x = 4 to 1 step -1
disg (x,m) = @"║ ║"
if ov == 0
if !done then disg(x,m) = cartouche(0)
done = _True
end if
if idx > 4
disg(x,m) = cartouche(5)
idx = idx - 5
else
y = idx % 5
if y > 0
if !done then disg(x,m) = cartouche (y)
done = _True
end if
end if
next x
disg (5,m) = cartouche(7)
next m
for x = 0 to 5
for m = 1 to al
print disg(x,m);
next m
print
next x
end fn
window 1
// Test data
CFStringRef Vigesimal
print "Converting 4005 to Mayan"
Vigesimal = fn decToVigesimal(4005)
fn VigesimalToMayan (Vigesimal)
print "Converting 8017 to Mayan"
Vigesimal = fn decToVigesimal(8017)
fn VigesimalToMayan (Vigesimal)
print "Converting 326205 to Mayan"
Vigesimal = fn decToVigesimal(326205)
fn VigesimalToMayan (Vigesimal)
print "Converting 886205 to Mayan"
Vigesimal = fn decToVigesimal(886205)
fn VigesimalToMayan (Vigesimal)
print "Interesting looking Mayan number"
Vigesimal = fn decToVigesimal(717784)
fn VigesimalToMayan (Vigesimal)
handleEvents