aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--challenge-001/paulo-custodio/test.pl5
-rw-r--r--challenge-120/paulo-custodio/fortran/ch-1.f9058
-rw-r--r--challenge-120/paulo-custodio/fortran/ch-2.f9050
-rw-r--r--challenge-120/paulo-custodio/perl/ch-1.pl1
5 files changed, 114 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 43ef1dae98..7412a4ad0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
*.o
*.obj
*.ali
+*.bak
ch-1
ch-2
diff --git a/challenge-001/paulo-custodio/test.pl b/challenge-001/paulo-custodio/test.pl
index 6d50c9592d..891786624f 100644
--- a/challenge-001/paulo-custodio/test.pl
+++ b/challenge-001/paulo-custodio/test.pl
@@ -21,6 +21,7 @@ our %LANG = (
cpp => 'cpp',
d => 'd',
forth => 'fs',
+ fortran => 'f90',
lua => 'lua',
pascal => 'pas',
perl => 'pl',
@@ -156,6 +157,10 @@ sub build {
if (/^forth$/) {
return "gforth $prog";
}
+ if (/^fortran$/) {
+ run("gfortran $prog -o $prog_wo_ext") if (!-f $exe || -M $exe > -M $prog);
+ return $exe;
+ }
if (/^lua$/) {
return "$LUA $prog";
}
diff --git a/challenge-120/paulo-custodio/fortran/ch-1.f90 b/challenge-120/paulo-custodio/fortran/ch-1.f90
new file mode 100644
index 0000000000..856659ac35
--- /dev/null
+++ b/challenge-120/paulo-custodio/fortran/ch-1.f90
@@ -0,0 +1,58 @@
+! Challenge 120
+!
+! TASK #1 - Swap Odd/Even bits
+! Submitted by: Mohammad S Anwar
+! You are given a positive integer $N less than or equal to 255.
+!
+! Write a script to swap the odd positioned bit with even positioned bit and
+! print the decimal equivalent of the new binary representation.
+!
+! Example
+! Input: $N = 101
+! Output: 154
+!
+! Binary representation of the given number is 01 10 01 01.
+! The new binary representation after the odd/even swap is 10 01 10 10.
+! The decimal equivalent of 10011010 is 154.
+!
+! Input: $N = 18
+! Output: 33
+!
+! Binary representation of the given number is 00 01 00 10.
+! The new binary representation after the odd/even swap is 00 10 00 01.
+! The decimal equivalent of 100001 is 33.
+
+program ch1
+ implicit none
+
+ integer :: n, stat
+ character(len=50) :: arg
+
+ call get_command_argument(1, arg)
+ if (len_trim(arg) /= 0) then
+ read(arg,*,iostat=stat) n
+ n = swap_bits(n)
+ print *, n
+ end if
+
+contains
+ function swap_bits(n)
+ integer :: swap_bits, n, output, shift
+
+ output = 0
+ shift = 1
+
+ do while (n > 0)
+ if (mod(n, 2) /= 0) then
+ output = output + 2*shift
+ end if
+ n = n / 2
+ if (mod(n, 2) /= 0) then
+ output = output + 1*shift
+ end if
+ n = n / 2
+ shift = shift*4
+ end do
+ swap_bits = output
+ end function swap_bits
+end program ch1
diff --git a/challenge-120/paulo-custodio/fortran/ch-2.f90 b/challenge-120/paulo-custodio/fortran/ch-2.f90
new file mode 100644
index 0000000000..2521e00a5b
--- /dev/null
+++ b/challenge-120/paulo-custodio/fortran/ch-2.f90
@@ -0,0 +1,50 @@
+! Challenge 120
+!
+! TASK #2 - Clock Angle
+! Submitted by: Mohammad S Anwar
+! You are given time $T in the format hh:mm.
+!
+! Write a script to find the smaller angle formed by the hands of an analog
+! clock at a given time.
+!
+! HINT: A analog clock is divided up into 12 sectors. One sector represents 30
+! degree (360/12 = 30).
+!
+! Example
+! Input: $T = '03:10'
+! Output: 35 degree
+!
+! The distance between the 2 and the 3 on the clock is 30 degree.
+! For the 10 minutes i.e. 1/6 of an hour that have passed.
+! The hour hand has also moved 1/6 of the distance between the 3 and the 4,
+! which adds 5 degree (1/6 of 30).
+! The total measure of the angle is 35 degree.
+!
+! Input: $T = '04:00'
+! Output: 120 degree
+
+program ch2
+ implicit none
+
+ integer :: hh, mm, hh_angle, mm_angle, angle, stat, p
+ character(len=50) :: arg
+
+ call get_command_argument(1, arg)
+ if (len_trim(arg) /= 0) then
+ p = index(arg, ':')
+ if (p /= 0) then
+ read(arg(:p-1),*,iostat=stat) hh
+ read(arg(p+1:),*,iostat=stat) mm
+
+ mm_angle = mm*360/60
+ hh_angle = mod(hh, 12)*360/12 + mm_angle/12
+
+ angle = abs(hh_angle - mm_angle)
+ if (angle > 180) then
+ angle = 360 - angle
+ end if
+
+ print *, angle
+ end if
+ end if
+end program ch2
diff --git a/challenge-120/paulo-custodio/perl/ch-1.pl b/challenge-120/paulo-custodio/perl/ch-1.pl
index 1f5768a304..f4a33cc653 100644
--- a/challenge-120/paulo-custodio/perl/ch-1.pl
+++ b/challenge-120/paulo-custodio/perl/ch-1.pl
@@ -41,4 +41,3 @@ sub swap_bits {
}
return $out;
}
-