Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
magic_square
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JangHyeongJun
magic_square
Commits
f3113cb4
Commit
f3113cb4
authored
4 years ago
by
JangHyeongJun
Browse files
Options
Downloads
Patches
Plain Diff
" test_nxn Finish."
parent
c9c9dd79
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test_nxn.py
+19
-9
19 additions, 9 deletions
test_nxn.py
with
19 additions
and
9 deletions
test_nxn.py
+
19
−
9
View file @
f3113cb4
...
...
@@ -25,13 +25,21 @@ def mktable(str):
table
=
[[
0
]
*
num
for
i
in
range
(
num
)]
# n차 테이블
return
table
def
isEvenMagic
(
str
):
with
open
(
"
4x4.txt
"
,
'
r
'
)
as
f
:
lines
=
f
.
readlines
()
# readlines가 EOF까지만 읽으므로, EOF를 체크할 필요가 없다.
try
:
# 스페이스로 구분해서 입력한경우
arr1
=
[
int
(
a
)
for
a
in
str
.
split
()]
#EOF에 대한 처리가 포함되어있음.
except
ValueError
:
# , 컴마로 구분해서 입력한경우
arr1
=
[
int
(
a
)
for
a
in
str
.
split
(
'
,
'
)]
def
isEvenMagic
(
ar
):
avg
=
ar
[
0
]
+
ar
[
1
]
+
ar
[
2
]
+
ar
[
3
]
#기준값 구해놓기
if
(
ar
[
0
]
+
ar
[
4
]
+
ar
[
8
]
+
ar
[
12
]
!=
avg
)
:
return
False
#1째 가로-새로줄 검사
if
(
ar
[
4
]
+
ar
[
5
]
+
ar
[
6
]
+
ar
[
7
]
!=
avg
or
ar
[
1
]
+
ar
[
5
]
+
ar
[
9
]
+
ar
[
13
]
!=
avg
)
:
return
False
#2째 가로-새로줄검사
if
(
ar
[
8
]
+
ar
[
9
]
+
ar
[
10
]
+
ar
[
11
]
!=
avg
or
ar
[
2
]
+
ar
[
6
]
+
ar
[
10
]
+
ar
[
14
]
!=
avg
)
:
return
False
#3째 가로-새로줄 검사
if
(
ar
[
12
]
+
ar
[
13
]
+
ar
[
14
]
+
ar
[
15
]
!=
avg
or
ar
[
3
]
+
ar
[
7
]
+
ar
[
11
]
+
ar
[
15
]
!=
avg
):
return
False
#마지막 가로-새로줄 검사
if
(
ar
[
0
]
+
ar
[
1
]
+
ar
[
4
]
+
ar
[
5
]
!=
avg
):
return
False
#1사분면 검사
if
(
ar
[
2
]
+
ar
[
3
]
+
ar
[
6
]
+
ar
[
7
]
!=
avg
):
return
False
#2사분면 검사
if
(
ar
[
8
]
+
ar
[
9
]
+
ar
[
12
]
+
ar
[
13
]
!=
avg
):
return
False
#3사분면 검사
if
(
ar
[
10
]
+
ar
[
11
]
+
ar
[
14
]
+
ar
[
15
]
!=
avg
):
return
False
#4사분면 검사
if
(
ar
[
3
]
+
ar
[
6
]
+
ar
[
9
]
+
ar
[
12
]
!=
avg
):
return
False
#대각선검사
if
(
ar
[
0
]
+
ar
[
5
]
+
ar
[
10
]
+
ar
[
15
]
!=
avg
):
return
False
#대각선검사
else
:
return
True
def
isOddMagic
(
table
):
...
...
@@ -77,8 +85,10 @@ else :
with
open
(
"
4x4.txt
"
,
'
r
'
)
as
f
:
lines
=
f
.
readlines
()
myset
=
set
(
lines
)
print
(
"
결과 파일 내 {}개의 중복이 존재합니다
"
.
format
(
len
(
lines
)
-
len
(
myset
)))
if
(
len
(
lines
)
-
len
(
myset
)
==
0
):
print
(
"
결과 파일 내 중복이 존재하지 않습니다.
"
)
else
:
print
(
"
결과 파일 내 {}개의 중복이 존재합니다
"
.
format
(
len
(
lines
)
-
len
(
myset
)))
for
i
in
lines
:
endd
=
isEvenMagic
()
arr
=
[
int
(
a
)
for
a
in
i
.
split
()]
#4x4.txt 파일의 한줄은 각각 type : str 이므로, 이를 list에 int 로 split 해서 처리함.
endd
=
isEvenMagic
(
arr
)
print
(
i
[
0
:
len
(
lines
[
0
])
-
1
],
'
-
'
,
endd
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment