Tagged Questions
5
votes
3answers
132 views
Pair matching elements from two lists
Here is a method that takes two lists (l1 and l2) and pairs up elements that "match". As you can see at the end of the code ...
4
votes
1answer
825 views
Tail-recursive factorial
Is there anything what could be improved on this code?
def factorial(n: Int, offset: Int = 1): Int = {
if(n == 0) offset else factorial(n - 1, (offset * n))
}
...
3
votes
2answers
146 views
Pascal triangle algorithm is good but fails
I have created a function which returns the number that corresponds to the given row and column from the pascal triangle. I have used the formula for this:
n! / r! * (r-n)!
The code:
...
3
votes
1answer
781 views
Recursive branch and bound for knapsack problem
I've got the imperative styled solution working perfectly.
What I'm wondering is how to make a recursive branch and bound.
This is my code below, Evaluate function returns the optimistic estimate, ...
2
votes
3answers
165 views
Is this a correct recursive Scala iterator creation?
I am diving into Scala (using 2.10) headfirst and am trying out a simple task of taking bulk data and then doing something with that stream. The first part is generating that stream. I have seem to be ...
2
votes
2answers
644 views
Code review of Pouring water from code chef using Scala
I had posted this question on Stackoverflow and it seems like code review might be a better venue for my query. My question is as follows:
I am trying to solve the pouring water problem from codechef ...
1
vote
2answers
58 views
Recursively print in scala
I have just picked up Scala like 2 hours ago, and I am thinking of printing a series like 1 to 10 but in a recursive fashion. I do not understand what is wrong with this:
...