Questions tagged [scala]

Scala is a general purpose programming language principally targeting the Java Virtual Machine. Designed to express common programming patterns in a concise, elegant, and type-safe way, it fuses both imperative and functional programming styles.

Filter by
Sorted by
Tagged with
2
votes
0answers
233 views

Scala Performance in Solving Sudoku

I translated Peter Norvig Python Sudoku solver to Scala and my Scala implementation was slower in the order of few magnitudes e.g. instantaneous, in Python, vs 4 to 5 seconds. I suspected I didn't ...
0
votes
1answer
71 views

Translate boolean flags to collection of numbers in scala

I'm having trouble to implement the following requirement in a functional way in scala. Given a predefined number of boolean flags, I want to build up a collection of numbers. For each (true) flag, a ...
3
votes
1answer
162 views

Scala Codility GenomicRangeQuery performance

I solved Codility's GenomicRangeQuery challenge in Scala. We are given a long DNA sequence (up to 100000 bases), where A, C, G, T are assigned values 1, 2, 3, 4, respectively. There are up to 50000 ...
2
votes
1answer
88 views

Generate a sequence of coin flips until pattern is hit

A book on probability says that a sequence of heads and tails is generated by a fair coin asking what is the probability that the pattern T, H, H, H occurs before the pattern H, H, H, H. I have made a ...
3
votes
1answer
679 views

Producer - multiple consumer implementation using futures

I've tried to implement a producer-multiple consumer pattern using futures and I was wondering should it ever deadlock, and if it should, why? I have this method ...
1
vote
0answers
90 views

Scala Functional Programming ODE Solver

I'm new to both Scala and Functional programming. I've been doing the excellent course Functional Programming Principles in Scala on Coursera and I want to test out what I've learned. I've written a ...
5
votes
1answer
167 views

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: ...
0
votes
1answer
1k views

Re-inventing the wheel: Binary search in Scala

I am trying to implement the code described in this post about how Reddit uses binary search to identify duplicate user names, in Scala. Just to clarify, this is mainly for me figuring out how these ...
1
vote
0answers
76 views

Extending a simple Tree parser and lexer

Yesterday, I decided to learn about scala's Parser-Combinator library. After a while, I was able to write a simple Tree parser and lexer which understands trees written like this: ...
3
votes
1answer
656 views

Scala traits for arithmetic expressions

I am learning Scala and want to know, what is preferred style of writing a function for a trait. First: ...
3
votes
1answer
81 views

Akka actor to calculate a soccer league rank

I am new to Scala / Akka and this is my first attempt at writing an actor. The task that I am trying to accomplish is: given a sequence of soccer matches, generate a ranking based on the usual rules ...
4
votes
1answer
352 views

Reverse Polish Notation calculator in Scala

I wrote an RPN solver in Scala. I'd love to get some feedback on approaches to make this feel more idiomatic. ...
3
votes
1answer
2k views

All combinations of 2-value variables

Introduction This code was part of one of my projects where it was used to generate boolean input values for truth tables. I have since generalized it for combinations of variables with only 2 values,...
8
votes
1answer
272 views

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

I am new to Scala so it might show. I am learning it for one of my classes and have to write a performance benchmark. I have written the Sieve of Eratosthenes in both Node.js and Scala, and my Node.js ...
6
votes
0answers
365 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
2
votes
1answer
991 views

Find maximum distance between elements of an array

I have written a program in scala which actually does the below For every number between the maximum and minimum value of the array calculate the distance for each and every element in the array ...
2
votes
2answers
63 views

Alternate Tree implementation

I am trying to implement algorithms related to trees in Scala. I have dabbled with the following implementations of a tree. Are there any pros and cons of preferring the non-...
5
votes
0answers
64 views

HListSum - Sum of HList's Nat's

I wrote HListSum, whose type parameter is an input HList. Its Out type member represents the ...
2
votes
1answer
193 views

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

I wrote the following to output, at the type level, the sum, Nat, of an input HList: ...
3
votes
3answers
1k views

Find next prime

I wrote small app finding next prime number starting from number passed as argument: ...
3
votes
0answers
38 views

Simplified Kata of BankOCR using Shapeless

I attempted to solve a simplification of User Story 2 using shapeless: Namely, define the implementation of: ...
3
votes
1answer
273 views

Haskell Parsec library implementation in Scala

I've been developing a compiler for a programming language I'm working on in Scala, and after having used Haskell's Parsec a lot for this sort of thing in the past I decided to reimplement the library ...
2
votes
1answer
225 views

Functional API wrapper written in Scala

I've been working on an small API wrapper for the GitHub API using Scala (full source on GitHub). I'm still very new to the language, so I was hoping to get some feedback about a couple of design ...
4
votes
1answer
506 views

Heap Sort in Scala

Trying to implement Heap Sort in Scala ...
2
votes
0answers
135 views

Reduce sample rate of GPS data based on distance between points

The algorithm needs to reduce an RDD[GPSRecord] based on the distance between several points, e.g. "give me only GPS records when the distance between them exceeds ...
0
votes
1answer
175 views

