Padovan sequence: Difference between revisions

Added 11l
(Added Quackery.)
(Added 11l)
Line 66:
* [https://www.youtube.com/watch?v=PsGUEj4w9Cc The Plastic Ratio] - Numberphile video.
 
 
=={{header|11l}}==
{{trans|Nim}}
 
<lang 11l>V pp = 1.324717957244746025960908854
V ss = 1.0453567932525329623
V Rules = [‘A’ = ‘B’, ‘B’ = ‘C’, ‘C’ = ‘AB’]
 
F padovan1(n)
V r = [1] * min(n, 3)
V (a, b, c) = (1, 1, 1)
V count = 3
L count < n
(a, b, c) = (b, c, a + b)
r [+]= c
count++
R r
 
F padovan2(n)
V r = [1] * (n > 1)
V p = 1.0
V count = 1
L count < n
r [+]= Int(round(p / :ss))
p *= :pp
count++
R r
 
F padovan3(n)
[String] r
V s = ‘A’
V count = 0
L count < n
r [+]= s
V next = ‘’
L(ch) s
next ‘’= Rules[ch]
s = next
count++
R r
 
print(‘First 20 terms of the Padovan sequence:’)
print(padovan1(20).join(‘ ’))
 
V list1 = padovan1(64)
V list2 = padovan2(64)
print(‘The first 64 iterative and calculated values ’(I list1 == list2 {‘are the same.’} E ‘differ.’))
 
print()
print(‘First 10 L-system strings:’)
print(padovan3(10).join(‘ ’))
print()
print(‘Lengths of the 32 first L-system strings:’)
V list3 = padovan3(32).map(x -> x.len)
print(list3.join(‘ ’))
print(‘These lengths are’(I list3 == list1[0.<32] {‘ ’} E ‘ not ’)‘the 32 first terms of the Padovan sequence.’)</lang>
 
{{out}}
<pre>
First 20 terms of the Padovan sequence:
1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151
The first 64 iterative and calculated values are the same.
 
First 10 L-system strings:
A B C AB BC CAB ABBC BCCAB CABABBC ABBCBCCAB
 
Lengths of the 32 first L-system strings:
1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 265 351 465 616 816 1081 1432 1897 2513 3329 4410
These lengths are the 32 first terms of the Padovan sequence.
</pre>
 
=={{header|ALGOL 68}}==
1,480

edits