daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. one sig Board {
  2.         cols : seq Columns
  3. } {
  4.         #cols = 9
  5.         not hasDups[cols]
  6. }
  7.  
  8. sig Columns {
  9.         cells : seq Values
  10. } {
  11.         #cells = 9
  12.         elems[cells] = Values
  13. }
  14.  
  15. abstract sig Values {}
  16. one sig V1, V2, V3, V4, V5, V6, V7, V8, V9 extends Values {}
  17.  
  18. fun row [ i :  Int ] : Values {
  19.     { elems[Board.cols].cells[i] }
  20. }
  21.  
  22. fun subsquare [ startRow : Int, startCol : Int ] : Values {
  23.     {
  24.         Board.cols[startCol].cells[startRow] +
  25.         Board.cols[startCol].cells[startRow + 1] +
  26.         Board.cols[startCol].cells[startRow + 2] +
  27.         Board.cols[startCol + 1].cells[startRow] +
  28.         Board.cols[startCol + 1].cells[startRow + 1] +
  29.         Board.cols[startCol + 1].cells[startRow + 2] +
  30.         Board.cols[startCol + 2].cells[startRow] +
  31.         Board.cols[startCol + 2].cells[startRow + 1] +
  32.         Board.cols[startCol + 2].cells[startRow + 2]
  33.     }
  34. }
  35.  
  36. fact EveryRowHasEveryNumber {
  37.     all v : Values | v in row[0]
  38.     all v : Values | v in row[1]
  39.     all v : Values | v in row[2]
  40.     all v : Values | v in row[3]
  41.     all v : Values | v in row[4]
  42.     all v : Values | v in row[5]
  43.     all v : Values | v in row[6]
  44.     all v : Values | v in row[7]
  45.     all v : Values | v in row[8]
  46. }
  47.  
  48. fact EveryColumnHasEveryNumber {
  49.     all c : elems[Board.cols] | !c.cells.hasDups
  50. }
  51.  
  52. fact EverySubsquareHasEveryNumber {
  53.     all v : Values | v in subsquare[0,0]
  54.     all v : Values | v in subsquare[0,3]
  55.     all v : Values | v in subsquare[0,6]
  56.     all v : Values | v in subsquare[3,0]
  57.     all v : Values | v in subsquare[3,3]
  58.     all v : Values | v in subsquare[3,6]
  59.     all v : Values | v in subsquare[6,0]
  60.     all v : Values | v in subsquare[6,3]
  61.     all v : Values | v in subsquare[6,6]
  62. }
  63.  
  64. pred Show[i : Int] {
  65.         //seq[i][j] = Int[7]
  66.         i in inds[Board.cols]
  67.         row[i] = Values
  68. }
  69.  
  70. run Show for 5 int, 9 seq, 9 Columns
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top