Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
41
Task/Dot-product/FutureBasic/dot-product.basic
Normal file
41
Task/Dot-product/FutureBasic/dot-product.basic
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
local fn DotProduct( a as CFArrayRef, b as CFArrayRef ) as double
|
||||
NSInteger i
|
||||
double dp = 0.0
|
||||
|
||||
if len(a) != len(b) then alert 1, NSAlertStyleWarning,, @"Vectors have unequal length.", @"Okay" : exit fn
|
||||
|
||||
for i = 0 to len(a)-1
|
||||
dp += fn NumberDoubleValue( a[i] ) * fn NumberDoubleValue( b[i] )
|
||||
next
|
||||
end fn = dp
|
||||
|
||||
CFArrayRef a, b
|
||||
NSUInteger i
|
||||
|
||||
a = @[@1, @3, @-5]
|
||||
b = @[@4, @-2, @-1]
|
||||
printf @"Dot product of [%@, %@, %@].[%@, %@, %@] = %.4f", a[0], a[1], a[2], b[0], b[1], b[2], fn DotProduct( a, b )
|
||||
|
||||
a = @[@1.0, @1.0, @3.14159]
|
||||
b = @[@-1.0, @2.618033989, @3.0]
|
||||
printf @"Dot product of [%@, %@, %@].[%@, %@, %@] = %.4f", a[0], a[1], a[2], b[0], b[1], b[2], fn DotProduct( a, b )
|
||||
|
||||
a = @[@8, @13, @-5]
|
||||
b = @[@4, @-7, @-11]
|
||||
printf @"Dot product of [%@, %@, %@].[%@, %@, %@] = %.4f", a[0], a[1], a[2], b[0], b[1], b[2], fn DotProduct( a, b )
|
||||
|
||||
a = @[@1, @2, @3]
|
||||
b = @[@7, @8, @9]
|
||||
printf @"Dot product of [%@, %@, %@].[%@, %@, %@] = %.4f", a[0], a[1], a[2], b[0], b[1], b[2], fn DotProduct( a, b )
|
||||
|
||||
CFMutableArrayRef x, y
|
||||
x = fn MutableArrayWithCapacity(0)
|
||||
y = fn MutableArrayWithCapacity(0)
|
||||
for i = 0 to 9 : MutableArrayInsertObjectAtIndex( x, fn NumberWithInteger(i+ 1), i ) : next
|
||||
for i = 0 to 9 : MutableArrayInsertObjectAtIndex( y, fn NumberWithInteger(i+11), i ) : next
|
||||
|
||||
printf @"Dot product of [1…10].[11…20] = %.4f", fn DotProduct( fn ArrayWithArray( x ), fn ArrayWithArray( y ) )
|
||||
|
||||
NSLog( @"%@", fn WindowPrintViewString( 1 ) )
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue