Skip to content

Commit 5de43d5

Browse files
authored
Add files via upload
1 parent bbd497a commit 5de43d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+12463
-0
lines changed

Diff for: mp1a-recursion/README.md

+656
Large diffs are not rendered by default.

Diff for: mp1a-recursion/Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

Diff for: mp1a-recursion/package.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: recursion
2+
version: 0.1.0.0
3+
license: NCSA
4+
author: "Nick Walker"
5+
maintainer: "[email protected]"
6+
copyright: "2019 Nick Walker"
7+
8+
extra-source-files:
9+
- README.md
10+
11+
description: Please see the README
12+
13+
dependencies:
14+
- base >= 4.7 && < 5
15+
16+
library:
17+
source-dirs: src
18+
19+
tests:
20+
recursion-test:
21+
main: Spec.hs
22+
source-dirs: test
23+
ghc-options:
24+
- -threaded
25+
- -rtsopts
26+
- -with-rtsopts=-N
27+
dependencies:
28+
- recursion
29+
- QuickCheck
30+
- test-framework
31+
- test-framework-quickcheck2

Diff for: mp1a-recursion/recursion.cabal

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cabal-version: 2.2
2+
3+
-- This file has been generated from package.yaml by hpack version 0.34.4.
4+
--
5+
-- see: https://github.com/sol/hpack
6+
7+
name: recursion
8+
version: 0.1.0.0
9+
description: Please see the README
10+
author: Nick Walker
11+
maintainer: [email protected]
12+
copyright: 2019 Nick Walker
13+
license: NCSA
14+
build-type: Simple
15+
extra-source-files:
16+
README.md
17+
18+
library
19+
exposed-modules:
20+
Lib
21+
other-modules:
22+
Paths_recursion
23+
hs-source-dirs:
24+
src
25+
build-depends:
26+
base >=4.7 && <5
27+
default-language: Haskell2010
28+
29+
test-suite recursion-test
30+
type: exitcode-stdio-1.0
31+
main-is: Spec.hs
32+
other-modules:
33+
Paths_recursion
34+
hs-source-dirs:
35+
test
36+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
37+
build-depends:
38+
QuickCheck
39+
, base >=4.7 && <5
40+
, recursion
41+
, test-framework
42+
, test-framework-quickcheck2
43+
default-language: Haskell2010

