blob: ab9180a435237f13a5ce64ac0d49f0f7c2e6b644 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
VowelStrings←{
⍝ ⍺: String sequence rules
⍺←('aei' 'ei' 'iaeou' 'oau' 'uoe') ⍝ Default
⍝ 'a' can only be followed by 'e' and 'i'
⍝ 'e' can only be followed by 'i'
⍝ 'i' can only be followed by 'a', 'e', 'o' and 'u'
⍝ 'o' can only be followed by 'a' and 'u'
⍝ 'u' can only be followed by 'o' and 'e'
(chars rules)←(⊃¨⍺)(⍺)
⍝ ⍵: String size (1≤⍵)∧(⍵≤≢⍺)
⍝ ←: All rule-obeying strings of length ⍵
Next←{⊃,/(⊆∘.,1↓rules⊃⍨chars⍳(⊃⌽))¨⊆⍵} ⍝ Rule-following superstring of length (1+≢⍵)
superstrings←Next⍣(⍵-1)¨chars ⍝ Length ⍵ superstrings of each char
⍪↑⊃,/superstrings ⍝ Return flat matrix
⍝ One-liner: ⍪↑⊃,/{⊃,/(⊆∘.,1↓rules⊃⍨chars⍳(⊃⌽))¨⊆⍵}⍣(⍵-1)¨chars
}
|