6 kyu
Calculate the function f(x) for a simple linear sequence (Medium)
317 of 1,169Mackay
Loading description...
Mathematics
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
This comment has been hidden.
Fixed in Python
python new test framework is required. updated in this fork
Great work.
Further simplified the test logic & Approved (don't worry, the honor still fully awarded to you, ofc)
NO random tests in C#
Assert.AreEqual
should be usedFor me the last 5 tests fail and I'm not sure why. Should return non-linear function and mine returns a function object... any suggestions?
Great!
You clearly didn't understand me, so I've removed the ability for you to comment for now to help you understand.
Edit: the restriction has been lifted
'Non-linear sequence' should be tested in sample tests
Python: Added in saudiGuy's fork
Python 3 should be enabled.
Done.
Haskell : https://www.codewars.com/kumite/5b9079b190a897f032000161?sel=5b9079b190a897f032000161
Fun Kata ! Made me think more abstract than normal.
PHP Translation Kumited - please accept :D
C# tests should use Assert.AreEqual(foo,bar) rather than Assert.True(foo==bar), so the "test failed" output will display the value the user's function generated. Makes for much easier debugging.
I liked the challenge of having to return a function. Nice twist!
what's the last test? I always got this: Nope! Try again. - Expected: Non-linear sequence, instead got: undefined
Which language? JavaScript? Most likely, you forgot to
return
in one of your branches.I mean I passed every test except the last one...so I want to see the last test array...javascript
I found my problem...I wrote 'return undefined' when the test was not linear...how absurd...
This comment has been hidden.
In case anyone else finds my experience helpful, I did this in Ruby and initially assumed a lambda should be returned either way. I assumed test cases would always look like
So I thought a non-linear sequence would need to return a lambda that always output "Non-linear sequence". In fact, the test cases do not include a
.call()
when the sequence is non-linear and so the string "Non-linear sequence" needs to be returned instead of a lambda in those cases.I had the same issue in Python, had to do a bit of debugging with calls to
print
to figure that out.Yes, you're right! Thanks so much!
I don't understand the instructions for this kata or the function invocation. As I understand it, I am suppoed to determine the function describing the linear sequence and return the term requested. I don't understand how the function is being invoked or how the requested term is being passed in. The examples show a function call like getSequence([1,2,3,4,5])(10). I wrote a function to determine the function of the linear sequence and return an arbitrary term, but I get an error when trying to access the term to generate ( that would be 10 in the example above). I tried to access it through arguments[1], but that doesn't work. Can someone clarify the instructions and how the function is used a bit?
You need to return a function from the method
getSequence
, which calculates the 'nth term' for any given value of n.So getSequence([1,2,3,4,5])(10) is equal to calling yourNewSequence(10), which should then calculate f(10) for the sequence [1,2,3,4,5].
Sorry if this isn't very clear!
This comment has been hidden.
Actually found this easier than rendering the correct function string. ;P