Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
d167a381
Commit
d167a381
authored
Feb 28, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://vo20.nl/git/uva
parents
d5155e87
23bf36ac
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
2 deletions
+101
-2
modsim/ass2/.gitignore
modsim/ass2/.gitignore
+2
-0
modsim/ass2/Makefile
modsim/ass2/Makefile
+2
-2
modsim/ass2/opg-v2.pdf
modsim/ass2/opg-v2.pdf
+0
-0
modsim/ass2/q7.c
modsim/ass2/q7.c
+97
-0
No files found.
modsim/ass2/.gitignore
View file @
d167a381
...
@@ -3,4 +3,6 @@ q2
...
@@ -3,4 +3,6 @@ q2
q3
q3
q4
q4
q5
q5
q6
q7
*.o
*.o
modsim/ass2/Makefile
View file @
d167a381
...
@@ -2,7 +2,7 @@ CC=clang
...
@@ -2,7 +2,7 @@ CC=clang
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-D_GNU_SOURCE
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-D_GNU_SOURCE
LFLAGS
=
-lm
LFLAGS
=
-lm
all
:
q1 q2 q3 q4 q5
all
:
q1 q2 q3 q4 q5
q7
q%
:
q%.o
q%
:
q%.o
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
$(CC)
$(CFLAGS)
$(LFLAGS)
-o
$@
$^
...
@@ -11,7 +11,7 @@ q%: q%.o
...
@@ -11,7 +11,7 @@ q%: q%.o
$(CC)
$(CFLAGS)
-o
$@
-c
$^
$(CC)
$(CFLAGS)
-o
$@
-c
$^
clean
:
clean
:
for
i
in
`
seq
6
`
;
do
\
for
i
in
`
seq
7
`
;
do
\
rm
-vf
q
$$
i
;
\
rm
-vf
q
$$
i
;
\
done
;
done
;
rm
-vf
*
.o
rm
-vf
*
.o
modsim/ass2/opg-v2.pdf
View file @
d167a381
No preview for this file type
modsim/ass2/q7.c
0 → 100644
View file @
d167a381
/*
* Usage: ./q7 [ generations [ max_age ] ]
*/
#include <stdlib.h>
#include <stdio.h>
typedef
struct
rabbit
{
int
age
;
struct
rabbit
*
prev
,
*
next
;
}
rabbit
;
rabbit
*
rabbits
=
NULL
;
int
rabbit_count
=
0
;
rabbit
*
rabbit_born
()
{
rabbit
*
r
=
(
rabbit
*
)
malloc
(
sizeof
(
rabbit
));
if
(
(
r
->
next
=
rabbits
)
)
rabbits
->
prev
=
r
;
r
->
age
=
0
;
rabbits
=
r
;
rabbit_count
++
;
return
r
;
}
void
rabbit_die
(
rabbit
**
ptr
)
{
rabbit
*
r
=
*
ptr
;
if
(
r
->
prev
!=
NULL
)
r
->
prev
->
next
=
r
->
next
;
if
(
r
->
next
!=
NULL
)
r
->
next
->
prev
=
r
->
prev
;
if
(
r
==
rabbits
)
rabbits
=
NULL
;
*
ptr
=
NULL
;
rabbit_count
--
;
free
(
r
);
}
void
sequence
(
int
generations
,
int
max_age
)
{
int
i
;
rabbit
*
r
,
*
next
=
NULL
;
printf
(
"0"
);
rabbits
=
rabbit_born
();
for
(
i
=
1
;
i
<
generations
;
i
++
)
{
for
(
r
=
rabbits
;
r
!=
NULL
;
r
=
next
)
{
next
=
r
->
next
;
if
(
r
->
age
++
)
{
rabbit_born
();
if
(
r
->
age
==
max_age
)
rabbit_die
(
&
r
);
}
}
printf
(
" %d"
,
rabbit_count
);
}
puts
(
""
);
while
(
rabbits
)
rabbit_die
(
&
rabbits
);
}
void
sequence_old
(
int
n
)
{
int
i
,
new
=
1
,
new_new
,
mature
=
0
,
died
=
0
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%d + %d = %d
\n
"
,
mature
,
new
,
new
+
mature
);
new_new
=
mature
;
mature
=
mature
+
new
-
died
;
new
=
new_new
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
max_age
=
0
,
generations
=
10
;
if
(
argc
>
1
)
{
generations
=
atoi
(
argv
[
1
]);
if
(
argc
>
2
)
max_age
=
atoi
(
argv
[
2
]);
}
sequence
(
generations
,
max_age
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment