# Euler problem 11.4

```
recursive function max_e11(a2d, i, j, acc) result(a)

integer, dimension(20, 20) :: a2d
integer :: i, j, acc, a, accm = 0
integer :: dia_l = 0, dia_r = 0, hori = 0, vert = 0
integer :: k = 0, x = 1, y = 1
integer :: lenx = 20, leny = 20

if (i <= (lenx - 3)) then
hori = 1
do k = 0, 3
hori = hori*a2d(i+k, j)
end do
end if

if (j <= (leny - 3)) then
vert = 1
do k = 0, 3
vert = vert*a2d(i, j+k)
end do
end if

if ((i <= (lenx - 3)) .and. (j <= (leny - 3))) then
dia_r = 1
do k = 0, 3
dia_r = dia_r*a2d(i+k, j+k)
end do
end if

if ((i >= 4) .and. (j <= (leny - 3))) then
dia_l = 1
do k = 0, 3
dia_l = dia_l*a2d(i-k, j+k)
end do
end if

if ((i == lenx) .and. (j == leny)) then
a = acc
else
accm = max(acc, hori, vert, dia_l, dia_r)

if (i == lenx) then
x = 1
y = j + 1
else
x = i + 1
y = j
end if

a = max_e11(a2d, x, y, accm)
end if
end function max_e11

program main

implicit none

integer :: p_max, p_count, i, j
integer(kind = 16) :: p_sum
logical, ALLOCATABLE, DIMENSION(:) :: is_prime
character(len=128) :: currentDir
integer, dimension(20, 20) :: D, M
integer :: max_e11

call GET_ENVIRONMENT_VARIABLE('PWD', currentDir)

print *, "dir == ", trim(currentDir)

open(1, file = "t.txt", status = "old")
close(1)

M = transpose(D)

write(*, *) M(1, 1)
write(*, *) max_e11(M, 1, 1, 0)
write(*, *) M(1, 1)

end program main
```

— Me@2022-12-24 11:50:15 AM

.

.

# Fortran Package Manager

.

The goal of this blog post is to set up an integrated programming environment for `Fortran`.

.

3. Install the package manager `Anaconda`.

4. Use `Anaconda` to install the `Fortran Package Manager` (fpm), by following the `fpm` installation guide.

4.1. Add the additional channel mentioned in the `fpm` installation guide.

4.2. Install the `fpm` itself:

```conda create -n fpm_env fpm

conda activate fpm_env```

5. Install the `Fortran language server`:

`conda install fortls`

6. Install the `Emacs` plugin:

```sudo apt-get install elpa-pyvenv
```

7. Open `Emacs`’ initialization file, whose location should be

```~/.emacs
```

8. Add the following code to the file.

```
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun gfortran-run ()

(interactive)

(save-buffer)

(unless visual-line-mode
(visual-line-mode 1))

(universal-argument)

(compile "fpm run"))

(global-set-key (kbd "C-x C-r") 'gfortran-run)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setenv "WORKON_HOME" "~/anaconda3/envs")

(pyvenv-mode 1)

(pyvenv-workon "fpm_env")

;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;```

— Me@2022-12-01 09:18:59 AM

.

.

# Why does the universe exist? 7.3

Euler problem 10.4

.

```program main

implicit none

integer :: p_max, p_count, i, j
integer(kind = 16) :: p_sum
logical, ALLOCATABLE, DIMENSION(:) :: is_prime

p_max = 2000000

ALLOCATE(is_prime(p_max))

is_prime = .true.

is_prime(1) = .false.

do i = 2, ceiling(sqrt(real(p_max)))
if (is_prime(i)) then
do j = i*i, p_max, i
is_prime(j) = .false.
end do
end if
end do

p_count = 0
p_sum = 0
do i = 1, p_max
if (is_prime(i)) then
p_count = p_count + 1
p_sum = p_sum + i
end if
end do

print *, "p_count == ", p_count
print *, "p_sum == ", p_sum

DEALLOCATE(is_prime)

end program main
```

For a universe part, which is partial in space or in time, you can ask for its cause.

But for the universe as a whole, you cannot.

If the big bang is the first cause, you cannot ask for the cause of its existence.

Asking for the cause of the existence of the universe is the same as asking for the cause of the first cause.

— Me@2012-10-15 08:33:01 AM

— Me@2022-11-27 09:09:53 PM

.

.