Scala implicit conversion to add methods to Int

I started learning Scala, and like most functional languages, things get messy pretty quickly for a beginner. Here I have built a wrapper class for Ints so that I ...
4
votes
1answer
274 views

Implement `Penultimate` in Shapeless

I attempted to define Penultimate, i.e. a type class for shapeless.HList's that have a second to last element. ...
1
vote
0answers
46 views

cake pattern object assembly - using a builder function in combination with the cake pattern

I am new to the cake pattern, this is my first attempt at using it. Am I doing something wrong if I use the apply method in ...
1
vote
0answers
45 views

Cake Pattern with implicitly added functionality

I have a scenario where I want to implement a variant of a Cake Pattern, but adding implicit functionality to a class (a Spark DataFrame). So, basically, I want to be able to run a code like the ...
-1
votes
1answer
1k views

Cartesian product in Scala

I'm using this code to compute a cartesian product: ...
2
votes
0answers
146 views

Calculating Pi to a tolerance

I'm taking my first steps in the Scala world, though I'm not wholly unfamiliar with functional style. Apparently one way of calculating Pi is to sum the terms of the infinite series: $$4 * (\frac{1}{...
1
vote
1answer
574 views

Singly linked list in Scala

I've written a basic implementation of a singly linked list in Scala. I would appreciate any feedback and improvements (especially the remove() method, I feel like ...
1
vote
1answer
71 views

Extends Scala iterator's drop method to allow for drop(x: Long)

I have a need to drop quantities of elements from an iterator beyond Int.MaxValue so I wrote a helper function that does just that. However, I can't help but feel ...
0
votes
1answer
520 views

Sort Stack using just an additional stack

The problem is from the cracking coding Interview programming book. The problem is that: Sort Stack: Write a program to sort a stack such that the smallest items are on the top. You can use an ...
5
votes
0answers
718 views

Akka Streams Flow through a cache

Assume I have a cache: ...
1
vote
1answer
106 views

Finding a passcode by comparing MD5 result

This function finds the 8 char passcode from a given "doorId". Is there a way to find the passcode in an undetermined number of steps without using a while? Maybe ...
2
votes
2answers
807 views

Intersection function in Scala

The problem is: Intersection: Given two (singly) linked lists, determine if the two lists intersect. Return the intersecting node. Note that the intersection is defined based on reference, not ...
2
votes
2answers
657 views

Check if a linked list is a palindrome in Scala

The problem: Palindrome: Implement a function to check if a linked list is a palindrome If it's a palindrome, the list must be the same backwards and forwards Below is the code I wrote: ...
1
vote
3answers
946 views

Sum Lists function in Scala

Sum Lists: You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1 's digit is at the head of the list. ...
0
votes
1answer
319 views

Check Permutation in Scala

The problem is: Given two strings, write a method to decide if one is a permutation of the other. I wrote the following code in scala, may I know any other optimization one? ...
4
votes
1answer
1k views

Merge sort in one Single Function in Scala

I have implemented a sortmerge in Scala in one single function. I would like to have it reviewed, so that I can have it well organized, and it is then doing what ...
3
votes
1answer
142 views

MarsRover in Scala

This is my first attempt at Scala programming. I tried to be functional but I'm not sure if I have achieved that. DataTypes.scala ...
1
vote
1answer
474 views

Print Connected Components Scala

Given a file containing adjacent IDs: i1, i2, i5 i3, i4 i2, i6, i7 i4, i8 i9, i3 I would like to print each of the connected components: ...
2
votes
1answer
320 views

FizzBuzz in Scala

As the title suggests, this is my FizzBuzz implementation in Scala. I started learning Scala (and functional programming in general) in small steps about two months ago, and one recent assignment ...
4
votes
1answer
529 views

A general-use For-comprehensible Loan Pattern

I use Scala's loan pattern in order to ensure and automate the resource aquisition and release after its use. When multiple resources have to be acquired at once, however, the function calls must be ...
3
votes
4answers
158 views

Displaying nested arithmetic expressions as a string using Scala pattern matching

I am learning the concepts of pattern matching in Scala. Following is an exercise for the same. The task is to define a show function that outputs an expression as ...
2
votes
1answer
1k views

Generating Fibonacci sequences in Scala

Would you consider this to be idiomatic Scala? If not, what would you do to improve it? ...
14
votes
1answer
325 views

All RGB colors in one image

This is a program to solve: Images with all Colors from Code Golf: Make images where each pixel is a unique color (no color is used twice and no color is missing). Create the image purely ...
2
votes
2answers
630 views

Sum of multiples of 3 or 5 below 1000 in Scala

I'm in the process of learning Scala, and started working through a series of coding puzzles that I've done previously in other languages. For example, this solution, coded in Erlang: ...
1
vote
1answer
527 views

Convert a List of graph edges to a Map of neighboring nodes

What would be best way achieving this? Is it possible to use Immutable map? ...

1 2 3 4 5 10