Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:11
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 dacr/7f48d5a6355a40dfcc0ef680d96c0d64 to your computer and use it in GitHub Desktop.
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/892b4bea0636ed6fa0642a7559897ca574c663f6
// summary : integer permutations up to a given value
// keywords : scala, permutations, wip
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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