Motzkin numbers: Difference between revisions

Added Uiua solution
m (→‎{{header|Wren}}: Minor tidy)
(Added Uiua solution)
 
Line 2,540:
41: 192137918101841817</pre>
 
=={{header|Uiua}}==
Due to limited precision in Uiua only the first 36 terms are generated accurately.
<syntaxhighlight lang="Uiua">
# Uses following formula to generate successive terms:
# m[i] = (m[i-2]*(3*i-3) + m[i-1]*(2*i+1)) / (i + 2)
 
# Collect the multiplicands from the above formula.
Multiplicands ← [⊃(-3×3|+1×2|÷:1+2)]⧻
# Apply formula to generate next Motzkin number.
Mn ← ×⊃(/+↙2|⊢↙¯1)×⊃(⊂:1↙¯2|Multiplicands)
# Generate list of terms to reasonable limit.
⍢(⊂⟜Mn|<36⧻) [1 1]
# Simple (=slow) prime test.
IsPrime ← ⊙◌⟨⟨=1⧻⍢(↘1|≠0◿⊢)⊂:1+2⇡⌊√.|1⟩=2.|0⟩≤1.
⍉⊟⟜∵IsPrime
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ 1 0
1 0
2 1
4 0
9 0
21 0
51 0
127 1
323 0
835 0
2188 0
5798 0
15511 1
41835 0
113634 0
310572 0
853467 0
2356779 0
6536382 0
18199284 0
50852019 0
142547559 0
400763223 0
1129760415 0
3192727797 0
9043402501 0
25669818476 0
73007772802 0
208023278209 0
593742784829 0
1697385471211 0
4859761676391 0
13933569346707 0
40002464776083 0
114988706524270 0
330931069469828 0
</pre>
=={{header|Wren}}==
{{libheader|Wren-long}}
130

edits