11 votes
Accepted

Sorting lists by various measures of goodness

You could try that: ...
Didier Dupont's user avatar
10 votes
Accepted

Game of Life in Scala with a sparse representation

You have an interesting implementation. I like your approach into making it "boundless" (that it could expand as-needed). I also like how you use "streams" to compute the values lazily. And some other ...
Sebastian N.'s user avatar
9 votes
Accepted

Improvements, TicTacToe in Scala

Sorry for the ridiculously long answer. I've added an (in my opinion) better way of doing this at the very bottom. Here are a few things you could improve: ...
user's user avatar
  • 499
8 votes
Accepted

Convert time 24hr format into time as words

Output quality $ scala time.TimeAsWords 00:01 One minute past twelve before midday. $ scala time.TimeAsWords 11:58 Two minutes to twelve before midday. I would ...
200_success's user avatar
7 votes

All RGB colors in one image

For a first try in Scala, this code is a nice attempt. There are not so many rudiments of imperative style programming, which are usually frequent. It is also quite concise and structured, which ...
Antot's user avatar
  • 3,647
7 votes
Accepted

Implement `Penultimate` in Shapeless

More static types One big improvement you could make would be to have the Penultimate.apply method provide the output type in its signature. For example, with your ...
Travis Brown's user avatar
7 votes
Accepted

Extracting numeric values from a string containing key:value pairs

You usually want a zero-width word boundary \b on either end of the regex, to avoid matching things like 1a:1a. There's no need ...
Oh My Goodness's user avatar
7 votes
Accepted

Computing average duration per user from a large CSV file that doesn't fit in memory

This is a comment on your Python solution (I don't know anything about Scala). You don't need to iterate over chunks of your file unless you want to do parallel processing. However, since there might ...
Graipher's user avatar
  • 40.9k
6 votes
Accepted

Rate limiter utility class

Slow tests The tests run slow because of the Thread.sleep calls. It would be better to inject a "time provider" in the implementation, so that you can fake ...
janos's user avatar
  • 111k
6 votes

Intersection function in Scala

intersecton(List(1, 2, 4), List(4, 5, 6)) incorrectly returns None. You've asked several questions recently, and I keep seeing ...
200_success's user avatar
6 votes
Accepted

Sieve of Eratosthenes performance; Scala very slow compared to Node.js

Lists vs. Arrays The Scala version of your code ran surprisingly slower because you used a ListBuffer. In Scala you can think of a ...
t. fochtman's user avatar
  • 1,557
6 votes
Accepted

Compare ZIP codes, disregarding leading zeros

The title of your post is Compare ZIP codes, disregarding leading zeros The solution is simple -- just drop the leading zeros. Then you can compare the strings directly. This leads us to ...
Nathan Davis's user avatar
6 votes

Functional K-way merge (Merge k sorted sequences)

I've been thinking about this question literally for weeks. It always seemed like this implementation suffers from "hammer syndrome" - if you have a really good hammer, you want to think every ...
Donald.McLean's user avatar
6 votes
Accepted

Scala Parentheses Balancing in Functional Programming

Style Type inference Scala supports type inference. Explicitly annotating the type of something whose type is obvious does not improve readability. You should annotate the types of your public APIs, ...
Jörg W Mittag's user avatar
5 votes

Merge sort in one Single Function in Scala

Let me very clear here: I don't like what you have done and I don't like what you want to do. With that out of the way, however, let me explain myself: Scala is heavily inspired by the functional ...
Tamoghna Chowdhury's user avatar
5 votes
Accepted

General FizzBuzz in Scala

Map is not guaranteed to impose or preserve any order for its entries. For example, if I change Factors to … ...
200_success's user avatar
5 votes
Accepted

Replace array element with multiplication of neighbors in Scala

The tricky part of this problem is how to handle the special cases for the start and end of the list, as well as how to handle short lists with fewer than three elements. The fact that you need to ...
200_success's user avatar
5 votes
Accepted

Improving my Tic Tac Toe Solution in Scala

you can remove main method and use extends App. It's safe 3 line of code. replace ...
Mikhail Ionkin's user avatar
5 votes

Scala Parentheses Balancing in Functional Programming

First off, I'm not sure why processChar throws an IllegalArgumentException on non-paren characters - wouldn't it be fine to just ...
Sara J's user avatar
  • 3,422
4 votes
Accepted

Limit HTTP request rate for spray/akka-http

I think you could rewrite your limit function like this : ...
Olivier's user avatar
  • 56
4 votes
Accepted

Anagram in Scala

Overall, short and sweet, with good detailed tests. Performance The anagram field (the subject) is lowercased and sorted many times. You could do perform these ...
janos's user avatar
  • 111k
4 votes

Monte-Carlo method to estimate Pi runs slower in multiple threads, than in single thread

The cause of the long execution times in the multithreaded case were the use of static methods, fields, objects. In the scala code code above, if I change the Circle class to object: ...
Adamsan's user avatar
  • 201
4 votes

Taking some JSON data, converting the date format and calculating a user average

This answer is by no means complete but I would like to give you a few hints. Use for-loops sparingly, prefer combinators - map, flatMap, filter, zip etc. For example in the last snippet, instead of ...
fahrenx's user avatar
  • 41
4 votes
Accepted

Sum of multiples of 3 or 5 below 1000 in Scala

In the Scala solution as in the Erlang solution, the accumulator is pointless. For max = 1000, you don't necessarily have to be concerned about tail recursion, and ...
200_success's user avatar
4 votes
Accepted

Sum of HList (where all elements are Nat's)

First for some little things. I'd put bounds on the L type parameter and the Out type member to capture the facts that you know ...
Travis Brown's user avatar
4 votes
Accepted

Producer - multiple consumer implementation using futures

I notice several things. You have a data race on the shared queue. The consumer has an unsynchronized access to the nonEmpty property. The ...
Sebastian Redl's user avatar
4 votes
Accepted

Scala Codility GenomicRangeQuery performance

The basic task here is to search for the minimum value in the current subset, but there is a known floor value so it would be nice if we could terminate the search early if the floor value is ...
jwvh's user avatar
  • 1,463
4 votes
Accepted

List replication problem from Hacker rank

Use scala.collection.generic.SeqFactory.fill(n:Int)(elem: =>A) instead of your self written one: ...
Zeta's user avatar
  • 19.3k
4 votes

Scala tic-tac-toe no mutable state

I won't comment about your algorithm, as I understand that that's not the focus of this review - suffice it to say that there are better ways of checking winning than comparing against hard-coded ...
Tamoghna Chowdhury's user avatar
4 votes

List of Happy Numbers in scala

Just a nitpick about naming: the "find" in findSquareSum is meaningless, and perhaps even misleading, since it's not searching for anything. Just ...
200_success's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible