Skip to content

Commit

Permalink
Fix some initializers, more compression
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 4, 2024
1 parent f26317b commit 49d6494
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
2 changes: 0 additions & 2 deletions fortran/src/include/constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ module constants
integer, parameter :: ERROR_ANSWER_TYPE_MISMATCH = 3
integer, parameter :: ERROR_PRIME_ALLOCATE_FAILED = 4
integer, parameter :: ERROR_UTILS_ALLOCATE_FAILED = 5

contains
end module constants

3 changes: 0 additions & 3 deletions fortran/src/include/math.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module math
use constants
implicit none

contains

pure integer(i18t) function factorial(n) result(answer)
integer, intent(in) :: n
integer :: i
Expand All @@ -12,6 +10,5 @@ pure integer(i18t) function factorial(n) result(answer)
answer = answer * i
end do
end function

end module math

5 changes: 0 additions & 5 deletions fortran/src/include/primes.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
module primes
use constants

implicit none
integer, private, parameter :: bits_per_int = 64
integer(i18t), private, allocatable :: prime_sieve(:)
integer(i18t), private :: current_n = 0
logical, private :: initialized = .false.

contains

subroutine sieve_up_to(n)
integer(i18t), intent(in) :: n
integer(i18t) :: p, i
Expand Down Expand Up @@ -126,5 +122,4 @@ logical function is_prime(num) result(ip)
ip = (check == 1 .or. check == 5) .and. is_composite(num) == 0
endif
end function

end module primes
4 changes: 0 additions & 4 deletions fortran/src/include/ranges.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module ranges
use constants
implicit none

contains

pure integer function range_entry3(start, step, idx) result(answer)
integer, intent(in) :: start, step, idx
answer = start + (step * idx)
Expand Down Expand Up @@ -34,6 +32,4 @@ pure integer function range_entry4(start, end, step, idx) result(answer)

answer = range_entry3(start, step, l_idx)
end function

end module ranges

12 changes: 7 additions & 5 deletions fortran/src/include/utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module utils

logical, private :: cache_inited = .false.
type(AnswerT), private, dimension(1024) :: cached_answers

contains
function get_data_file(filename) result(contents)
character(len=*), intent(in) :: filename
Expand Down Expand Up @@ -124,10 +123,15 @@ function get_answer(id) result(answer)

subroutine parse_line(line, id_out, type_out, length_out, value_out)
character(len=*), intent(in) :: line
character(len=32), intent(out) :: value_out = ''
character(len=4), intent(out) :: id_out = '', type_out = '', length_out = ''
character(len=32), intent(out) :: value_out
character(len=4), intent(out) :: id_out, type_out, length_out
integer :: pos, i, last_pos = 0

id_out = ''
type_out = ''
length_out = ''
value_out = ''

do i = 1, 4
pos = index(line(last_pos + 1:), char(9)) ! Find tab character
if (pos == 0) then ! Tab not found, assign remaining part to the last variable
Expand Down Expand Up @@ -163,6 +167,4 @@ subroutine parse_line(line, id_out, type_out, length_out, value_out)
end if
end do
end subroutine parse_line

end module utils

0 comments on commit 49d6494

Please sign in to comment.