Skip to content

Instantly share code, notes, and snippets.

View SRechenberger's full-sized avatar
💭
:godmode:

Sascha Rechenberger SRechenberger

💭
:godmode:
View GitHub Profile
@jubinjacob19
jubinjacob19 / YCombinator.kt
Last active March 4, 2020 03:43
The Y combinator in Kotlin. A single argument Y combinator is used to find the factorial of a number.
fun main(args: Array<String>) {
if (args.count() == 0) {
println("Please input a number")
} else {
try {
val n = args[0].toInt()
val factorial = y<Int,Int> {f-> { n->
if (n == 0) 1
else n * f(n - 1)
} }