From b030823122864999ced2b576ca11e13ef4680274 Mon Sep 17 00:00:00 2001 From: ykkTechc <102883569+ykkTechc@users.noreply.github.com> Date: Fri, 24 Jun 2022 15:24:52 +0900 Subject: [PATCH 1/6] Revert "03_php_algorithm lesson01 ~ 02" This reverts commit 969f4da1704e37701fa4ca4c7d1a96934e62edee. --- algorithm01.php | 59 --------------------------------------------- algorithm02.php | 64 ------------------------------------------------- 2 files changed, 123 deletions(-) delete mode 100644 algorithm01.php delete mode 100644 algorithm02.php diff --git a/algorithm01.php b/algorithm01.php deleted file mode 100644 index 2366ae9..0000000 --- a/algorithm01.php +++ /dev/null @@ -1,59 +0,0 @@ - - - - - -世界のナベアツプログラム - - -
- '; - } - array_reduce(range(1, 100), 'aho_wan_echo'); - ?> -
- - diff --git a/algorithm02.php b/algorithm02.php deleted file mode 100644 index 43bd20c..0000000 --- a/algorithm02.php +++ /dev/null @@ -1,64 +0,0 @@ -"; - return ['お釣り', $tmp]; -} - -?> - - - - -お釣り - - -
- ' . PHP_EOL; - foreach ($ar as [$key, $val]) { - echo $key . '円 x ' . $val . '枚
' . PHP_EOL; - } - ?> -
- - - From 68fde1893ede559a7ac33d681d69b3d550eae494 Mon Sep 17 00:00:00 2001 From: ykkTechc <102883569+ykkTechc@users.noreply.github.com> Date: Fri, 24 Jun 2022 15:28:08 +0900 Subject: [PATCH 2/6] Revert "Revert "03_php_algorithm lesson01 ~ 02"" This reverts commit b030823122864999ced2b576ca11e13ef4680274. --- algorithm01.php | 59 +++++++++++++++++++++++++++++++++++++++++++++ algorithm02.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 algorithm01.php create mode 100644 algorithm02.php diff --git a/algorithm01.php b/algorithm01.php new file mode 100644 index 0000000..2366ae9 --- /dev/null +++ b/algorithm01.php @@ -0,0 +1,59 @@ + + + + + +世界のナベアツプログラム + + +
+ '; + } + array_reduce(range(1, 100), 'aho_wan_echo'); + ?> +
+ + diff --git a/algorithm02.php b/algorithm02.php new file mode 100644 index 0000000..43bd20c --- /dev/null +++ b/algorithm02.php @@ -0,0 +1,64 @@ +"; + return ['お釣り', $tmp]; +} + +?> + + + + +お釣り + + +
+ ' . PHP_EOL; + foreach ($ar as [$key, $val]) { + echo $key . '円 x ' . $val . '枚
' . PHP_EOL; + } + ?> +
+ + + From 2b93a5281f0a2587b9952047136cd02e8b35ba20 Mon Sep 17 00:00:00 2001 From: ykkTechc <102883569+ykkTechc@users.noreply.github.com> Date: Fri, 24 Jun 2022 17:20:14 +0900 Subject: [PATCH 3/6] 03_php_algorithm lesson01~02 --- algorithm01.php | 1 + algorithm02.php | 1 + 2 files changed, 2 insertions(+) diff --git a/algorithm01.php b/algorithm01.php index 2366ae9..2b9f8b0 100644 --- a/algorithm01.php +++ b/algorithm01.php @@ -56,4 +56,5 @@ function aho_wan_echo($t, $i) ?> + diff --git a/algorithm02.php b/algorithm02.php index 43bd20c..b1bb76e 100644 --- a/algorithm02.php +++ b/algorithm02.php @@ -1,4 +1,5 @@ Date: Fri, 24 Jun 2022 18:37:19 +0900 Subject: [PATCH 4/6] =?UTF-8?q?03=5Fphp=5Falgorithm=20lesson01~02=20?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=90=8D=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- algorithm01.php => algorithm_01.php | 0 algorithm02.php => algorithm_02.php | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) rename algorithm01.php => algorithm_01.php (100%) rename algorithm02.php => algorithm_02.php (83%) diff --git a/algorithm01.php b/algorithm_01.php similarity index 100% rename from algorithm01.php rename to algorithm_01.php diff --git a/algorithm02.php b/algorithm_02.php similarity index 83% rename from algorithm02.php rename to algorithm_02.php index b1bb76e..cedaf76 100644 --- a/algorithm02.php +++ b/algorithm_02.php @@ -1,5 +1,4 @@ "; @@ -52,13 +51,14 @@ function calc($yen, $product) {
- ' . PHP_EOL; - foreach ($ar as [$key, $val]) { - echo $key . '円 x ' . $val . '枚
' . PHP_EOL; - } - ?> +' . PHP_EOL; +foreach ($ar as [$key, $val]) { + echo $key . '円 x ' . $val . '枚
' . PHP_EOL; +} +?>
From ae9657f4e61cae4a66656b61a1cdba3323ac9bdf Mon Sep 17 00:00:00 2001 From: ykkTechc <102883569+ykkTechc@users.noreply.github.com> Date: Fri, 24 Jun 2022 18:49:27 +0900 Subject: [PATCH 5/6] =?UTF-8?q?03=5Fphp=5Falgorithm=20lesson01~02=20?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=90=8D=E5=A4=89=E6=9B=B4?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- algorithm_01.php => algorithm01.php | 0 algorithm_02.php => algorithm02.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename algorithm_01.php => algorithm01.php (100%) rename algorithm_02.php => algorithm02.php (100%) diff --git a/algorithm_01.php b/algorithm01.php similarity index 100% rename from algorithm_01.php rename to algorithm01.php diff --git a/algorithm_02.php b/algorithm02.php similarity index 100% rename from algorithm_02.php rename to algorithm02.php From 2976eadba37fe1af779ff761b11bb47bc77e8881 Mon Sep 17 00:00:00 2001 From: ykkTechc <102883569+ykkTechc@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:27:28 +0900 Subject: [PATCH 6/6] =?UTF-8?q?03=5Fphp=5Falgorithm=20lesson01~02=20?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- algorithm01.php | 13 ++++++------- algorithm02.php | 50 ++++++++++++++++++++++++------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/algorithm01.php b/algorithm01.php index 2b9f8b0..5dc82a7 100644 --- a/algorithm01.php +++ b/algorithm01.php @@ -28,11 +28,11 @@ function nabeatu($i) { - if (($i % 15) === 0) { - return "アホわん"; - } elseif (($i % 3) === 0) { + if (($i % 3 === 0) && ($i % 5 === 0)) { + return $i." アホわん"; + } elseif (($i % 3) === 0 ) { return $i." アホ"; - } elseif (($i % 5) === 0) { + } elseif (($i % 5) === 0 ) { return $i." わん"; } else { return $i; @@ -48,13 +48,12 @@ function nabeatu($i)
'; + echo nabeatu($i),'
'; } array_reduce(range(1, 100), 'aho_wan_echo'); ?>
- diff --git a/algorithm02.php b/algorithm02.php index cedaf76..a1ce3f5 100644 --- a/algorithm02.php +++ b/algorithm02.php @@ -18,28 +18,35 @@ // 100円玉で購入した場合、 // 50円足りません。 -$yen = 10000; // 購入金額 -$product = 1000; // 商品金額 +$yen = 100; // 購入金額 +$product = 150; // 商品金額 function calc($yen, $product) { - $change = $yen - $product; - - if ($change == 0) return ['お釣りなし']; - - if ($change < 0) return [$change . '円足りません']; + if ($yen < 500) { + echo $yen."円玉で購入した場合、"; + echo "
"; + } else { + echo $yen."円札で購入した場合、"; + echo "
"; + } - $curr = [10000, 5000, 1000, 500, 100, 50, 10, 5, 1]; - $tmp = []; - foreach ($curr as $val) { - if ($change < $val) continue; - $tmp[] = [$val, intdiv($change, $val)]; - $change = $change % $val; + if ($yen < $product) { + echo ($product - $yen) . '円足りません。'; + return; + } + $change = $yen - $product; + $money = array(10000,5000,1000,500,100,50,10,5,1);{ + foreach ($money as $i => $j) { + $number[$i] = floor($change / $j); + $change -= $j * $number[$i]; + if ($j > 500) { + echo $j . "円札×" . $number[$i] . "枚" . "、"; + } elseif ($j < 10000) { + echo $j . "円玉×" . $number[$i] . "枚" . "、"; + } + } } - - echo $yen . '円で購入した場合'; - echo "
"; - return ['お釣り', $tmp]; } ?> @@ -51,14 +58,7 @@ function calc($yen, $product) {
-' . PHP_EOL; -foreach ($ar as [$key, $val]) { - echo $key . '円 x ' . $val . '枚
' . PHP_EOL; -} -?> +