Skip to content

Commit

Permalink
Mark many functions as pure (no side effects)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 4, 2024
1 parent 766c21a commit f26317b
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion fortran/problem_linker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cat <<EOF3 >> $OUTPUT_FILE
end select
end function run_problem
logical function is_slow(id)
pure logical function is_slow(id)
integer(i4t), intent(in) :: id
select case (id)
EOF3
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/include/math.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module math

contains

integer(i18t) function factorial(n) result(answer)
pure integer(i18t) function factorial(n) result(answer)
integer, intent(in) :: n
integer :: i
answer = 1
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/include/primes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ subroutine clear_prime_bit(num)
end subroutine clear_prime_bit

! Function to check if a bit is set
logical function get_prime_bit(num) result(bit)
pure logical function get_prime_bit(num) result(bit)
integer(i18t), intent(in) :: num
bit = logical(btest(prime_sieve(num / bits_per_int + 1), mod(num, bits_per_int)))
end function get_prime_bit
Expand Down
4 changes: 2 additions & 2 deletions fortran/src/include/ranges.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module ranges

contains

integer function range_entry3(start, step, idx) result(answer)
pure integer function range_entry3(start, step, idx) result(answer)
integer, intent(in) :: start, step, idx
answer = start + (step * idx)
end function

integer function range_entry4(start, end, step, idx) result(answer)
pure integer function range_entry4(start, end, step, idx) result(answer)
integer, intent(in) :: start, end, step, idx
integer :: length, l_idx

Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0001.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
module Problem0001
implicit none
contains
integer function p0001() result(answer)
pure integer function p0001() result(answer)
integer :: i
answer = 0

Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0002.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
module Problem0002
implicit none
contains
integer function p0002() result(answer)
pure integer function p0002() result(answer)
integer :: a = 1, b = 2, i, tmp
answer = 0

Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0004.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module Problem0004
implicit none
contains
integer function p0004() result(answer)
pure integer function p0004() result(answer)
integer :: i, j, k, n, prod, length
logical :: is_palindrome
character(len=8) :: string
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0006.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
module Problem0006
implicit none
contains
integer function p0006() result(answer)
pure integer function p0006() result(answer)
integer :: sum = 1, sum_of_squares = 1, i
answer = 0

Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0008.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Problem0008
use constants
implicit none
contains
integer(i18t) function p0008() result(answer)
pure integer(i18t) function p0008() result(answer)
integer :: i, j
integer(i18t) :: tmp
integer(i1t), dimension(1000) :: digits
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0009.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
module Problem0009
implicit none
contains
integer function p0009() result(answer)
pure integer function p0009() result(answer)
integer :: a, b, c = 3, a_square, b_square, c_square

do
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0011.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Problem0011
use constants
implicit none
contains
integer(i18t) function p0011() result(answer)
pure integer(i18t) function p0011() result(answer)
integer(i2t), dimension(20, 20) :: grid
integer(i18t) :: tmp
integer :: i, j
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0013.f90
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module Problem0013
use constants
implicit none
contains
integer(i18t) function p0013() result(answer)
pure integer(i18t) function p0013() result(answer)
integer(i18t), dimension(3, 100) :: numbers
integer(i18t), dimension(3) :: arr = (/ 0, 0, 0 /)
integer(i18t) :: ten18 = 1000000000000000000_8
Expand Down
4 changes: 2 additions & 2 deletions fortran/src/p0017.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module Problem0017
implicit none
contains
integer recursive function to_string_len(n) result(answer)
pure integer recursive function to_string_len(n) result(answer)
integer, intent(in) :: n
integer :: tmp
answer = 0
Expand Down Expand Up @@ -71,7 +71,7 @@ integer recursive function to_string_len(n) result(answer)
end if
end function

integer function p0017() result(answer)
pure integer function p0017() result(answer)
integer :: x

answer = 0
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0028.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module Problem0028
use ranges
implicit none
contains
integer function p0028() result(answer)
pure integer function p0028() result(answer)
integer :: i, start

answer = 1
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0034.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Problem0034
use math
implicit none
contains
integer(i18t) function p0034() result(answer)
pure integer(i18t) function p0034() result(answer)
integer :: i, j
integer(i18t) tmp
character(len=5) string
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0076.f90
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module Problem0076
use constants
implicit none
contains
integer function p0076() result(answer)
pure integer function p0076() result(answer)
integer :: idx, i, sum = 100
integer, dimension(100) :: counts
answer = 0
Expand Down
2 changes: 1 addition & 1 deletion fortran/src/p0836.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Problem0836
implicit none
integer, parameter :: p0836_len = 14
contains
character(p0836_len) function p0836()
pure character(p0836_len) function p0836()
p0836 = 'aprilfoolsjoke'
end function p0836
end module Problem0836
Expand Down

0 comments on commit f26317b

Please sign in to comment.