diff --git a/README.md b/README.md index b299366..fc0551d 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,14 @@ PROJECT EULER ============= * project euler problems with irpf90 + +PROBLEM2 +-------- + +* 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. diff --git a/problem2/IRPF90_man/limit.l b/problem2/IRPF90_man/limit.l new file mode 100644 index 0000000..57c9a93 --- /dev/null +++ b/problem2/IRPF90_man/limit.l @@ -0,0 +1,15 @@ +.TH "IRPF90 entities" l limit "IRPF90 entities" limit +.SH Declaration +.nf +integer :: limit +integer :: term1 +integer :: term2 +.ni +.SH Description +! enter limit +.SH File +.P +limit.irp.f +.SH Needed by +sum +.br diff --git a/problem2/IRPF90_man/sum.l b/problem2/IRPF90_man/sum.l new file mode 100644 index 0000000..343dda0 --- /dev/null +++ b/problem2/IRPF90_man/sum.l @@ -0,0 +1,14 @@ +.TH "IRPF90 entities" l sum "IRPF90 entities" sum +.SH Declaration +.nf +integer :: sum +.ni +.SH Description +! calculates the sum of the factors of +! two integers between 1 to limit +.SH File +.P +sum.irp.f +.SH Needs +limit +.br diff --git a/problem2/IRPF90_man/term1.l b/problem2/IRPF90_man/term1.l new file mode 100644 index 0000000..b06bd0c --- /dev/null +++ b/problem2/IRPF90_man/term1.l @@ -0,0 +1,15 @@ +.TH "IRPF90 entities" l term1 "IRPF90 entities" term1 +.SH Declaration +.nf +integer :: limit +integer :: term1 +integer :: term2 +.ni +.SH Description +! enter limit +.SH File +.P +limit.irp.f +.SH Needed by +sum +.br diff --git a/problem2/IRPF90_man/term2.l b/problem2/IRPF90_man/term2.l new file mode 100644 index 0000000..5a0c5af --- /dev/null +++ b/problem2/IRPF90_man/term2.l @@ -0,0 +1,15 @@ +.TH "IRPF90 entities" l term2 "IRPF90 entities" term2 +.SH Declaration +.nf +integer :: limit +integer :: term1 +integer :: term2 +.ni +.SH Description +! enter limit +.SH File +.P +limit.irp.f +.SH Needed by +sum +.br diff --git a/problem2/IRPF90_temp/Makefile b/problem2/IRPF90_temp/Makefile new file mode 100644 index 0000000..4602bb7 --- /dev/null +++ b/problem2/IRPF90_temp/Makefile @@ -0,0 +1,12 @@ +IRPF90 = irpf90 #-a -d +FC = gfortran +FCFLAGS= -O2 + +SRC= +OBJ= +LIB= + +include irpf90.make + +irpf90.make: $(wildcard *.irp.f) + $(IRPF90) diff --git a/problem2/IRPF90_temp/README.md b/problem2/IRPF90_temp/README.md new file mode 100644 index 0000000..0b8a41a --- /dev/null +++ b/problem2/IRPF90_temp/README.md @@ -0,0 +1,10 @@ +PROBLEM 2 +---------- + +* 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. diff --git a/problem2/IRPF90_temp/irp_stack.irp.F90 b/problem2/IRPF90_temp/irp_stack.irp.F90 new file mode 100644 index 0000000..5869495 --- /dev/null +++ b/problem2/IRPF90_temp/irp_stack.irp.F90 @@ -0,0 +1,38 @@ + +module irp_stack_mod + integer, parameter :: STACKMAX=1000 + character*(128),allocatable :: irp_stack(:,:) + double precision,allocatable :: irp_cpu(:,:) + integer,allocatable :: stack_index(:) + logical :: alloc = .False. + character*(128) :: white = '' +end module + +subroutine irp_enter(irp_where) + use irp_stack_mod + integer :: ithread + integer :: nthread + character*(*) :: irp_where + +!$OMP CRITICAL + ithread = 0 + nthread = 1 + +!$OMP END CRITICAL + + +end subroutine + +subroutine irp_leave (irp_where) + use irp_stack_mod + character*(*) :: irp_where + integer :: ithread + double precision :: cpu + +!$OMP CRITICAL + ithread = 0 + + +!$OMP END CRITICAL +end subroutine + diff --git a/problem2/IRPF90_temp/irp_stack.irp.o b/problem2/IRPF90_temp/irp_stack.irp.o new file mode 100644 index 0000000..9b8cb95 Binary files /dev/null and b/problem2/IRPF90_temp/irp_stack.irp.o differ diff --git a/problem2/IRPF90_temp/irp_stack_mod.mod b/problem2/IRPF90_temp/irp_stack_mod.mod new file mode 100644 index 0000000..4c7ba10 --- /dev/null +++ b/problem2/IRPF90_temp/irp_stack_mod.mod @@ -0,0 +1,42 @@ +GFORTRAN module version '9' created from IRPF90_temp/irp_stack.irp.F90 +MD5:f65ae2717456353521ba97c4b0936c36 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'alloc' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 () () 0 () () +() 0 0) +3 'irp_cpu' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (REAL 8 0 0 0 REAL ()) +0 0 () (2 0 DEFERRED () () () ()) 0 () () () 0 0) +4 'irp_stack' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) ( +CHARACTER 1 0 0 0 CHARACTER ((CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 +'128'))) 0 0 () (2 0 DEFERRED () () () ()) 0 () () () 0 0) +5 'irp_stack_mod' 'irp_stack_mod' '' 1 ((MODULE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () +0 () () () 0 0) +6 'stack_index' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (INTEGER 4 +0 0 0 INTEGER ()) 0 0 () (1 0 DEFERRED () ()) 0 () () () 0 0) +7 'stackmax' 'irp_stack_mod' '' 1 ((PARAMETER UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 +() (CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 '1000') () 0 () () () 0 0) +8 'white' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (CHARACTER 1 0 0 0 CHARACTER ((CONSTANT ( +INTEGER 4 0 0 0 INTEGER ()) 0 '128'))) 0 0 () () 0 () () () 0 0) +) + +('alloc' 0 2 'irp_cpu' 0 3 'irp_stack' 0 4 'irp_stack_mod' 0 5 +'stack_index' 0 6 'stackmax' 0 7 'white' 0 8) diff --git a/problem2/IRPF90_temp/irp_touches.irp.F90 b/problem2/IRPF90_temp/irp_touches.irp.F90 new file mode 100644 index 0000000..2809175 --- /dev/null +++ b/problem2/IRPF90_temp/irp_touches.irp.F90 @@ -0,0 +1,4 @@ +subroutine irp_finalize_1930907644 + use sum_mod + use limit_mod +end diff --git a/problem2/IRPF90_temp/irp_touches.irp.o b/problem2/IRPF90_temp/irp_touches.irp.o new file mode 100644 index 0000000..433aa60 Binary files /dev/null and b/problem2/IRPF90_temp/irp_touches.irp.o differ diff --git a/problem2/IRPF90_temp/irpf90.make b/problem2/IRPF90_temp/irpf90.make new file mode 100644 index 0000000..2c9e45b --- /dev/null +++ b/problem2/IRPF90_temp/irpf90.make @@ -0,0 +1,42 @@ +SRC += IRPF90_temp/irp_stack.irp.F90 IRPF90_temp/irp_touches.irp.F90 IRPF90_temp/prob2.irp.F90 IRPF90_temp/prob2.irp.module.F90 IRPF90_temp/sum.irp.F90 IRPF90_temp/sum.irp.module.F90 IRPF90_temp/limit.irp.F90 IRPF90_temp/limit.irp.module.F90 +OBJ += IRPF90_temp/irp_stack.irp.o IRPF90_temp/sum.irp.o IRPF90_temp/sum.irp.module.o IRPF90_temp/limit.irp.o IRPF90_temp/limit.irp.module.o +OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(OBJ))) IRPF90_temp/irp_touches.irp.o +ALL = prob2 +ALL_OBJ = prob2.irp.module.o prob2.irp.o +ALL_OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(ALL_OBJ))) +all:$(ALL) + @$(MAKE) -s move +prob2: IRPF90_temp/prob2.irp.o IRPF90_temp/prob2.irp.module.o $(OBJ1) + $(FC) -o $@ IRPF90_temp/$@.irp.o IRPF90_temp/$@.irp.module.o $(OBJ1) $(LIB) + @$(MAKE) -s move +IRPF90_temp/prob2.irp.o: IRPF90_temp/prob2.irp.module.o IRPF90_temp/sum.irp.module.o +IRPF90_temp/sum.irp.o: IRPF90_temp/sum.irp.module.o IRPF90_temp/limit.irp.module.o +IRPF90_temp/limit.irp.o: IRPF90_temp/limit.irp.module.o +IRPF90_temp/irp_touches.irp.o: IRPF90_temp/sum.irp.o IRPF90_temp/sum.irp.o IRPF90_temp/limit.irp.o IRPF90_temp/limit.irp.o +IRPF90_temp/%.irp.module.o: IRPF90_temp/%.irp.module.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.module.F90 -o IRPF90_temp/$*.irp.module.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.module.o IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.o: %.F90 + $(FC) $(FCFLAGS) -c $*.F90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f90 + $(FC) $(FCFLAGS) -c $*.f90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f + $(FC) $(FCFLAGS) -c $*.f -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.F + $(FC) $(FCFLAGS) -c $*.F -o IRPF90_temp/$*.o +IRPF90_temp/%.irp.F90: irpf90.make + +move: + @mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING= + +clean: + rm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL) + +veryclean: + - $(MAKE) clean + + - rm -rf IRPF90_temp/ IRPF90_man/ irpf90.make irpf90_variables dist + diff --git a/problem2/IRPF90_temp/irpf90_entities b/problem2/IRPF90_temp/irpf90_entities new file mode 100644 index 0000000..13bce6a --- /dev/null +++ b/problem2/IRPF90_temp/irpf90_entities @@ -0,0 +1,4 @@ +limit.irp.f : integer :: limit +sum.irp.f : integer :: sum +limit.irp.f : integer :: term1 +limit.irp.f : integer :: term2 diff --git a/problem2/IRPF90_temp/limit.irp.F90 b/problem2/IRPF90_temp/limit.irp.F90 new file mode 100644 index 0000000..60e926e --- /dev/null +++ b/problem2/IRPF90_temp/limit.irp.F90 @@ -0,0 +1,31 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +subroutine provide_limit + use limit_mod + implicit none + character*(13) :: irp_here = 'provide_limit' + integer :: irp_err + logical :: irp_dimensions_OK + if (.not.limit_is_built) then + call bld_limit + limit_is_built = .True. + + endif +end subroutine provide_limit + +subroutine bld_limit + use limit_mod + character*(5) :: irp_here = 'limit' ! limit.irp.f: 1 + write(6,*)'limit?' ! limit.irp.f: 7 + read(5,*)limit ! limit.irp.f: 8 + write(6,*)'term1?' ! limit.irp.f: 9 + read(5,*)term1 ! limit.irp.f: 10 + write(6,*)'term2?' ! limit.irp.f: 11 + read(5,*)term2 ! limit.irp.f: 12 +end subroutine bld_limit diff --git a/problem2/IRPF90_temp/limit.irp.f b/problem2/IRPF90_temp/limit.irp.f new file mode 100644 index 0000000..550922e --- /dev/null +++ b/problem2/IRPF90_temp/limit.irp.f @@ -0,0 +1,14 @@ +BEGIN_PROVIDER [integer, limit] +&BEGIN_PROVIDER [integer, term1] +&BEGIN_PROVIDER [integer, term2] + BEGIN_DOC + ! enter limit + END_DOC + write(6,*)'limit?' + read(5,*)limit + write(6,*)'term1?' + read(5,*)term1 + write(6,*)'term2?' + read(5,*)term2 + +END_PROVIDER diff --git a/problem2/IRPF90_temp/limit.irp.module.F90 b/problem2/IRPF90_temp/limit.irp.module.F90 new file mode 100644 index 0000000..9f7f75b --- /dev/null +++ b/problem2/IRPF90_temp/limit.irp.module.F90 @@ -0,0 +1,14 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module limit_mod + integer :: limit + logical :: limit_is_built = .False. + integer :: term2 + integer :: term1 +end module limit_mod diff --git a/problem2/IRPF90_temp/limit.irp.module.o b/problem2/IRPF90_temp/limit.irp.module.o new file mode 100644 index 0000000..b7c6e53 Binary files /dev/null and b/problem2/IRPF90_temp/limit.irp.module.o differ diff --git a/problem2/IRPF90_temp/limit.irp.o b/problem2/IRPF90_temp/limit.irp.o new file mode 100644 index 0000000..09bf53b Binary files /dev/null and b/problem2/IRPF90_temp/limit.irp.o differ diff --git a/problem2/IRPF90_temp/limit_mod.mod b/problem2/IRPF90_temp/limit_mod.mod new file mode 100644 index 0000000..dc4476b --- /dev/null +++ b/problem2/IRPF90_temp/limit_mod.mod @@ -0,0 +1,35 @@ +GFORTRAN module version '9' created from IRPF90_temp/limit.irp.module.F90 +MD5:728dd39b4b8a1d2766ed03cd34d22276 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'limit' 'limit_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 () () 0 () () +() 0 0) +3 'limit_is_built' 'limit_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 +() () 0 () () () 0 0) +4 'limit_mod' 'limit_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +5 'term1' 'limit_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 () () 0 () () +() 0 0) +6 'term2' 'limit_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 () () 0 () () +() 0 0) +) + +('limit' 0 2 'limit_is_built' 0 3 'limit_mod' 0 4 'term1' 0 5 'term2' 0 +6) diff --git a/problem2/IRPF90_temp/prob2 b/problem2/IRPF90_temp/prob2 new file mode 100644 index 0000000..d45ab1d Binary files /dev/null and b/problem2/IRPF90_temp/prob2 differ diff --git a/problem2/IRPF90_temp/prob2.irp.F90 b/problem2/IRPF90_temp/prob2.irp.F90 new file mode 100644 index 0000000..22e736e --- /dev/null +++ b/problem2/IRPF90_temp/prob2.irp.F90 @@ -0,0 +1,21 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +program irp_program ! prob1: 0 + call prob1 ! prob2.irp.f: 0 + call irp_finalize_1930907644() ! prob2.irp.f: 0 +end program ! prob2.irp.f: 0 +subroutine prob1 ! prob2.irp.f: 1 + use sum_mod + implicit none ! prob2.irp.f: 3 + character*(5) :: irp_here = 'prob1' ! prob2.irp.f: 1 + if (.not.sum_is_built) then + call provide_sum + endif + write(6,*)sum ! prob2.irp.f: 5 +end ! prob2.irp.f: 7 diff --git a/problem2/IRPF90_temp/prob2.irp.f b/problem2/IRPF90_temp/prob2.irp.f new file mode 100644 index 0000000..547c1ce --- /dev/null +++ b/problem2/IRPF90_temp/prob2.irp.f @@ -0,0 +1,8 @@ + program prob1 + + implicit none + + write(6,*)sum + + end + diff --git a/problem2/IRPF90_temp/prob2.irp.module.F90 b/problem2/IRPF90_temp/prob2.irp.module.F90 new file mode 100644 index 0000000..60954d8 --- /dev/null +++ b/problem2/IRPF90_temp/prob2.irp.module.F90 @@ -0,0 +1,10 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module prob2_mod +end module prob2_mod diff --git a/problem2/IRPF90_temp/prob2.irp.module.o b/problem2/IRPF90_temp/prob2.irp.module.o new file mode 100644 index 0000000..9557983 Binary files /dev/null and b/problem2/IRPF90_temp/prob2.irp.module.o differ diff --git a/problem2/IRPF90_temp/prob2.irp.o b/problem2/IRPF90_temp/prob2.irp.o new file mode 100644 index 0000000..66286b2 Binary files /dev/null and b/problem2/IRPF90_temp/prob2.irp.o differ diff --git a/problem2/IRPF90_temp/prob2_mod.mod b/problem2/IRPF90_temp/prob2_mod.mod new file mode 100644 index 0000000..4edae4d --- /dev/null +++ b/problem2/IRPF90_temp/prob2_mod.mod @@ -0,0 +1,22 @@ +GFORTRAN module version '9' created from IRPF90_temp/prob2.irp.module.F90 +MD5:56defbc4b9b690d1563ebed7fe5ee2e7 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'prob2_mod' 'prob2_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +) + +('prob2_mod' 0 2) diff --git a/problem2/IRPF90_temp/sum.irp.F90 b/problem2/IRPF90_temp/sum.irp.F90 new file mode 100644 index 0000000..836e87a --- /dev/null +++ b/problem2/IRPF90_temp/sum.irp.F90 @@ -0,0 +1,50 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +subroutine provide_sum + use sum_mod + use limit_mod + implicit none + character*(11) :: irp_here = 'provide_sum' + integer :: irp_err + logical :: irp_dimensions_OK + if (.not.limit_is_built) then + call provide_limit + endif + if (.not.sum_is_built) then + call bld_sum + sum_is_built = .True. + + endif +end subroutine provide_sum + +subroutine bld_sum + use sum_mod + use limit_mod + implicit none ! sum.irp.f: 2 + character*(3) :: irp_here = 'sum' ! sum.irp.f: 1 + integer :: i,j,tmp ! sum.irp.f: 8 + sum=0 ! sum.irp.f: 9 + do while (term1.le.limit .or. term2.le.limit) ! sum.irp.f: 11 + write(6,*)term1,term2 ! sum.irp.f: 13 + if(MOD(term1,2).eq.0) then ! sum.irp.f: 15 +sum=sum+term1 ! sum.irp.f: 15 + endif ! sum.irp.f: 15 + if(MOD(term2,2).eq.0) then ! sum.irp.f: 17 +sum=sum+term2 ! sum.irp.f: 17 + endif ! sum.irp.f: 17 + term1=term1+(term2) ! sum.irp.f: 19 + term2=term2+(term1) ! sum.irp.f: 20 + enddo ! sum.irp.f: 22 + if(MOD(term1,2).eq.0) then ! sum.irp.f: 24 +sum=sum+term1 ! sum.irp.f: 24 + endif ! sum.irp.f: 24 + if(MOD(term2,2).eq.0) then ! sum.irp.f: 26 +sum=sum+term2 ! sum.irp.f: 26 + endif ! sum.irp.f: 26 +end subroutine bld_sum diff --git a/problem2/IRPF90_temp/sum.irp.f b/problem2/IRPF90_temp/sum.irp.f new file mode 100644 index 0000000..5b7ddc2 --- /dev/null +++ b/problem2/IRPF90_temp/sum.irp.f @@ -0,0 +1,29 @@ +BEGIN_PROVIDER [integer, sum] + implicit none + BEGIN_DOC + ! calculates the sum of the factors of + ! two integers between 1 to limit + END_DOC + + integer :: i,j,tmp + sum=0 + + do while (term1.le.limit .or. term2.le.limit) + + write(6,*)term1,term2 + + if(MOD(term1,2).eq.0)sum=sum+term1 + + if(MOD(term2,2).eq.0)sum=sum+term2 + + term1+=term2 + term2+=term1 + + enddo + + if(MOD(term1,2).eq.0)sum=sum+term1 + + if(MOD(term2,2).eq.0)sum=sum+term2 + + +END_PROVIDER diff --git a/problem2/IRPF90_temp/sum.irp.module.F90 b/problem2/IRPF90_temp/sum.irp.module.F90 new file mode 100644 index 0000000..961d405 --- /dev/null +++ b/problem2/IRPF90_temp/sum.irp.module.F90 @@ -0,0 +1,12 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module sum_mod + integer :: sum + logical :: sum_is_built = .False. +end module sum_mod diff --git a/problem2/IRPF90_temp/sum.irp.module.o b/problem2/IRPF90_temp/sum.irp.module.o new file mode 100644 index 0000000..e77ce97 Binary files /dev/null and b/problem2/IRPF90_temp/sum.irp.module.o differ diff --git a/problem2/IRPF90_temp/sum.irp.o b/problem2/IRPF90_temp/sum.irp.o new file mode 100644 index 0000000..eab1ebc Binary files /dev/null and b/problem2/IRPF90_temp/sum.irp.o differ diff --git a/problem2/IRPF90_temp/sum_mod.mod b/problem2/IRPF90_temp/sum_mod.mod new file mode 100644 index 0000000..fec3c04 --- /dev/null +++ b/problem2/IRPF90_temp/sum_mod.mod @@ -0,0 +1,26 @@ +GFORTRAN module version '9' created from IRPF90_temp/sum.irp.module.F90 +MD5:2062756ca08c72ef516ad2ce64c3e19d -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'sum' 'sum_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN +IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 () () 0 () () () 0 0) +3 'sum_is_built' 'sum_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 () () 0 () () +() 0 0) +4 'sum_mod' 'sum_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN +UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 0) +) + +('sum' 0 2 'sum_is_built' 0 3 'sum_mod' 0 4) diff --git a/problem2/Makefile b/problem2/Makefile new file mode 100644 index 0000000..4602bb7 --- /dev/null +++ b/problem2/Makefile @@ -0,0 +1,12 @@ +IRPF90 = irpf90 #-a -d +FC = gfortran +FCFLAGS= -O2 + +SRC= +OBJ= +LIB= + +include irpf90.make + +irpf90.make: $(wildcard *.irp.f) + $(IRPF90) diff --git a/problem2/README.md b/problem2/README.md new file mode 100644 index 0000000..0b8a41a --- /dev/null +++ b/problem2/README.md @@ -0,0 +1,10 @@ +PROBLEM 2 +---------- + +* 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. diff --git a/problem2/irpf90.make b/problem2/irpf90.make new file mode 100644 index 0000000..2c9e45b --- /dev/null +++ b/problem2/irpf90.make @@ -0,0 +1,42 @@ +SRC += IRPF90_temp/irp_stack.irp.F90 IRPF90_temp/irp_touches.irp.F90 IRPF90_temp/prob2.irp.F90 IRPF90_temp/prob2.irp.module.F90 IRPF90_temp/sum.irp.F90 IRPF90_temp/sum.irp.module.F90 IRPF90_temp/limit.irp.F90 IRPF90_temp/limit.irp.module.F90 +OBJ += IRPF90_temp/irp_stack.irp.o IRPF90_temp/sum.irp.o IRPF90_temp/sum.irp.module.o IRPF90_temp/limit.irp.o IRPF90_temp/limit.irp.module.o +OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(OBJ))) IRPF90_temp/irp_touches.irp.o +ALL = prob2 +ALL_OBJ = prob2.irp.module.o prob2.irp.o +ALL_OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(ALL_OBJ))) +all:$(ALL) + @$(MAKE) -s move +prob2: IRPF90_temp/prob2.irp.o IRPF90_temp/prob2.irp.module.o $(OBJ1) + $(FC) -o $@ IRPF90_temp/$@.irp.o IRPF90_temp/$@.irp.module.o $(OBJ1) $(LIB) + @$(MAKE) -s move +IRPF90_temp/prob2.irp.o: IRPF90_temp/prob2.irp.module.o IRPF90_temp/sum.irp.module.o +IRPF90_temp/sum.irp.o: IRPF90_temp/sum.irp.module.o IRPF90_temp/limit.irp.module.o +IRPF90_temp/limit.irp.o: IRPF90_temp/limit.irp.module.o +IRPF90_temp/irp_touches.irp.o: IRPF90_temp/sum.irp.o IRPF90_temp/sum.irp.o IRPF90_temp/limit.irp.o IRPF90_temp/limit.irp.o +IRPF90_temp/%.irp.module.o: IRPF90_temp/%.irp.module.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.module.F90 -o IRPF90_temp/$*.irp.module.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.module.o IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.o: %.F90 + $(FC) $(FCFLAGS) -c $*.F90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f90 + $(FC) $(FCFLAGS) -c $*.f90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f + $(FC) $(FCFLAGS) -c $*.f -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.F + $(FC) $(FCFLAGS) -c $*.F -o IRPF90_temp/$*.o +IRPF90_temp/%.irp.F90: irpf90.make + +move: + @mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING= + +clean: + rm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL) + +veryclean: + - $(MAKE) clean + + - rm -rf IRPF90_temp/ IRPF90_man/ irpf90.make irpf90_variables dist + diff --git a/problem2/irpf90_entities b/problem2/irpf90_entities new file mode 100644 index 0000000..13bce6a --- /dev/null +++ b/problem2/irpf90_entities @@ -0,0 +1,4 @@ +limit.irp.f : integer :: limit +sum.irp.f : integer :: sum +limit.irp.f : integer :: term1 +limit.irp.f : integer :: term2 diff --git a/problem2/limit.irp.f b/problem2/limit.irp.f new file mode 100644 index 0000000..550922e --- /dev/null +++ b/problem2/limit.irp.f @@ -0,0 +1,14 @@ +BEGIN_PROVIDER [integer, limit] +&BEGIN_PROVIDER [integer, term1] +&BEGIN_PROVIDER [integer, term2] + BEGIN_DOC + ! enter limit + END_DOC + write(6,*)'limit?' + read(5,*)limit + write(6,*)'term1?' + read(5,*)term1 + write(6,*)'term2?' + read(5,*)term2 + +END_PROVIDER diff --git a/problem2/prob2 b/problem2/prob2 new file mode 100755 index 0000000..ae3676b Binary files /dev/null and b/problem2/prob2 differ diff --git a/problem2/prob2.irp.f b/problem2/prob2.irp.f new file mode 100755 index 0000000..547c1ce --- /dev/null +++ b/problem2/prob2.irp.f @@ -0,0 +1,8 @@ + program prob1 + + implicit none + + write(6,*)sum + + end + diff --git a/problem2/sum.irp.f b/problem2/sum.irp.f new file mode 100644 index 0000000..5b7ddc2 --- /dev/null +++ b/problem2/sum.irp.f @@ -0,0 +1,29 @@ +BEGIN_PROVIDER [integer, sum] + implicit none + BEGIN_DOC + ! calculates the sum of the factors of + ! two integers between 1 to limit + END_DOC + + integer :: i,j,tmp + sum=0 + + do while (term1.le.limit .or. term2.le.limit) + + write(6,*)term1,term2 + + if(MOD(term1,2).eq.0)sum=sum+term1 + + if(MOD(term2,2).eq.0)sum=sum+term2 + + term1+=term2 + term2+=term1 + + enddo + + if(MOD(term1,2).eq.0)sum=sum+term1 + + if(MOD(term2,2).eq.0)sum=sum+term2 + + +END_PROVIDER diff --git a/problem3/IRPF90_man/factors.l b/problem3/IRPF90_man/factors.l new file mode 100644 index 0000000..585252a --- /dev/null +++ b/problem3/IRPF90_man/factors.l @@ -0,0 +1,17 @@ +.TH "IRPF90 entities" l factors "IRPF90 entities" factors +.SH Declaration +.nf +integer, allocatable :: factors (100000) +integer :: j +.ni +.SH Description +! stores factors +.SH File +.P +factors.irp.f +.SH Needs +number +.br +.SH Needed by +lgpf +.br diff --git a/problem3/IRPF90_man/j.l b/problem3/IRPF90_man/j.l new file mode 100644 index 0000000..0ed4cc6 --- /dev/null +++ b/problem3/IRPF90_man/j.l @@ -0,0 +1,17 @@ +.TH "IRPF90 entities" l j "IRPF90 entities" j +.SH Declaration +.nf +integer, allocatable :: factors (100000) +integer :: j +.ni +.SH Description +! stores factors +.SH File +.P +factors.irp.f +.SH Needs +number +.br +.SH Needed by +lgpf +.br diff --git a/problem3/IRPF90_man/lgpf.l b/problem3/IRPF90_man/lgpf.l new file mode 100644 index 0000000..7161045 --- /dev/null +++ b/problem3/IRPF90_man/lgpf.l @@ -0,0 +1,13 @@ +.TH "IRPF90 entities" l lgpf "IRPF90 entities" lgpf +.SH Declaration +.nf +integer :: lgpf +.ni +.SH Description +! serches for largest factor +.SH File +.P +lgpf.irp.f +.SH Needs +factors +.br diff --git a/problem3/IRPF90_man/number.l b/problem3/IRPF90_man/number.l new file mode 100644 index 0000000..95018d1 --- /dev/null +++ b/problem3/IRPF90_man/number.l @@ -0,0 +1,13 @@ +.TH "IRPF90 entities" l number "IRPF90 entities" number +.SH Declaration +.nf +integer (kind=selected_int_kind(18)) :: number +.ni +.SH Description +! enter limit +.SH File +.P +number.irp.f +.SH Needed by +factors +.br diff --git a/problem3/IRPF90_temp/Makefile b/problem3/IRPF90_temp/Makefile new file mode 100644 index 0000000..4602bb7 --- /dev/null +++ b/problem3/IRPF90_temp/Makefile @@ -0,0 +1,12 @@ +IRPF90 = irpf90 #-a -d +FC = gfortran +FCFLAGS= -O2 + +SRC= +OBJ= +LIB= + +include irpf90.make + +irpf90.make: $(wildcard *.irp.f) + $(IRPF90) diff --git a/problem3/IRPF90_temp/README.md b/problem3/IRPF90_temp/README.md new file mode 100644 index 0000000..e877150 --- /dev/null +++ b/problem3/IRPF90_temp/README.md @@ -0,0 +1,6 @@ +PROBLEM 3 +---------- + +* The prime factors of 13195 are 5, 7, 13 and 29. + +What is the largest prime factor of the number 600851475143 ? diff --git a/problem3/IRPF90_temp/factors.irp.F90 b/problem3/IRPF90_temp/factors.irp.F90 new file mode 100644 index 0000000..4f140e3 --- /dev/null +++ b/problem3/IRPF90_temp/factors.irp.F90 @@ -0,0 +1,68 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +subroutine provide_factors + use factors_mod + use number_mod + implicit none + character*(15) :: irp_here = 'provide_factors' + integer :: irp_err + logical :: irp_dimensions_OK + if (.not.number_is_built) then + call provide_number + endif + if (allocated (factors) ) then + irp_dimensions_OK = .True. + irp_dimensions_OK = irp_dimensions_OK.AND.(SIZE(factors,1)==(100000)) + if (.not.irp_dimensions_OK) then + deallocate(factors,stat=irp_err) + if (irp_err /= 0) then + print *, irp_here//': Deallocation failed: factors' + print *, ' size: (100000)' + endif + if ((100000>0)) then + allocate(factors(100000),stat=irp_err) + if (irp_err /= 0) then + print *, irp_here//': Allocation failed: factors' + print *, ' size: (100000)' + endif + endif + endif + else + if ((100000>0)) then + allocate(factors(100000),stat=irp_err) + if (irp_err /= 0) then + print *, irp_here//': Allocation failed: factors' + print *, ' size: (100000)' + endif + endif + endif + if (.not.factors_is_built) then + call bld_factors + factors_is_built = .True. + + endif +end subroutine provide_factors + +subroutine bld_factors + use factors_mod + use number_mod + implicit none ! factors.irp.f: 7 + character*(7) :: irp_here = 'factors' ! factors.irp.f: 1 + integer :: i ! factors.irp.f: 8 + j=1 ! factors.irp.f: 10 + do i=1,int(SQRT(float(number))) ! factors.irp.f: 12 + if(MOD(number,i).eq.0)then ! factors.irp.f: 13 + factors(j)=i ! factors.irp.f: 14 + j=j+(1) ! factors.irp.f: 15 + endif ! factors.irp.f: 16 + enddo ! factors.irp.f: 17 + do i=1,j ! factors.irp.f: 18 + write(6,*)factors(i) ! factors.irp.f: 19 + enddo ! factors.irp.f: 20 +end subroutine bld_factors diff --git a/problem3/IRPF90_temp/factors.irp.f b/problem3/IRPF90_temp/factors.irp.f new file mode 100644 index 0000000..3b2e292 --- /dev/null +++ b/problem3/IRPF90_temp/factors.irp.f @@ -0,0 +1,22 @@ +BEGIN_PROVIDER [integer, factors, (100000)] +&BEGIN_PROVIDER [integer, j] + BEGIN_DOC + ! stores factors + END_DOC + + implicit none + integer :: i + + j=1 + + do i=1,int(SQRT(float(number))) + if(MOD(number,i).eq.0)then + factors(j)=i + j+=1 + endif + enddo + do i=1,j + write(6,*)factors(i) + enddo + +END_PROVIDER diff --git a/problem3/IRPF90_temp/factors.irp.module.F90 b/problem3/IRPF90_temp/factors.irp.module.F90 new file mode 100644 index 0000000..f376b41 --- /dev/null +++ b/problem3/IRPF90_temp/factors.irp.module.F90 @@ -0,0 +1,13 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module factors_mod + integer :: j + integer, allocatable :: factors (:) + logical :: factors_is_built = .False. +end module factors_mod diff --git a/problem3/IRPF90_temp/factors.irp.module.o b/problem3/IRPF90_temp/factors.irp.module.o new file mode 100644 index 0000000..dc34ea8 Binary files /dev/null and b/problem3/IRPF90_temp/factors.irp.module.o differ diff --git a/problem3/IRPF90_temp/factors.irp.o b/problem3/IRPF90_temp/factors.irp.o new file mode 100644 index 0000000..b07a95b Binary files /dev/null and b/problem3/IRPF90_temp/factors.irp.o differ diff --git a/problem3/IRPF90_temp/factors_mod.mod b/problem3/IRPF90_temp/factors_mod.mod new file mode 100644 index 0000000..64b9824 --- /dev/null +++ b/problem3/IRPF90_temp/factors_mod.mod @@ -0,0 +1,30 @@ +GFORTRAN module version '9' created from IRPF90_temp/factors.irp.module.F90 +MD5:09de44d49e41542ef1349f99ab6f7c28 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'factors' 'factors_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (INTEGER 4 0 0 0 +INTEGER ()) 0 0 () (1 0 DEFERRED () ()) 0 () () () 0 0) +3 'factors_is_built' 'factors_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 +() () 0 () () () 0 0) +4 'factors_mod' 'factors_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +5 'j' 'factors_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN +IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 () () 0 () () () 0 0) +) + +('factors' 0 2 'factors_is_built' 0 3 'factors_mod' 0 4 'j' 0 5) diff --git a/problem3/IRPF90_temp/inp b/problem3/IRPF90_temp/inp new file mode 100644 index 0000000..b676561 --- /dev/null +++ b/problem3/IRPF90_temp/inp @@ -0,0 +1 @@ +600851475143 diff --git a/problem3/IRPF90_temp/irp_stack.irp.F90 b/problem3/IRPF90_temp/irp_stack.irp.F90 new file mode 100644 index 0000000..5869495 --- /dev/null +++ b/problem3/IRPF90_temp/irp_stack.irp.F90 @@ -0,0 +1,38 @@ + +module irp_stack_mod + integer, parameter :: STACKMAX=1000 + character*(128),allocatable :: irp_stack(:,:) + double precision,allocatable :: irp_cpu(:,:) + integer,allocatable :: stack_index(:) + logical :: alloc = .False. + character*(128) :: white = '' +end module + +subroutine irp_enter(irp_where) + use irp_stack_mod + integer :: ithread + integer :: nthread + character*(*) :: irp_where + +!$OMP CRITICAL + ithread = 0 + nthread = 1 + +!$OMP END CRITICAL + + +end subroutine + +subroutine irp_leave (irp_where) + use irp_stack_mod + character*(*) :: irp_where + integer :: ithread + double precision :: cpu + +!$OMP CRITICAL + ithread = 0 + + +!$OMP END CRITICAL +end subroutine + diff --git a/problem3/IRPF90_temp/irp_stack.irp.o b/problem3/IRPF90_temp/irp_stack.irp.o new file mode 100644 index 0000000..9b8cb95 Binary files /dev/null and b/problem3/IRPF90_temp/irp_stack.irp.o differ diff --git a/problem3/IRPF90_temp/irp_stack_mod.mod b/problem3/IRPF90_temp/irp_stack_mod.mod new file mode 100644 index 0000000..4c7ba10 --- /dev/null +++ b/problem3/IRPF90_temp/irp_stack_mod.mod @@ -0,0 +1,42 @@ +GFORTRAN module version '9' created from IRPF90_temp/irp_stack.irp.F90 +MD5:f65ae2717456353521ba97c4b0936c36 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'alloc' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 () () 0 () () +() 0 0) +3 'irp_cpu' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (REAL 8 0 0 0 REAL ()) +0 0 () (2 0 DEFERRED () () () ()) 0 () () () 0 0) +4 'irp_stack' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) ( +CHARACTER 1 0 0 0 CHARACTER ((CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 +'128'))) 0 0 () (2 0 DEFERRED () () () ()) 0 () () () 0 0) +5 'irp_stack_mod' 'irp_stack_mod' '' 1 ((MODULE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () +0 () () () 0 0) +6 'stack_index' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (INTEGER 4 +0 0 0 INTEGER ()) 0 0 () (1 0 DEFERRED () ()) 0 () () () 0 0) +7 'stackmax' 'irp_stack_mod' '' 1 ((PARAMETER UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 +() (CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 '1000') () 0 () () () 0 0) +8 'white' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (CHARACTER 1 0 0 0 CHARACTER ((CONSTANT ( +INTEGER 4 0 0 0 INTEGER ()) 0 '128'))) 0 0 () () 0 () () () 0 0) +) + +('alloc' 0 2 'irp_cpu' 0 3 'irp_stack' 0 4 'irp_stack_mod' 0 5 +'stack_index' 0 6 'stackmax' 0 7 'white' 0 8) diff --git a/problem3/IRPF90_temp/irp_touches.irp.F90 b/problem3/IRPF90_temp/irp_touches.irp.F90 new file mode 100644 index 0000000..7f8cfc7 --- /dev/null +++ b/problem3/IRPF90_temp/irp_touches.irp.F90 @@ -0,0 +1,9 @@ +subroutine irp_finalize_68190058 + use lgpf_mod + use factors_mod + use number_mod + if (allocated(factors)) then + factors_is_built = .False. + deallocate(factors) + endif +end diff --git a/problem3/IRPF90_temp/irp_touches.irp.o b/problem3/IRPF90_temp/irp_touches.irp.o new file mode 100644 index 0000000..4477379 Binary files /dev/null and b/problem3/IRPF90_temp/irp_touches.irp.o differ diff --git a/problem3/IRPF90_temp/irpf90.make b/problem3/IRPF90_temp/irpf90.make new file mode 100644 index 0000000..f05fd9c --- /dev/null +++ b/problem3/IRPF90_temp/irpf90.make @@ -0,0 +1,43 @@ +SRC += IRPF90_temp/irp_stack.irp.F90 IRPF90_temp/irp_touches.irp.F90 IRPF90_temp/lgpf.irp.F90 IRPF90_temp/lgpf.irp.module.F90 IRPF90_temp/factors.irp.F90 IRPF90_temp/factors.irp.module.F90 IRPF90_temp/number.irp.F90 IRPF90_temp/number.irp.module.F90 IRPF90_temp/prob3.irp.F90 IRPF90_temp/prob3.irp.module.F90 +OBJ += IRPF90_temp/irp_stack.irp.o IRPF90_temp/lgpf.irp.o IRPF90_temp/lgpf.irp.module.o IRPF90_temp/factors.irp.o IRPF90_temp/factors.irp.module.o IRPF90_temp/number.irp.o IRPF90_temp/number.irp.module.o +OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(OBJ))) IRPF90_temp/irp_touches.irp.o +ALL = prob3 +ALL_OBJ = prob3.irp.module.o prob3.irp.o +ALL_OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(ALL_OBJ))) +all:$(ALL) + @$(MAKE) -s move +prob3: IRPF90_temp/prob3.irp.o IRPF90_temp/prob3.irp.module.o $(OBJ1) + $(FC) -o $@ IRPF90_temp/$@.irp.o IRPF90_temp/$@.irp.module.o $(OBJ1) $(LIB) + @$(MAKE) -s move +IRPF90_temp/lgpf.irp.o: IRPF90_temp/lgpf.irp.module.o IRPF90_temp/factors.irp.module.o +IRPF90_temp/factors.irp.o: IRPF90_temp/factors.irp.module.o IRPF90_temp/number.irp.module.o +IRPF90_temp/number.irp.o: IRPF90_temp/number.irp.module.o +IRPF90_temp/prob3.irp.o: IRPF90_temp/prob3.irp.module.o IRPF90_temp/lgpf.irp.module.o +IRPF90_temp/irp_touches.irp.o: IRPF90_temp/lgpf.irp.o IRPF90_temp/lgpf.irp.o IRPF90_temp/factors.irp.o IRPF90_temp/factors.irp.o IRPF90_temp/number.irp.o IRPF90_temp/number.irp.o +IRPF90_temp/%.irp.module.o: IRPF90_temp/%.irp.module.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.module.F90 -o IRPF90_temp/$*.irp.module.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.module.o IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.o: %.F90 + $(FC) $(FCFLAGS) -c $*.F90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f90 + $(FC) $(FCFLAGS) -c $*.f90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f + $(FC) $(FCFLAGS) -c $*.f -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.F + $(FC) $(FCFLAGS) -c $*.F -o IRPF90_temp/$*.o +IRPF90_temp/%.irp.F90: irpf90.make + +move: + @mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING= + +clean: + rm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL) + +veryclean: + - $(MAKE) clean + + - rm -rf IRPF90_temp/ IRPF90_man/ irpf90.make irpf90_variables dist + diff --git a/problem3/IRPF90_temp/irpf90_entities b/problem3/IRPF90_temp/irpf90_entities new file mode 100644 index 0000000..f4be075 --- /dev/null +++ b/problem3/IRPF90_temp/irpf90_entities @@ -0,0 +1,4 @@ +factors.irp.f : integer, allocatable :: factors (100000) +factors.irp.f : integer :: j +lgpf.irp.f : integer :: lgpf +number.irp.f : integer (kind=18) :: number diff --git a/problem3/IRPF90_temp/lgpf.irp.F90 b/problem3/IRPF90_temp/lgpf.irp.F90 new file mode 100644 index 0000000..2a6c087 --- /dev/null +++ b/problem3/IRPF90_temp/lgpf.irp.F90 @@ -0,0 +1,46 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +subroutine provide_lgpf + use lgpf_mod + use factors_mod + implicit none + character*(12) :: irp_here = 'provide_lgpf' + integer :: irp_err + logical :: irp_dimensions_OK + if (.not.factors_is_built) then + call provide_factors + endif + if (.not.lgpf_is_built) then + call bld_lgpf + lgpf_is_built = .True. + + endif +end subroutine provide_lgpf + +subroutine bld_lgpf + use lgpf_mod + use factors_mod + implicit none ! lgpf.irp.f: 2 + character*(4) :: irp_here = 'lgpf' ! lgpf.irp.f: 1 + integer :: i,k ! lgpf.irp.f: 7 + logical :: prim ! lgpf.irp.f: 8 + lgpf=0 ! lgpf.irp.f: 10 + prim=.TRUE. ! lgpf.irp.f: 11 + do i=1,j ! lgpf.irp.f: 12 + do k=2,factors(i)-1 ! lgpf.irp.f: 13 + if(MOD(factors(i),k).eq.0) then ! lgpf.irp.f: 14 +prim=.FALSE. ! lgpf.irp.f: 14 + endif ! lgpf.irp.f: 14 + enddo ! lgpf.irp.f: 15 + if(lgpf.le.factors(i) .and. prim) then ! lgpf.irp.f: 17 +lgpf=factors(i) ! lgpf.irp.f: 17 + endif ! lgpf.irp.f: 17 + prim=.TRUE. ! lgpf.irp.f: 19 + enddo ! lgpf.irp.f: 21 +end subroutine bld_lgpf diff --git a/problem3/IRPF90_temp/lgpf.irp.f b/problem3/IRPF90_temp/lgpf.irp.f new file mode 100644 index 0000000..ae32551 --- /dev/null +++ b/problem3/IRPF90_temp/lgpf.irp.f @@ -0,0 +1,23 @@ +BEGIN_PROVIDER [integer, lgpf] + implicit none + BEGIN_DOC + ! serches for largest factor + END_DOC + + integer :: i,k + logical :: prim + + lgpf=0 + prim=.TRUE. + do i=1,j + do k=2,factors(i)-1 + if(MOD(factors(i),k).eq.0)prim=.FALSE. + enddo + + if(lgpf.le.factors(i) .and. prim)lgpf=factors(i) + + prim=.TRUE. + + enddo + +END_PROVIDER diff --git a/problem3/IRPF90_temp/lgpf.irp.module.F90 b/problem3/IRPF90_temp/lgpf.irp.module.F90 new file mode 100644 index 0000000..1361cba --- /dev/null +++ b/problem3/IRPF90_temp/lgpf.irp.module.F90 @@ -0,0 +1,12 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module lgpf_mod + integer :: lgpf + logical :: lgpf_is_built = .False. +end module lgpf_mod diff --git a/problem3/IRPF90_temp/lgpf.irp.module.o b/problem3/IRPF90_temp/lgpf.irp.module.o new file mode 100644 index 0000000..d8cc907 Binary files /dev/null and b/problem3/IRPF90_temp/lgpf.irp.module.o differ diff --git a/problem3/IRPF90_temp/lgpf.irp.o b/problem3/IRPF90_temp/lgpf.irp.o new file mode 100644 index 0000000..983d73b Binary files /dev/null and b/problem3/IRPF90_temp/lgpf.irp.o differ diff --git a/problem3/IRPF90_temp/lgpf_mod.mod b/problem3/IRPF90_temp/lgpf_mod.mod new file mode 100644 index 0000000..6286254 --- /dev/null +++ b/problem3/IRPF90_temp/lgpf_mod.mod @@ -0,0 +1,27 @@ +GFORTRAN module version '9' created from IRPF90_temp/lgpf.irp.module.F90 +MD5:4f74381022eeb4c514e433ec2b52241b -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'lgpf' 'lgpf_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN +IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 () () 0 () () () 0 0) +3 'lgpf_is_built' 'lgpf_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 () () 0 () () +() 0 0) +4 'lgpf_mod' 'lgpf_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +) + +('lgpf' 0 2 'lgpf_is_built' 0 3 'lgpf_mod' 0 4) diff --git a/problem3/IRPF90_temp/number.irp.F90 b/problem3/IRPF90_temp/number.irp.F90 new file mode 100644 index 0000000..9e5d3cd --- /dev/null +++ b/problem3/IRPF90_temp/number.irp.F90 @@ -0,0 +1,28 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +subroutine provide_number + use number_mod + implicit none + character*(14) :: irp_here = 'provide_number' + integer :: irp_err + logical :: irp_dimensions_OK + if (.not.number_is_built) then + call bld_number + number_is_built = .True. + + endif +end subroutine provide_number + +subroutine bld_number + use number_mod + implicit none ! number.irp.f: 2 + character*(6) :: irp_here = 'number' ! number.irp.f: 1 + write(6,*)'number?' ! number.irp.f: 6 + read(5,*)number ! number.irp.f: 7 +end subroutine bld_number diff --git a/problem3/IRPF90_temp/number.irp.f b/problem3/IRPF90_temp/number.irp.f new file mode 100644 index 0000000..bc9fae5 --- /dev/null +++ b/problem3/IRPF90_temp/number.irp.f @@ -0,0 +1,9 @@ +BEGIN_PROVIDER [integer (kind=selected_int_kind(18)), number] + implicit none + BEGIN_DOC + ! enter limit + END_DOC + write(6,*)'number?' + read(5,*)number + +END_PROVIDER diff --git a/problem3/IRPF90_temp/number.irp.module.F90 b/problem3/IRPF90_temp/number.irp.module.F90 new file mode 100644 index 0000000..dd99fe8 --- /dev/null +++ b/problem3/IRPF90_temp/number.irp.module.F90 @@ -0,0 +1,12 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module number_mod + integer (kind=selected_int_kind(18)) :: number + logical :: number_is_built = .False. +end module number_mod diff --git a/problem3/IRPF90_temp/number.irp.module.o b/problem3/IRPF90_temp/number.irp.module.o new file mode 100644 index 0000000..c9cbd48 Binary files /dev/null and b/problem3/IRPF90_temp/number.irp.module.o differ diff --git a/problem3/IRPF90_temp/number.irp.o b/problem3/IRPF90_temp/number.irp.o new file mode 100644 index 0000000..d672498 Binary files /dev/null and b/problem3/IRPF90_temp/number.irp.o differ diff --git a/problem3/IRPF90_temp/number_mod.mod b/problem3/IRPF90_temp/number_mod.mod new file mode 100644 index 0000000..2ac9aea --- /dev/null +++ b/problem3/IRPF90_temp/number_mod.mod @@ -0,0 +1,32 @@ +GFORTRAN module version '9' created from IRPF90_temp/number.irp.module.F90 +MD5:dfffe4260bca832dc7c3a8c2607b816f -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'number' 'number_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 8 0 0 0 INTEGER ()) 0 0 () () 0 () () +() 0 0) +3 'number_is_built' 'number_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 +() () 0 () () () 0 0) +4 'number_mod' 'number_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +5 'selected_int_kind' '(intrinsic)' '' 1 ((PROCEDURE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN UNKNOWN 0 0 FUNCTION) (REAL 4 0 0 0 REAL ()) 0 0 () +() 5 () () () 0 0) +) + +('number' 0 2 'number_is_built' 0 3 'number_mod' 0 4 'selected_int_kind' +0 5) diff --git a/problem3/IRPF90_temp/prob3 b/problem3/IRPF90_temp/prob3 new file mode 100644 index 0000000..89588af Binary files /dev/null and b/problem3/IRPF90_temp/prob3 differ diff --git a/problem3/IRPF90_temp/prob3.irp.F90 b/problem3/IRPF90_temp/prob3.irp.F90 new file mode 100644 index 0000000..2f757b8 --- /dev/null +++ b/problem3/IRPF90_temp/prob3.irp.F90 @@ -0,0 +1,21 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +program irp_program ! prob3: 0 + call prob3 ! prob3.irp.f: 0 + call irp_finalize_68190058() ! prob3.irp.f: 0 +end program ! prob3.irp.f: 0 +subroutine prob3 ! prob3.irp.f: 1 + use lgpf_mod + implicit none ! prob3.irp.f: 3 + character*(5) :: irp_here = 'prob3' ! prob3.irp.f: 1 + if (.not.lgpf_is_built) then + call provide_lgpf + endif + write(6,*)lgpf ! prob3.irp.f: 5 +end ! prob3.irp.f: 7 diff --git a/problem3/IRPF90_temp/prob3.irp.f b/problem3/IRPF90_temp/prob3.irp.f new file mode 100644 index 0000000..c92f02d --- /dev/null +++ b/problem3/IRPF90_temp/prob3.irp.f @@ -0,0 +1,8 @@ + program prob3 + + implicit none + + write(6,*)lgpf + + end + diff --git a/problem3/IRPF90_temp/prob3.irp.module.F90 b/problem3/IRPF90_temp/prob3.irp.module.F90 new file mode 100644 index 0000000..10fe6fc --- /dev/null +++ b/problem3/IRPF90_temp/prob3.irp.module.F90 @@ -0,0 +1,10 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module prob3_mod +end module prob3_mod diff --git a/problem3/IRPF90_temp/prob3.irp.module.o b/problem3/IRPF90_temp/prob3.irp.module.o new file mode 100644 index 0000000..7de7f7c Binary files /dev/null and b/problem3/IRPF90_temp/prob3.irp.module.o differ diff --git a/problem3/IRPF90_temp/prob3.irp.o b/problem3/IRPF90_temp/prob3.irp.o new file mode 100644 index 0000000..37358ed Binary files /dev/null and b/problem3/IRPF90_temp/prob3.irp.o differ diff --git a/problem3/IRPF90_temp/prob3_mod.mod b/problem3/IRPF90_temp/prob3_mod.mod new file mode 100644 index 0000000..85ed49a --- /dev/null +++ b/problem3/IRPF90_temp/prob3_mod.mod @@ -0,0 +1,22 @@ +GFORTRAN module version '9' created from IRPF90_temp/prob3.irp.module.F90 +MD5:218541de81e2f6aee72882e30947237a -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'prob3_mod' 'prob3_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +) + +('prob3_mod' 0 2) diff --git a/problem3/Makefile b/problem3/Makefile new file mode 100644 index 0000000..4602bb7 --- /dev/null +++ b/problem3/Makefile @@ -0,0 +1,12 @@ +IRPF90 = irpf90 #-a -d +FC = gfortran +FCFLAGS= -O2 + +SRC= +OBJ= +LIB= + +include irpf90.make + +irpf90.make: $(wildcard *.irp.f) + $(IRPF90) diff --git a/problem3/README.md b/problem3/README.md new file mode 100644 index 0000000..e877150 --- /dev/null +++ b/problem3/README.md @@ -0,0 +1,6 @@ +PROBLEM 3 +---------- + +* The prime factors of 13195 are 5, 7, 13 and 29. + +What is the largest prime factor of the number 600851475143 ? diff --git a/problem3/factors.irp.f b/problem3/factors.irp.f new file mode 100644 index 0000000..3b2e292 --- /dev/null +++ b/problem3/factors.irp.f @@ -0,0 +1,22 @@ +BEGIN_PROVIDER [integer, factors, (100000)] +&BEGIN_PROVIDER [integer, j] + BEGIN_DOC + ! stores factors + END_DOC + + implicit none + integer :: i + + j=1 + + do i=1,int(SQRT(float(number))) + if(MOD(number,i).eq.0)then + factors(j)=i + j+=1 + endif + enddo + do i=1,j + write(6,*)factors(i) + enddo + +END_PROVIDER diff --git a/problem3/inp b/problem3/inp new file mode 100644 index 0000000..b676561 --- /dev/null +++ b/problem3/inp @@ -0,0 +1 @@ +600851475143 diff --git a/problem3/irpf90.make b/problem3/irpf90.make new file mode 100644 index 0000000..f05fd9c --- /dev/null +++ b/problem3/irpf90.make @@ -0,0 +1,43 @@ +SRC += IRPF90_temp/irp_stack.irp.F90 IRPF90_temp/irp_touches.irp.F90 IRPF90_temp/lgpf.irp.F90 IRPF90_temp/lgpf.irp.module.F90 IRPF90_temp/factors.irp.F90 IRPF90_temp/factors.irp.module.F90 IRPF90_temp/number.irp.F90 IRPF90_temp/number.irp.module.F90 IRPF90_temp/prob3.irp.F90 IRPF90_temp/prob3.irp.module.F90 +OBJ += IRPF90_temp/irp_stack.irp.o IRPF90_temp/lgpf.irp.o IRPF90_temp/lgpf.irp.module.o IRPF90_temp/factors.irp.o IRPF90_temp/factors.irp.module.o IRPF90_temp/number.irp.o IRPF90_temp/number.irp.module.o +OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(OBJ))) IRPF90_temp/irp_touches.irp.o +ALL = prob3 +ALL_OBJ = prob3.irp.module.o prob3.irp.o +ALL_OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(ALL_OBJ))) +all:$(ALL) + @$(MAKE) -s move +prob3: IRPF90_temp/prob3.irp.o IRPF90_temp/prob3.irp.module.o $(OBJ1) + $(FC) -o $@ IRPF90_temp/$@.irp.o IRPF90_temp/$@.irp.module.o $(OBJ1) $(LIB) + @$(MAKE) -s move +IRPF90_temp/lgpf.irp.o: IRPF90_temp/lgpf.irp.module.o IRPF90_temp/factors.irp.module.o +IRPF90_temp/factors.irp.o: IRPF90_temp/factors.irp.module.o IRPF90_temp/number.irp.module.o +IRPF90_temp/number.irp.o: IRPF90_temp/number.irp.module.o +IRPF90_temp/prob3.irp.o: IRPF90_temp/prob3.irp.module.o IRPF90_temp/lgpf.irp.module.o +IRPF90_temp/irp_touches.irp.o: IRPF90_temp/lgpf.irp.o IRPF90_temp/lgpf.irp.o IRPF90_temp/factors.irp.o IRPF90_temp/factors.irp.o IRPF90_temp/number.irp.o IRPF90_temp/number.irp.o +IRPF90_temp/%.irp.module.o: IRPF90_temp/%.irp.module.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.module.F90 -o IRPF90_temp/$*.irp.module.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.module.o IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.o: %.F90 + $(FC) $(FCFLAGS) -c $*.F90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f90 + $(FC) $(FCFLAGS) -c $*.f90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f + $(FC) $(FCFLAGS) -c $*.f -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.F + $(FC) $(FCFLAGS) -c $*.F -o IRPF90_temp/$*.o +IRPF90_temp/%.irp.F90: irpf90.make + +move: + @mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING= + +clean: + rm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL) + +veryclean: + - $(MAKE) clean + + - rm -rf IRPF90_temp/ IRPF90_man/ irpf90.make irpf90_variables dist + diff --git a/problem3/irpf90_entities b/problem3/irpf90_entities new file mode 100644 index 0000000..88dbb8a --- /dev/null +++ b/problem3/irpf90_entities @@ -0,0 +1,4 @@ +factors.irp.f : integer, allocatable :: factors (100000) +factors.irp.f : integer :: j +lgpf.irp.f : integer :: lgpf +number.irp.f : integer (kind=selected_int_kind(18)) :: number diff --git a/problem3/lgpf.irp.f b/problem3/lgpf.irp.f new file mode 100644 index 0000000..ae32551 --- /dev/null +++ b/problem3/lgpf.irp.f @@ -0,0 +1,23 @@ +BEGIN_PROVIDER [integer, lgpf] + implicit none + BEGIN_DOC + ! serches for largest factor + END_DOC + + integer :: i,k + logical :: prim + + lgpf=0 + prim=.TRUE. + do i=1,j + do k=2,factors(i)-1 + if(MOD(factors(i),k).eq.0)prim=.FALSE. + enddo + + if(lgpf.le.factors(i) .and. prim)lgpf=factors(i) + + prim=.TRUE. + + enddo + +END_PROVIDER diff --git a/problem3/number.irp.f b/problem3/number.irp.f new file mode 100644 index 0000000..bc9fae5 --- /dev/null +++ b/problem3/number.irp.f @@ -0,0 +1,9 @@ +BEGIN_PROVIDER [integer (kind=selected_int_kind(18)), number] + implicit none + BEGIN_DOC + ! enter limit + END_DOC + write(6,*)'number?' + read(5,*)number + +END_PROVIDER diff --git a/problem3/prob3 b/problem3/prob3 new file mode 100755 index 0000000..f3fd8ba Binary files /dev/null and b/problem3/prob3 differ diff --git a/problem3/prob3.irp.f b/problem3/prob3.irp.f new file mode 100755 index 0000000..c92f02d --- /dev/null +++ b/problem3/prob3.irp.f @@ -0,0 +1,8 @@ + program prob3 + + implicit none + + write(6,*)lgpf + + end + diff --git a/problem4/IRPF90_temp/Makefile b/problem4/IRPF90_temp/Makefile new file mode 100644 index 0000000..4602bb7 --- /dev/null +++ b/problem4/IRPF90_temp/Makefile @@ -0,0 +1,12 @@ +IRPF90 = irpf90 #-a -d +FC = gfortran +FCFLAGS= -O2 + +SRC= +OBJ= +LIB= + +include irpf90.make + +irpf90.make: $(wildcard *.irp.f) + $(IRPF90) diff --git a/problem4/IRPF90_temp/README.md b/problem4/IRPF90_temp/README.md new file mode 100644 index 0000000..0065736 --- /dev/null +++ b/problem4/IRPF90_temp/README.md @@ -0,0 +1,7 @@ +PROBLEM 3 +---------- + +* A palindromic number reads the same both ways. The largest palindrome made + from the product of two 2-digit numbers is 9009 = 91 99. + + Find the largest palindrome made from the product of two 3-digit numbers. diff --git a/problem4/IRPF90_temp/irp_stack.irp.F90 b/problem4/IRPF90_temp/irp_stack.irp.F90 new file mode 100644 index 0000000..5869495 --- /dev/null +++ b/problem4/IRPF90_temp/irp_stack.irp.F90 @@ -0,0 +1,38 @@ + +module irp_stack_mod + integer, parameter :: STACKMAX=1000 + character*(128),allocatable :: irp_stack(:,:) + double precision,allocatable :: irp_cpu(:,:) + integer,allocatable :: stack_index(:) + logical :: alloc = .False. + character*(128) :: white = '' +end module + +subroutine irp_enter(irp_where) + use irp_stack_mod + integer :: ithread + integer :: nthread + character*(*) :: irp_where + +!$OMP CRITICAL + ithread = 0 + nthread = 1 + +!$OMP END CRITICAL + + +end subroutine + +subroutine irp_leave (irp_where) + use irp_stack_mod + character*(*) :: irp_where + integer :: ithread + double precision :: cpu + +!$OMP CRITICAL + ithread = 0 + + +!$OMP END CRITICAL +end subroutine + diff --git a/problem4/IRPF90_temp/irp_stack.irp.o b/problem4/IRPF90_temp/irp_stack.irp.o new file mode 100644 index 0000000..9b8cb95 Binary files /dev/null and b/problem4/IRPF90_temp/irp_stack.irp.o differ diff --git a/problem4/IRPF90_temp/irp_stack_mod.mod b/problem4/IRPF90_temp/irp_stack_mod.mod new file mode 100644 index 0000000..4c7ba10 --- /dev/null +++ b/problem4/IRPF90_temp/irp_stack_mod.mod @@ -0,0 +1,42 @@ +GFORTRAN module version '9' created from IRPF90_temp/irp_stack.irp.F90 +MD5:f65ae2717456353521ba97c4b0936c36 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'alloc' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (LOGICAL 4 0 0 0 LOGICAL ()) 0 0 () () 0 () () +() 0 0) +3 'irp_cpu' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (REAL 8 0 0 0 REAL ()) +0 0 () (2 0 DEFERRED () () () ()) 0 () () () 0 0) +4 'irp_stack' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) ( +CHARACTER 1 0 0 0 CHARACTER ((CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 +'128'))) 0 0 () (2 0 DEFERRED () () () ()) 0 () () () 0 0) +5 'irp_stack_mod' 'irp_stack_mod' '' 1 ((MODULE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () +0 () () () 0 0) +6 'stack_index' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0 ALLOCATABLE DIMENSION) (INTEGER 4 +0 0 0 INTEGER ()) 0 0 () (1 0 DEFERRED () ()) 0 () () () 0 0) +7 'stackmax' 'irp_stack_mod' '' 1 ((PARAMETER UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN IMPLICIT-SAVE 0 0) (INTEGER 4 0 0 0 INTEGER ()) 0 0 +() (CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 '1000') () 0 () () () 0 0) +8 'white' 'irp_stack_mod' '' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN IMPLICIT-SAVE 0 0) (CHARACTER 1 0 0 0 CHARACTER ((CONSTANT ( +INTEGER 4 0 0 0 INTEGER ()) 0 '128'))) 0 0 () () 0 () () () 0 0) +) + +('alloc' 0 2 'irp_cpu' 0 3 'irp_stack' 0 4 'irp_stack_mod' 0 5 +'stack_index' 0 6 'stackmax' 0 7 'white' 0 8) diff --git a/problem4/IRPF90_temp/irp_touches.irp.F90 b/problem4/IRPF90_temp/irp_touches.irp.F90 new file mode 100644 index 0000000..25f4020 --- /dev/null +++ b/problem4/IRPF90_temp/irp_touches.irp.F90 @@ -0,0 +1,3 @@ +subroutine irp_finalize_1703613751 + use is_palindrome_mod +end diff --git a/problem4/IRPF90_temp/irp_touches.irp.o b/problem4/IRPF90_temp/irp_touches.irp.o new file mode 100644 index 0000000..27dfb8a Binary files /dev/null and b/problem4/IRPF90_temp/irp_touches.irp.o differ diff --git a/problem4/IRPF90_temp/irpf90.make b/problem4/IRPF90_temp/irpf90.make new file mode 100644 index 0000000..36dabb4 --- /dev/null +++ b/problem4/IRPF90_temp/irpf90.make @@ -0,0 +1,41 @@ +SRC += IRPF90_temp/irp_stack.irp.F90 IRPF90_temp/irp_touches.irp.F90 IRPF90_temp/prob4.irp.F90 IRPF90_temp/prob4.irp.module.F90 IRPF90_temp/is_palindrome.irp.F90 IRPF90_temp/is_palindrome.irp.module.F90 +OBJ += IRPF90_temp/irp_stack.irp.o IRPF90_temp/is_palindrome.irp.o IRPF90_temp/is_palindrome.irp.module.o +OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(OBJ))) IRPF90_temp/irp_touches.irp.o +ALL = prob4 +ALL_OBJ = prob4.irp.module.o prob4.irp.o +ALL_OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(ALL_OBJ))) +all:$(ALL) + @$(MAKE) -s move +prob4: IRPF90_temp/prob4.irp.o IRPF90_temp/prob4.irp.module.o $(OBJ1) + $(FC) -o $@ IRPF90_temp/$@.irp.o IRPF90_temp/$@.irp.module.o $(OBJ1) $(LIB) + @$(MAKE) -s move +IRPF90_temp/prob4.irp.o: IRPF90_temp/prob4.irp.module.o +IRPF90_temp/is_palindrome.irp.o: IRPF90_temp/is_palindrome.irp.module.o +IRPF90_temp/irp_touches.irp.o: IRPF90_temp/is_palindrome.irp.o IRPF90_temp/is_palindrome.irp.o +IRPF90_temp/%.irp.module.o: IRPF90_temp/%.irp.module.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.module.F90 -o IRPF90_temp/$*.irp.module.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.module.o IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.o: %.F90 + $(FC) $(FCFLAGS) -c $*.F90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f90 + $(FC) $(FCFLAGS) -c $*.f90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f + $(FC) $(FCFLAGS) -c $*.f -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.F + $(FC) $(FCFLAGS) -c $*.F -o IRPF90_temp/$*.o +IRPF90_temp/%.irp.F90: irpf90.make + +move: + @mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING= + +clean: + rm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL) + +veryclean: + - $(MAKE) clean + + - rm -rf IRPF90_temp/ IRPF90_man/ irpf90.make irpf90_variables dist + diff --git a/problem4/IRPF90_temp/irpf90_entities b/problem4/IRPF90_temp/irpf90_entities new file mode 100644 index 0000000..e69de29 diff --git a/problem4/IRPF90_temp/is_palindrome.irp.F90 b/problem4/IRPF90_temp/is_palindrome.irp.F90 new file mode 100644 index 0000000..c0c8267 --- /dev/null +++ b/problem4/IRPF90_temp/is_palindrome.irp.F90 @@ -0,0 +1,33 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + + subroutine is_palindrome(number,palin) ! is_palindrome.irp.f: 1 + implicit none ! is_palindrome.irp.f: 3 + character*(13) :: irp_here = 'is_palindrome' ! is_palindrome.irp.f: 1 + logical :: palin ! is_palindrome.irp.f: 4 + integer :: number,digit(1000),i,n1,j ! is_palindrome.irp.f: 5 + palin=.FALSE. ! is_palindrome.irp.f: 7 + do i=1,1000 ! is_palindrome.irp.f: 8 + digit(i)=10 ! is_palindrome.irp.f: 9 + enddo ! is_palindrome.irp.f: 10 + i=0 ! is_palindrome.irp.f: 12 + do while (number.gt.0) ! is_palindrome.irp.f: 13 + n1=number-10*(number/10) ! is_palindrome.irp.f: 15 + digit(i)=n1 ! is_palindrome.irp.f: 16 + number=number/10 ! is_palindrome.irp.f: 17 + i=i+(1) ! is_palindrome.irp.f: 18 + enddo ! is_palindrome.irp.f: 19 + palin=.TRUE. ! is_palindrome.irp.f: 22 + do j=0,int((i-1)/2) ! is_palindrome.irp.f: 23 + if(digit(j).ne.digit((i-1)-j))then ! is_palindrome.irp.f: 24 + palin=.FALSE. ! is_palindrome.irp.f: 25 + EXIT ! is_palindrome.irp.f: 26 + endif ! is_palindrome.irp.f: 27 + enddo ! is_palindrome.irp.f: 28 + return ! is_palindrome.irp.f: 30 +end ! is_palindrome.irp.f: 31 diff --git a/problem4/IRPF90_temp/is_palindrome.irp.f b/problem4/IRPF90_temp/is_palindrome.irp.f new file mode 100644 index 0000000..536aac2 --- /dev/null +++ b/problem4/IRPF90_temp/is_palindrome.irp.f @@ -0,0 +1,31 @@ + subroutine is_palindrome(number,palin) + + implicit none + logical :: palin + integer :: number,digit(1000),i,n1,j + + palin=.FALSE. + do i=1,1000 + digit(i)=10 + enddo + + i=0 + do while (number.gt.0) + + n1=number-10*(number/10) + digit(i)=n1 + number=number/10 + i+=1 + enddo + +! write(6,*)(digit(j),j=i-1,0,-1) + palin=.TRUE. + do j=0,int((i-1)/2) + if(digit(j).ne.digit((i-1)-j))then + palin=.FALSE. + EXIT + endif + enddo + + return + end diff --git a/problem4/IRPF90_temp/is_palindrome.irp.module.F90 b/problem4/IRPF90_temp/is_palindrome.irp.module.F90 new file mode 100644 index 0000000..16ba904 --- /dev/null +++ b/problem4/IRPF90_temp/is_palindrome.irp.module.F90 @@ -0,0 +1,10 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module is_palindrome_mod +end module is_palindrome_mod diff --git a/problem4/IRPF90_temp/is_palindrome.irp.module.o b/problem4/IRPF90_temp/is_palindrome.irp.module.o new file mode 100644 index 0000000..07d30d5 Binary files /dev/null and b/problem4/IRPF90_temp/is_palindrome.irp.module.o differ diff --git a/problem4/IRPF90_temp/is_palindrome.irp.o b/problem4/IRPF90_temp/is_palindrome.irp.o new file mode 100644 index 0000000..c0558b0 Binary files /dev/null and b/problem4/IRPF90_temp/is_palindrome.irp.o differ diff --git a/problem4/IRPF90_temp/is_palindrome_mod.mod b/problem4/IRPF90_temp/is_palindrome_mod.mod new file mode 100644 index 0000000..1061537 --- /dev/null +++ b/problem4/IRPF90_temp/is_palindrome_mod.mod @@ -0,0 +1,22 @@ +GFORTRAN module version '9' created from IRPF90_temp/is_palindrome.irp.module.F90 +MD5:e4d5be9bc62ccc4859322533ab0d164b -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'is_palindrome_mod' 'is_palindrome_mod' '' 1 ((MODULE UNKNOWN-INTENT +UNKNOWN-PROC UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () +0 () () () 0 0) +) + +('is_palindrome_mod' 0 2) diff --git a/problem4/IRPF90_temp/o b/problem4/IRPF90_temp/o new file mode 100644 index 0000000..73bc8a9 --- /dev/null +++ b/problem4/IRPF90_temp/o @@ -0,0 +1,30 @@ + 861168 + 888888 + 861168 + 828828 + 886688 + 824428 + 906609 + 819918 + 824428 + 819918 + 828828 + 855558 + 840048 + 737737 + 853358 + 809908 + 793397 + 749947 + 821128 + 801108 + 749947 + 828828 + 802208 + 780087 + 737737 + 807708 + 698896 + 678876 + 804408 + 906609 diff --git a/problem4/IRPF90_temp/prob4 b/problem4/IRPF90_temp/prob4 new file mode 100644 index 0000000..e37dbdb Binary files /dev/null and b/problem4/IRPF90_temp/prob4 differ diff --git a/problem4/IRPF90_temp/prob4.irp.F90 b/problem4/IRPF90_temp/prob4.irp.F90 new file mode 100644 index 0000000..b1bbb5a --- /dev/null +++ b/problem4/IRPF90_temp/prob4.irp.F90 @@ -0,0 +1,57 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +program irp_program ! prob4: 0 + call prob4 ! prob4.irp.f: 0 + call irp_finalize_1703613751() ! prob4.irp.f: 0 +end program ! prob4.irp.f: 0 +subroutine prob4 ! prob4.irp.f: 1 + implicit none ! prob4.irp.f: 3 + character*(5) :: irp_here = 'prob4' ! prob4.irp.f: 1 + integer :: i,j,number,k,ilim,jlim,palin(10000),maxpalin,cp,lim ! prob4.irp.f: 5 + logical :: palindrome ! prob4.irp.f: 6 + palindrome=.FALSE. ! prob4.irp.f: 8 + maxpalin=0 ! prob4.irp.f: 9 + cp=0 ! prob4.irp.f: 10 + do i=999,100,-1 ! prob4.irp.f: 11 + do j=999,i,-1 ! prob4.irp.f: 12 + number=i*j ! prob4.irp.f: 13 + call is_palindrome(number,palindrome) ! prob4.irp.f: 15 + if(palindrome)then ! prob4.irp.f: 17 + EXIT ! prob4.irp.f: 19 + endif ! prob4.irp.f: 20 + if(palindrome) then ! prob4.irp.f: 21 +EXIT ! prob4.irp.f: 21 + endif ! prob4.irp.f: 21 + enddo ! prob4.irp.f: 22 + if(palindrome) then ! prob4.irp.f: 23 +EXIT ! prob4.irp.f: 23 + endif ! prob4.irp.f: 23 + enddo ! prob4.irp.f: 24 + ilim=i ! prob4.irp.f: 25 + jlim=j ! prob4.irp.f: 26 + palindrome=.FALSE. ! prob4.irp.f: 27 + lim=MIN(ilim,jlim) ! prob4.irp.f: 29 + lim=lim-100 ! prob4.irp.f: 30 + do i=999,lim,-1 ! prob4.irp.f: 31 + do j=999,j,-1 ! prob4.irp.f: 32 + number=i*j ! prob4.irp.f: 33 + call is_palindrome(number,palindrome) ! prob4.irp.f: 34 + if(palindrome)then ! prob4.irp.f: 35 + cp=cp+(1) ! prob4.irp.f: 36 + palin(cp)=i*j ! prob4.irp.f: 37 + endif ! prob4.irp.f: 38 + enddo ! prob4.irp.f: 39 + enddo ! prob4.irp.f: 40 + do i=1,cp ! prob4.irp.f: 42 + if(maxpalin.le.palin(i)) then ! prob4.irp.f: 43 +maxpalin=palin(i) ! prob4.irp.f: 43 + endif ! prob4.irp.f: 43 + enddo ! prob4.irp.f: 44 + write(6,*)maxpalin ! prob4.irp.f: 46 +end ! prob4.irp.f: 49 diff --git a/problem4/IRPF90_temp/prob4.irp.f b/problem4/IRPF90_temp/prob4.irp.f new file mode 100644 index 0000000..1d74478 --- /dev/null +++ b/problem4/IRPF90_temp/prob4.irp.f @@ -0,0 +1,49 @@ + program prob4 + + implicit none + + integer :: i,j,number,k,ilim,jlim,palin(10000),maxpalin,cp,lim + logical :: palindrome + + palindrome=.FALSE. + maxpalin=0 + cp=0 + do i=999,100,-1 + do j=999,i,-1 + number=i*j +! write(6,*)number + call is_palindrome(number,palindrome) +! write(6,*)palindrome + if(palindrome)then +! write(6,*)i*j + EXIT + endif + if(palindrome)EXIT + enddo + if(palindrome)EXIT + enddo + ilim=i + jlim=j + palindrome=.FALSE. + + lim=MIN(ilim,jlim) + lim=lim-100 + do i=999,lim,-1 + do j=999,j,-1 + number=i*j + call is_palindrome(number,palindrome) + if(palindrome)then + cp+=1 + palin(cp)=i*j + endif + enddo + enddo + + do i=1,cp + if(maxpalin.le.palin(i))maxpalin=palin(i) + enddo + + write(6,*)maxpalin + + + end diff --git a/problem4/IRPF90_temp/prob4.irp.module.F90 b/problem4/IRPF90_temp/prob4.irp.module.F90 new file mode 100644 index 0000000..cc67007 --- /dev/null +++ b/problem4/IRPF90_temp/prob4.irp.module.F90 @@ -0,0 +1,10 @@ +! -*- F90 -*- +! +!-----------------------------------------------! +! This file was generated with the irpf90 tool. ! +! ! +! DO NOT MODIFY IT BY HAND ! +!-----------------------------------------------! + +module prob4_mod +end module prob4_mod diff --git a/problem4/IRPF90_temp/prob4.irp.module.o b/problem4/IRPF90_temp/prob4.irp.module.o new file mode 100644 index 0000000..2d5a1c3 Binary files /dev/null and b/problem4/IRPF90_temp/prob4.irp.module.o differ diff --git a/problem4/IRPF90_temp/prob4.irp.o b/problem4/IRPF90_temp/prob4.irp.o new file mode 100644 index 0000000..7be6b0a Binary files /dev/null and b/problem4/IRPF90_temp/prob4.irp.o differ diff --git a/problem4/IRPF90_temp/prob4_mod.mod b/problem4/IRPF90_temp/prob4_mod.mod new file mode 100644 index 0000000..36e2e72 --- /dev/null +++ b/problem4/IRPF90_temp/prob4_mod.mod @@ -0,0 +1,22 @@ +GFORTRAN module version '9' created from IRPF90_temp/prob4.irp.module.F90 +MD5:097acd06dda68ff8847be5a48b268e79 -- If you edit this, you'll get what you deserve. + +(() () () () () () () () () () () () () () () () () () () () () () () () +() () ()) + +() + +() + +() + +() + +() + +(2 'prob4_mod' 'prob4_mod' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC +UNKNOWN UNKNOWN 0 0) (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 +0) +) + +('prob4_mod' 0 2) diff --git a/problem4/Makefile b/problem4/Makefile new file mode 100644 index 0000000..4602bb7 --- /dev/null +++ b/problem4/Makefile @@ -0,0 +1,12 @@ +IRPF90 = irpf90 #-a -d +FC = gfortran +FCFLAGS= -O2 + +SRC= +OBJ= +LIB= + +include irpf90.make + +irpf90.make: $(wildcard *.irp.f) + $(IRPF90) diff --git a/problem4/README.md b/problem4/README.md new file mode 100644 index 0000000..0065736 --- /dev/null +++ b/problem4/README.md @@ -0,0 +1,7 @@ +PROBLEM 3 +---------- + +* A palindromic number reads the same both ways. The largest palindrome made + from the product of two 2-digit numbers is 9009 = 91 99. + + Find the largest palindrome made from the product of two 3-digit numbers. diff --git a/problem4/irpf90.make b/problem4/irpf90.make new file mode 100644 index 0000000..36dabb4 --- /dev/null +++ b/problem4/irpf90.make @@ -0,0 +1,41 @@ +SRC += IRPF90_temp/irp_stack.irp.F90 IRPF90_temp/irp_touches.irp.F90 IRPF90_temp/prob4.irp.F90 IRPF90_temp/prob4.irp.module.F90 IRPF90_temp/is_palindrome.irp.F90 IRPF90_temp/is_palindrome.irp.module.F90 +OBJ += IRPF90_temp/irp_stack.irp.o IRPF90_temp/is_palindrome.irp.o IRPF90_temp/is_palindrome.irp.module.o +OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(OBJ))) IRPF90_temp/irp_touches.irp.o +ALL = prob4 +ALL_OBJ = prob4.irp.module.o prob4.irp.o +ALL_OBJ1 = $(patsubst %, IRPF90_temp/%,$(notdir $(ALL_OBJ))) +all:$(ALL) + @$(MAKE) -s move +prob4: IRPF90_temp/prob4.irp.o IRPF90_temp/prob4.irp.module.o $(OBJ1) + $(FC) -o $@ IRPF90_temp/$@.irp.o IRPF90_temp/$@.irp.module.o $(OBJ1) $(LIB) + @$(MAKE) -s move +IRPF90_temp/prob4.irp.o: IRPF90_temp/prob4.irp.module.o +IRPF90_temp/is_palindrome.irp.o: IRPF90_temp/is_palindrome.irp.module.o +IRPF90_temp/irp_touches.irp.o: IRPF90_temp/is_palindrome.irp.o IRPF90_temp/is_palindrome.irp.o +IRPF90_temp/%.irp.module.o: IRPF90_temp/%.irp.module.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.module.F90 -o IRPF90_temp/$*.irp.module.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.module.o IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.irp.o: IRPF90_temp/%.irp.F90 + $(FC) $(FCFLAGS) -c IRPF90_temp/$*.irp.F90 -o IRPF90_temp/$*.irp.o +IRPF90_temp/%.o: %.F90 + $(FC) $(FCFLAGS) -c $*.F90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f90 + $(FC) $(FCFLAGS) -c $*.f90 -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.f + $(FC) $(FCFLAGS) -c $*.f -o IRPF90_temp/$*.o +IRPF90_temp/%.o: %.F + $(FC) $(FCFLAGS) -c $*.F -o IRPF90_temp/$*.o +IRPF90_temp/%.irp.F90: irpf90.make + +move: + @mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING= + +clean: + rm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL) + +veryclean: + - $(MAKE) clean + + - rm -rf IRPF90_temp/ IRPF90_man/ irpf90.make irpf90_variables dist + diff --git a/problem4/irpf90_entities b/problem4/irpf90_entities new file mode 100644 index 0000000..e69de29 diff --git a/problem4/is_palindrome.irp.f b/problem4/is_palindrome.irp.f new file mode 100644 index 0000000..536aac2 --- /dev/null +++ b/problem4/is_palindrome.irp.f @@ -0,0 +1,31 @@ + subroutine is_palindrome(number,palin) + + implicit none + logical :: palin + integer :: number,digit(1000),i,n1,j + + palin=.FALSE. + do i=1,1000 + digit(i)=10 + enddo + + i=0 + do while (number.gt.0) + + n1=number-10*(number/10) + digit(i)=n1 + number=number/10 + i+=1 + enddo + +! write(6,*)(digit(j),j=i-1,0,-1) + palin=.TRUE. + do j=0,int((i-1)/2) + if(digit(j).ne.digit((i-1)-j))then + palin=.FALSE. + EXIT + endif + enddo + + return + end diff --git a/problem4/o b/problem4/o new file mode 100644 index 0000000..73bc8a9 --- /dev/null +++ b/problem4/o @@ -0,0 +1,30 @@ + 861168 + 888888 + 861168 + 828828 + 886688 + 824428 + 906609 + 819918 + 824428 + 819918 + 828828 + 855558 + 840048 + 737737 + 853358 + 809908 + 793397 + 749947 + 821128 + 801108 + 749947 + 828828 + 802208 + 780087 + 737737 + 807708 + 698896 + 678876 + 804408 + 906609 diff --git a/problem4/prob4 b/problem4/prob4 new file mode 100755 index 0000000..f886e85 Binary files /dev/null and b/problem4/prob4 differ diff --git a/problem4/prob4.irp.f b/problem4/prob4.irp.f new file mode 100644 index 0000000..1d74478 --- /dev/null +++ b/problem4/prob4.irp.f @@ -0,0 +1,49 @@ + program prob4 + + implicit none + + integer :: i,j,number,k,ilim,jlim,palin(10000),maxpalin,cp,lim + logical :: palindrome + + palindrome=.FALSE. + maxpalin=0 + cp=0 + do i=999,100,-1 + do j=999,i,-1 + number=i*j +! write(6,*)number + call is_palindrome(number,palindrome) +! write(6,*)palindrome + if(palindrome)then +! write(6,*)i*j + EXIT + endif + if(palindrome)EXIT + enddo + if(palindrome)EXIT + enddo + ilim=i + jlim=j + palindrome=.FALSE. + + lim=MIN(ilim,jlim) + lim=lim-100 + do i=999,lim,-1 + do j=999,j,-1 + number=i*j + call is_palindrome(number,palindrome) + if(palindrome)then + cp+=1 + palin(cp)=i*j + endif + enddo + enddo + + do i=1,cp + if(maxpalin.le.palin(i))maxpalin=palin(i) + enddo + + write(6,*)maxpalin + + + end