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

Factorial function seems to not work #39

Open
yohannesm opened this issue Jul 18, 2018 · 6 comments
Open

Factorial function seems to not work #39

yohannesm opened this issue Jul 18, 2018 · 6 comments

Comments

@yohannesm
Copy link

I can't refer the variable result that's definitely in scope for the function for some reason.

Also, Looking at the source code, the code is actually different than the one shown here.

scala_exercises_factorial_error

@FRosner
Copy link
Member

FRosner commented Jul 18, 2018

Thanks for reporting this. Why are you trying to subtract result here? When expanding the function call for factorial(3) and factorial(4) on paper what will your solution yield?

@yohannesm
Copy link
Author

oh my bad. It should be -1. Instead of result, but I still feel weird why I can't reference that whilst it's being referenced next to it. Anyway you can close it then, not really an issue.

@FRosner
Copy link
Member

FRosner commented Jul 18, 2018

No problem. I agree with you that it is weird and I am curious about the difference in the code. Could you send a link to the line in the code? You can do so by opening the file on GitHub and then clicking on the line number. Then you can copy the link from your address bar :)

@mzacha02
Copy link

mzacha02 commented Oct 5, 2019

def factorial(n: Int): Int =
if (n == 1) n
else factorial(n - 1) * n

factorial(3) shouldBe 6
factorial(4) shouldBe 24

this is not working as is coming back with error ERROR -> not found: value n at [224, 224, 224]

I run the code in my IDE and is working buty in your test n is not recognised.

@vtripolitakis
Copy link

def factorial(n: Int): Int =
if (n == 1) n
else factorial(n - 1) * n

factorial(3) shouldBe 6
factorial(4) shouldBe 24

this is not working as is coming back with error ERROR -> not found: value n at [224, 224, 224]

I run the code in my IDE and is working buty in your test n is not recognised.

this answer should also be accepted

@fixablecar
Copy link

Error related to dependency was shown whatever I put in the answer box in this Function Loops tutorial page.

Evaluation failed : Unresolved Dependency : Error downloading org.scala-exercises:exercises-scalatutorial_2.13:0.6.0-SNAPSHOT not found: /app/.ivy2/local/org.scala-exercises/exercises-scalatutorial_2.13/0.6.0-SNAPSHOT/ivys/ivy.xml not found: https://repo1.maven.org/maven2/org/scala-exercises/exercises-scalatutorial_2.13/0.6.0-SNAPSHOT/exercises-scalatutorial_2.13-0.6.0-SNAPSHOT.pom not found: https://oss.sonatype.org/content/repositories/releases/org/scala-exercises/exercises-scalatutorial_2.13/0.6.0-SNAPSHOT/exercises-scalatutorial_2.13-0.6.0-SNAPSHOT.pom not found: https://oss.sonatype.org/content/repositories/snapshots/org/scala-exercises/exercises-scalatutorial_2.13/0.6.0-SNAPSHOT/exercises-scalatutorial_2.13-0.6.0-SNAPSHOT.pom

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

No branches or pull requests

5 participants