Skip to content

Instantly share code, notes, and snippets.

@asbubam
Last active December 16, 2015 09:39
Show Gist options
  • Save asbubam/5414698 to your computer and use it in GitHub Desktop.
Save asbubam/5414698 to your computer and use it in GitHub Desktop.
Euler scala Ex02
object Ex02 extends App {
var index = 0
var sum = 0
/*
질문1) 여기서 아래처럼 루프를 돌리려고 했으나 에러발생
var fiboResult = 0
while((fiboResult = fibo(index)) <= 4000000) {
Ex02.scala:6: error: value <= is not a member of Unit
while((fiboResult = fibo(index)) <= 4000000) {
^
one error found
function의 입력값이 같으면, 출력값도 같음이 보장되서
fibo(n)을 여러번 호출할경우, 같은 결과값이 어딘가에 저장되어 있다 사용되는지
질문2) 다들 탭사이즈는 어떻게...쓰고 계신지?
질문3) 요렇게 파일저장하고
scalac Ex02.scala,
scala Ex02
를 계속 반복해서 코딩, 테스트 했는데 더 편한방법은 없는지?
*/
while(fibo(index) <= 4000000) {
if(fibo(index) % 2 == 0) sum = sum + fibo(index)
index = index + 1
}
println("sum: " + sum)
def fibo(n: Int): Int = {
if (n == 0 || n == 1) n
else fibo(n - 1) + fibo(n - 2)
}
}
@anarcher
Copy link

저는 scala(repl)에서 :load filename.scala 으로 로딩해서 테스트하곤 합니다.

@allieus
Copy link

allieus commented Apr 29, 2013

바로 scala Ex02.scala 로 실행하는 방법이랑,

sbt 를 이용하는 방법도 있습니다. http://www.scala-sbt.org/0.12.3/docs/Detailed-Topics/Triggered-Execution.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment