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
Christopher Alan Lif
soft160_recursion_lab
Commits
7719de8a
Commit
7719de8a
authored
7 years ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit.
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
fibonacci.py
+141
-0
141 additions, 0 deletions
fibonacci.py
with
143 additions
and
0 deletions
.gitignore
0 → 100644
+
2
−
0
View file @
7719de8a
*~
.idea
This diff is collapsed.
Click to expand it.
fibonacci.py
0 → 100644
+
141
−
0
View file @
7719de8a
#! /usr/bin/python3
def
scalar_fibonacci
(
n
):
"""
Given a nonnegative integer n, return the nth Fibonacci number. For example:
>>>
scalar_fibonacci
(
0
)
0
>>>
scalar_fibonacci
(
1
)
1
>>>
scalar_fibonacci
(
2
)
1
>>>
scalar_fibonacci
(
3
)
2
>>>
scalar_fibonacci
(
4
)
3
>>>
scalar_fibonacci
(
5
)
5
>>>
scalar_fibonacci
(
35
)
9227465
"""
return
0
# stub
def
vector_fibonacci
(
n
):
"""
Given a positive integer n, return a tuple containing the (n-1)th Fibonacci number and the nth Fibonacci number.
For example:
>>>
vector_fibonacci
(
1
)
(
0
,
1
)
>>>
vector_fibonacci
(
2
)
(
1
,
1
)
>>>
vector_fibonacci
(
3
)
(
1
,
2
)
>>>
vector_fibonacci
(
4
)
(
2
,
3
)
>>>
vector_fibonacci
(
5
)
(
3
,
5
)
>>>
vector_fibonacci
(
35
)
(
5702887
,
9227465
)
>>>
vector_fibonacci
(
350
)
(
3865462327928467072415604609040860366007401579690263197296200323999931849
,
6254449428820551641549772190170184190608177514674331726439961915653414425
)
"""
return
0
,
1
# stub
def
maximal_repetition_free_prefix
(
sequence
):
"""
Given a sequence, return its longest repetition-free prefix. For example:
>>>
maximal_repetition_free_prefix
([])
[]
>>>
maximal_repetition_free_prefix
([
5
])
[
5
]
>>>
maximal_repetition_free_prefix
([
5
,
4
])
[
5
,
4
]
>>>
maximal_repetition_free_prefix
([
5
,
5
])
[
5
]
>>>
maximal_repetition_free_prefix
([
5
,
4
,
5
])
[
5
,
4
]
>>>
maximal_repetition_free_prefix
([
5
,
4
,
5
,
3
])
[
5
,
4
]
>>>
maximal_repetition_free_prefix
([
3
,
2
,
1
,
2
,
4
])
[
3
,
2
,
1
]
"""
return
[]
# stub
def
maximal_repetition_free_subsequence
(
sequence
):
"""
Given a sequence, return the last of its longest repetition-free subsequences. For example:
>>>
maximal_repetition_free_subsequence
([])
[]
>>>
maximal_repetition_free_subsequence
([
5
])
[
5
]
>>>
maximal_repetition_free_subsequence
([
5
,
4
])
[
5
,
4
]
>>>
maximal_repetition_free_subsequence
([
5
,
4
,
5
])
[
4
,
5
]
>>>
maximal_repetition_free_subsequence
([
5
,
4
,
5
,
3
])
[
4
,
5
,
3
]
>>>
maximal_repetition_free_subsequence
([
3
,
2
,
1
,
2
,
4
])
[
1
,
2
,
4
]
>>>
maximal_repetition_free_subsequence
([
1
,
2
,
1
,
2
,
1
,
2
,
1
])
[
2
,
1
]
"""
return
[]
# stub
def
maximal_repetition_free_subsequence_version_2
(
sequence
):
"""
Given a sequence, return the last of its longest repetition-free subsequences. For example:
>>>
maximal_repetition_free_subsequence_version_2
([])
[]
>>>
maximal_repetition_free_subsequence_version_2
([
5
])
[
5
]
>>>
maximal_repetition_free_subsequence_version_2
([
5
,
4
])
[
5
,
4
]
>>>
maximal_repetition_free_subsequence_version_2
([
5
,
4
,
5
])
[
4
,
5
]
>>>
maximal_repetition_free_subsequence_version_2
([
5
,
4
,
5
,
3
])
[
4
,
5
,
3
]
>>>
maximal_repetition_free_subsequence_version_2
([
3
,
2
,
1
,
2
,
4
])
[
1
,
2
,
4
]
>>>
maximal_repetition_free_subsequence_version_2
([
1
,
2
,
1
,
2
,
1
,
2
,
1
])
[
2
,
1
]
"""
result
=
[]
for
start
in
range
(
len
(
sequence
)):
for
end
in
range
(
start
+
1
,
len
(
sequence
)
+
1
):
if
end
-
start
>=
len
(
result
):
if
len
(
set
(
sequence
[
start
:
end
]))
==
end
-
start
:
result
=
sequence
[
start
:
end
]
return
result
def
maximal_repetition_free_subsequence_version_3
(
sequence
):
"""
Given a sequence, return the last of its longest repetition-free subsequences. For example:
>>>
maximal_repetition_free_subsequence_version_3
([])
[]
>>>
maximal_repetition_free_subsequence_version_3
([
5
])
[
5
]
>>>
maximal_repetition_free_subsequence_version_3
([
5
,
4
])
[
5
,
4
]
>>>
maximal_repetition_free_subsequence_version_3
([
5
,
4
,
5
])
[
4
,
5
]
>>>
maximal_repetition_free_subsequence_version_3
([
5
,
4
,
5
,
3
])
[
4
,
5
,
3
]
>>>
maximal_repetition_free_subsequence_version_3
([
3
,
2
,
1
,
2
,
4
])
[
1
,
2
,
4
]
>>>
maximal_repetition_free_subsequence_version_3
([
1
,
2
,
1
,
2
,
1
,
2
,
1
])
[
2
,
1
]
"""
return
[]
# stub
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