I don't think it can be done in O(n). Your own solution isn't either, it's O(n^2) just like this one. I think it can be done in O(n log n) or O(n*w) ( where w = bit width of n ), but no better.
People will vote lots of bad oneliners Clever and even Best Practice. (!!) indeed is a bad idea here, as it is almost always.
Confused as to why this solution is considered best practice and clever. It's a fairly simple solution that is at least O(n^2) for a problem that can be solved in O(n). The (!!) operator is also fairly inefficient.
Well, gosh. I understand how fix works but I don't know how to make these functions applicable, as the way I'd usually define these would involve calling secondary functions recursively. But with fix, as far as I can see, you can only recur on the primary, main function.
I'll sleep on it; after all, this is Haskell—there's always a trick!
EDIT: I should point out that I have solutions, just they are not in O(n) time and so they fail the "Submit" test :/
This comment is hidden because it contains spoiler information about the solution
I was afraid that there would be phrases like "TREE FIDDY" or "THREE FIFTY", and wrote unnecessary command s.toLowerCase().
i did something similar but i find it not very functional
This comment is hidden because it contains spoiler information about the solution
Q: Does this have a problem with empty input?
but it's beautiful of list monad ;)
This comment is hidden because it contains spoiler information about the solution
Fixed
You're right,
parse
is only a partial function.I don't think it can be done in
O(n)
. Your own solution isn't either, it'sO(n^2)
just like this one. I think it can be done inO(n log n)
orO(n*w)
( where w = bit width of n ), but no better.People will vote lots of bad oneliners Clever and even Best Practice.
(!!)
indeed is a bad idea here, as it is almost always.Confused as to why this solution is considered best practice and clever. It's a fairly simple solution that is at least O(n^2) for a problem that can be solved in O(n). The (!!) operator is also fairly inefficient.
Great solution, but it does not work with this limitation: "input may contain any valid ASCII characters"
Well, gosh. I understand how fix works but I don't know how to make these functions applicable, as the way I'd usually define these would involve calling secondary functions recursively. But with fix, as far as I can see, you can only recur on the primary, main function.
I'll sleep on it; after all, this is Haskell—there's always a trick!
EDIT: I should point out that I have solutions, just they are not in O(n) time and so they fail the "Submit" test :/
The sample test for laziness is calling foldr instead of fixFoldr in Haskell
Loading more items...