Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projecteuler
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
projecteuler
Commits
0a0bd415
Commit
0a0bd415
authored
Jan 06, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added bruteforce attempts for problems 243 and 364.
parent
4540b70b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
.gitignore
.gitignore
+3
-0
problem243.py
problem243.py
+28
-0
problem364.py
problem364.py
+53
-0
No files found.
.gitignore
0 → 100644
View file @
0a0bd415
*.pyc
*.swp
*~
problem243.py
0 → 100644
View file @
0a0bd415
def
is_resilient
(
n
,
d
):
if
n
==
1
:
return
True
for
div
in
xrange
(
2
,
min
(
n
,
d
)
+
1
):
if
not
n
%
div
and
not
d
%
div
:
return
False
return
True
def
resilience
(
d
):
r
=
0
for
n
in
xrange
(
1
,
d
):
if
is_resilient
(
n
,
d
):
r
+=
1
return
r
/
(
d
-
1.
)
smallest
=
15499.
/
94744
d
=
2
while
True
:
if
resilience
(
d
)
<
smallest
:
print
d
break
d
+=
1
problem364.py
0 → 100644
View file @
0a0bd415
from
copy
import
copy
from
sys
import
argv
,
exit
,
setrecursionlimit
setrecursionlimit
(
10000000
)
def
T
(
N
,
seats
=
None
):
if
not
seats
:
seats
=
[
False
]
*
N
elif
all
(
seats
):
return
1
t
=
0
seated
=
False
# 1. If there is any seat whose adjacent seat(s) are not occupied, take
# such a seat
for
i
,
taken
in
enumerate
(
seats
):
if
not
taken
and
(
not
i
or
not
seats
[
i
-
1
])
\
and
(
i
==
N
-
1
or
not
seats
[
i
+
1
]):
new_seats
=
copy
(
seats
)
new_seats
[
i
]
=
True
t
+=
T
(
N
,
new_seats
)
seated
=
True
# 2. If there is no such seat and there is any seat for which only one
# adjacent seat is occupied take such a seat
if
not
seated
:
for
i
,
taken
in
enumerate
(
seats
):
if
not
taken
and
((
not
i
and
seats
[
1
])
\
or
(
i
==
N
-
1
and
seats
[
N
-
2
])
or
(
seats
[
i
-
1
]
^
seats
[
i
+
1
])):
new_seats
=
copy
(
seats
)
new_seats
[
i
]
=
True
t
+=
T
(
N
,
new_seats
)
seated
=
True
# 3.Otherwise take one of the remaining available seats
if
not
seated
:
for
i
,
taken
in
enumerate
(
seats
):
if
not
taken
:
new_seats
=
copy
(
seats
)
new_seats
[
i
]
=
True
t
+=
T
(
N
,
new_seats
)
del
seats
return
t
if
len
(
argv
)
<
2
:
print
'Usage: python %s N'
%
argv
[
0
]
exit
(
1
)
print
T
(
int
(
argv
[
1
]))
%
100000007
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