Skip to content

Commit

Permalink
Solve p6, p9 in fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 18, 2024
1 parent 87dcb26 commit 3a0a11d
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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| |
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`|
+-----------+-----------+------------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
18 changes: 18 additions & 0 deletions docs/src/fortran/p0006.rst
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions docs/src/fortran/p0009.rst
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions fortran/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`__
11 changes: 11 additions & 0 deletions fortran/src/p0001.for
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions fortran/src/p0002.for
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 42 additions & 0 deletions fortran/src/p0006.for
Original file line number Diff line number Diff line change
@@ -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 3025385 = 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
45 changes: 45 additions & 0 deletions fortran/src/p0009.for
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions fortran/src/p0836.for
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3a0a11d

Please sign in to comment.