Last active
April 2, 2023 10:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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