Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
prog3-coursework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ik1g19
prog3-coursework
Commits
54291f1b
Commit
54291f1b
authored
4 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
fixed addToGrid, insertAt2D and insertAt
parent
9f39595a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cw/src/Challenges.hs
+8
-4
8 additions, 4 deletions
cw/src/Challenges.hs
with
8 additions
and
4 deletions
cw/src/Challenges.hs
+
8
−
4
View file @
54291f1b
...
@@ -94,7 +94,7 @@ nextPos DownBack (x,y) = (x-1,y+1)
...
@@ -94,7 +94,7 @@ nextPos DownBack (x,y) = (x-1,y+1)
elemAt
::
[[
a
]]
->
(
Int
,
Int
)
->
a
elemAt
::
[[
a
]]
->
(
Int
,
Int
)
->
a
elemAt
ass
(
x
,
y
)
=
(
ass
!!
y
)
!!
x
--ass means list of list of a's, not associated with other meaning
elemAt
ass
(
x
,
y
)
=
(
ass
!!
y
)
!!
x
--ass means list of list of a's, not associated with
any
other meaning
--returns specified adjacent element in grid, relative to given position
--returns specified adjacent element in grid, relative to given position
...
@@ -167,7 +167,7 @@ insertString rg s gen | elemAt rg (x,y) /= Rand &&
...
@@ -167,7 +167,7 @@ insertString rg s gen | elemAt rg (x,y) /= Rand &&
vDirs
=
validDirs
rg
s
(
x
,
y
)
vDirs
=
validDirs
rg
s
(
x
,
y
)
addToGrid
::
Orientation
->
String
->
(
Int
,
Int
)
->
RandGrid
addToGrid
::
Orientation
->
String
->
(
Int
,
Int
)
->
RandGrid
addToGrid
dir
(
c
:
cs
)
(
x'
,
y'
)
=
addToGrid
dir
cs
(
nextPos
dir
(
x'
,
y'
))
charAdded
addToGrid
dir
(
c
:
cs
)
(
x'
,
y'
)
=
addToGrid
dir
cs
charAdded
(
nextPos
dir
(
x'
,
y'
))
where
where
charAdded
=
insertAt2D
(
Letter
c
)
(
x'
,
y'
)
rg
charAdded
=
insertAt2D
(
Letter
c
)
(
x'
,
y'
)
rg
--addToGrid dir = map (\(c,(m,n)) -> insertAt2D (Letter c) (m,n) rg) (zip s (take (length s) $ iterate (nextPos dir) (x,y)))
--addToGrid dir = map (\(c,(m,n)) -> insertAt2D (Letter c) (m,n) rg) (zip s (take (length s) $ iterate (nextPos dir) (x,y)))
...
@@ -175,11 +175,15 @@ insertString rg s gen | elemAt rg (x,y) /= Rand &&
...
@@ -175,11 +175,15 @@ insertString rg s gen | elemAt rg (x,y) /= Rand &&
--inserts element at location in 2d array
--inserts element at location in 2d array
insertAt2D
::
a
->
(
Int
,
Int
)
->
[[
a
]]
->
[[
a
]]
insertAt2D
::
a
->
(
Int
,
Int
)
->
[[
a
]]
->
[[
a
]]
insertAt2D
newElement
(
x
,
y
)
grid
=
insertAt
a
x
(
grid
!!
y
)
insertAt2D
newElement
(
x
,
y
)
grid
|
y
==
0
=
insertAt
newElement
x
(
grid
!!
y
)
:
drop
1
belowRows
|
y
==
length
grid
-
1
=
aboveRows
++
[
insertAt
newElement
x
(
grid
!!
y
)]
|
otherwise
=
aboveRows
++
[
insertAt
newElement
x
(
grid
!!
y
)]
++
drop
1
belowRows
where
(
aboveRows
,
belowRows
)
=
splitAt
y
grid
--using code from https://stackoverflow.com/questions/43291442/haskell-insert-an-element-on-nth-position
--using code from https://stackoverflow.com/questions/43291442/haskell-insert-an-element-on-nth-position
insertAt
::
a
->
Int
->
[
a
]
->
[
a
]
insertAt
::
a
->
Int
->
[
a
]
->
[
a
]
insertAt
newElement
0
as
=
newElement
:
as
insertAt
newElement
0
as
=
newElement
:
drop
1
as
insertAt
newElement
i
(
a
:
as
)
=
a
:
insertAt
newElement
(
i
-
1
)
as
insertAt
newElement
i
(
a
:
as
)
=
a
:
insertAt
newElement
(
i
-
1
)
as
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment