Jump to content

Periodic table: Difference between revisions

Line 313:
 
==={{header|FutureBasic}}===
Old fashioned way:
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn PeriodicTable( n as NSInteger ) as CFDictionaryRef
NSInteger i, row = 0, start = 0, finish, limits(6,6)
CFDictionaryRef dict = NULL
 
if n < 1 or n > 118 then NSLog( @"Atomic number is out of range." ) : exit fn
if n == 1 then dict = @{@"row":@1, @"col":@1} : exit fn
if n == 2 then dict = @{@"row":@1, @"col":@18} : exit fn
if n >= 57 and n <= 71 then dict = @{@"row":@8, @"col":fn NumberWithInteger( n - 53 )} : exit fn
if n >= 89 and n <= 103 then dict = @{@"row":@9, @"col":fn NumberWithInteger( n - 85 )} : exit fn
 
limits(0,0) = 3 : limits(0,1) = 10
limits(1,0) = 11 : limits(1,1) = 18
limits(2,0) = 19 : limits(2,1) = 36
limits(3,0) = 37 : limits(3,1) = 54
limits(4,0) = 55 : limits(4,1) = 86
limits(5,0) = 87 : limits(5,1) = 118
 
for i = 0 to 5
if ( n >= limits(i,0) and n <= limits(i,1) )
row = i + 2
start = limits(i,0)
finish = limits(i,1)
break
end if
next
 
if ( n < start + 2 or row == 4 or row == 5 )
dict = @{@"row":fn NumberWithInteger(row), @"col":fn NumberWithInteger( n - start + 1 )} : exit fn
end if
dict = @{@"row":fn NumberWithInteger(row), @"col":fn NumberWithInteger( n - finish + 18 )}
end fn = dict
 
 
local fn BuildTable
NSInteger i, count
CFArrayRef numbers = @[@1, @2, @29, @42, @57, @58, @59, @71, @72, @89, @90, @103, @113]
 
count = fn ArrayCount( numbers )
 
for i = 0 to count -1
CFDictionaryRef coordinates = fn PeriodicTable( fn NumberIntegerValue( numbers[i] ) )
NSLog( @"Atomic number %3d -> (%d, %d)", fn NumberIntegerValue( numbers[i] ), fn NumberIntegerValue( coordinates[@"row"] ), fn NumberIntegerValue( coordinates[@"col"] ) )
next
end fn
 
fn BuildTable
 
HandleEvents
</syntaxhighlight>
{{out}}
<pre>
Atomic number 1 -> (1, 1)
Atomic number 2 -> (1, 18)
Atomic number 29 -> (4, 11)
Atomic number 42 -> (5, 6)
Atomic number 57 -> (8, 4)
Atomic number 58 -> (8, 5)
Atomic number 59 -> (8, 6)
Atomic number 71 -> (8, 18)
Atomic number 72 -> (6, 4)
Atomic number 89 -> (9, 4)
Atomic number 90 -> (9, 5)
Atomic number 103 -> (9, 18)
Atomic number 113 -> (7, 13)
 
</pre>
 
Modern way.
<syntaxhighlight lang="futurebasic">
_window = 1
729

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.