diff --git a/README.rst b/README.rst index 817132db..f49ee94e 100644 --- a/README.rst +++ b/README.rst @@ -85,7 +85,7 @@ Olivia's Project Euler Solutions | | | | |CodeQL| |br| | | | | | |C#-lint| | +------------+----------------------------+--------+-------------------+ - | Fortran | (In Progress) | 3 | (In Progress) | + | Fortran | (In Progress) | 5 | (In Progress) | +------------+----------------------------+--------+-------------------+ | Java | Java 8+ in Corretto, |br| | 22 | |Javai| |br| | | | Dragonwell, Liberica, |br| | | |Ja-Cov| |br| | diff --git a/docs/index.rst b/docs/index.rst index 279e991a..75521a51 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -88,13 +88,13 @@ Problems Solved +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`005`|:c-d:`0005`|:cp-d:`0005`|:cs-d:`0005`| |:ja-d:`0005`|:js-d:`0005`|:lu-d:`0005`|:py-d:`0005`|:rs-d:`0005`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`006`|:c-d:`0006`|:cp-d:`0006`|:cs-d:`0006`| |:ja-d:`0006`|:js-d:`0006`|:lu-d:`0006`|:py-d:`0006`|:rs-d:`0006`| + |:prob:`006`|:c-d:`0006`|:cp-d:`0006`|:cs-d:`0006`|:fr-d:`0006`|:ja-d:`0006`|:js-d:`0006`|:lu-d:`0006`|:py-d:`0006`|:rs-d:`0006`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`007`|:c-d:`0007`|:cp-d:`0007`|:cs-d:`0007`| |:ja-d:`0007`|:js-d:`0007`|:lu-d:`0007`|:py-d:`0007`|:rs-d:`0007`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`008`|:c-d:`0008`|:cp-d:`0008`|:cs-d:`0008`| |:ja-d:`0008`|:js-d:`0008`|:lu-d:`0008`|:py-d:`0008`|:rs-d:`0008`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ - |:prob:`009`|:c-d:`0009`|:cp-d:`0009`|:cs-d:`0009`| |:ja-d:`0009`|:js-d:`0009`|:lu-d:`0009`|:py-d:`0009`|:rs-d:`0009`| + |:prob:`009`|:c-d:`0009`|:cp-d:`0009`|:cs-d:`0009`|:fr-d:`0009`|:ja-d:`0009`|:js-d:`0009`|:lu-d:`0009`|:py-d:`0009`|:rs-d:`0009`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`010`|:c-d:`0010`|:cp-d:`0010`|:cs-d:`0010`| |:ja-d:`0010`|:js-d:`0010`|:lu-d:`0010`|:py-d:`0010`|:rs-d:`0010`| +-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/src/fortran/p0006.rst b/docs/src/fortran/p0006.rst new file mode 100644 index 00000000..dc3c494a --- /dev/null +++ b/docs/src/fortran/p0006.rst @@ -0,0 +1,18 @@ +Fortran Implementation of Problem 6 +=================================== + +View source code :source:`fortran/src/p0006.for` + +.. f:module:: Problem0006 + +.. f:function:: integer Problem0006/p0006() + +.. f:currentmodule:: + +.. f:program:: test0006 + +.. literalinclude:: ../../../fortran/src/p0006.for + :language: Fortran + :linenos: + +.. tags:: arithmetic-progression, sequence-summation diff --git a/docs/src/fortran/p0009.rst b/docs/src/fortran/p0009.rst new file mode 100644 index 00000000..17486b75 --- /dev/null +++ b/docs/src/fortran/p0009.rst @@ -0,0 +1,18 @@ +Fortran Implementation of Problem 9 +=================================== + +View source code :source:`fortran/src/p0009.for` + +.. f:module:: Problem0009 + +.. f:function:: integer Problem0009/p0009() + +.. f:currentmodule:: + +.. f:program:: test0009 + +.. literalinclude:: ../../../fortran/src/p0009.for + :language: Fortran + :linenos: + +.. tags:: pythagorean-triple diff --git a/fortran/README.rst b/fortran/README.rst index 2955cb70..8dc94eb7 100644 --- a/fortran/README.rst +++ b/fortran/README.rst @@ -26,3 +26,6 @@ Problems Solved - ☒ `1 <./src/p0001.for>`__ - ☒ `2 <./src/p0002.for>`__ +- ☒ `6 <./src/p0006.for>`__ +- ☒ `9 <./src/p0009.for>`__ +- ☒ `836 <./src/p0836.for>`__ diff --git a/fortran/src/p0001.for b/fortran/src/p0001.for index 0dd0b8d5..7756bfc6 100644 --- a/fortran/src/p0001.for +++ b/fortran/src/p0001.for @@ -1,3 +1,14 @@ +! Project Euler Question 1 +! +! I did it the old-fashioned way in this language +! +! Problem: +! +! If we list all the natural numbers below 10 that are multiples of 3 or 5, we +! get 3, 5, 6 and 9. The sum of these multiples is 23. +! +! Find the sum of all the multiples of 3 or 5 below 1000. + module Problem0001 implicit none contains diff --git a/fortran/src/p0002.for b/fortran/src/p0002.for index a4aac144..a2134d9a 100644 --- a/fortran/src/p0002.for +++ b/fortran/src/p0002.for @@ -1,3 +1,17 @@ +! Project Euler Problem 2 +! +! I modeled this after the C++ solution, because it was by far the simplest +! +! Problem: +! +! Each new term in the Fibonacci sequence is generated by adding the previous two +! terms. By starting with 1 and 2, the first 10 terms will be: +! +! 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... +! +! By considering the terms in the Fibonacci sequence whose values do not exceed +! four million, find the sum of the even-valued terms. + module Problem0002 implicit none contains diff --git a/fortran/src/p0006.for b/fortran/src/p0006.for new file mode 100644 index 00000000..a5c000a4 --- /dev/null +++ b/fortran/src/p0006.for @@ -0,0 +1,42 @@ +! Project Euler Problem 6 +! +! This turned out to be really easy +! +! Problem: +! +! The sum of the squares of the first ten natural numbers is, +! 1**2 + 2**2 + ... + 10**2 = 385 +! +! The square of the sum of the first ten natural numbers is, +! (1 + 2 + ... + 10)**2 = 55**2 = 3025 +! +! Hence the difference between the sum of the squares of the first ten natural +! numbers and the square of the sum is 3025 − 385 = 2640. +! +! Find the difference between the sum of the squares of the first one hundred +! natural numbers and the square of the sum. + +module Problem0006 + implicit none +contains + integer function p0006() result(answer) + integer :: sum + integer :: sum_of_squares + integer :: i + answer = 0 + sum = 1 + sum_of_squares = 1 + + do i = 2, 100 + sum = sum + i + sum_of_squares = sum_of_squares + i * i + end do + + answer = sum * sum - sum_of_squares + end function p0006 +end module Problem0006 + +program test0006 + use Problem0006 + print *, p0006() +end program test0006 diff --git a/fortran/src/p0009.for b/fortran/src/p0009.for new file mode 100644 index 00000000..d101459d --- /dev/null +++ b/fortran/src/p0009.for @@ -0,0 +1,45 @@ +! Project Euler Problem 9 +! +! This was pretty fun to port +! +! Problem: +! +! A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, +! a**2 + b**2 = c**2 +! +! For example, 3**2 + 4**2 = 9 + 16 = 25 = 5**2. +! +! There exists exactly one Pythagorean triplet for which a + b + c = 1000. +! Find the product abc. + +module Problem0009 + implicit none +contains + integer function p0009() result(answer) + integer :: a, b, c, a_square, b_square, c_square + c = 3 + + do + c_square = c * c + + do b = 2, c + b_square = b * b + + do a = 1, b + a_square = a * a + + if (a_square + b_square == c_square .and. a + b + c == 1000) then + answer = a * b * c + return + end if + end do + end do + c = c + 1 + end do + end function p0009 +end module Problem0009 + +program test0009 + use Problem0009 + print *, p0009() +end program test0009 diff --git a/fortran/src/p0836.for b/fortran/src/p0836.for index 6fb73793..b944aa07 100644 --- a/fortran/src/p0836.for +++ b/fortran/src/p0836.for @@ -1,3 +1,18 @@ +! Project Euler Problem 836 +! +! Alright, this was funny +! +! Problem: +! +! Let A be an **affine plane** over a **radically integral local field** F with residual characteristic p. +! +! We consider an **open oriented line section** U of A with normalized Haar measure m. +! +! Define f(m,p) as the maximal possible discriminant of the **jacobian** associated to the +! **orthogonal kernel embedding** of U into A. +! +! Find f(20230401, 57). Give as your answer the concatenation of the first letters of each bolded word. + module Problem0836 implicit none contains