-
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
Showing
35 changed files
with
1,366 additions
and
2 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,34 @@ | ||
cabal-version: 1.12 | ||
|
||
-- This file has been generated from package.yaml by hpack version 0.35.1. | ||
-- | ||
-- see: https://github.com/sol/hpack | ||
|
||
name: collatz-conjecture | ||
version: 1.2.1.4 | ||
build-type: Simple | ||
|
||
library | ||
exposed-modules: | ||
CollatzConjecture | ||
other-modules: | ||
Paths_collatz_conjecture | ||
hs-source-dirs: | ||
src | ||
ghc-options: -Wall | ||
build-depends: | ||
base | ||
default-language: Haskell2010 | ||
|
||
test-suite test | ||
type: exitcode-stdio-1.0 | ||
main-is: Tests.hs | ||
other-modules: | ||
Paths_collatz_conjecture | ||
hs-source-dirs: | ||
test | ||
build-depends: | ||
base | ||
, collatz-conjecture | ||
, hspec | ||
default-language: Haskell2010 |
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
module CollatzConjecture (collatz) where | ||
module CollatzConjecture | ||
( collatz | ||
) where | ||
|
||
collatz :: Integer -> Maybe Integer | ||
collatz n = error "You need to implement this function." | ||
|
||
-- | ||
collatz n | n < 1 = Nothing | ||
| n == 1 = Just 0 | ||
| even n = (n `div` | ||
| otherwise = n * 3 + 1 |
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,12 @@ | ||
# This file was autogenerated by Stack. | ||
# You should not edit this file by hand. | ||
# For more information, please see the documentation at: | ||
# https://docs.haskellstack.org/en/stable/lock_files | ||
|
||
packages: [] | ||
snapshots: | ||
- completed: | ||
sha256: 9fa4bece7acfac1fc7930c5d6e24606004b09e80aa0e52e9f68b148201008db9 | ||
size: 649606 | ||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/18.yaml | ||
original: lts-20.18 |
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,34 @@ | ||
{ | ||
"authors": [ | ||
"petertseng" | ||
], | ||
"contributors": [ | ||
"chastell", | ||
"iHiD", | ||
"kytrinyx", | ||
"lpalma", | ||
"ppartarr", | ||
"rbasso", | ||
"sshine", | ||
"tejasbubane", | ||
"tqa236" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/Hamming.hs", | ||
"package.yaml" | ||
], | ||
"test": [ | ||
"test/Tests.hs" | ||
], | ||
"example": [ | ||
".meta/examples/success-standard/src/Hamming.hs" | ||
], | ||
"invalidator": [ | ||
"stack.yaml" | ||
] | ||
}, | ||
"blurb": "Calculate the Hamming difference between two DNA strands.", | ||
"source": "The Calculating Point Mutations problem at Rosalind", | ||
"source_url": "https://rosalind.info/problems/hamm/" | ||
} |
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 @@ | ||
{"track":"haskell","exercise":"hamming","id":"b700b38ddb564020a7e2ec1f437b446c","url":"https://exercism.org/tracks/haskell/exercises/hamming","handle":"vpayno","is_requester":true,"auto_approve":false} |
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,86 @@ | ||
# Help | ||
|
||
## Running the tests | ||
|
||
To run the test suite, execute the following command: | ||
|
||
```bash | ||
stack test | ||
``` | ||
|
||
#### If you get an error message like this... | ||
|
||
``` | ||
No .cabal file found in directory | ||
``` | ||
|
||
or | ||
|
||
``` | ||
RedownloadInvalidResponse Request { | ||
... | ||
} | ||
"/home/username/.stack/build-plan/lts-xx.yy.yaml" (Response {responseStatus = Status {statusCode = 404, statusMessage = "Not Found"}, | ||
``` | ||
|
||
You are probably running an old stack version and need | ||
to upgrade it. Try running: | ||
|
||
```bash | ||
stack upgrade | ||
``` | ||
|
||
Or see other options for upgrading at [Stack documentation](https://docs.haskellstack.org/en/stable/install_and_upgrade/#upgrade). | ||
|
||
#### Otherwise, if you get an error message like this... | ||
|
||
``` | ||
No compiler found, expected minor version match with... | ||
Try running "stack setup" to install the correct GHC... | ||
``` | ||
|
||
Just do as it says and it will download and install | ||
the correct compiler version: | ||
|
||
```bash | ||
stack setup | ||
``` | ||
|
||
If you want to play with your solution in GHCi, just run the command: | ||
|
||
```bash | ||
stack ghci | ||
``` | ||
|
||
## Submitting your solution | ||
|
||
You can submit your solution using the `exercism submit src/Hamming.hs package.yaml` command. | ||
This command will upload your solution to the Exercism website and print the solution page's URL. | ||
|
||
It's possible to submit an incomplete solution which allows you to: | ||
|
||
- See how others have completed the exercise | ||
- Request help from a mentor | ||
|
||
## Need to get help? | ||
|
||
If you'd like help solving the exercise, check the following pages: | ||
|
||
- The [Haskell track's documentation](https://exercism.org/docs/tracks/haskell) | ||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) | ||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) | ||
|
||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. | ||
|
||
## Getting Started | ||
|
||
Please refer to the [installation](https://exercism.io/tracks/haskell/installation) | ||
and [learning](https://exercism.io/tracks/haskell/learning) help pages. | ||
|
||
## Feedback, Issues, Pull Requests | ||
|
||
The [exercism/haskell](https://github.com/exercism/haskell) repository on | ||
GitHub is the home for all of the Haskell exercises. | ||
|
||
If you have feedback about an exercise, or want to help implementing a new | ||
one, head over there and create an issue. We'll do our best to help you! |
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,49 @@ | ||
# Hamming | ||
|
||
Welcome to Hamming on Exercism's Haskell Track. | ||
If you need help running the tests or submitting your code, check out `HELP.md`. | ||
|
||
## Instructions | ||
|
||
Calculate the Hamming Distance between two DNA strands. | ||
|
||
Your body is made up of cells that contain DNA. Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells. In fact, the average human body experiences about 10 quadrillion cell divisions in a lifetime! | ||
|
||
When cells divide, their DNA replicates too. Sometimes during this process mistakes happen and single pieces of DNA get encoded with the incorrect information. If we compare two strands of DNA and count the differences between them we can see how many mistakes occurred. This is known as the "Hamming Distance". | ||
|
||
We read DNA using the letters C,A,G and T. Two strands might look like this: | ||
|
||
GAGCCTACTAACGGGAT | ||
CATCGTAATGACGGCCT | ||
^ ^ ^ ^ ^ ^^ | ||
|
||
They have 7 differences, and therefore the Hamming Distance is 7. | ||
|
||
The Hamming Distance is useful for lots of things in science, not just biology, so it's a nice phrase to be familiar with :) | ||
|
||
The Hamming distance is only defined for sequences of equal length, so | ||
an attempt to calculate it between sequences of different lengths should | ||
not work. The general handling of this situation (e.g., raising an | ||
exception vs returning a special value) may differ between languages. | ||
|
||
## Source | ||
|
||
### Created by | ||
|
||
- @petertseng | ||
|
||
### Contributed to by | ||
|
||
- @chastell | ||
- @iHiD | ||
- @kytrinyx | ||
- @lpalma | ||
- @ppartarr | ||
- @rbasso | ||
- @sshine | ||
- @tejasbubane | ||
- @tqa236 | ||
|
||
### Based on | ||
|
||
The Calculating Point Mutations problem at Rosalind - https://rosalind.info/problems/hamm/ |
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 @@ | ||
name: hamming | ||
version: 2.3.0.10 | ||
|
||
dependencies: | ||
- base | ||
|
||
library: | ||
exposed-modules: Hamming | ||
source-dirs: src | ||
ghc-options: -Wall | ||
# dependencies: | ||
# - foo # List here the packages you | ||
# - bar # want to use in your solution. | ||
|
||
tests: | ||
test: | ||
main: Tests.hs | ||
source-dirs: test | ||
dependencies: | ||
- hamming | ||
- hspec |
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,4 @@ | ||
module Hamming (distance) where | ||
|
||
distance :: String -> String -> Maybe Int | ||
distance xs ys = error "You need to implement this function." |
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 @@ | ||
resolver: lts-20.18 |
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,74 @@ | ||
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
import Data.Foldable (for_) | ||
import Test.Hspec (Spec, describe, it, shouldBe) | ||
import Test.Hspec.Runner (configFailFast, defaultConfig, hspecWith) | ||
|
||
import Hamming (distance) | ||
|
||
main :: IO () | ||
main = hspecWith defaultConfig {configFailFast = True} specs | ||
|
||
specs :: Spec | ||
specs = describe "distance" $ for_ cases test | ||
where | ||
|
||
test Case{..} = it description assertion | ||
where | ||
assertion = expression `shouldBe` fromIntegral <$> expected | ||
expression = distance strand1 strand2 | ||
|
||
data Case = Case { description :: String | ||
, strand1 :: String | ||
, strand2 :: String | ||
, expected :: Maybe Integer | ||
} | ||
|
||
cases :: [Case] | ||
cases = [ Case { description = "empty strands" | ||
, strand1 = "" | ||
, strand2 = "" | ||
, expected = Just 0 | ||
} | ||
, Case { description = "single letter identical strands" | ||
, strand1 = "A" | ||
, strand2 = "A" | ||
, expected = Just 0 | ||
} | ||
, Case { description = "single letter different strands" | ||
, strand1 = "G" | ||
, strand2 = "T" | ||
, expected = Just 1 | ||
} | ||
, Case { description = "long identical strands" | ||
, strand1 = "GGACTGAAATCTG" | ||
, strand2 = "GGACTGAAATCTG" | ||
, expected = Just 0 | ||
} | ||
, Case { description = "long different strands" | ||
, strand1 = "GGACGGATTCTG" | ||
, strand2 = "AGGACGGATTCT" | ||
, expected = Just 9 | ||
} | ||
, Case { description = "disallow first strand longer" | ||
, strand1 = "AATG" | ||
, strand2 = "AAA" | ||
, expected = Nothing | ||
} | ||
, Case { description = "disallow second strand longer" | ||
, strand1 = "ATA" | ||
, strand2 = "AGTG" | ||
, expected = Nothing | ||
} | ||
, Case { description = "disallow left empty strand" | ||
, strand1 = "" | ||
, strand2 = "G" | ||
, expected = Nothing | ||
} | ||
, Case { description = "disallow right empty strand" | ||
, strand1 = "G" | ||
, strand2 = "" | ||
, expected = Nothing | ||
} | ||
] |
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,29 @@ | ||
{ | ||
"authors": [ | ||
"Average-user" | ||
], | ||
"contributors": [ | ||
"iHiD", | ||
"petertseng", | ||
"ppartarr", | ||
"sshine", | ||
"tejasbubane" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/ProteinTranslation.hs", | ||
"package.yaml" | ||
], | ||
"test": [ | ||
"test/Tests.hs" | ||
], | ||
"example": [ | ||
".meta/examples/success-standard/src/ProteinTranslation.hs" | ||
], | ||
"invalidator": [ | ||
"stack.yaml" | ||
] | ||
}, | ||
"blurb": "Translate RNA sequences into proteins.", | ||
"source": "Tyler Long" | ||
} |
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 @@ | ||
{"track":"haskell","exercise":"protein-translation","id":"549646afc02849b8868a8b46b9d1f833","url":"https://exercism.org/tracks/haskell/exercises/protein-translation","handle":"vpayno","is_requester":true,"auto_approve":false} |
Oops, something went wrong.