• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Cammat.bas

a guest Sep 18th, 2019 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function Cammat1(n as integer) as LongInt
2.     if n <= 2 then return n+1
3.
4.     dim as LongInt c(n)
5.     c(0) = 1: c(1) = 2: c(2) = 3
6.
7.     for i as integer = 3 to n
8.         dim as integer sigmaVal = 0
9.         for k as integer = 0 to (i-2)\2
10.             if (k AND 1) then
11.                 sigmaVal -= c((i-2)-2*k)
12.             else
13.                 sigmaVal += c((i-2)-2*k)
14.             end if
15.         next k
16.         c(i) = c(i-1) + sigmaVal
17.     next i
18.
19.     return c(n)
20. end function
21.
22. function Cammat2(n as integer) as LongInt
23.     if n <= 2 then return n+1
24.
25.     dim as LongInt c(n)
26.     c(0) = 1: c(1) = 2: c(2) = 3
27.
28.     for i as integer = 3 to n
29.         dim as integer sigmaVal = 0, sign = 1
30.         for k as integer = 0 to (i-2)\2
31.             sigmaVal += sign * c((i-2)-2*k)
32.             sign = -sign
33.         next k
34.         c(i) = c(i-1) + sigmaVal
35.     next i
36.
37.     return c(n)
38. end function
39.
40. dim as double startTime, endTime
41. dim as LongInt result
42.
43. startTime = timer
44. for x as integer = 0 to 5000
45.     result = Cammat1(35)
46. next x
47. endTime = timer
48.
49. print "Cammat (if / else):"
50. print result, endTime-startTime
51.
52. startTime = timer
53. for x as integer = 0 to 5000
54.     result = Cammat2(35)
55. next x
56. endTime = timer
57.
58. print "Cammat (sign * result):"
59. print result, endTime-startTime
60. sleep
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top