Last active
August 29, 2015 14:21
-
-
Save jsvensson/b9b1f42ce3d8e89261bc to your computer and use it in GitHub Desktop.
Revisions
-
jsvensson revised this gist
May 21, 2015 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,8 @@ class Josephus { def prisoners = (1..size).toArray() while(prisoners.length > survivors) { (steps-1).times { prisoners = prisoners.tail() + prisoners.head() } // Execute first prisoner prisoners = prisoners.tail() -
jsvensson created this gist
May 21, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ class Josephus { void execute(size = 41, steps = 3, survivors = 2) { def prisoners = (1..size).toArray() while(prisoners.length > survivors) { // Ugly hack to rotate a list (steps-1).times { def first = prisoners.head() prisoners = prisoners.tail() + first } // Execute first prisoner prisoners = prisoners.tail() } println("${prisoners.length} prisoners left") println(prisoners) } }