Diff for: mp1a-recursion/src/Lib.hs

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
--- Getting Started
2+
--- ===============
3+
4+
--- Relevant Files
5+
--- --------------
6+
7+
module Lib where
8+
9+
-- This line imports the Prelude module without certain functions
10+
import Prelude hiding ( take, drop, reverse
11+
, zip, zipWith
12+
, map, foldl, foldr
13+
, iterate, repeat
14+
, replicate, cycle
15+
, (++)
16+
)
17+
-- When you are allowed to use builtin functions Prepend them with "P."
18+
-- for example `P.take`
19+
import qualified Prelude as P
20+
21+
--- Problems
22+
--- ========
23+
24+
--- Recursion
25+
--- ---------
26+
27+
--- ### mytake
28+
29+
-- don't forget to put the type declaration or you will lose points!
30+
mytake :: (Num a1, Ord a1) => a1 -> [a2] -> [a2]
31+
32+
mytake 0 _ = []
33+
mytake n [] = []
34+
mytake n (x:xs) | n>0 = x : mytake (n-1) xs
35+
| n<0 = []
36+
37+
--- ### mydrop
38+
39+
-- don't forget to put the type declaration or you will lose points!
40+
mydrop :: Int -> [a] -> [a]
41+
mydrop 0 (x:xs) = (x:xs)
42+
mydrop n [] = []
43+
mydrop n (x:xs) | n>0 = mydrop (n-1) xs
44+
| n<0 = (x:xs)
45+
46+
--- ### rev
47+
48+
-- don't forget to put the type declaration or you will lose points!
49+
rev :: [a] -> [a]
50+
rev []=[]
51+
rev (x:xs) = aux (x:xs) []
52+
where aux [] a =a
53+
aux (x:xs) a = aux xs (x:a)
54+
55+
--- ### app
56+
57+
-- don't forget to put the type declaration or you will lose points!
58+
app :: [a] -> [a] -> [a]
59+
app [] y = y
60+
app x [] = x
61+
app (x:xs) y = x: app xs y
62+
63+
--- ### inclist
64+
65+
-- don't forget to put the type declaration or you will lose points!
66+
inclist :: Num a => [a] -> [a]
67+
inclist []= []
68+
inclist (x:xs)= x+1: inclist xs
69+
70+
--- ### sumlist
71+
72+
-- don't forget to put the type declaration or you will lose points!
73+
sumlist :: Num a => [a] -> a
74+
sumlist []=0
75+
sumlist (x:xs) =x+ sumlist (xs)
76+
77+
--- ### myzip
78+
79+
-- don't forget to put the type declaration or you will lose points!
80+
myzip :: [a] -> [b] -> [(a,b)]
81+
myzip _ [] = []
82+
myzip [] _ = []
83+
myzip (x:xs) (y:ys) =(x,y) : myzip xs ys
84+
85+
--- ### addpairs
86+
87+
-- don't forget to put the type declaration or you will lose points!
88+
addpairs :: (Num a) => [a] -> [a] -> [a]
89+
addpairs _ [] = []
90+
addpairs [] _ = []
91+
addpairs x y = [ x+y| (x,y) <-myzip x y]
92+
93+
--- ### ones
94+
95+
-- don't forget to put the type declaration or you will lose points!
96+
ones :: [Integer]
97+
ones = [1,1..]
98+
99+
--- ### nats
100+
101+
-- don't forget to put the type declaration or you will lose points!
102+
nats :: [Integer]
103+
nats=[0,1..]
104+
105+
--- ### fib
106+
107+
-- don't forget to put the type declaration or you will lose points!
108+
fib :: [Integer]
109+
fib = 0:1: addpairs fib (tail fib)
110+
--- Set Theory
111+
--- ----------
112+
113+
--- ### add
114+
115+
-- don't forget to put the type declaration or you will lose points! F
116+
add :: Ord a => a -> [a] -> [a]
117+
add a [] =[a]
118+
add a x = quicksort (a:x)
119+
where quicksort []= []
120+
quicksort(x:xs) =
121+
let smallerSorted = quicksort [a | a <- xs, a <x]
122+
biggerSorted = quicksort [a | a <- xs, a > x]
123+
in smallerSorted P.++ [x] P.++ biggerSorted
124+
125+
--- ### union
126+
127+
-- don't forget to put the type declaration or you will lose points! F
128+
union xs [] = xs
129+
union [] ys = ys
130+
union (x:xs) (y:ys) | x==y = union xs (y:ys)
131+
| x < y = x:union xs (y:ys)
132+
| x > y = y:union (x:xs) ys
133+
134+
--- ### intersect
135+
136+
-- don't forget to put the type declaration or you will lose points!
137+
keepdups :: Ord a =>[a] -> [a]
138+
keepdups l = [d|(z,d)<- P.zip [0..] l, elem d $ P.take z l]
139+
intersect :: Ord a => [a] -> [a] -> [a]
140+
intersect l1 l2 = let l = l1 P.++ l2 in keepdups l
141+
142+
--- ### powerset
143+
144+
-- don't forget to put the type declaration or you will lose points! F
145+
map' :: (a -> b) -> [a] -> [b]
146+
map' _ [] = []
147+
map' f (x:xs) = f x : map' f xs
148+
149+
powerset :: Ord a => [a] -> [[a]]
150+
powerset [] = [[]]
151+
powerset (x:xs) = union xss (map' (x:) xss)
152+
where xss = powerset xs
153+
154+
--- Higher Order Functions
155+
--- ----------------------
156+
157+
--- ### inclist'
158+
159+
-- don't forget to put the type declaration or you will lose points! F
160+
inclist' :: Num a => [a] -> [a]
161+
inclist' l = P.map (+1) l
162+
163+
--- ### sumlist'
164+
165+
-- don't forget to put the type declaration or you will lose points!
166+
sumlist' :: (Num a) => [a] -> a
167+
sumlist' xs = P.foldl (\acc x -> acc + x) 0 xs
168+
169+
any :: (a -> Bool) -> [a] -> Bool
170+
any p [] = False
171+
any p (x:xs) = if (p x) then True else any p xs
172+
173+
-----is it a tail recursion?
174+
all' p [] = True
175+
all' p (x:xs) | p x = all' p xs -----p x == True
176+
| otherwise = False
177+
178+
all2 p xx = aux p xx True
179+
where aux p [] a =a
180+
aux p (x:xs) a = aux p xs (a==p x)
181+
182+
report a = a
183+
nth 0 (x:xs) = x
184+
nth n (x:xs) = nth (n-1) xs
185+
---kmultlist :: (Ord t, Num t, Show t) => [t] -> (t -> t) -> t
186+
kmultlist xx k = aux xx [k]
187+
where aux [] klist =trace "Base case." $ (head klist) 1
188+
aux (0:xs) _ = trace "Skip case."$ k 0
189+
aux (x:xs) klist | trace ("where we are:" ++ show x) $ x < 0 = (nth (0-x) klist) 1
190+
| trace ("Recursion case." ++ show (x,xs)) otherwise = aux xs ( (\v -> (head klist) (v * x)) : klist)
191+
192+
-----kmultlist [2, 3, 4, 5, 6, -2, 0, 2, 4, 6] report

Diff for: mp1a-recursion/stack.yaml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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-17.1
12+
# resolver: nightly-2015-09-21
13+
# resolver: ghc-7.10.2
14+
# resolver: ghcjs-0.1.0_ghc-7.10.2
15+
#
16+
# The location of a snapshot can be provided as a file or url. Stack assumes
17+
# a snapshot provided as a file might change, whereas a url resource does not.
18+
#
19+
# resolver: ./custom-snapshot.yaml
20+
# resolver: https://example.com/snapshots/2018-01-01.yaml
21+
resolver: lts-17.9
22+
23+
# User packages to be built.
24+
# Various formats can be used as shown in the example below.
25+
#
26+
# packages:
27+
# - some-directory
28+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
29+
# - location:
30+
# git: https://github.com/commercialhaskell/stack.git
31+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
32+
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
33+
# subdirs:
34+
# - auto-update
35+
# - wai
36+
packages:
37+
- .
38+
# Dependency packages to be pulled from upstream that are not in the resolver
39+
# using the same syntax as the packages field.
40+
# (e.g., acme-missiles-0.3)
41+
# extra-deps: []
42+
43+
# Override default flag values for local packages and extra-deps
44+
# flags: {}
45+
46+
# Extra package databases containing global packages
47+
# extra-package-dbs: []
48+
49+
# Control whether we use the GHC we find on the path
50+
# system-ghc: true
51+
#
52+
# Require a specific version of stack, using version ranges
53+
# require-stack-version: -any # Default
54+
# require-stack-version: ">=1.8"
55+
#
56+
# Override the architecture used by stack, especially useful on Windows
57+
# arch: i386
58+
# arch: x86_64
59+
#
60+
# Extra directories used by stack for building
61+
# extra-include-dirs: [/path/to/dir]
62+
# extra-lib-dirs: [/path/to/dir]
63+
#
64+
# Allow a newer minor version of GHC than the snapshot specifies
65+
# compiler-check: newer-minor
66+
extra-deps:
67+
- regex-posix-clib-2.7
68+
69+
flags:
70+
regex-posix:
71+
_regex-posix-clib: true

Diff for: mp1a-recursion/stack.yaml.lock

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file was autogenerated by Stack.
2+
# You should not edit this file by hand.
3+
# For more information, please see the documentation at:
4+
# https://docs.haskellstack.org/en/stable/lock_files
5+
6+
packages:
7+
- completed:
8+
hackage: regex-posix-clib-2.7@sha256:998fca06da3d719818f0691ef0b8b9b7375afeea228cb08bd9e2db53f96b0cd7,1232
9+
pantry-tree:
10+
size: 524
11+
sha256: 5bf20952472d930323766d250f5fbbe3fe6f2cd3d931e5cf7b62a238ab2099ff
12+
original:
13+
hackage: regex-posix-clib-2.7
14+
snapshots:
15+
- completed:
16+
size: 567037
17+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml
18+
sha256: d7d8d5106e53d1669964bd8bd2b0f88a5ad192d772f5376384b76738fd992311
19+
original: lts-17.9

0 commit comments

Comments
 (0)