-
-
Save rsp/a43d817e67a70815ec3fcbf58657dfbc to your computer and use it in GitHub Desktop.
inFullMobile Language Wars: Round 1 - Kotlin Solution 1 by @rainqer - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.infullmobile.languagewars | |
fun f(a: ((Int) -> Int) -> ((Int) -> Int)): ((Int) -> Int) -> (Int) -> Int { | |
val invocationCount = a(increment)(0) | |
return if (invocationCount > 0) { x: (Int) -> Int -> { input -> applyXTimes(x, invocationCount - 1)(input) } } | |
else { _ -> { input -> input } } | |
} | |
fun applyXTimes(x: (Int) -> Int, count: Int): (Int) -> Int | |
= { argument -> (1..count).fold(argument, { acc, _ -> x(acc) }) } | |
val increment: (Int) -> Int = { counter -> counter + 1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment