Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jinhua115315
Python
提交
ea2ddaaf
P
Python
项目概览
jinhua115315
/
Python
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
P
Python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ea2ddaaf
编写于
10月 20, 2018
作者:
A
Alex Brown
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
all valid python 3
上级
b566055e
变更
37
展开全部
隐藏空白更改
内联
并排
Showing
37 changed file
with
76 addition
and
1436 deletion
+76
-1436
boolean_algebra/quine_mc_cluskey.py
boolean_algebra/quine_mc_cluskey.py
+3
-3
ciphers/affine_cipher.py
ciphers/affine_cipher.py
+3
-3
ciphers/brute_force_caesar_cipher.py
ciphers/brute_force_caesar_cipher.py
+1
-1
ciphers/caesar_cipher.py
ciphers/caesar_cipher.py
+4
-4
ciphers/rsa_cipher.py
ciphers/rsa_cipher.py
+1
-1
ciphers/simple_substitution_cipher.py
ciphers/simple_substitution_cipher.py
+2
-2
ciphers/transposition_cipher.py
ciphers/transposition_cipher.py
+3
-3
ciphers/transposition_cipher_encrypt_decrypt_file.py
ciphers/transposition_cipher_encrypt_decrypt_file.py
+3
-3
ciphers/vigenere_cipher.py
ciphers/vigenere_cipher.py
+3
-3
data_structures/graph/bellman_ford.py
data_structures/graph/bellman_ford.py
+6
-6
data_structures/graph/dijkstra.py
data_structures/graph/dijkstra.py
+6
-6
data_structures/graph/floyd_warshall.py
data_structures/graph/floyd_warshall.py
+5
-5
graphs/minimum_spanning_tree_kruskal.py
graphs/minimum_spanning_tree_kruskal.py
+2
-2
graphs/minimum_spanning_tree_prims.py
graphs/minimum_spanning_tree_prims.py
+2
-2
graphs/scc_kosaraju.py
graphs/scc_kosaraju.py
+2
-2
machine_learning/perceptron.py
machine_learning/perceptron.py
+2
-2
maths/sieve_of_eratosthenes.py
maths/sieve_of_eratosthenes.py
+2
-2
neural_network/perceptron.py
neural_network/perceptron.py
+1
-1
other/nested_brackets.py
other/nested_brackets.py
+1
-1
other/tower_of_hanoi.py
other/tower_of_hanoi.py
+1
-1
project_euler/problem_02/sol3.py
project_euler/problem_02/sol3.py
+1
-1
project_euler/problem_03/sol1.py
project_euler/problem_03/sol1.py
+1
-1
project_euler/problem_03/sol2.py
project_euler/problem_03/sol2.py
+1
-1
project_euler/problem_04/sol1.py
project_euler/problem_04/sol1.py
+2
-2
project_euler/problem_04/sol2.py
project_euler/problem_04/sol2.py
+2
-2
project_euler/problem_05/sol1.py
project_euler/problem_05/sol1.py
+2
-2
project_euler/problem_05/sol2.py
project_euler/problem_05/sol2.py
+1
-1
project_euler/problem_06/sol1.py
project_euler/problem_06/sol1.py
+2
-2
project_euler/problem_06/sol2.py
project_euler/problem_06/sol2.py
+2
-2
project_euler/problem_07/sol1.py
project_euler/problem_07/sol1.py
+2
-2
project_euler/problem_07/sol2.py
project_euler/problem_07/sol2.py
+1
-1
project_euler/problem_08/sol1.py
project_euler/problem_08/sol1.py
+1
-1
project_euler/problem_09/sol2.py
project_euler/problem_09/sol2.py
+1
-1
project_euler/problem_13/sol1.py
project_euler/problem_13/sol1.py
+2
-2
project_euler/problem_16/sol1.py
project_euler/problem_16/sol1.py
+1
-1
project_euler/problem_20/sol1.py
project_euler/problem_20/sol1.py
+1
-1
tags
tags
+0
-1360
未找到文件。
boolean_algebra/quine_mc_cluskey.py
浏览文件 @
ea2ddaaf
...
...
@@ -99,8 +99,8 @@ def prime_implicant_chart(prime_implicants, binary):
return
chart
def
main
():
no_of_variable
=
int
(
raw_
input
(
"Enter the no. of variables
\n
"
))
minterms
=
[
int
(
x
)
for
x
in
raw_
input
(
"Enter the decimal representation of Minterms 'Spaces Seprated'
\n
"
).
split
()]
no_of_variable
=
int
(
input
(
"Enter the no. of variables
\n
"
))
minterms
=
[
int
(
x
)
for
x
in
input
(
"Enter the decimal representation of Minterms 'Spaces Seprated'
\n
"
).
split
()]
binary
=
decimal_to_binary
(
no_of_variable
,
minterms
)
prime_implicants
=
check
(
binary
)
...
...
@@ -113,4 +113,4 @@ def main():
print
(
essential_prime_implicants
)
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
main
()
ciphers/affine_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -4,9 +4,9 @@ import sys, random, cryptomath_module as cryptoMath
SYMBOLS
=
""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
def
main
():
message
=
raw_
input
(
'Enter message: '
)
key
=
int
(
raw_
input
(
'Enter key [2000 - 9000]: '
))
mode
=
raw_
input
(
'Encrypt/Decrypt [E/D]: '
)
message
=
input
(
'Enter message: '
)
key
=
int
(
input
(
'Enter key [2000 - 9000]: '
))
mode
=
input
(
'Encrypt/Decrypt [E/D]: '
)
if
mode
.
lower
().
startswith
(
'e'
):
mode
=
'encrypt'
...
...
ciphers/brute_force_caesar_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -44,7 +44,7 @@ def decrypt(message):
print
(
"Decryption using Key #%s: %s"
%
(
key
,
translated
))
def
main
():
message
=
raw_
input
(
"Encrypted message: "
)
message
=
input
(
"Encrypted message: "
)
message
=
message
.
upper
()
decrypt
(
message
)
...
...
ciphers/caesar_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -40,25 +40,25 @@ def main():
print
(
"3.BruteForce"
)
print
(
"4.Quit"
)
while
True
:
choice
=
raw_
input
(
"What would you like to do?: "
)
choice
=
input
(
"What would you like to do?: "
)
if
choice
not
in
[
'1'
,
'2'
,
'3'
,
'4'
]:
print
(
"Invalid choice"
)
elif
choice
==
'1'
:
strng
=
raw_
input
(
"Please enter the string to be ecrypted: "
)
strng
=
input
(
"Please enter the string to be ecrypted: "
)
while
True
:
key
=
int
(
input
(
"Please enter off-set between 1-94: "
))
if
key
in
range
(
1
,
95
):
print
(
encrypt
(
strng
,
key
))
main
()
elif
choice
==
'2'
:
strng
=
raw_
input
(
"Please enter the string to be decrypted: "
)
strng
=
input
(
"Please enter the string to be decrypted: "
)
while
True
:
key
=
raw_int
(
input
(
"Please enter off-set between 1-94: "
))
if
key
>
0
and
key
<=
94
:
print
(
decrypt
(
strng
,
key
))
main
()
elif
choice
==
'3'
:
strng
=
raw_
input
(
"Please enter the string to be decrypted: "
)
strng
=
input
(
"Please enter the string to be decrypted: "
)
brute_force
(
strng
)
main
()
elif
choice
==
'4'
:
...
...
ciphers/rsa_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -6,7 +6,7 @@ BYTE_SIZE = 256
def
main
():
filename
=
'encrypted_file.txt'
response
=
raw_
input
(
'Encrypte\Decrypt [e\d]: '
)
response
=
input
(
'Encrypte\Decrypt [e\d]: '
)
if
response
.
lower
().
startswith
(
'e'
):
mode
=
'encrypt'
...
...
ciphers/simple_substitution_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -4,9 +4,9 @@ import sys, random
LETTERS
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def
main
():
message
=
raw_
input
(
'Enter message: '
)
message
=
input
(
'Enter message: '
)
key
=
'LFWOAYUISVKMNXPBDCRJTQEGHZ'
resp
=
raw_
input
(
'Encrypt/Decrypt [e/d]: '
)
resp
=
input
(
'Encrypt/Decrypt [e/d]: '
)
checkValidKey
(
key
)
...
...
ciphers/transposition_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -2,9 +2,9 @@ from __future__ import print_function
import
math
def
main
():
message
=
raw_
input
(
'Enter message: '
)
key
=
int
(
raw_
input
(
'Enter key [2-%s]: '
%
(
len
(
message
)
-
1
)))
mode
=
raw_
input
(
'Encryption/Decryption [e/d]: '
)
message
=
input
(
'Enter message: '
)
key
=
int
(
input
(
'Enter key [2-%s]: '
%
(
len
(
message
)
-
1
)))
mode
=
input
(
'Encryption/Decryption [e/d]: '
)
if
mode
.
lower
().
startswith
(
'e'
):
text
=
encryptMessage
(
key
,
message
)
...
...
ciphers/transposition_cipher_encrypt_decrypt_file.py
浏览文件 @
ea2ddaaf
...
...
@@ -5,15 +5,15 @@ import transposition_cipher as transCipher
def
main
():
inputFile
=
'Prehistoric Men.txt'
outputFile
=
'Output.txt'
key
=
int
(
raw_
input
(
'Enter key: '
))
mode
=
raw_
input
(
'Encrypt/Decrypt [e/d]: '
)
key
=
int
(
input
(
'Enter key: '
))
mode
=
input
(
'Encrypt/Decrypt [e/d]: '
)
if
not
os
.
path
.
exists
(
inputFile
):
print
(
'File %s does not exist. Quitting...'
%
inputFile
)
sys
.
exit
()
if
os
.
path
.
exists
(
outputFile
):
print
(
'Overwrite %s? [y/n]'
%
outputFile
)
response
=
raw_
input
(
'> '
)
response
=
input
(
'> '
)
if
not
response
.
lower
().
startswith
(
'y'
):
sys
.
exit
()
...
...
ciphers/vigenere_cipher.py
浏览文件 @
ea2ddaaf
...
...
@@ -2,9 +2,9 @@ from __future__ import print_function
LETTERS
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def
main
():
message
=
raw_
input
(
'Enter message: '
)
key
=
raw_
input
(
'Enter key [alphanumeric]: '
)
mode
=
raw_
input
(
'Encrypt/Decrypt [e/d]: '
)
message
=
input
(
'Enter message: '
)
key
=
input
(
'Enter key [alphanumeric]: '
)
mode
=
input
(
'Encrypt/Decrypt [e/d]: '
)
if
mode
.
lower
().
startswith
(
'e'
):
mode
=
'encrypt'
...
...
data_structures/graph/bellman_ford.py
浏览文件 @
ea2ddaaf
...
...
@@ -35,8 +35,8 @@ def BellmanFord(graph, V, E, src):
#MAIN
V
=
int
(
raw_
input
(
"Enter number of vertices: "
))
E
=
int
(
raw_
input
(
"Enter number of edges: "
))
V
=
int
(
input
(
"Enter number of vertices: "
))
E
=
int
(
input
(
"Enter number of edges: "
))
graph
=
[
dict
()
for
j
in
range
(
E
)]
...
...
@@ -45,10 +45,10 @@ for i in range(V):
for
i
in
range
(
E
):
print
(
"
\n
Edge "
,
i
+
1
)
src
=
int
(
raw_
input
(
"Enter source:"
))
dst
=
int
(
raw_
input
(
"Enter destination:"
))
weight
=
float
(
raw_
input
(
"Enter weight:"
))
src
=
int
(
input
(
"Enter source:"
))
dst
=
int
(
input
(
"Enter destination:"
))
weight
=
float
(
input
(
"Enter weight:"
))
graph
[
i
]
=
{
"src"
:
src
,
"dst"
:
dst
,
"weight"
:
weight
}
gsrc
=
int
(
raw_
input
(
"
\n
Enter shortest path source:"
))
gsrc
=
int
(
input
(
"
\n
Enter shortest path source:"
))
BellmanFord
(
graph
,
V
,
E
,
gsrc
)
data_structures/graph/dijkstra.py
浏览文件 @
ea2ddaaf
...
...
@@ -38,8 +38,8 @@ def Dijkstra(graph, V, src):
#MAIN
V
=
int
(
raw_
input
(
"Enter number of vertices: "
))
E
=
int
(
raw_
input
(
"Enter number of edges: "
))
V
=
int
(
input
(
"Enter number of vertices: "
))
E
=
int
(
input
(
"Enter number of edges: "
))
graph
=
[[
float
(
'inf'
)
for
i
in
range
(
V
)]
for
j
in
range
(
V
)]
...
...
@@ -48,10 +48,10 @@ for i in range(V):
for
i
in
range
(
E
):
print
(
"
\n
Edge "
,
i
+
1
)
src
=
int
(
raw_
input
(
"Enter source:"
))
dst
=
int
(
raw_
input
(
"Enter destination:"
))
weight
=
float
(
raw_
input
(
"Enter weight:"
))
src
=
int
(
input
(
"Enter source:"
))
dst
=
int
(
input
(
"Enter destination:"
))
weight
=
float
(
input
(
"Enter weight:"
))
graph
[
src
][
dst
]
=
weight
gsrc
=
int
(
raw_
input
(
"
\n
Enter shortest path source:"
))
gsrc
=
int
(
input
(
"
\n
Enter shortest path source:"
))
Dijkstra
(
graph
,
V
,
gsrc
)
data_structures/graph/floyd_warshall.py
浏览文件 @
ea2ddaaf
...
...
@@ -30,8 +30,8 @@ def FloydWarshall(graph, V):
#MAIN
V
=
int
(
raw_
input
(
"Enter number of vertices: "
))
E
=
int
(
raw_
input
(
"Enter number of edges: "
))
V
=
int
(
input
(
"Enter number of vertices: "
))
E
=
int
(
input
(
"Enter number of edges: "
))
graph
=
[[
float
(
'inf'
)
for
i
in
range
(
V
)]
for
j
in
range
(
V
)]
...
...
@@ -40,9 +40,9 @@ for i in range(V):
for
i
in
range
(
E
):
print
(
"
\n
Edge "
,
i
+
1
)
src
=
int
(
raw_
input
(
"Enter source:"
))
dst
=
int
(
raw_
input
(
"Enter destination:"
))
weight
=
float
(
raw_
input
(
"Enter weight:"
))
src
=
int
(
input
(
"Enter source:"
))
dst
=
int
(
input
(
"Enter destination:"
))
weight
=
float
(
input
(
"Enter weight:"
))
graph
[
src
][
dst
]
=
weight
FloydWarshall
(
graph
,
V
)
graphs/minimum_spanning_tree_kruskal.py
浏览文件 @
ea2ddaaf
from
__future__
import
print_function
num_nodes
,
num_edges
=
list
(
map
(
int
,
raw_
input
().
split
()))
num_nodes
,
num_edges
=
list
(
map
(
int
,
input
().
split
()))
edges
=
[]
for
i
in
range
(
num_edges
):
node1
,
node2
,
cost
=
list
(
map
(
int
,
raw_
input
().
split
()))
node1
,
node2
,
cost
=
list
(
map
(
int
,
input
().
split
()))
edges
.
append
((
i
,
node1
,
node2
,
cost
))
edges
=
sorted
(
edges
,
key
=
lambda
edge
:
edge
[
3
])
...
...
graphs/minimum_spanning_tree_prims.py
浏览文件 @
ea2ddaaf
...
...
@@ -101,8 +101,8 @@ def PrimsAlgorithm(l):
return
TreeEdges
# < --------- Prims Algorithm --------- >
n
=
int
(
raw_
input
(
"Enter number of vertices: "
))
e
=
int
(
raw_
input
(
"Enter number of edges: "
))
n
=
int
(
input
(
"Enter number of vertices: "
))
e
=
int
(
input
(
"Enter number of edges: "
))
adjlist
=
defaultdict
(
list
)
for
x
in
range
(
e
):
l
=
[
int
(
x
)
for
x
in
input
().
split
()]
...
...
graphs/scc_kosaraju.py
浏览文件 @
ea2ddaaf
from
__future__
import
print_function
# n - no of nodes, m - no of edges
n
,
m
=
list
(
map
(
int
,
raw_
input
().
split
()))
n
,
m
=
list
(
map
(
int
,
input
().
split
()))
g
=
[[]
for
i
in
range
(
n
)]
#graph
r
=
[[]
for
i
in
range
(
n
)]
#reversed graph
# input graph data (edges)
for
i
in
range
(
m
):
u
,
v
=
list
(
map
(
int
,
raw_
input
().
split
()))
u
,
v
=
list
(
map
(
int
,
input
().
split
()))
g
[
u
].
append
(
v
)
r
[
v
].
append
(
u
)
...
...
machine_learning/perceptron.py
浏览文件 @
ea2ddaaf
...
...
@@ -120,5 +120,5 @@ network.trannig()
while
True
:
sample
=
[]
for
i
in
range
(
3
):
sample
.
insert
(
i
,
float
(
raw_input
(
'value: '
)))
network
.
sort
(
sample
)
\ No newline at end of file
sample
.
insert
(
i
,
float
(
input
(
'value: '
)))
network
.
sort
(
sample
)
maths/sieve_of_eratosthenes.py
浏览文件 @
ea2ddaaf
import
math
n
=
int
(
raw_
input
(
"Enter n: "
))
n
=
int
(
input
(
"Enter n: "
))
def
sieve
(
n
):
l
=
[
True
]
*
(
n
+
1
)
...
...
@@ -21,4 +21,4 @@ def sieve(n):
return
prime
print
(
sieve
(
n
))
\ No newline at end of file
neural_network/perceptron.py
浏览文件 @
ea2ddaaf
...
...
@@ -120,5 +120,5 @@ network.trannig()
while
True
:
sample
=
[]
for
i
in
range
(
3
):
sample
.
insert
(
i
,
float
(
raw_
input
(
'value: '
)))
sample
.
insert
(
i
,
float
(
input
(
'value: '
)))
network
.
sort
(
sample
)
other/nested_brackets.py
浏览文件 @
ea2ddaaf
...
...
@@ -37,7 +37,7 @@ def is_balanced(S):
def
main
():
S
=
raw_
input
(
"Enter sequence of brackets: "
)
S
=
input
(
"Enter sequence of brackets: "
)
if
is_balanced
(
S
):
print
((
S
,
"is balanced"
))
...
...
other/tower_of_hanoi.py
浏览文件 @
ea2ddaaf
...
...
@@ -19,7 +19,7 @@ def moveDisk(fp,tp):
print
((
'moving disk from'
,
fp
,
'to'
,
tp
))
def
main
():
height
=
int
(
raw_
input
(
'Height of hanoi: '
))
height
=
int
(
input
(
'Height of hanoi: '
))
moveTower
(
height
,
'A'
,
'B'
,
'C'
)
if
__name__
==
'__main__'
:
...
...
project_euler/problem_02/sol3.py
浏览文件 @
ea2ddaaf
...
...
@@ -7,7 +7,7 @@ By considering the terms in the Fibonacci sequence whose values do not exceed n,
e.g. for n=10, we have {2,8}, sum is 10.
'''
"""Python 3"""
n
=
int
(
raw_
input
())
n
=
int
(
input
())
a
=
0
b
=
2
count
=
0
...
...
project_euler/problem_03/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -19,7 +19,7 @@ def isprime(no):
return
True
maxNumber
=
0
n
=
int
(
raw_
input
())
n
=
int
(
input
())
if
(
isprime
(
n
)):
print
(
n
)
else
:
...
...
project_euler/problem_03/sol2.py
浏览文件 @
ea2ddaaf
...
...
@@ -4,7 +4,7 @@ The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor o
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
'''
from
__future__
import
print_function
n
=
int
(
raw_
input
())
n
=
int
(
input
())
prime
=
1
i
=
2
while
(
i
*
i
<=
n
):
...
...
project_euler/problem_04/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -4,7 +4,7 @@ A palindromic number reads the same both ways. The largest palindrome made from
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
'''
from
__future__
import
print_function
limit
=
int
(
raw_
input
(
"limit? "
))
limit
=
int
(
input
(
"limit? "
))
# fetchs the next number
for
number
in
range
(
limit
-
1
,
10000
,
-
1
):
...
...
@@ -26,4 +26,4 @@ for number in range(limit-1,10000,-1):
print
(
number
)
exit
(
0
)
divisor
-=
1
\ No newline at end of file
divisor
-=
1
project_euler/problem_04/sol2.py
浏览文件 @
ea2ddaaf
...
...
@@ -12,8 +12,8 @@ for i in range(999,100,-1):
arr
.
append
(
i
*
j
)
arr
.
sort
()
n
=
int
(
raw_
input
())
n
=
int
(
input
())
for
i
in
arr
[::
-
1
]:
if
(
i
<
n
):
print
(
i
)
exit
(
0
)
\ No newline at end of file
exit
(
0
)
project_euler/problem_05/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -5,7 +5,7 @@ What is the smallest positive number that is evenly divisible(divisible with no
'''
from
__future__
import
print_function
n
=
int
(
raw_
input
())
n
=
int
(
input
())
i
=
0
while
1
:
i
+=
n
*
(
n
-
1
)
...
...
@@ -18,4 +18,4 @@ while 1:
if
(
i
==
0
):
i
=
1
print
(
i
)
break
\ No newline at end of file
break
project_euler/problem_05/sol2.py
浏览文件 @
ea2ddaaf
...
...
@@ -13,7 +13,7 @@ def gcd(x,y):
def
lcm
(
x
,
y
):
return
(
x
*
y
)
//
gcd
(
x
,
y
)
n
=
int
(
raw_
input
())
n
=
int
(
input
())
g
=
1
for
i
in
range
(
1
,
n
+
1
):
g
=
lcm
(
g
,
i
)
...
...
project_euler/problem_06/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -12,9 +12,9 @@ from __future__ import print_function
suma
=
0
sumb
=
0
n
=
int
(
raw_
input
())
n
=
int
(
input
())
for
i
in
range
(
1
,
n
+
1
):
suma
+=
i
**
2
sumb
+=
i
sum
=
sumb
**
2
-
suma
print
(
sum
)
\ No newline at end of file
print
(
sum
)
project_euler/problem_06/sol2.py
浏览文件 @
ea2ddaaf
...
...
@@ -9,8 +9,8 @@ Hence the difference between the sum of the squares of the first ten natural num
Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
'''
from
__future__
import
print_function
n
=
int
(
raw_
input
())
n
=
int
(
input
())
suma
=
n
*
(
n
+
1
)
/
2
suma
**=
2
sumb
=
n
*
(
n
+
1
)
*
(
2
*
n
+
1
)
/
6
print
(
suma
-
sumb
)
\ No newline at end of file
print
(
suma
-
sumb
)
project_euler/problem_07/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -16,7 +16,7 @@ def isprime(n):
if
(
n
%
i
==
0
):
return
False
return
True
n
=
int
(
raw_
input
())
n
=
int
(
input
())
i
=
0
j
=
1
while
(
i
!=
n
and
j
<
3
):
...
...
@@ -27,4 +27,4 @@ while(i!=n):
j
+=
2
if
(
isprime
(
j
)):
i
+=
1
print
(
j
)
\ No newline at end of file
print
(
j
)
project_euler/problem_07/sol2.py
浏览文件 @
ea2ddaaf
...
...
@@ -4,7 +4,7 @@ def isprime(number):
if
number
%
i
==
0
:
return
False
return
True
n
=
int
(
raw_
input
(
'Enter The N
\'
th Prime Number You Want To Get: '
))
# Ask For The N'th Prime Number Wanted
n
=
int
(
input
(
'Enter The N
\'
th Prime Number You Want To Get: '
))
# Ask For The N'th Prime Number Wanted
primes
=
[]
num
=
2
while
len
(
primes
)
<
n
:
...
...
project_euler/problem_08/sol1.py
浏览文件 @
ea2ddaaf
import
sys
def
main
():
LargestProduct
=
-
sys
.
maxsize
-
1
number
=
raw_
input
().
strip
()
number
=
input
().
strip
()
for
i
in
range
(
len
(
number
)
-
13
):
product
=
1
for
j
in
range
(
13
):
...
...
project_euler/problem_09/sol2.py
浏览文件 @
ea2ddaaf
...
...
@@ -6,7 +6,7 @@ Find maximum possible value of product of a,b,c among all such Pythagorean tripl
product
=-
1
d
=
0
N
=
int
(
raw_
input
())
N
=
int
(
input
())
for
a
in
range
(
1
,
N
//
3
):
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c """
b
=
(
N
*
N
-
2
*
a
*
N
)
//
(
2
*
N
-
2
*
a
)
...
...
project_euler/problem_13/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -4,11 +4,11 @@ Work out the first ten digits of the sum of the N 50-digit numbers.
'''
from
__future__
import
print_function
n
=
int
(
raw_
input
().
strip
())
n
=
int
(
input
().
strip
())
array
=
[]
for
i
in
range
(
n
):
array
.
append
(
int
(
raw_
input
().
strip
()))
array
.
append
(
int
(
input
().
strip
()))
print
(
str
(
sum
(
array
))[:
10
])
project_euler/problem_16/sol1.py
浏览文件 @
ea2ddaaf
power
=
int
(
raw_
input
(
"Enter the power of 2: "
))
power
=
int
(
input
(
"Enter the power of 2: "
))
num
=
2
**
power
string_num
=
str
(
num
)
...
...
project_euler/problem_20/sol1.py
浏览文件 @
ea2ddaaf
...
...
@@ -15,7 +15,7 @@ def split_and_add(number):
return
sum_of_digits
# Taking the user input.
number
=
int
(
raw_
input
(
"Enter the Number: "
))
number
=
int
(
input
(
"Enter the Number: "
))
# Assigning the factorial from the factorial function.
factorial
=
factorial
(
number
)
...
...
tags
已删除
100644 → 0
浏览文件 @
b566055e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录