From dcade47ca7f5b2f19f726af67d080bfe689421c0 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 11 Nov 2022 23:37:16 +0500 Subject: [PATCH 1/3] Luna --- index.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..dda084f --- /dev/null +++ b/index.php @@ -0,0 +1,31 @@ + "VISA","5"=>"Mastercard ","220"=>"MIR"]; + + $card = str_replace(' ','',$card); + $arr = array(); + for($i = 0; $i < strlen($card); $i++){ + $arr[$i] = (int)($card[$i]); + } + for($j = 0; $j < count($arr); $j+=2){ + $arr[$j]*= 2; + if($arr[$j] >= 10){ + $arr[$j] = $arr[$j] % 10 + intdiv($arr[$j],$arr[$j]%10); + } + } + if(array_key_exists($card[0],$paymentSystem)){ + $paymentSystem = $paymentSystem[$card[0]]; + } + elseif(array_key_exists(substr($card,0,3),$paymentSystem)){ + $paymentSystem = $paymentSystem[substr($card,0,3)]; + } + else{ + $paymentSystem = "UNKNOWN"; + } + $isvalid = (array_sum($arr) % 10 == 0) ? "true" : "false"; + return ["isValid" => $isvalid, "paymentSystem"=> $paymentSystem]; + +} +print_r(isValid("2201 1111 1111 1111")); + +?> From a7c7e3413d18d148cab5fc9c8322ab35200fb71c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 12 Nov 2022 00:39:01 +0500 Subject: [PATCH 2/3] version 2 --- index.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index dda084f..40f8244 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,7 @@ function isValid($card){ for($j = 0; $j < count($arr); $j+=2){ $arr[$j]*= 2; if($arr[$j] >= 10){ - $arr[$j] = $arr[$j] % 10 + intdiv($arr[$j],$arr[$j]%10); + $arr[$j] = $arr[$j] % 10 + intdiv($arr[$j],10); } } if(array_key_exists($card[0],$paymentSystem)){ @@ -26,6 +26,8 @@ function isValid($card){ return ["isValid" => $isvalid, "paymentSystem"=> $paymentSystem]; } -print_r(isValid("2201 1111 1111 1111")); +$numberOfCard = readline("Введите номер карты:"); + +print_r(isValid($numberOfCard)); ?> From 36b7b9ff2f34f23d6f7460bf3f32406d41bd2f4e Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 12 Nov 2022 00:41:48 +0500 Subject: [PATCH 3/3] version2 --- .idea/.gitignore | 8 ++++++++ .idea/ex1.iml | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/php.xml | 4 ++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 34 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/ex1.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ex1.iml b/.idea/ex1.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/ex1.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c176c3a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..7e5d55a --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file