All Questions
9 questions
3
votes
1
answer
335
views
Efficiently calculate value of Pascal's Triangle using memoization and recursion
So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
2
votes
0
answers
187
views
generic implementation approaches for a recursive function
Let's take the famous fibonacci problem as an example but this is a generic problem. Also, taking scala as the language as it's rather feature-rich. I want to know which solution you'd prefer.
we all ...
1
vote
1
answer
124
views
Find first repeating Char in String
Given a string, find the first repeating character in it.
Examples:
firstUnique("Vikrant") → None
...
4
votes
2
answers
452
views
Replace array element with multiplication of neighbors in Scala
Given an array of integers, update the index with multiplication of previous and next integers,
Input: 2 , 3, 4, 5, 6
Output: 2*3, 2*4, 3*5, 4*6, 5*6
Following ...
0
votes
1
answer
2k
views
Cartesian product in Scala
I'm using this code to compute a cartesian product:
...
2
votes
1
answer
116
views
Selecting subset of size k using recursion [closed]
Sometimes I need to implement recursive algorithms that pass a certain state from one recursive call to another. For example, a greedy subset selection: we have a set of candidate objects, and we ...
3
votes
3
answers
1k
views
Tail-Recursion to get a Map of word counts
I want to read a file and store the number of occurrences of each word in a Map, using tail recursion. I came up with the following; it seems to work; does it look like it's right?
...
3
votes
3
answers
134
views
Removing nested blocks from a string
I wrote this function in scala that uses tail recursion to remove nested blocks from a text.
Usage examples:
...
5
votes
1
answer
3k
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))
}
...