Padovan n-step number sequences: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way)
Line 1,067: Line 1,067:


<lang python>'''Padovan n-step number sequences'''
<lang python>'''Padovan n-step number sequences'''

from itertools import chain, islice, repeat
from itertools import chain, islice, repeat


# nStepPadovan :: Int -> [Int]
# nStepPadovan :: Int -> [Int]
def nStepPadovan(n):
def nStepPadovan(n):
Line 1,083: Line 1,083:
)
)
)
)


# recurrence :: Int -> [Int] -> Int
# recurrence :: Int -> [Int] -> Int
def recurrence(n):
def recurrence(n):
Line 1,093: Line 1,093:
return h, t + [sum(take(n)(xs))]
return h, t + [sum(take(n)(xs))]
return go
return go


# ------------------------- TEST -------------------------
# ------------------------- TEST -------------------------
# main :: IO ()
# main :: IO ()
def main():
def main():
'''First 15 terms each n-step Fibonacci(n) series
'''First 15 terms each nStepPadovan(n) series
where n is drawn from [2..8]
where n is drawn from [2..8]
'''
'''
Line 1,121: Line 1,121:
spacedTable(table)
spacedTable(table)
)
)


# ----------------------- GENERIC ------------------------
# ----------------------- GENERIC ------------------------

# take :: Int -> [a] -> [a]
# take :: Int -> [a] -> [a]
# take :: Int -> String -> String
# take :: Int -> String -> String
Line 1,138: Line 1,138:
)
)
return go
return go


# unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
# unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
def unfoldr(f):
def unfoldr(f):
Line 1,155: Line 1,155:
valueResidue = f(valueResidue[1])
valueResidue = f(valueResidue[1])
return go
return go


# ---------------------- FORMATTING ----------------------
# ---------------------- FORMATTING ----------------------

# spacedTable :: [[String]] -> String
# spacedTable :: [[String]] -> String
def spacedTable(rows):
def spacedTable(rows):
Line 1,174: Line 1,174:
for row in rows
for row in rows
])
])


# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':