Skip to content

Instantly share code, notes, and snippets.

@brunkb
Created February 1, 2016 17:24
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 brunkb/cdbbbf2ddfdd3d420c73 to your computer and use it in GitHub Desktop.
Save brunkb/cdbbbf2ddfdd3d420c73 to your computer and use it in GitHub Desktop.
Scanner as a recursive function
String testString = "SOSSOSSDSSKS"
def countSOS = { index = 0, count = 0 ->
println "${testString}, ${index}, ${count}"
index > testString.size() - 1 ?
count : curry(index + 1, count += (testString[index] != "SOS"[index % 3] ? 1 : 0)).call()
}.trampoline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment