Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shape: intCollection
  2.     | nodes intArray mySize iterator iteratorIdx iteratorUpdater  nodesCount node a b c change multipleBy|
  3.  
  4.     intArray := intCollection asArray.
  5.     mySize := intArray size.
  6.  
  7.     iterator := Array new: mySize.
  8.     nodesCount := 1.
  9.     1 to: mySize do: [:idx|
  10.         iterator at: idx put: 1.
  11.         nodesCount := nodesCount * (intArray  at: idx)
  12.     ].
  13.  
  14.     nodes := Array new: nodesCount.
  15.     1 to: nodesCount do: [:idx |
  16.         nodes at: idx put: (Torus new: mySize ).
  17.     ].
  18.  
  19.  
  20.  
  21.     1 to: nodesCount do: [:idx |
  22.         node := (nodes at: idx).
  23.  
  24.         multipleBy := 1.
  25.         1 to: mySize do: [:i |
  26.             "next"
  27.             a := iterator at: i.
  28.             b := a + 1.
  29.             (b <= (intArray at: i)) ifTrue: [
  30.                 change := multipleBy.
  31.                 c := idx + change.
  32.             ] ifFalse: [
  33.                 change := ((iterator at: i) - 1) * multipleBy .
  34.                 c := idx - change.
  35.             ].
  36.             (node next) at: i put: (nodes at: c).
  37.  
  38.             "previous"
  39.             b := a - 1.
  40.             (b > 0) ifTrue: [
  41.                 change := multipleBy.
  42.                 c := idx - change.
  43.             ] ifFalse: [
  44.                 change := ((intArray at: i) - 1) * multipleBy .
  45.                 c := idx + change.
  46.             ].
  47.             (node previous) at: i put: (nodes at: c).
  48.             multipleBy := multipleBy * (intArray  at: i).
  49.         ].
  50.  
  51.         (idx < nodesCount) ifTrue: [
  52.             iteratorIdx := 1.
  53.             iteratorUpdater := (iterator at: iteratorIdx) + 1.
  54.             [iteratorUpdater > (intArray at: iteratorIdx )] whileTrue: [
  55.                 iterator at: iteratorIdx put: 1.
  56.                 iteratorIdx := iteratorIdx + 1.
  57.                 iteratorUpdater := (iterator at: iteratorIdx) + 1.
  58.             ].
  59.             iterator at: iteratorIdx put: iteratorUpdater.
  60.         ].
  61.  
  62.     ].
  63.     ^(nodes at: 1).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement