Ad
Code
Diff
  • fun return_int(i: Int) = i
    • fn return_int(i: i32) -> i32 { i }
    • fun return_int(i: Int) = i
Code
Diff
  • fn return_int(i: i32) -> i32 { i }
    • public class Program
    • {
    • public static int GetValue(int i)
    • {
    • return i;
    • }
    • }
    • fn return_int(i: i32) -> i32 { i }
Code
Diff
  • package solution
    
    /**
    * more words, but no HEAP usage on every cycle (no Triple construction)
    */
    fun tribonacci(n: Int, signature: Triple<Int, Int, Int> = Triple(1, 1, 1)) = sequence<Int> {
       var a1 = signature.first
       var a2 = signature.second
       var a3 = signature.third
       var next = a1 + a2 + a3;
       while(true) {
           yield(a1);
           a1 = a2;
           a2 = a3;
           a3 = next;
           next = a1+a2+a3;
       } 
    }.take(n).toList()
    
    
    • package solution
    • fun tribonacci(n: Int, signature: Triple<Int, Int, Int> = Triple(1, 1, 1)) =
    • generateSequence(signature) { Triple(it.second, it.third, it.first + it.second + it.third) }
    • .map { it.first }
    • .take(n)
    • .toList()
    • /**
    • * more words, but no HEAP usage on every cycle (no Triple construction)
    • */
    • fun tribonacci(n: Int, signature: Triple<Int, Int, Int> = Triple(1, 1, 1)) = sequence<Int> {
    • var a1 = signature.first
    • var a2 = signature.second
    • var a3 = signature.third
    • var next = a1 + a2 + a3;
    • while(true) {
    • yield(a1);
    • a1 = a2;
    • a2 = a3;
    • a3 = next;
    • next = a1+a2+a3;
    • }
    • }.take(n).toList()