Fix folder structure
This commit is contained in:
parent
f984f716ea
commit
62086e4812
16 changed files with 1926 additions and 124 deletions
19
.direnv/bin/nix-direnv-reload
Executable file
19
.direnv/bin/nix-direnv-reload
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
if [[ ! -d "/home/leonv/Git/Sudoku" ]]; then
|
||||||
|
echo "Cannot find source directory; Did you move it?"
|
||||||
|
echo "(Looking for "/home/leonv/Git/Sudoku")"
|
||||||
|
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# rebuild the cache forcefully
|
||||||
|
_nix_direnv_force_reload=1 direnv exec "/home/leonv/Git/Sudoku" true
|
||||||
|
|
||||||
|
# Update the mtime for .envrc.
|
||||||
|
# This will cause direnv to reload again - but without re-building.
|
||||||
|
touch "/home/leonv/Git/Sudoku/.envrc"
|
||||||
|
|
||||||
|
# Also update the timestamp of whatever profile_rc we have.
|
||||||
|
# This makes sure that we know we are up to date.
|
||||||
|
touch -r "/home/leonv/Git/Sudoku/.envrc" "/home/leonv/Git/Sudoku/.direnv"/*.rc
|
1
.direnv/flake-inputs/2hc9lg18zd6yabw9jqj0wy3s9kyvkzp0-source
Symbolic link
1
.direnv/flake-inputs/2hc9lg18zd6yabw9jqj0wy3s9kyvkzp0-source
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/2hc9lg18zd6yabw9jqj0wy3s9kyvkzp0-source
|
1
.direnv/flake-inputs/79qk1r0q5xc9g3qhw0m143x04q6d7x2m-source
Symbolic link
1
.direnv/flake-inputs/79qk1r0q5xc9g3qhw0m143x04q6d7x2m-source
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/79qk1r0q5xc9g3qhw0m143x04q6d7x2m-source
|
1
.direnv/flake-inputs/bv68i4l7g6s5sixxm0c9lcjdxhlkg0n5-source
Symbolic link
1
.direnv/flake-inputs/bv68i4l7g6s5sixxm0c9lcjdxhlkg0n5-source
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/bv68i4l7g6s5sixxm0c9lcjdxhlkg0n5-source
|
1
.direnv/flake-inputs/hmiyz975p0bfnzfcbamn6d0v1gfv15ds-source
Symbolic link
1
.direnv/flake-inputs/hmiyz975p0bfnzfcbamn6d0v1gfv15ds-source
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/hmiyz975p0bfnzfcbamn6d0v1gfv15ds-source
|
1
.direnv/flake-inputs/lwyjz70qh12nq6cb7fixl85vryzxqm3c-source
Symbolic link
1
.direnv/flake-inputs/lwyjz70qh12nq6cb7fixl85vryzxqm3c-source
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/lwyjz70qh12nq6cb7fixl85vryzxqm3c-source
|
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/nix/store/dl8p5s0m5prz82vbshy9n1k12yj1imsg-ghc-shell-for-Sudoku-0.1.0.0-0-env
|
1883
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
1883
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
File diff suppressed because one or more lines are too long
23
LICENSE
23
LICENSE
|
@ -1,9 +1,20 @@
|
||||||
MIT License
|
Copyright (c) 2024 Leon Vatthauer
|
||||||
|
|
||||||
Copyright (c) 2024 leonv
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
20
src/LICENSE
20
src/LICENSE
|
@ -1,20 +0,0 @@
|
||||||
Copyright (c) 2024 Leon Vatthauer
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included
|
|
||||||
in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
@ -1,97 +0,0 @@
|
||||||
{-# LANGUAGE InstanceSigs #-}
|
|
||||||
|
|
||||||
module Types where
|
|
||||||
|
|
||||||
import Control.Monad.State (State)
|
|
||||||
import Data.Char (digitToInt, intToDigit)
|
|
||||||
import Data.Vector (Vector)
|
|
||||||
|
|
||||||
-- * Stateful Sudoku Type
|
|
||||||
|
|
||||||
data SudokuState = SudokuState
|
|
||||||
{ dimension :: Int,
|
|
||||||
grid :: Vector Int,
|
|
||||||
idxs :: Vector (Int, Int)
|
|
||||||
}
|
|
||||||
|
|
||||||
type SudokuMonad = State SudokuState
|
|
||||||
|
|
||||||
getField :: (Int, Int) -> SudokuMonad Int
|
|
||||||
getField (x, y) = do
|
|
||||||
state <- get
|
|
||||||
return $ (x + y * dimension state) ! grid state
|
|
||||||
|
|
||||||
getRow :: (Int, Int) -> SudokuMonad Int
|
|
||||||
getRow (x, _) = return x
|
|
||||||
|
|
||||||
getCol :: (Int, Int) -> SudokuMonad Int
|
|
||||||
getCol (_, y) = return y
|
|
||||||
|
|
||||||
getBox :: (Int, Int) -> SudokuMonad Int
|
|
||||||
getBox (x, y) = do
|
|
||||||
d <- gets dimension
|
|
||||||
let xPart = x `div` d
|
|
||||||
let yPart = y `div` d
|
|
||||||
return $ xPart + d * yPart
|
|
||||||
|
|
||||||
-- * Stateless Sudoku Type
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
-- $statelessFlattened
|
|
||||||
--
|
|
||||||
-- Here we define a simpler Sudoku type that would be very inneficient to work with
|
|
||||||
-- but is suitable for pretty printing and reading
|
|
||||||
|
|
||||||
-- | Contains metadata concerning a Sudoku field
|
|
||||||
data Sudoku = Sudoku
|
|
||||||
{ -- | The dim of the Sudoku, e.g. a 9x9 Sudoku field has dim 3
|
|
||||||
dim :: Int,
|
|
||||||
-- | The Sudoku field as a flattened list
|
|
||||||
grd :: [Int]
|
|
||||||
}
|
|
||||||
|
|
||||||
instance Show Sudoku where
|
|
||||||
show :: Sudoku -> String
|
|
||||||
show = map intToDigit . grd
|
|
||||||
|
|
||||||
instance Read Sudoku where
|
|
||||||
readsPrec :: Int -> ReadS Sudoku
|
|
||||||
readsPrec _ s =
|
|
||||||
if isInt dimDouble
|
|
||||||
then [(Sudoku (floor dimDouble) (map digitToInt s), "")]
|
|
||||||
else error ("Trying to parse malformed sudoku (number of digits [" ++ show (length s) ++ "] is not a quadratic root):\n" ++ s)
|
|
||||||
where
|
|
||||||
isInt x = x == fromInteger (round x)
|
|
||||||
dimDouble = sqrt . sqrt $ (fromIntegral (length s) :: Double)
|
|
||||||
|
|
||||||
-- | Pretty printing of values. Analogous to the `Show` class, but does not harmonize with `Read`.
|
|
||||||
class Pretty a where
|
|
||||||
-- | Works like `show`, but is not inverse to `read`.
|
|
||||||
pretty :: a -> String
|
|
||||||
|
|
||||||
-- TODO improve pretty printer, this is kind of a mess
|
|
||||||
instance Pretty Sudoku where
|
|
||||||
pretty :: Sudoku -> String
|
|
||||||
pretty s = prettyHelper (dim s - 1, dim s, grd s)
|
|
||||||
where
|
|
||||||
-- prettyBlock (isLast, n, list)
|
|
||||||
prettyBlock :: (Bool, Int, [Int]) -> String
|
|
||||||
prettyBlock (_, _, []) = ""
|
|
||||||
prettyBlock (True, n, _) | n == 0 = ""
|
|
||||||
prettyBlock (False, n, _) | n == 0 = "|"
|
|
||||||
prettyBlock (b, n, x : xs) = intToDigit x : ' ' : prettyBlock (b, n - 1, xs)
|
|
||||||
-- prettyRow (n, dim, list)
|
|
||||||
prettyRow :: (Int, Int, [Int]) -> String
|
|
||||||
prettyRow (n, dim, xs) | n == 0 = prettyBlock (True, dim, xs)
|
|
||||||
prettyRow (n, dim, xs) = prettyBlock (False, dim, xs) ++ (' ' : prettyRow (n - 1, dim, drop dim xs))
|
|
||||||
-- prettyCol (isLast, n, dim, list)
|
|
||||||
prettyCol :: (Bool, Int, Int, [Int]) -> String
|
|
||||||
prettyCol (True, n, _, _) | n == 0 = ""
|
|
||||||
prettyCol (False, n, dim, _) | n == 0 = replicate (2 * dim * dim - 1 + 2 * (dim - 1)) '-'
|
|
||||||
prettyCol (_, _, _, []) = ""
|
|
||||||
prettyCol (b, n, dim, xs) = prettyRow (dim - 1, dim, xs) ++ ('\n' : prettyCol (b, n - 1, dim, drop (dim * dim) xs))
|
|
||||||
-- prettyHelper (n, dim, list)
|
|
||||||
prettyHelper :: (Int, Int, [Int]) -> String
|
|
||||||
prettyHelper (n, dim, xs) | n == 0 = prettyCol (True, dim, dim, xs)
|
|
||||||
prettyHelper (n, dim, xs) = prettyCol (False, dim, dim, xs) ++ ('\n' : prettyHelper (n - 1, dim, drop (dim * dim) xs))
|
|
Loading…
Reference in a new issue