Last active
February 3, 2026 20:19
-
-
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
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 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