You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
1.9 KiB

  1. function herman() {
  2. int x1 := 0;
  3. int x2 := 0;
  4. int x3 := 0;
  5. int x4 := 0;
  6. int x5 := 0;
  7. int x6 := 0;
  8. int x7 := 0;
  9. int x8 := 0;
  10. int x9 := 0;
  11. int x10 := 0;
  12. int oldx1 := 0;
  13. int oldx2 := 0;
  14. int oldx3 := 0;
  15. int oldx4 := 0;
  16. int oldx5 := 0;
  17. int oldx6 := 0;
  18. int oldx7 := 0;
  19. int oldx8 := 0;
  20. int oldx9 := 0;
  21. int oldx10 := 0;
  22. // determine starting token setup on the ring.
  23. {x1 := 0;} [] {x1 := 1;}
  24. {x2 := 0;} [] {x2 := 1;}
  25. {x3 := 0;} [] {x3 := 1;}
  26. {x4 := 0;} [] {x4 := 1;}
  27. {x5 := 0;} [] {x5 := 1;}
  28. {x6 := 0;} [] {x6 := 1;}
  29. {x7 := 0;} [] {x7 := 1;}
  30. {x8 := 0;} [] {x8 := 1;}
  31. {x9 := 0;} [] {x9 := 1;}
  32. {x10 := 0;} [] {x10 := 1;}
  33. // finds a ring configuration with exactly one token in the ring.
  34. while((x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10) != 1) {
  35. oldx1 := x1;
  36. oldx2 := x2;
  37. oldx3 := x3;
  38. oldx4 := x4;
  39. oldx5 := x5;
  40. oldx6 := x6;
  41. oldx7 := x7;
  42. oldx8 := x8;
  43. oldx9 := x9;
  44. oldx10 := x10;
  45. if(x1 = oldx10) {
  46. {x1 := 0;} [0.5] {x1 := 1;}
  47. } else {
  48. x1 := oldx10;
  49. }
  50. oldx10 := 0;
  51. if(x2 = oldx1) {
  52. {x2 := 0;} [0.5] {x2 := 1;}
  53. } else {
  54. x2 := oldx1;
  55. }
  56. oldx1 := 0;
  57. if(x3 = oldx2) {
  58. {x3 := 0;} [0.5] {x3 := 1;}
  59. } else {
  60. x3 := oldx2;
  61. }
  62. oldx2 := 0;
  63. if(x4 = oldx3) {
  64. {x4 := 0;} [0.5] {x4 := 1;}
  65. } else {
  66. x4 := oldx3;
  67. }
  68. oldx3 := 0;
  69. if(x5 = oldx4) {
  70. {x5 := 0;} [0.5] {x5 := 1;}
  71. } else {
  72. x5 := oldx4;
  73. }
  74. oldx4 := 0;
  75. if(x6 = oldx5) {
  76. {x6 := 0;} [0.5] {x6 := 1;}
  77. } else {
  78. x6 := oldx5;
  79. }
  80. oldx5 := 0;
  81. if(x7 = oldx6) {
  82. {x7 := 0;} [0.5] {x7 := 1;}
  83. } else {
  84. x7 := oldx6;
  85. }
  86. oldx6 := 0;
  87. if(x8 = oldx7) {
  88. {x7 := 0;} [0.5] {x7 := 1;}
  89. } else {
  90. x8 := oldx7;
  91. }
  92. oldx7 := 0;
  93. if(x9 = oldx8) {
  94. {x9 := 0;} [0.5] {x9 := 1;}
  95. } else {
  96. x9 := oldx8;
  97. }
  98. oldx8 := 0;
  99. if(x10 = oldx9) {
  100. {x10 := 0;} [0.5] {x10 := 1;}
  101. } else {
  102. x10 := oldx9;
  103. }
  104. oldx9 := 0;
  105. }
  106. }