Skip to main content

All Questions

Tagged with
3votes
1answer
319views

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 ...
Martin Boros's user avatar
2votes
0answers
187views

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 ...
Maths noob's user avatar
1vote
1answer
121views

Find first repeating Char in String

Given a string, find the first repeating character in it. Examples: firstUnique("Vikrant")None ...
vikrant's user avatar
4votes
2answers
450views

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 ...
vikrant's user avatar
1vote
1answer
99views

Check if list contains a pair which adds up to a given sum

Kindly review this scala code for given problem and suggest improvements. Problem - Given an array of integers and a target sum, check if array contains a pair which adds up to sum. Example - <...
vikrant's user avatar
5votes
1answer
249views

Bowling game Kata in Scala - pattern match

This is a functional approach to problem described by standard Bowling Game Kata - to implement the rules of calculating a score in a bowling game. The inspiration was the implementation by Uncle Bob: ...
Sebastian Kramer's user avatar
0votes
1answer
2kviews

Cartesian product in Scala

I'm using this code to compute a cartesian product: ...
Alban Dericbourg's user avatar
2votes
1answer
100views

Building and querying an immutable phone book

I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution. Here is an ...
Guillaume's user avatar
0votes
2answers
1kviews

Recursive Scala Case class Reduction

I have a case class that is recursive and looks like this: ...
joesan's user avatar
2votes
1answer
105views

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 ...
wxd's user avatar
  • 37
2votes
3answers
1kviews

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? ...
Cam Hashemi's user avatar
3votes
3answers
131views

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: ...
escargot agile's user avatar
3votes
3answers
3kviews

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: ...
Bula's user avatar
  • 369
10votes
5answers
22kviews

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 ...
Dominykas Mostauskis's user avatar
4votes
1answer
3kviews

Recursive branch and bound Knapsack solution [closed]

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, ...
Looft's user avatar

153050per page
close