3 kyu
Recurrence relations
281Ivana
Description:
Say we have a function of this type:
f :: Ord a => a -> Either b ([a], [b] -> b)
any recursive function of one argument can be implemented in such a way that it fits this type signature - provided with an argument it returns either the result (Left-case) or a pair of new arguments for the function and a function to fold the results (Right-case). For example
factorial i | i == 0 = Left 1
| otherwise = Right ([i-1], (*i).head)
fibonacci i | i < 2 = Left i
| otherwise = Right ([i-1, i-2], sum)
gives us the usual factorial and Fibonacci functions (for more examples, see the test cases).
Task
Your task is to write an evaluator for such functions, i.e a function
evaluateFunction :: Ord a => (a -> Either b ([a], [b] -> b)) -> a -> b
that takes a function of a previously described form and turns it into a simple a -> b function (again, see examples in the test cases).
Performance
Fundamentals
Similar Kata:
Stats:
Created | Mar 16, 2015 |
Published | Mar 16, 2015 |
Warriors Trained | 959 |
Total Skips | 254 |
Total Code Submissions | 1027 |
Total Times Completed | 281 |
Haskell Completions | 281 |
Total Stars | 96 |
% of votes with a positive feedback rating | 99% of 72 |
Total "Very Satisfied" Votes | 71 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 11 |
Average Assessed Rank | 3 kyu |
Highest Assessed Rank | 2 kyu |
Lowest Assessed Rank | 5 kyu |