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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
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 …
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
4
votes
Accepted
Clean up tags from a text
Beautify your regex
Say No to Pattern.compile and instead of
Pattern.compile("^((?!(\\{.*\\})).)*$")
use scalish ...
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 ...
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 ...
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 ...
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:
...
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:
...
3
votes
Accepted
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 ...
3
votes
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, ...
3
votes
Accepted
Reading a certain number of lines from a file
That implementation is very procedural. getLines() returns an Iterator, which supports a ...
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.
...
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 ...
3
votes
Accepted
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scala × 494functional-programming × 105
beginner × 46
algorithm × 34
programming-challenge × 25
strings × 25
performance × 22
recursion × 18
interview-questions × 17
unit-testing × 14
error-handling × 13
comparative-review × 12
apache-spark × 12
graph × 11
akka × 11
object-oriented × 10
parsing × 10
tree × 10
sorting × 8
regex × 7
file-system × 7
immutability × 7
array × 6
design-patterns × 6
json × 6