Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SpartanBots
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
Roshan Rabinarayan
SpartanBots
Commits
f3a19c48
Commit
f3a19c48
authored
Sep 18, 2020
by
Roshan Rabinarayan
Browse files
Options
Browse Files
Download
Plain Diff
updated q5
parents
fcc97202
acf87d55
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
2 deletions
+90
-2
q1/q1.py
q1/q1.py
+14
-1
q1/sieve.py
q1/sieve.py
+29
-0
q1/test.sh
q1/test.sh
+16
-0
q2/main.py
q2/main.py
+20
-0
q2/output
q2/output
+5
-0
q2/q2.py
q2/q2.py
+6
-1
No files found.
q1/q1.py
View file @
f3a19c48
import
functools
as
ft
import
sys
def
Fib
(
n
):
## write your code here
\ No newline at end of file
primes
=
range
(
2
,
n
+
1
)
space
=
filter
(
lambda
x
:
x
*
x
<=
n
,
primes
)
multiples
=
map
(
lambda
x
:
set
(
range
(
x
*
x
,
n
+
1
,
x
)),
space
)
uniq
=
ft
.
reduce
(
lambda
x
,
y
:
x
.
union
(
y
),
multiples
)
actual_primes
=
filter
(
lambda
x
:
x
not
in
uniq
,
primes
)
output
=
ft
.
reduce
(
lambda
x
,
y
:
str
(
x
)
+
" "
+
str
(
y
),
actual_primes
)
print
(
output
+
" "
)
Fib
(
int
(
sys
.
argv
[
1
]))
\ No newline at end of file
q1/sieve.py
0 → 100644
View file @
f3a19c48
import
sys
def
SieveOfEratosthenes
(
n
):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
prime
=
[
True
]
*
(
n
+
1
)
p
=
2
while
(
p
*
p
<=
n
):
# If prime[p] is not changed, then it is a prime
if
(
prime
[
p
]
==
True
):
# Update all multiples of p
for
i
in
range
(
p
*
2
,
n
+
1
,
p
):
prime
[
i
]
=
False
p
+=
1
prime
[
0
]
=
False
prime
[
1
]
=
False
# Print all prime numbers
for
p
in
range
(
n
+
1
):
if
prime
[
p
]:
print
(
str
(
p
)
+
" "
,
end
=
''
),
#Use print(p) for python 3
print
()
SieveOfEratosthenes
(
int
(
sys
.
argv
[
1
]))
\ No newline at end of file
q1/test.sh
0 → 100644
View file @
f3a19c48
#!/bin/bash
for
i
in
{
10..1000
}
do
python3 q1.py
$i
>
mine
python3 sieve.py
$i
>
sieves
diff
-Z
mine sieves
>
result
if
[[
-s
result
]]
;
then
echo
failed
$i
else
echo
passed
$i
fi
rm
-f
result
rm
-f
mine
rm
-f
sieves
done
\ No newline at end of file
q2/main.py
View file @
f3a19c48
...
...
@@ -12,3 +12,23 @@ print(l)
L
=
[[
"this"
],[
"is"
],[
"the"
],[
"easiest"
],[
"problem"
],[
"of"
],[
"this"
],[
"outlab"
]]
l
=
collapse
(
L
)
print
(
l
)
L
=
[[
"this"
]]
l
=
collapse
(
L
)
print
(
l
)
L
=
[[],
[
"Once"
,
"upon"
,
"a"
,
"time"
],
[
"in"
,
"a"
,
"galaxy"
,
"far"
,
"far"
,
"away"
]]
l
=
collapse
(
L
)
print
(
l
)
L
=
[[
str
(
2
),
"+"
,
str
(
2
)],
[
'='
],
[
str
(
5
)]]
l
=
collapse
(
L
)
print
(
l
)
L
=
[[],[],[],[],[],[]]
l
=
collapse
(
L
)
print
(
l
)
L
=
[[
str
(
2
),
"+"
,
str
(
2
)],
[
'='
],
[
str
(
5
)]]
l
=
collapse
(
L
)
print
(
l
)
\ No newline at end of file
q2/output
View file @
f3a19c48
this is an interesting python programming exercise.
this is a bad problem
this is the easiest problem of this outlab
this
Once upon a time in a galaxy far far away
2 + 2 = 5
2 + 2 = 5
\ No newline at end of file
q2/q2.py
View file @
f3a19c48
import
functools
import
operator
def
collapse
(
L
)
:
flat
=
functools
.
reduce
(
lambda
x
,
y
:
x
+
y
,
L
)
if
flat
:
return
functools
.
reduce
(
lambda
x
,
y
:
x
+
" "
+
y
,
flat
)
else
:
return
""
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