diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-07-07 09:51:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-07 09:51:40 +0100 |
| commit | a138dca3eff46a5fd036e2390f36c8bb9ab0df27 (patch) | |
| tree | 4a67380b28dcc3ef05b7d1ff631dc7315b0bce72 | |
| parent | dc30a7471d8a9e9616bf38801b90981a6eac4240 (diff) | |
| parent | 5516343a9bbb9423587e63419c0184726397d0f8 (diff) | |
| download | perlweeklychallenge-club-a138dca3eff46a5fd036e2390f36c8bb9ab0df27.tar.gz perlweeklychallenge-club-a138dca3eff46a5fd036e2390f36c8bb9ab0df27.tar.bz2 perlweeklychallenge-club-a138dca3eff46a5fd036e2390f36c8bb9ab0df27.zip | |
Merge pull request #4453 from E7-87-83/newt
blogpost added; ch-2.sh fixed
| -rw-r--r-- | challenge-120/cheok-yin-fung/bash/ch-2.sh | 27 | ||||
| -rw-r--r-- | challenge-120/cheok-yin-fung/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-120/cheok-yin-fung/perl/ch-2.pl | 3 |
3 files changed, 25 insertions, 6 deletions
diff --git a/challenge-120/cheok-yin-fung/bash/ch-2.sh b/challenge-120/cheok-yin-fung/bash/ch-2.sh index 964b3e203a..05a7a94302 100644 --- a/challenge-120/cheok-yin-fung/bash/ch-2.sh +++ b/challenge-120/cheok-yin-fung/bash/ch-2.sh @@ -2,21 +2,36 @@ # The Weekly Challenge - 120 # Task 2 Clock Angle # Usage: $ chmod +x ch-2.sh -# $ ./ch-2.sh hh mm +# $ ./ch-2.sh "hh:mm" # current time: date +"%H:%M" +# ref: +# 1. Abigail's submission +# 2. https://riptutorial.com/bash/example/19469/regex-matching -hr_hand_inc_per_deg=2 #unit: minute per degree +hr_hand_inc=2 #unit: minute per degree minute_hand_rate=6 #unit: degree per minute -h=$1 -m=$2 +pat='^([0-9][0-9]):([0-9][0-9])$' -deg_h=$((($h*30+$m/$hr_hand_inc_per_deg)%360)) +[[ $1 =~ $pat ]] +if [ ! ${BASH_REMATCH[0]} ]; +then + echo Usage: $ ./ch-2.sh "hh:mm" + exit +fi + +h=${BASH_REMATCH[1]} +m=${BASH_REMATCH[2]} + +h=$(("1$h"-100)) +m=$(("1$m"-100)) + +deg_h=$((($h*30+$m/$hr_hand_inc)%360)) deg_m=$((($minute_hand_rate*$m)%360 )) half=0 -if [ $(($m%$hr_hand_inc_per_deg)) -eq 1 ]; +if [ $(($m%$hr_hand_inc)) -eq 1 ]; then half=5 if [ $deg_h -gt $deg_m ]; diff --git a/challenge-120/cheok-yin-fung/blog.txt b/challenge-120/cheok-yin-fung/blog.txt new file mode 100644 index 0000000000..c677798785 --- /dev/null +++ b/challenge-120/cheok-yin-fung/blog.txt @@ -0,0 +1 @@ +https://e7-87-83.github.io/coding/challenge_120.html diff --git a/challenge-120/cheok-yin-fung/perl/ch-2.pl b/challenge-120/cheok-yin-fung/perl/ch-2.pl index b626643592..0e256601d4 100644 --- a/challenge-120/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-120/cheok-yin-fung/perl/ch-2.pl @@ -35,6 +35,9 @@ sub clock_angle { } +# ref: https://www.omnicalculator.com/math/clock-angle +# #clock-angles-the-angle-between-clock-hands + ok ( clock_angle("03:10") == 35, "Example 1"); ok ( clock_angle("04:00") == 120 , "Example 2"); ok ( clock_angle("12:00") == 0 , "noon"); |
