Skip to main content
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
  • 539
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
  • 41.7k
7 votes
Accepted

Improving my Tic Tac Toe Solution in Scala

you can remove the main method and use extends App. It's free 3 lines of code. replace ...
Mikhail Ionkin's user avatar
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 something ...
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
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

Improving my Tic Tac Toe Solution in Scala

You are right that the readMove could be made better. There's no need for throwing an exception, especially since you're catching it immediately. A simple if/else ...
user's user avatar
  • 539
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
  • 4,221
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
4 votes
Accepted

Print words in decreasing order of frequency in Scala

Using just a priority queue Yes, it's possible, although you would need a special implementation of priority queue, which internally is a hash map + a heap. This trick is commonly used in Dijkstra's ...
Sumik's user avatar
  • 111
4 votes
Accepted

Clean up tags from a text

Beautify your regex Say No to Pattern.compile and instead of Pattern.compile("^((?!(\\{.*\\})).)*$") use scalish ...
Gudsaf's user avatar
  • 176
4 votes
Accepted

Checking whether a graph is connected in an immutable way

completeness Code posted to Code Review should be complete, correct, and ready for review. You've got everything here except for the import statement needed to ...
jwvh's user avatar
  • 1,473
3 votes
Accepted

Scala type matching map

It's been a couple of months so maybe you've moved on, but I had a look through this today. I also may have read too much into your example use case, so apologies if this isn't helpful. If like in ...
Daniel's user avatar
  • 46
3 votes

Take a number and sum its digits raised to the consecutive powers

Recommendations: For starters I would recommend passing an Int to your function and then converting it to a String before ...
t. fochtman's user avatar
  • 1,607
3 votes
Accepted

Shell script to parse variable definitions from Scala build file

If you don't mind spinning up sbt to extract the settings keys you could use the following: ...
t. fochtman's user avatar
  • 1,607
3 votes

Shell script to parse variable definitions from Scala build file

I'd use awk to generate shell syntax, and source it in the shell: ...
glenn jackman's user avatar
3 votes
Accepted

Report a status based on a list of results

Something like this maybe? ...
Dima's user avatar
  • 191
3 votes

Construct date sequence in Scala

Any better/simple solution to do this ? Yes. Functionality now built into Java 9 and later. java.time.LocalDate::datesUntil ➙ Stream of ...
Basil Bourque's user avatar
3 votes

Compare ZIP codes, disregarding leading zeros

This would be my approach. ...
jwvh's user avatar
  • 1,473
3 votes
Accepted

Joining Apache Spark data frames, with many conditional substitutions

Indeed, the sequence of when statements is very repetitive and can be refactored. All whens are similar, except the last one, ...
Antot's user avatar
  • 3,742
3 votes
Accepted

Reading a certain number of lines from a file

That implementation is very procedural. getLines() returns an Iterator, which supports a ...
200_success's user avatar
3 votes
Accepted

Solution to a simple Hackerrank problem: Compare the Triplets

You don't have to traverse the competitions array twice. The results can be collected in a tuple result after a single traversal. ...
jwvh's user avatar
  • 1,473
3 votes
Accepted

Program to calculate some stats from Facebook messages

First of all, it should be underlined that the code in the question is quite neat, clean, readable and adequate to the task to solve. However, I have several suggestions, but they are more a kind of ...
Antot's user avatar
  • 3,742
3 votes
Accepted

Binary search in Scala

Your code can be much improved by adding a few data structures: ...
lex82's user avatar
  • 1,153
3 votes
Accepted

List of Happy Numbers in scala

In findSquareSum(), what you've labelled as product is actually a sum. So that's a little confusing. The digits squared is a ...
jwvh's user avatar
  • 1,473
3 votes

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

Graipher's answer already addresses some of the higher-level issues with your Python solution. Like him, I cannot speak to the Scala solution. Instead, I'll focus on your core function and how to ...
aghast's user avatar
  • 12.6k

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