solution :: [[Int]]
solution = do
    (d10, xs) <- pickOne [0..9]
    (d9, ys) <- pickOne xs
    solve' [d9,d10] ys initPrimeList
  where
    initPrimeList = [17,13,11,7,5,3,2]
    solve' chosenList remained primeList
      | null primeList = pure (remained <> chosenList)
      | otherwise = do
          -- choose x,
          -- and look into current chosen list of digits to get y and z
          (x,remained') <- pickOne remained
          let (y:z:_) = chosenList
              chosenList' = x : chosenList
              (p:primeList') = primeList
              n = x * 100 + y * 10 + z
          guard $ n `rem` p == 0
          solve' chosenList' remained' primeList'
solution :: [[Int]]
solution = do
    (d10, xs) <- pickOne [0..9]
    (d9, ys) <- pickOne xs
    solve' [d9,d10] ys initPrimeList
  where
    initPrimeList = [17,13,11,7,5,3,2]
    solve' chosenList remained primeList
      | null primeList = pure (remained <> chosenList)
      | otherwise = do
          -- choose x,
          -- and look into current chosen list of digits to get y and z
          (x,remained') <- pickOne remained
          let (y:z:_) = chosenList
              chosenList' = x : chosenList
              (p:primeList') = primeList
              n = x * 100 + y * 10 + z
          guard $ n `rem` p == 0
          solve' chosenList' remained' primeList'
solution = do
    (d10, xs) <- pickOne [0..9]
    (d9, ys) <- pickOne xs
    solve' [d9,d10] ys initPrimeList
  where
    initPrimeList = [17,13,11,7,5,3,2]
    solve' chosenList remained primeList
      | null primeList = pure (remained <> chosenList)
      | otherwise = do
          -- choose x,
          -- and look into current chosen list of digits to get y and z
          (x,remained') <- pickOne remained
          let (y:z:_) = chosenList
              chosenList' = x : chosenList
              (p:primeList') = primeList
              n = x * 100 + y * 10 + z
          guard $ n `rem` p == 0
          solve' chosenList' remained' primeList'