Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution2.5.2.2.scala provided #65

Merged
merged 5 commits into from
Aug 24, 2024
Merged

Conversation

andreas-roehler
Copy link
Contributor

No description provided.

*/

def collatzSequence(n: Int, xs: List[Int] = List(0)): List[Int] =
if xs.head == 1 then xs.init
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use syntax that is compatible with both Scala 2 and Scala 3. This code uses if then else, which works only with Scala 3.

*/

def collatzSequence(n: Int, xs: List[Int] = List(0)): List[Int] =
if xs.head == 1 then xs.init
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if xs.head == 1 then xs.init
if (xs.head == 1) xs.init


def collatzSequence(n: Int, xs: List[Int] = List(0)): List[Int] =
if xs.head == 1 then xs.init
else if n % 2 == 0 then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if n % 2 == 0 then
else if (n % 2 == 0)

@winitzki winitzki merged commit 8c4be0d into winitzki:master Aug 24, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants