RosettaCodeData/Task/Padovan-sequence/11l/padovan-sequence.11l

53 lines
1.2 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.)