subroutine difn(a,b,c,d) integer, intent(in) :: a,b,c integer, intent(inout) :: d integer, dimension(15,1) :: dmat integer, dimension(10,1) :: nmat integer :: nnonzero,indc integer, dimension(4,1) :: ns,nns character (5) :: as,bs,cs integer :: at,bt,ct write(as,fmt='(i5)') a write(bs,fmt='(i5)') b write(cs,fmt='(i5)') c do i=1,5 read(as(i:i),fmt='(i1)') at dmat(i,1)=at read(bs(i:i),fmt='(i1)') bt dmat(i+5,1)=bt read(cs(i:i),fmt='(i1)') ct dmat(i+10,1)=ct end do do i=1,10 nmat(i,1)=0 end do do i=1,15 do j=0,9 if (dmat(i,1)==j) then nmat(j+1,1)=nmat(j+1,1)+1 end if end do end do nnonzero=0 do i=1,10 if (nmat(i,1)/=0) then nnonzero=nnonzero+1 end if end do d=0 indc=0 if (nnonzero==4) then do i=1,10 if (nmat(i,1)/=0) then ns(indc+1,1)=i-1 nns(indc+1,1)=nmat(i,1) indc=indc+1 end if end do end if if (nns(1,1)/=nns(2,1).and.nns(1,1)/=nns(3,1).and.& nns(1,1)/=nns(4,1).and.nns(2,1)/=nns(3,1).and.& nns(2,1)/=nns(4,1).and.nns(3,1)/=nns(4,1)) then indc=0 do i=1,4 do j=1,4 if (ns(i,1)==nns(j,1)) then indc=indc+1 end if end do end do if (indc==4) then print *,ns print *,nns d=1 end if end if end subroutine program enigma15492 integer :: a,b,c,ind integer, dimension(217,1) :: squares do i=100,316 squares(i-99,1)=i**(2) end do do i=1,217 do j=i+1,217 do k=j+1,217 ind=0 call difn(squares(i,1),squares(j,1),squares(k,1),ind) if (ind==1) then print *,squares(i,1),squares(j,1),squares(k,1) end if end do end do end do end program enigma15492