Skip to content

Instantly share code, notes, and snippets.

@je6bmq
Created November 5, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save je6bmq/f010704a03176aaed8cfad126758e73d to your computer and use it in GitHub Desktop.
Save je6bmq/f010704a03176aaed8cfad126758e73d to your computer and use it in GitHub Desktop.
tailrec fun PPAP( pcount:Int=0, isA:Boolean=false)
{
val rnd=Random()
val c=if (rnd.nextBoolean()) "P" else "A"
print(c)
when(c)
{
"P" -> when{
isA && pcount>=2->println("")
else ->PPAP(pcount+1,false)
}
else ->PPAP(if (isA||pcount<2) 0 else pcount,true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment