Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Cammat1(n as integer) as LongInt
- if n <= 2 then return n+1
- dim as LongInt c(n)
- c(0) = 1: c(1) = 2: c(2) = 3
- for i as integer = 3 to n
- dim as integer sigmaVal = 0
- for k as integer = 0 to (i-2)\2
- if (k AND 1) then
- sigmaVal -= c((i-2)-2*k)
- else
- sigmaVal += c((i-2)-2*k)
- end if
- next k
- c(i) = c(i-1) + sigmaVal
- next i
- return c(n)
- end function
- function Cammat2(n as integer) as LongInt
- if n <= 2 then return n+1
- dim as LongInt c(n)
- c(0) = 1: c(1) = 2: c(2) = 3
- for i as integer = 3 to n
- dim as integer sigmaVal = 0, sign = 1
- for k as integer = 0 to (i-2)\2
- sigmaVal += sign * c((i-2)-2*k)
- sign = -sign
- next k
- c(i) = c(i-1) + sigmaVal
- next i
- return c(n)
- end function
- dim as double startTime, endTime
- dim as LongInt result
- startTime = timer
- for x as integer = 0 to 5000
- result = Cammat1(35)
- next x
- endTime = timer
- print "Cammat (if / else):"
- print result, endTime-startTime
- startTime = timer
- for x as integer = 0 to 5000
- result = Cammat2(35)
- next x
- endTime = timer
- print "Cammat (sign * result):"
- print result, endTime-startTime
- sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement