<commit_before>package no.knowit.scala_functional.euler_two

import annotation.tailrec
import org.junit.Test
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.is
import org.junit.Assert.assertThat


// http://projecteuler.net/problem=2
// Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
//
// 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
//
// By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

class FibonacciTest {

  // Implement classical fibonnacci, the slow one!
  // f(x) = f(x - 1) + f(x - 2) where f(1) = 1 and f(0) = 0
  def fibSlow(n: Long): Long =
    if (n <= 1) n else fibSlow(n - 1) + fibSlow(n - 2)

  // Create a tail call optimized version of fiboncacci
  // f(n) = fr(n, 0, 1)
  // fr(n, b, a) = fr(n-1, a + b, b) where fr(1) = 1 and fr(0) = 0
  def fibFastRecursive(num: Long) = {
    @tailrec
    def fib(num: Long, b: Long, a: Long): Long =
      if (num < 1) a else fib(num - 1, a + b, b);<commit_msg>Added missing runwith<commit_after>package no.knowit.scala_functional.euler_two

import annotation.tailrec
import org.junit.Test
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.is
import org.junit.Assert.assertThat
import org.junit.runner.RunWith
import org.junit.runners.JUnit4


// http://projecteuler.net/problem=2
// Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
//
// 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
//
// By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

@RunWith(classOf[JUnit4])
class FibonacciTest {

  // Implement classical fibonnacci, the slow one!
  // f(x) = f(x - 1) + f(x - 2) where f(1) = 1 and f(0) = 0
  def fibSlow(n: Long): Long =
    if (n <= 1) n else fibSlow(n - 1) + fibSlow(n - 2)

  // Create a tail call optimized version of fiboncacci
  // f(n) = fr(n, 0, 1)
  // fr(n, b, a) = fr(n-1, a + b, b) where fr(1) = 1 and fr(0) = 0
  def fibFastRecursive(num: Long) = {
    @tailrec
    def fib(num: Long, b: Long, a: Long): Long =
      if (num < 1) a else fib(num - 1, a + b, b);
{'fraction_non_alphanumeric': 0.13261802575107295, 'fraction_numerical': 0.03347639484978541, 'mean_word_length': 3.118374558303887, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6653094', 'n_tokens_mistral': 934, 'n_tokens_neox': 841, 'n_words': 308}