3 ms·
Your solution is more concise and I like the way it reads, but I'm not sure it actually fulfills the problem definition: As the page explains: The goal of thi
by rpeden 7y ago
Your solution is more concise and I like the way it reads, but I'm not sure it actually fulfills the problem definition:
As the page explains:
The goal of this task isn't to simply process the four lists of words with explicit, deterministic program flow such as nested iteration, to trivially demonstrate the correct output. The goal is to implement the Amb operator, or a facsimile thereof that is possible within the language limitations.
- tigershark 7y agoI completely agree, but it’s an almost generic way of solving that problem in C#. It’s pretty much equivalent to the F#, Haskell and python list comprehension solution listed in that page. The only difference is that the F# and Haskell solutions are kind of cheating creating an amb function that is just id (the identity function) while the python solution is more honest because you don’t really need amb to solve that problem with list comprehension (or the list monad). My solution is not completely generic just because of the limitations in C# LINQ query syntax that requires you to use the equals keyword and you can have the second argument appear only after the equals keyword, so for example I had to cheat using b / 8 in the solution (instead of the more obvious a*b == 8) to find the number that multiplied by themselves give 8. So in that case it will explode if 0 is an element of the second array, and it’s easily solved just by adding a where clause in the definition of the second array, but I didn’t want to overcomplicate the solution because it doesn’t add anything useful about the general problem. If I wanted to cheat like the F# and Haskell solutions I could have added just this line: T[] Amb(params T[] l) => l; and I would have defined the arrays in this way: var w1 = Amb("the", "that", "a"); But i thought that it was an unnecessary gimmick just to have the Amb operator appear there even if it’s not needed (0 lines of code Amb definition as some comments in here suggest).