Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
0020e804
Commit
0020e804
authored
6 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
added method calculate_luhn_checksum
parent
34ce8645
No related branches found
No related tags found
1 merge request
!178
Feature/import data pdp
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/algorithm/luhn_algorithm.py
+9
-3
9 additions, 3 deletions
smash/web/algorithm/luhn_algorithm.py
with
9 additions
and
3 deletions
smash/web/algorithm/luhn_algorithm.py
+
9
−
3
View file @
0020e804
def
digits_of
(
n
):
return
[
int
(
d
)
for
d
in
str
(
n
)]
class
LuhnAlgorithm
(
object
):
def
__init__
(
self
):
pass
@staticmethod
def
luhn_checksum
(
card_number
):
def
digits_of
(
n
):
return
[
int
(
d
)
for
d
in
str
(
n
)]
digits
=
digits_of
(
card_number
)
odd_digits
=
digits
[
-
1
::
-
2
]
even_digits
=
digits
[
-
2
::
-
2
]
...
...
@@ -19,3 +21,7 @@ class LuhnAlgorithm(object):
@staticmethod
def
is_luhn_valid
(
card_number
):
return
LuhnAlgorithm
.
luhn_checksum
(
card_number
)
==
0
@staticmethod
def
calculate_luhn_checksum
(
card_number
):
return
(
10
-
LuhnAlgorithm
.
luhn_checksum
(
card_number
+
'
0
'
))
%
10
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