├── .gitignore ├── Setup.hs ├── ChangeLog.md ├── test └── Spec.hs ├── README.md ├── src └── Lib.hs ├── gosper.txt ├── .github └── workflows │ └── ci.yaml ├── app ├── Reader.hs └── Main.hs ├── package.yaml ├── LICENSE └── stack.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work/ 2 | conway-haskell.cabal 3 | *~ -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # Changelog for conway-haskell 2 | 3 | ## Unreleased changes 4 | -------------------------------------------------------------------------------- /test/Spec.hs: -------------------------------------------------------------------------------- 1 | main :: IO () 2 | main = putStrLn "Test suite not yet implemented" 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # conway-haskell 2 | 3 | ``` 4 | stack setup 5 | stack build 6 | stack exec conway-haskell-exe 7 | ``` 8 | -------------------------------------------------------------------------------- /src/Lib.hs: -------------------------------------------------------------------------------- 1 | module Lib 2 | ( someFunc 3 | ) where 4 | 5 | someFunc :: IO () 6 | someFunc = putStrLn "someFunc" 7 | -------------------------------------------------------------------------------- /gosper.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 36 3 | ........................X...........  4 | ......................X.X...........  5 | ............XX......XX............XX  6 | ...........X...X....XX............XX  7 | XX........X.....X...XX..............  8 | XX........X...X.XX....X.X...........  9 | ..........X.....X.......X...........  10 | ...........X...X....................  11 | ............XX...................... -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-22.04 12 | 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-haskell@v1 16 | with: 17 | ghc-version: "8.10.3" 18 | cabal-version: "3.2" 19 | - name: Setup stack 20 | run: stack setup 21 | - name: Build 22 | run: stack build 23 | -------------------------------------------------------------------------------- /app/Reader.hs: -------------------------------------------------------------------------------- 1 | module Reader (readVacaFile) where 2 | 3 | import qualified Data.Matrix as Matrix 4 | import System.IO 5 | 6 | readVacaFile :: IO (Matrix.Matrix Int) 7 | readVacaFile = do 8 | file <- readFile "gosper.txt" 9 | let alto = read (lines file !! 0) :: Int 10 | let ancho = read (lines file !! 1) :: Int 11 | let m = drop 2 (lines file) 12 | let matrix = buildMatrix alto ancho m 13 | return matrix 14 | 15 | buildMatrix :: Int -> Int -> [String] -> Matrix.Matrix Int 16 | buildMatrix alto ancho m = Matrix.matrix alto ancho builder 17 | where 18 | builder (i,j) = if (m !! (i-1)) !! (j-1) == 'X' then 1 else 0 19 | -------------------------------------------------------------------------------- /package.yaml: -------------------------------------------------------------------------------- 1 | name: conway-haskell 2 | version: 0.1.0.0 3 | github: "aarroyoc/conway-haskell" 4 | license: BSD3 5 | author: "Adrian Arroyo Calle" 6 | maintainer: "example@example.com" 7 | copyright: "2018 Adrian Arroyo Calle" 8 | 9 | extra-source-files: 10 | - README.md 11 | - ChangeLog.md 12 | 13 | # Metadata used when publishing your package 14 | synopsis: Short description of your package 15 | # category: Web 16 | 17 | # To avoid duplicated efforts in documentation and dealing with the 18 | # complications of embedding Haddock markup inside cabal files, it is 19 | # common to point users to the README.md file. 20 | description: Please see the README on Github at 21 | 22 | dependencies: 23 | - base >= 4.7 && < 5 24 | - matrix 25 | - vector 26 | 27 | library: 28 | source-dirs: src 29 | 30 | executables: 31 | conway-haskell-exe: 32 | main: Main.hs 33 | source-dirs: app 34 | ghc-options: 35 | - -threaded 36 | - -rtsopts 37 | - -with-rtsopts=-N 38 | dependencies: 39 | - conway-haskell 40 | 41 | tests: 42 | conway-haskell-test: 43 | main: Spec.hs 44 | source-dirs: test 45 | ghc-options: 46 | - -threaded 47 | - -rtsopts 48 | - -with-rtsopts=-N 49 | dependencies: 50 | - conway-haskell 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Author name here (c) 2018 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Author name here nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Data.Matrix 4 | import qualified Data.Maybe as Maybe 5 | import qualified Data.Vector as Vector 6 | import qualified Reader 7 | 8 | main :: IO () 9 | main = do 10 | matrix <- Reader.readVacaFile 11 | putStrLn "Iterar cuantas veces?" 12 | n <- getLine 13 | let times = read n :: Int 14 | let finalMatrix = Prelude.iterate Main.iterate matrix 15 | putStrLn $ prettyMatrix $ finalMatrix !! times 16 | 17 | 18 | iterate :: Matrix Int -> Matrix Int 19 | iterate m = 20 | if hasToGrow then 21 | matrix (nrows m +2) (ncols m +2) (\(i,j) -> builder (i-1,j-1)) 22 | else 23 | matrix (nrows m) (ncols m) builder 24 | where 25 | builder (i,j) = 26 | if get (i,j) == 0 then 27 | if hasToBorn (i,j) then 28 | 1 29 | else 30 | 0 31 | else 32 | if hasToDie (i,j) then 33 | 0 34 | else 35 | 1 36 | hasToGrow = 37 | Vector.sum (getCol (ncols m) m) > 0 || 38 | Vector.sum (getRow (nrows m) m) > 0 || 39 | Vector.sum (getCol 1 m) > 0 || 40 | Vector.sum (getRow 1 m) > 0 41 | get (i,j) = Maybe.fromMaybe 0 (safeGet i j m) 42 | hasToBorn (i,j) = sumNeighbors (i,j) == 3 43 | hasToDie (i,j) = sumNeighbors (i,j) /= 2 && sumNeighbors (i,j) /= 3 44 | sumNeighbors (i,j) = 45 | get (i-1,j-1) + get (i,j-1) + get (i+1,j-1) 46 | + get (i-1,j) + get (i+1,j) 47 | + get (i-1,j+1) + get (i,j+1) + get (i+1,j+1) 48 | 49 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-12.0 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | # extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | # flags: {} 46 | 47 | # Extra package databases containing global packages 48 | # extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=1.6" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor 67 | --------------------------------------------------------------------------------