aboutsummaryrefslogtreecommitdiff
path: root/challenge-103
diff options
context:
space:
mode:
authorCris-HD <crisn7@hotmail.com>2021-03-14 18:28:23 +0100
committerCris-HD <crisn7@hotmail.com>2021-03-14 18:28:23 +0100
commita02538ffee2ff5ea9f7a1932eb04f2a87db615af (patch)
tree4898d372d9cbc39c3473e673593437f358bd0bdb /challenge-103
parent4a289a702db8c240e4362ae01c10c203cb19c968 (diff)
downloadperlweeklychallenge-club-a02538ffee2ff5ea9f7a1932eb04f2a87db615af.tar.gz
perlweeklychallenge-club-a02538ffee2ff5ea9f7a1932eb04f2a87db615af.tar.bz2
perlweeklychallenge-club-a02538ffee2ff5ea9f7a1932eb04f2a87db615af.zip
Added challenge 103 solution
Diffstat (limited to 'challenge-103')
-rw-r--r--challenge-103/cristian-heredia/perl/ch-1.pl67
-rw-r--r--challenge-103/cristian-heredia/python/ch-1.py51
2 files changed, 118 insertions, 0 deletions
diff --git a/challenge-103/cristian-heredia/perl/ch-1.pl b/challenge-103/cristian-heredia/perl/ch-1.pl
new file mode 100644
index 0000000000..2baa5d2a1e
--- /dev/null
+++ b/challenge-103/cristian-heredia/perl/ch-1.pl
@@ -0,0 +1,67 @@
+=begin
+
+TASK #1 › Chinese Zodiac
+Submitted by: Mohammad S Anwar
+You are given a year $year.
+
+Write a script to determine the Chinese Zodiac for the given year $year. Please check out wikipage for more information about it.
+
+The animal cycle: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig.
+The element cycle: Wood, Fire, Earth, Metal, Water.
+
+Example 1:
+ Input: 2017
+ Output: Fire Rooster
+Example 2:
+ Input: 1938
+ Output: Earth Tiger
+
+=end
+=cut
+
+#Firt year to start: 1924 wood rat
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my @animals = qw(Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig);
+
+my $i;
+my $year = 2017;
+my $counter = 0;
+
+calculateElement();
+
+sub calculateElement {
+ my ($lastChar) = $year =~ /(.?)$/;
+
+ if ($lastChar == 0 or $lastChar == 1) {
+ print "Metal ";
+ }
+ elsif ($lastChar == 2 or $lastChar == 3) {
+ print "Water ";
+ }
+ elsif ($lastChar == 4 or $lastChar == 5) {
+ print "Wood ";
+ }
+ elsif ($lastChar == 6 or $lastChar == 7) {
+ print "Fire ";
+ }
+ else {
+ print "Earth ";
+ }
+ calculateAnimal();
+}
+
+sub calculateAnimal {
+ for ($i = 1924; $i<$year; $i++){
+ if ($counter == 11){
+ $counter = 0;
+ }
+ else {
+ $counter++;
+ }
+ }
+ print "$animals[$counter]";
+}
diff --git a/challenge-103/cristian-heredia/python/ch-1.py b/challenge-103/cristian-heredia/python/ch-1.py
new file mode 100644
index 0000000000..a0af98fa80
--- /dev/null
+++ b/challenge-103/cristian-heredia/python/ch-1.py
@@ -0,0 +1,51 @@
+'''
+
+TASK #1 › Chinese Zodiac
+Submitted by: Mohammad S Anwar
+You are given a year $year.
+
+Write a script to determine the Chinese Zodiac for the given year $year. Please check out wikipage for more information about it.
+
+The animal cycle: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig.
+The element cycle: Wood, Fire, Earth, Metal, Water.
+
+Example 1:
+ Input: 2017
+ Output: Fire Rooster
+Example 2:
+ Input: 1938
+ Output: Earth Tiger
+
+'''
+
+#Firt year to start: 1924 wood rat
+
+
+animals = ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"]
+year = '2017'
+
+
+def calculateElement():
+ if (year[-1] == '0' or year[-1] == '1'):
+ return "Metal"
+ elif (year[-1] == '2' or year[-1] == '3'):
+ return "Water"
+ elif (year[-1] == '4' or year[-1] == '5'):
+ return "Wood"
+ elif (year[-1] == '6' or year[-1] == '7'):
+ return "Fire"
+ else:
+ return "Earth"
+
+def calculateAnimal():
+ start = 1924
+ counter = 0
+ while start < int(year):
+ if (counter == 11):
+ counter = 0
+ else:
+ counter += 1
+ start += 1
+ return animals[counter]
+
+print( calculateElement(), calculateAnimal())