Padovan sequence: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 70: | Line 70: | ||
{{trans|Nim}} |
{{trans|Nim}} |
||
< |
<syntaxhighlight lang="11l">V pp = 1.324717957244746025960908854 |
||
V ss = 1.0453567932525329623 |
V ss = 1.0453567932525329623 |
||
V Rules = [‘A’ = ‘B’, ‘B’ = ‘C’, ‘C’ = ‘AB’] |
V Rules = [‘A’ = ‘B’, ‘B’ = ‘C’, ‘C’ = ‘AB’] |
||
Line 121: | Line 121: | ||
V list3 = padovan3(32).map(x -> x.len) |
V list3 = padovan3(32).map(x -> x.len) |
||
print(list3.join(‘ ’)) |
print(list3.join(‘ ’)) |
||
print(‘These lengths are’(I list3 == list1[0.<32] {‘ ’} E ‘ not ’)‘the 32 first terms of the Padovan sequence.’)</ |
print(‘These lengths are’(I list3 == list1[0.<32] {‘ ’} E ‘ not ’)‘the 32 first terms of the Padovan sequence.’)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 138: | Line 138: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68">BEGIN # show members of the Padovan Sequence calculated in various ways # |
||
# returns the first n elements of the Padovan sequence by the # |
# returns the first n elements of the Padovan sequence by the # |
||
# recurance relation: P(n)=P(n-2)+P(n-3) # |
# recurance relation: P(n)=P(n-2)+P(n-3) # |
||
Line 222: | Line 222: | ||
) |
) |
||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 235: | Line 235: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
< |
<syntaxhighlight lang="applescript">--------------------- PADOVAN NUMBERS -------------------- |
||
-- padovans :: [Int] |
-- padovans :: [Int] |
||
Line 502: | Line 502: | ||
set my text item delimiters to dlm |
set my text item delimiters to dlm |
||
s |
s |
||
end unlines</ |
end unlines</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 20 padovans: |
<pre>First 20 padovans: |
||
Line 521: | Line 521: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <math.h> |
#include <math.h> |
||
Line 618: | Line 618: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 640: | Line 640: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <map> |
#include <map> |
||
#include <cmath> |
#include <cmath> |
||
Line 721: | Line 721: | ||
"floor- and L-system-based", 32); |
"floor- and L-system-based", 32); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 743: | Line 743: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="clojure">(def padovan (map first (iterate (fn [[a b c]] [b c (+ a b)]) [1 1 1]))) |
||
(def pad-floor |
(def pad-floor |
||
Line 782: | Line 782: | ||
"The L-system, recurrence and floor based algorithms " |
"The L-system, recurrence and floor based algorithms " |
||
(if (comp-all 32) "match" "not match") |
(if (comp-all 32) "match" "not match") |
||
" to n=32"))))</ |
" to n=32"))))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 802: | Line 802: | ||
Thanks Rudy Velthuis for the [https://github.com/rvelthuis/DelphiBigNumbers Velthuis.BigDecimals] library.<br> |
Thanks Rudy Velthuis for the [https://github.com/rvelthuis/DelphiBigNumbers Velthuis.BigDecimals] library.<br> |
||
Boost.Generics.Collection is part of [https://github.com/MaiconSoft/DelphiBoostLib DelphiBoostLib]. |
Boost.Generics.Collection is part of [https://github.com/MaiconSoft/DelphiBoostLib DelphiBoostLib]. |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program Padovan_sequence; |
program Padovan_sequence; |
||
Line 905: | Line 905: | ||
end, 'floor- and L-system-based', 32); |
end, 'floor- and L-system-based', 32); |
||
readln; |
readln; |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
< |
<syntaxhighlight lang="factor">USING: L-system accessors io kernel make math math.functions |
||
memoize prettyprint qw sequences ; |
memoize prettyprint qw sequences ; |
||
Line 940: | Line 940: | ||
32 <iota> [ pfloor ] map 32 plsys [ length ] map assert= |
32 <iota> [ pfloor ] map 32 plsys [ length ] map assert= |
||
"The L-system, recurrence and floor based algorithms match to n=31." print</ |
"The L-system, recurrence and floor based algorithms match to n=31." print</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 967: | Line 967: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 1,073: | Line 1,073: | ||
} |
} |
||
fmt.Println("\nThe recurrence and L-system based functions", s, "the same results for 32 terms.") |
fmt.Println("\nThe recurrence and L-system based functions", s, "the same results for 32 terms.") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,092: | Line 1,092: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">-- list of Padovan numbers using recurrence |
||
pRec = map (\(a,_,_) -> a) $ iterate (\(a,b,c) -> (b,c,a+b)) (1,1,1) |
pRec = map (\(a,_,_) -> a) $ iterate (\(a,b,c) -> (b,c,a+b)) (1,1,1) |
||
Line 1,132: | Line 1,132: | ||
putStr $ if checkN 32 pFloor (map length lSystem) |
putStr $ if checkN 32 pFloor (map length lSystem) |
||
then "match" else "do not match" |
then "match" else "do not match" |
||
putStr " from P_0 to P_31.\n"</ |
putStr " from P_0 to P_31.\n"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,147: | Line 1,147: | ||
and a variant expressed in terms of '''unfoldr''', which allows for a coherent treatment of these three cases – isolating the respects in which they differ – and also lends itself to a simple translation to the N-Step Padovan case, covered in another task. |
and a variant expressed in terms of '''unfoldr''', which allows for a coherent treatment of these three cases – isolating the respects in which they differ – and also lends itself to a simple translation to the N-Step Padovan case, covered in another task. |
||
< |
<syntaxhighlight lang="haskell">import Data.List (unfoldr) |
||
--------------------- PADOVAN NUMBERS -------------------- |
--------------------- PADOVAN NUMBERS -------------------- |
||
Line 1,203: | Line 1,203: | ||
prefixesMatch :: Eq a => [a] -> [a] -> Int -> Bool |
prefixesMatch :: Eq a => [a] -> [a] -> Int -> Bool |
||
prefixesMatch xs ys n = and (zipWith (==) (take n xs) ys)</ |
prefixesMatch xs ys n = and (zipWith (==) (take n xs) ys)</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 20 padovans: |
<pre>First 20 padovans: |
||
Line 1,226: | Line 1,226: | ||
Implementation: |
Implementation: |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
padovanSeq=: (],+/@(_2 _3{]))^:([-3:)&1 1 1 |
padovanSeq=: (],+/@(_2 _3{]))^:([-3:)&1 1 1 |
||
Line 1,234: | Line 1,234: | ||
padovanL=: rplc&('A';'B'; 'B';'C'; 'C';'AB')@]^:[&'A' |
padovanL=: rplc&('A';'B'; 'B';'C'; 'C';'AB')@]^:[&'A' |
||
seqLen=. #@(-.&' ')"1 |
seqLen=. #@(-.&' ')"1 |
||
</syntaxhighlight> |
|||
</lang> |
|||
Typically, inductive sequences based on a function F with an initial value G can be expressed using an expression of the form F@]^:[@G or something similar. Here, [ represents the argument to the derived recurrence function. For padovanSeq, we are generating a sequence, so we want to retain the previous values. So instead of just using f=: +/@(_2 3{]) which adds up the second and third numbers from the end of the sequence, we also retain the previous values using F=: ],f |
Typically, inductive sequences based on a function F with an initial value G can be expressed using an expression of the form F@]^:[@G or something similar. Here, [ represents the argument to the derived recurrence function. For padovanSeq, we are generating a sequence, so we want to retain the previous values. So instead of just using f=: +/@(_2 3{]) which adds up the second and third numbers from the end of the sequence, we also retain the previous values using F=: ],f |
||
Line 1,242: | Line 1,242: | ||
Task examples: |
Task examples: |
||
<syntaxhighlight lang="j"> |
|||
<lang J> |
|||
padovanSeq 20 |
padovanSeq 20 |
||
1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 |
1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 |
||
Line 1,260: | Line 1,260: | ||
(padovanSeq 32) -: seqLen padovanL i.32 |
(padovanSeq 32) -: seqLen padovanL i.32 |
||
1 |
1 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
< |
<syntaxhighlight lang="javascript">(() => { |
||
"use strict"; |
"use strict"; |
||
Line 1,457: | Line 1,457: | ||
// MAIN --- |
// MAIN --- |
||
return main(); |
return main(); |
||
})();</ |
})();</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 20 padovans: |
<pre>First 20 padovans: |
||
Line 1,483: | Line 1,483: | ||
streams of the Padovan strings and numbers respectively. |
streams of the Padovan strings and numbers respectively. |
||
< |
<syntaxhighlight lang="jq"># Output: first $n Padovans |
||
def padovanRecur($n): |
def padovanRecur($n): |
||
[range(0;$n) | 1] as $p |
[range(0;$n) | 1] as $p |
||
Line 1,531: | Line 1,531: | ||
; |
; |
||
task</ |
task</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,548: | Line 1,548: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">""" Recursive Padovan """ |
||
rPadovan(n) = (n < 4) ? one(n) : rPadovan(n - 3) + rPadovan(n - 2) |
rPadovan(n) = (n < 4) ? one(n) : rPadovan(n - 3) + rPadovan(n - 2) |
||
Line 1,574: | Line 1,574: | ||
foreach(i -> println(rpad(i, 4), rpad(lr[i], 12), rpad(lf[i], 12), |
foreach(i -> println(rpad(i, 4), rpad(lr[i], 12), rpad(lf[i], 12), |
||
rpad(i < 33 ? lL[i] : "", 12), (i < 11 ? sL[i] : "")), 1:64) |
rpad(i < 33 ? lL[i] : "", 12), (i < 11 ? sL[i] : "")), 1:64) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
N Recursive Floor LSystem String |
N Recursive Floor LSystem String |
||
Line 1,645: | Line 1,645: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[Padovan1,a,p,s] |
||
p=N[Surd[((9+Sqrt[69])/18),3]+Surd[((9-Sqrt[69])/18),3],200]; |
p=N[Surd[((9+Sqrt[69])/18),3]+Surd[((9-Sqrt[69])/18),3],200]; |
||
s=1.0453567932525329623; |
s=1.0453567932525329623; |
||
Line 1,654: | Line 1,654: | ||
Padovan1[64]===Padovan2[64] |
Padovan1[64]===Padovan2[64] |
||
SubstitutionSystem[{"A"->"B","B"->"C","C"->"AB"},"A",10]//Column |
SubstitutionSystem[{"A"->"B","B"->"C","C"->"AB"},"A",10]//Column |
||
(StringLength/@SubstitutionSystem[{"A"->"B","B"->"C","C"->"AB"},"A",31])==Padovan2[32]</ |
(StringLength/@SubstitutionSystem[{"A"->"B","B"->"C","C"->"AB"},"A",31])==Padovan2[32]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{1,1,1,2,2,3,4,5,7,9,12,16,21,28,37,49,65,86,114,151} |
<pre>{1,1,1,2,2,3,4,5,7,9,12,16,21,28,37,49,65,86,114,151} |
||
Line 1,673: | Line 1,673: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import sequtils, strutils, tables |
||
const |
const |
||
Line 1,734: | Line 1,734: | ||
echo "These lengths are", |
echo "These lengths are", |
||
if list3 == list1[0..31]: " " else: " not ", |
if list3 == list1[0..31]: " " else: " not ", |
||
"the 32 first terms of the Padovan sequence."</ |
"the 32 first terms of the Padovan sequence."</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,750: | Line 1,750: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature <state say>; |
use feature <state say>; |
||
Line 1,774: | Line 1,774: | ||
$pr[$_] == $pf[$_] and $pr[$_] == length $L[$_] or die "Uh oh, n=$_: $pr[$_] vs $pf[$_] vs " . length $L[$_] for 0 .. $n-1; |
$pr[$_] == $pf[$_] and $pr[$_] == length $L[$_] or die "Uh oh, n=$_: $pr[$_] vs $pf[$_] vs " . length $L[$_] for 0 .. $n-1; |
||
say '100% agreement among all 3 methods.';</ |
say '100% agreement among all 3 methods.';</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 |
<pre>1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 |
||
Line 1,783: | Line 1,783: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">padovan</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">padovan</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span> |
||
Line 1,818: | Line 1,818: | ||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 10 L-system strings: %v\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">l10</span><span style="color: #0000FF;">})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 10 L-system strings: %v\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">l10</span><span style="color: #0000FF;">})</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"recursive, algorithmic, and l-system agree to n=64\n"</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"recursive, algorithmic, and l-system agree to n=64\n"</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,830: | Line 1,830: | ||
=={{Header|Python}}== |
=={{Header|Python}}== |
||
===Python: Idiomatic=== |
===Python: Idiomatic=== |
||
< |
<syntaxhighlight lang="python">from math import floor |
||
from collections import deque |
from collections import deque |
||
from typing import Dict, Generator |
from typing import Dict, Generator |
||
Line 1,878: | Line 1,878: | ||
print("\nThe L-system, recurrence and floor based algorithms match to n=31 .") |
print("\nThe L-system, recurrence and floor based algorithms match to n=31 .") |
||
else: |
else: |
||
print("\nThe L-system, recurrence and floor based algorithms DIFFER!")</ |
print("\nThe L-system, recurrence and floor based algorithms DIFFER!")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,901: | Line 1,901: | ||
===Python: Expressed in terms of a generic anamorphism (unfoldr)=== |
===Python: Expressed in terms of a generic anamorphism (unfoldr)=== |
||
< |
<syntaxhighlight lang="python">'''Padovan series''' |
||
from itertools import chain, islice |
from itertools import chain, islice |
||
Line 2,036: | Line 2,036: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 20 padovans: |
<pre>First 20 padovans: |
||
Line 2,059: | Line 2,059: | ||
<code>v**</code> is defined at [[Exponentiation operator#Quackery]]. |
<code>v**</code> is defined at [[Exponentiation operator#Quackery]]. |
||
< |
<syntaxhighlight lang="quackery">( --------------------- Recurrence -------------------- ) |
||
[ dup 0 = iff |
[ dup 0 = iff |
||
Line 2,125: | Line 2,125: | ||
[ say "The first 32 recurrence terms and L System lengths are the same." ] |
[ say "The first 32 recurrence terms and L System lengths are the same." ] |
||
else [ say "Oh no! It's all gone pear-shaped!" ] |
else [ say "Oh no! It's all gone pear-shaped!" ] |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 2,139: | Line 2,139: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>constant p = 1.32471795724474602596; |
||
constant s = 1.0453567932525329623; |
constant s = 1.0453567932525329623; |
||
constant %rules = A => 'B', B => 'C', C => 'AB'; |
constant %rules = A => 'B', B => 'C', C => 'AB'; |
||
Line 2,154: | Line 2,154: | ||
say "Recurrence == Floor to N=64" if (@pad-recur Z== @pad-floor).head(64).all; |
say "Recurrence == Floor to N=64" if (@pad-recur Z== @pad-floor).head(64).all; |
||
say "Recurrence == L-len to N=32" if (@pad-recur Z== @pad-L-len).head(32).all;</ |
say "Recurrence == L-len to N=32" if (@pad-recur Z== @pad-L-len).head(32).all;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,164: | Line 2,164: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm computes the Padovan seq. (using 2 methods), and also computes the L─strings.*/ |
||
numeric digits 40 /*better precision for Plastic ratio. */ |
numeric digits 40 /*better precision for Plastic ratio. */ |
||
parse arg n nF Ln cL . /*obtain optional arguments from the CL*/ |
parse arg n nF Ln cL . /*obtain optional arguments from the CL*/ |
||
Line 2,214: | Line 2,214: | ||
end /*j*/ |
end /*j*/ |
||
say |
say |
||
if ok then say 'all ' cL what; return</ |
if ok then say 'all ' cL what; return</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 2,228: | Line 2,228: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">padovan = Enumerator.new do |y| |
||
ar = [1, 1, 1] |
ar = [1, 1, 1] |
||
loop do |
loop do |
||
Line 2,259: | Line 2,259: | ||
bool = l_system.take(n).map(&:size) == padovan.take(n) |
bool = l_system.take(n).map(&:size) == padovan.take(n) |
||
puts "Sizes of first #{n} l_system strings equal to recurrence padovan? #{bool}." |
puts "Sizes of first #{n} l_system strings equal to recurrence padovan? #{bool}." |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>Recurrence Padovan: [1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151] |
<pre>Recurrence Padovan: [1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151] |
||
Line 2,269: | Line 2,269: | ||
</pre> |
</pre> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">fn padovan_recur() -> impl std::iter::Iterator<Item = usize> { |
||
let mut p = vec![1, 1, 1]; |
let mut p = vec![1, 1, 1]; |
||
let mut n = 0; |
let mut n = 0; |
||
Line 2,330: | Line 2,330: | ||
.eq(padovan_recur().take(32)) |
.eq(padovan_recur().take(32)) |
||
); |
); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,346: | Line 2,346: | ||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">import Foundation |
||
class PadovanRecurrence: Sequence, IteratorProtocol { |
class PadovanRecurrence: Sequence, IteratorProtocol { |
||
Line 2,410: | Line 2,410: | ||
b = PadovanLSystem().prefix(32).map{$0.count} |
b = PadovanLSystem().prefix(32).map{$0.count} |
||
.elementsEqual(PadovanRecurrence().prefix(32)) |
.elementsEqual(PadovanRecurrence().prefix(32)) |
||
print("\nLength of first 32 strings produced from the L-system = Padovan sequence? \(b)")</ |
print("\nLength of first 32 strings produced from the L-system = Padovan sequence? \(b)")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,429: | Line 2,429: | ||
{{libheader|Wren-dynamic}} |
{{libheader|Wren-dynamic}} |
||
L-System stuff is based on the Julia implementation. |
L-System stuff is based on the Julia implementation. |
||
< |
<syntaxhighlight lang="ecmascript">import "/big" for BigRat |
||
import "/dynamic" for Struct |
import "/dynamic" for Struct |
||
Line 2,492: | Line 2,492: | ||
areSame = (0...32).all { |i| recur[i] == lsyst[i] } |
areSame = (0...32).all { |i| recur[i] == lsyst[i] } |
||
s = areSame ? "give" : "do not give" |
s = areSame ? "give" : "do not give" |
||
System.print("\nThe recurrence and L-system based functions %(s) the same results for 32 terms.")</ |
System.print("\nThe recurrence and L-system based functions %(s) the same results for 32 terms.")</syntaxhighlight> |
||
{{out}} |
{{out}} |