-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87dcb26
commit 3a0a11d
Showing
10 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters