Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module X where
  2.  
  3. type Cell     = Char
  4. type Table    = [[Cell]]
  5. type ClueLine = [Int]
  6. type Clues    = ([ClueLine],[ClueLine])
  7.  
  8. unknown = 'u'
  9. empty   = 'e'
  10. full    = 'f'
  11.  
  12. duckClues  = (duckRows,duckCols)    :: Clues
  13. poundClues = (poundRows,poundCols) :: Clues
  14.  
  15. duckRows = [[3], [5], [4,3], [7], [5], [3], [5], [1,8],
  16.            [3,3,3], [7,3,2], [5,4,2], [8,2], [10], [2,3], [6]]
  17.  
  18. duckCols = [[3], [4], [5], [4], [5], [6], [3,2,1], [2,2,5],
  19.            [4,2,6], [8,2,3], [8,2,1,1], [2,6,2,1], [4,6], [2,4], [1]]
  20.  
  21.  
  22. poundRows = [[4], [2,1], [1,2], [2,2], [2], [8], [2], [8],
  23.             [2], [2], [2,2,2], [6,3], [2,5,3], [2,2,6], [4,4]]
  24.  
  25. poundCols = [[2],[4],[2,1],[1,1,2,1],[1,1,4],[11],[12],
  26.             [2,1,1,2],[1,1,1,3],[1,1,1,2],[1,1,1,2],[3,3],[2,3],[3],[2]]
  27.  
  28.  
  29. -- MEGOLDASOK INNEN
  30. showCell :: Cell -> Char
  31. showCell 'f' = '#'
  32. showCell 'e' = ' '
  33. showCell 'u' = '?'
  34. showCell _   = '0'
  35.  
  36. showRow :: [Cell] -> String
  37. showRow []  = "||\n"
  38. showRow row = "|"++[showCell c | c <- row]++"|\n"
  39.  
  40. showTable :: Table -> String
  41. showTable []  = []
  42. showTable tbl = concat [showRow row | row <- tbl]
  43.  
  44. emptyLineOptions :: ClueLine -> Int -> [[Cell]]
  45. emptyLineOptions [clue] n =
  46.         [(replicate i 'e')++(replicate clue 'f')++(replicate (n-i-clue) 'e' )| i <- [0..n-clue]]  -- egy clue JO
  47.  
  48. emptyLineOptions clues n
  49.     | and [null clues, n<0] =
  50.         [] -- nincs clue, neg sor JO
  51.  
  52.     | and [null clues, n>=0] =
  53.         [replicate n 'e'] -- nincs clue, nemneg sor JO
  54.  
  55.     | (sum clues) > n =
  56.         []
  57.  
  58.     | n > (sum clues + (length clues-1)) =
  59.         concat [emptyLineOptions [c] ((sum clues)-c) | c <- clues] -- van clue, nincs hely
  60.  
  61.     | otherwise =
  62.         [] -- sok clue, van hely
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement