Motzkin numbers: Difference between revisions

Motzkin numbers en Yabasic
(Motzkin numbers en BASIC256)
(Motzkin numbers en Yabasic)
Line 1,846:
41 192,137,918,101,841,817 false
</pre>
 
=={{header|Yabasic}}==
<lang yabasic>dim M(41)
M(0) = 1 : M(1) = 1
print str$(M(0), "%19g")
print str$(M(1), "%19g")
for n = 2 to 41
M(n) = M(n-1)
for i = 0 to n-2
M(n) = M(n) + M(i)*M(n-2-i)
next i
print str$(M(n), "%19.0f"),
if isPrime(M(n)) then print "is a prime" else print : fi
next n
end
 
sub isPrime(v)
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 3) = 0 then return v = 3 : fi
d = 5
while d * d <= v
if mod(v, d) = 0 then return False else d = d + 2 : fi
wend
return True
end sub</lang>
2,130

edits