Skip to content

Instantly share code, notes, and snippets.

@rsp
Last active November 29, 2017 13:54
Show Gist options
  • Save rsp/a43d817e67a70815ec3fcbf58657dfbc to your computer and use it in GitHub Desktop.
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
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