Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soft160_recursion_lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brandon Joseph Huettner
soft160_recursion_lab
Commits
f87cde1f
Commit
f87cde1f
authored
7 years ago
by
Brandon
Browse files
Options
Downloads
Patches
Plain Diff
First commit.
parent
738b6428
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
lab.py
+28
-13
28 additions, 13 deletions
lab.py
with
28 additions
and
13 deletions
lab.py
+
28
−
13
View file @
f87cde1f
...
@@ -20,8 +20,11 @@ def scalar_fibonacci(n):
...
@@ -20,8 +20,11 @@ def scalar_fibonacci(n):
>>>
scalar_fibonacci
(
35
)
>>>
scalar_fibonacci
(
35
)
9227465
9227465
"""
"""
return
0
# stub
if
n
==
0
:
return
0
if
n
==
1
:
return
1
return
def
vector_fibonacci
(
n
):
def
vector_fibonacci
(
n
):
"""
"""
...
@@ -41,32 +44,44 @@ def vector_fibonacci(n):
...
@@ -41,32 +44,44 @@ def vector_fibonacci(n):
>>>
vector_fibonacci
(
35
)
>>>
vector_fibonacci
(
35
)
(
5702887
,
9227465
)
(
5702887
,
9227465
)
>>>
vector_fibonacci
(
350
)
>>>
vector_fibonacci
(
350
)
(
3865462327928467072415604609040860366007401579690263197296200323999931849
,
6254449428820551641549772190170184190608177514674331726439961915653414425
)
(
3865462327928467072415604609040860366007401579690263197296200323999931849
L
,
6254449428820551641549772190170184190608177514674331726439961915653414425
L
)
"""
"""
return
0
,
1
# stub
if
n
<=
0
:
return
(
0
,
0
)
if
n
==
1
:
return
(
0
,
1
)
if
n
==
2
:
return
(
1
,
1
)
x
=
vector_fibonacci
(
n
-
1
)
return
(
x
[
1
],
x
[
0
]
+
x
[
1
])
def
maximal_repetition_free_prefix
(
sequence
):
def
maximal_repetition_free_prefix
(
sequence
,
x
):
"""
"""
Given a sequence, return its longest repetition-free prefix. For example:
Given a sequence, return its longest repetition-free prefix. For example:
>>>
maximal_repetition_free_prefix
([])
>>>
maximal_repetition_free_prefix
([]
,
0
)
[]
[]
>>>
maximal_repetition_free_prefix
([
5
])
>>>
maximal_repetition_free_prefix
([
5
]
,
0
)
[
5
]
[
5
]
>>>
maximal_repetition_free_prefix
([
5
,
4
])
>>>
maximal_repetition_free_prefix
([
5
,
4
]
,
0
)
[
5
,
4
]
[
5
,
4
]
>>>
maximal_repetition_free_prefix
([
5
,
5
])
>>>
maximal_repetition_free_prefix
([
5
,
5
]
,
0
)
[
5
]
[
5
]
>>>
maximal_repetition_free_prefix
([
5
,
4
,
5
])
>>>
maximal_repetition_free_prefix
([
5
,
4
,
5
]
,
0
)
[
5
,
4
]
[
5
,
4
]
>>>
maximal_repetition_free_prefix
([
5
,
4
,
5
,
3
])
>>>
maximal_repetition_free_prefix
([
5
,
4
,
5
,
3
]
,
0
)
[
5
,
4
]
[
5
,
4
]
>>>
maximal_repetition_free_prefix
([
3
,
2
,
1
,
2
,
4
])
>>>
maximal_repetition_free_prefix
([
3
,
2
,
1
,
2
,
4
]
,
0
)
[
3
,
2
,
1
]
[
3
,
2
,
1
]
"""
"""
return
[]
# stub
if
len
(
sequence
)
<
2
:
return
sequence
elif
sequence
[
x
]
in
sequence
[
0
:
x
+
1
]:
return
sequence
[
0
:
x
-
2
]
else
:
return
maximal_repetition_free_prefix
(
sequence
,
x
+
1
)
def
maximal_repetition_free_subsequence
(
sequence
):
def
maximal_repetition_free_subsequence
(
sequence
):
...
...
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