Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
38
Task/Benfords-law/Chipmunk-Basic/benfords-law.basic
Normal file
38
Task/Benfords-law/Chipmunk-Basic/benfords-law.basic
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
100 cls
|
||||
110 n = 1000
|
||||
120 dim actual(n)
|
||||
130 for nr = 1 to n
|
||||
140 num$ = str$(fibonacci(nr))
|
||||
150 j = val(left$(num$,1))
|
||||
160 actual(j) = actual(j)+1
|
||||
170 next
|
||||
180 print "First 1000 Fibonacci numbers"
|
||||
190 print "Digit Actual freq Expected freq"
|
||||
200 for i = 1 to 9
|
||||
210 freq = frequency(i)*100
|
||||
220 print format$(i,"###");
|
||||
230 print using " ##.###";actual(i)/10;
|
||||
240 print using " ##.###";freq
|
||||
250 next
|
||||
260 end
|
||||
270 sub frequency(n)
|
||||
280 frequency = (log10(n+1)-log10(n))
|
||||
290 end sub
|
||||
300 sub log10(n)
|
||||
310 log10 = log(n)/log(10)
|
||||
320 end sub
|
||||
330 sub fibonacci(n)
|
||||
335 rem https://rosettacode.org/wiki/Fibonacci_sequence#Chipmunk_Basic
|
||||
340 n1 = 0
|
||||
350 n2 = 1
|
||||
360 for k = 1 to abs(n)
|
||||
370 sum = n1+n2
|
||||
380 n1 = n2
|
||||
390 n2 = sum
|
||||
400 next k
|
||||
410 if n < 0 then
|
||||
420 fibonacci = n1*((-1)^((-n)+1))
|
||||
430 else
|
||||
440 fibonacci = n1
|
||||
450 endif
|
||||
460 end sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue