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
a1b27e17
Commit
a1b27e17
authored
Sep 19, 2020
by
Samarth Joshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating soln to return list
parent
932a7a51
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
16 deletions
+11
-16
q1/q1.py
q1/q1.py
+4
-12
q1/sieve.py
q1/sieve.py
+6
-3
q1/test.sh
q1/test.sh
+1
-1
No files found.
q1/q1.py
View file @
a1b27e17
import
functools
as
ft
import
functools
as
ft
import
sys
import
sys
import
math
def
Fib
(
n
):
def
Fib
(
n
):
primes
=
range
(
2
,
n
+
1
)
uniq
=
ft
.
reduce
(
lambda
x
,
y
:
x
.
union
(
y
),
map
(
lambda
x
:
set
(
range
(
x
*
x
,
n
+
1
,
x
)),
filter
(
lambda
x
:
x
*
x
<=
n
,
range
(
2
,
n
+
1
))),
set
())
return
list
(
filter
(
lambda
x
:
x
not
in
uniq
,
range
(
2
,
n
+
1
)))
space
=
filter
(
lambda
x
:
x
*
x
<=
n
,
primes
)
print
(
Fib
(
int
(
sys
.
argv
[
1
])))
multiples
=
map
(
lambda
x
:
set
(
range
(
x
*
x
,
n
+
1
,
x
)),
space
)
\ No newline at end of file
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
View file @
a1b27e17
...
@@ -5,6 +5,8 @@ def SieveOfEratosthenes(n):
...
@@ -5,6 +5,8 @@ def SieveOfEratosthenes(n):
# Create a boolean array "prime[0..n]" and initialize
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
# finally be false if i is Not a prime, else true.
if
n
==
0
:
return
list
()
prime
=
[
True
]
*
(
n
+
1
)
prime
=
[
True
]
*
(
n
+
1
)
p
=
2
p
=
2
while
(
p
*
p
<=
n
):
while
(
p
*
p
<=
n
):
...
@@ -19,11 +21,12 @@ def SieveOfEratosthenes(n):
...
@@ -19,11 +21,12 @@ def SieveOfEratosthenes(n):
prime
[
0
]
=
False
prime
[
0
]
=
False
prime
[
1
]
=
False
prime
[
1
]
=
False
# Print all prime numbers
# Print all prime numbers
listp
=
[]
for
p
in
range
(
n
+
1
):
for
p
in
range
(
n
+
1
):
if
prime
[
p
]:
if
prime
[
p
]:
print
(
str
(
p
)
+
" "
,
end
=
''
),
#Use print(p) for python 3
listp
.
append
(
p
),
#Use print(p) for python 3
print
()
return
listp
SieveOfEratosthenes
(
int
(
sys
.
argv
[
1
]
))
print
(
SieveOfEratosthenes
(
int
(
sys
.
argv
[
1
])
))
\ No newline at end of file
q1/test.sh
View file @
a1b27e17
#!/bin/bash
#!/bin/bash
for
i
in
{
10..1
000
}
for
i
in
{
2698..10
000
}
do
do
python3 q1.py
$i
>
mine
python3 q1.py
$i
>
mine
python3 sieve.py
$i
>
sieves
python3 sieve.py
$i
>
sieves
...
...
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