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.3.scala #70

Merged
merged 4 commits into from
Sep 30, 2024
Merged

solution2.5.2.3.scala #70

merged 4 commits into from
Sep 30, 2024

Conversation

andreas-roehler
Copy link
Contributor

No description provided.


def cubesReach1(x: Int): Boolean = {
val a = Cubes.cubes(x)
a.length == 1
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this condition a.length == 1? The question was, whether the sequence of "cubes" ever reaches the number 1, not whether that sequence consists of a single element.

}

def cubesReach1(x: Int): Boolean = {
val a = Cubes.cubes(x)
Copy link
Owner

Choose a reason for hiding this comment

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

Warum hier Cubes.cubes(x) und nicht einfach cubes(x)? Die Funktion cubes wurde gerade definiert.

Signed-off-by: Andreas Roehler <[email protected]>
val a = Cubes.cubes(x)
a.length == 1
val a = cubes(x)
a.length == 1 && a(0) == 1
Copy link
Owner

Choose a reason for hiding this comment

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

Why is the condition a.length == 1 necessary?

Copy link
Owner

@winitzki winitzki Sep 30, 2024

Choose a reason for hiding this comment

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

Here are some tests that I would suggest:

assert ( cubesReach1(20) == false )
assert ( cubesReach1(50) == false )
assert ( cubesReach1(100) == true )
assert ( cubesReach1(112) == true )
assert ( cubesReach1(114) == false )
assert ( cubesReach1(778) == true )

For example, the sequence for 778 is [1198, 1243, 100, 1].

Signed-off-by: Andreas Roehler <[email protected]>
@winitzki winitzki merged commit 181a602 into winitzki:master Sep 30, 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