-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8272d56
Showing
6 changed files
with
770 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist-newstyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Revision history for diceroll | ||
|
||
## 0.1.0.0 -- 2020-02-06 | ||
|
||
* First version. Released on an unsuspecting world. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Diceroll | ||
Diceroll is a Haskell script that generates all possible unique combinations for a given list of values whose sum equals an inputted value. | ||
|
||
### Usage | ||
Using cabal: | ||
``` | ||
cabal run diceroll <number> | ||
``` | ||
Using the compiled exe: | ||
``` | ||
diceroll.exe <number> | ||
``` | ||
|
||
\* If no number is provided it will default to 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import System.Environment (getArgs) | ||
import Data.List (sort) | ||
computelist :: (Int, [Int],[[Int]]) -> IO () -- Creates list out of list of positions | ||
computelist (x,l,m) = do | ||
let list = [1,2,3,4,5,6] -- List of possible combinations | ||
let newa = [list!!(l!!0),list!!(l!!1),list!!(l!!2),list!!(l!!3),list!!(l!!4),list!!(l!!5),list!!(l!!6),list!!(l!!7)] -- Creates list from list combinations and positions | ||
if sum newa == x -- Checks if sum of elements of list matches x | ||
then print newa -- Prints output if it does | ||
else return () -- Returns if it doesn't | ||
if sum l == 8*(length list -1) -- Checks if list has reached the end of the possibilities | ||
then return() -- Returns if it does | ||
else do | ||
let newlist = nextList(l,m,length list -1,7) -- Creates a new list if possibilities are available | ||
computelist(x,newlist,addM(newlist,m)) -- Recurses function with new list and adds the list of the list of lists | ||
|
||
lastN :: Int -> [a] -> [a] -- Returns last n elements of list | ||
lastN n xs = drop (length xs - n) xs | ||
|
||
incrementX :: ([Int],Int) -> [Int] -- Increments i element of list by 1 | ||
incrementX (l,i) = take i l ++ [l!!i + 1] ++ lastN (7-i) l | ||
|
||
resetM :: ([Int],Int) -> [Int] -- Sets the i element of list to 0 | ||
resetM (l,i) = take i l ++ [0] ++ lastN (7-i) l | ||
|
||
addM :: ([Int], [[Int]]) -> [[Int]] -- Adds list of integers to list of lists of integers | ||
addM (l,m) = m ++ [l] | ||
|
||
checkRep :: ([Int],[[Int]]) -> Bool -- Checks if list is in the list of lists | ||
checkRep (l,m) = do | ||
if elem l m | ||
then False | ||
else True | ||
|
||
incrementM :: ([Int], Int, Int) -> [Int] -- Returns an incremented matrix | ||
incrementM (l,i,len) = do | ||
if l!!i < len -- Checks if element i can be incremented | ||
then incrementX(l,i) -- Increments if it can | ||
else if i > 0 --checks if i is grester than zero | ||
then incrementM(resetM(l,i),i-1,len) -- Recurses to increment matrix on the i value above if it is | ||
else [len,len,len,len,len,len,len,len] -- Else returns the list of the final values | ||
|
||
|
||
nextList :: ([Int], [[Int]], Int, Int) -> [Int] --Returns a new unique matrix | ||
nextList (l,m,len,n) = do | ||
let new = incrementM(l,n,len) -- Creates a new list that has an incremented value | ||
if checkRep(sort(new),m) -- Checks if list is already in list of lists | ||
then new -- Returns the matrix if it is unique | ||
else nextList(new,m,len,n) -- Recurses fucntion to generate new unique list | ||
|
||
main :: IO () | ||
main = do | ||
let basem = [0,0,0,0,0,0,0,0] -- Sets base list as all 0's | ||
args <- getArgs -- Fetches command line arguments | ||
let len = if length args> 0 then read(args !! 0) :: Int else 20 -- Sets desired lenght to the first argument or defaults to 20 | ||
computelist(len, basem,[basem]) -- Computes list with the input parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cabal-version: 2.4 | ||
name: diceroll | ||
version: 0.1.0.0 | ||
synopsis: A basic diceroll combinations calculator | ||
description: Diceroll is a Haskell script that generates all possible unique combinations for a given list of values whose sum equals an inputted value. | ||
bug-reports: https://github.com/TheGhostOfInky/diceroll/issues | ||
license: GPL-3.0-or-later | ||
author: TheGhostOfInky | ||
maintainer: theghostofinky@gmail.com | ||
extra-source-files: CHANGELOG.md | ||
|
||
executable diceroll | ||
ghc-options: | ||
-threaded | ||
-funfolding-use-threshold=16 | ||
-O2 | ||
-optc-O3 | ||
main-is: diceroll.hs | ||
build-depends: base ^>=4.16.0.0 | ||
hs-source-dirs: app | ||
default-language: Haskell2010 |