Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:19
Show Gist options
  • Select an option

  • Save dacr/7f48d5a6355a40dfcc0ef680d96c0d64 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/7f48d5a6355a40dfcc0ef680d96c0d64 to your computer and use it in GitHub Desktop.
integer permutations up to a given value / published by https://github.com/dacr/code-examples-manager #ca3f51c0-2346-4733-8aeb-6753b82a2bca/2bc231ef5aba26dcdf43f25c5c541a96eed02128
// summary : integer permutations up to a given value
// keywords : scala, permutations, wip
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : ca3f51c0-2346-4733-8aeb-6753b82a2bca
// created-on : 2020-03-25T07:24:27Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
// Baby code implementation
def walk(v:Array[Int]):Unit = {
val mm = 3
def incrementable(pos:Int): Boolean = {
if (pos >=v.size) false
else {
if (v(pos) == mm ) {
v(pos)=0
incrementable(pos+1)
} else {
v(pos) +=1
true
}
}
}
while(incrementable(0)) {
println(v.mkString(","))
}
}
walk(Array(0,0))
// higher function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment