Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ script:
matrix
networking_flow
other
project_euler
searches
sorts
strings
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
4 changes: 3 additions & 1 deletion project_euler/problem_11/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""

from __future__ import print_function
import os

try:
xrange # Python 2
Expand Down Expand Up @@ -85,7 +86,8 @@ def solution():
70600674
"""
grid = []
with open("grid.txt") as file:
path = os.path.split(os.path.realpath(__file__))
with open(path[0] + "/grid.txt") as file:
for line in file:
grid.append(line.strip("\n").split(" "))

Expand Down
4 changes: 3 additions & 1 deletion project_euler/problem_11/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""

from __future__ import print_function
import os

try:
xrange # Python 2
Expand All @@ -38,7 +39,8 @@ def solution():
>>> solution()
70600674
"""
with open("grid.txt", "r") as f:
path = os.path.split(os.path.realpath(__file__))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More intuitive to do is.path.dirname() rather than .split()[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed "os.path.split(os.path.realpath(file))" to "os.path.dirname(file)". Thanks for suggestion.

with open(path[0] + "/grid.txt") as f:
l = []
for i in xrange(20):
l.append([int(x) for x in f.readline().split()])
Expand Down
Empty file.
Empty file.
4 changes: 3 additions & 1 deletion project_euler/problem_13/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
numbers.
"""
from __future__ import print_function
import os

try:
raw_input # Python 2
Expand All @@ -16,7 +17,8 @@ def solution(array):

>>> sum = 0
>>> array = []
>>> with open("num.txt",'r') as f:
>>> path = os.path.split(os.path.realpath(__file__))
>>> with open(path[0] + "/num.txt","r") as f:
... for line in f:
... array.append(int(line))
...
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 5 additions & 1 deletion project_euler/problem_22/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

What is the total of all the name scores in the file?
"""
import os


try:
xrange # Python 2
except NameError:
Expand All @@ -27,7 +30,8 @@ def solution():
>>> solution()
871198282
"""
with open("p022_names.txt") as file:
path = os.path.split(os.path.realpath(__file__))
with open(path[0] + "/p022_names.txt") as file:
names = str(file.readlines()[0])
names = names.replace('"', "").split(",")

Expand Down
4 changes: 3 additions & 1 deletion project_euler/problem_22/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

What is the total of all the name scores in the file?
"""
import os


def solution():
Expand All @@ -25,7 +26,8 @@ def solution():
"""
total_sum = 0
temp_sum = 0
with open("p022_names.txt") as file:
path = os.path.split(os.path.realpath(__file__))
with open(path[0] + "/p022_names.txt") as file:
name = str(file.readlines()[0])
name = name.replace('"', "").split(",")

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.