From 0619e579c3e52414c7173b957d1c409dc5708518 Mon Sep 17 00:00:00 2001 From: Patrik Tesarik Date: Thu, 6 Sep 2018 23:10:07 +0200 Subject: [PATCH 1/8] Delete monte_carlo_pi.f90 --- contents/monte_carlo_integration/code/fortran/monte_carlo_pi.f90 | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 contents/monte_carlo_integration/code/fortran/monte_carlo_pi.f90 diff --git a/contents/monte_carlo_integration/code/fortran/monte_carlo_pi.f90 b/contents/monte_carlo_integration/code/fortran/monte_carlo_pi.f90 deleted file mode 100644 index e69de29bb..000000000 From 3e86449900be9d6007506ae341ae17e20f3d7022 Mon Sep 17 00:00:00 2001 From: depate Date: Wed, 12 Sep 2018 22:50:19 +0200 Subject: [PATCH 2/8] init --- contents/bubble_sort/code/fortran/bubble.f90 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 contents/bubble_sort/code/fortran/bubble.f90 diff --git a/contents/bubble_sort/code/fortran/bubble.f90 b/contents/bubble_sort/code/fortran/bubble.f90 new file mode 100644 index 000000000..1031a3617 --- /dev/null +++ b/contents/bubble_sort/code/fortran/bubble.f90 @@ -0,0 +1,15 @@ +SUBROUTINE bubblesort(array) + IMPLICIT NONE + INTEGER :: len_array + REAL(8), ALLOCATABLE, DIMENSION(:,:) :: array + + + for i +END SUBROUTINE bubblesort + +PROGRAM + IMPLICIT NONE + INTEGER :: cols, rows + + +END PROGRAMM From 5d1602aa2c4e38df55f2e5f3adaad5761751b18d Mon Sep 17 00:00:00 2001 From: Patrik Tesarik Date: Sun, 23 Sep 2018 02:52:46 +0200 Subject: [PATCH 3/8] further implementation --- contents/bubble_sort/code/fortran/bubble.f90 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contents/bubble_sort/code/fortran/bubble.f90 b/contents/bubble_sort/code/fortran/bubble.f90 index 1031a3617..bf28f4dd0 100644 --- a/contents/bubble_sort/code/fortran/bubble.f90 +++ b/contents/bubble_sort/code/fortran/bubble.f90 @@ -1,15 +1,18 @@ SUBROUTINE bubblesort(array) IMPLICIT NONE - INTEGER :: len_array + INTEGER :: len_array REAL(8), ALLOCATABLE, DIMENSION(:,:) :: array - for i + DO + + END DO END SUBROUTINE bubblesort -PROGRAM - IMPLICIT NONE - INTEGER :: cols, rows +PROGRAM main + +IMPLICIT NONE +INTEGER :: cols, rows END PROGRAMM From 1ea8e186748cadef359def352046566145838660 Mon Sep 17 00:00:00 2001 From: Patrik Tesarik Date: Sun, 23 Sep 2018 16:36:06 +0200 Subject: [PATCH 4/8] next --- contents/bubble_sort/code/fortran/bubble.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contents/bubble_sort/code/fortran/bubble.f90 b/contents/bubble_sort/code/fortran/bubble.f90 index bf28f4dd0..9e6733bb1 100644 --- a/contents/bubble_sort/code/fortran/bubble.f90 +++ b/contents/bubble_sort/code/fortran/bubble.f90 @@ -1,8 +1,9 @@ SUBROUTINE bubblesort(array) IMPLICIT NONE - INTEGER :: len_array + INTEGER :: array_length, array_shape REAL(8), ALLOCATABLE, DIMENSION(:,:) :: array + len_array = size(array) DO From 824060b5210140b7345a71ed4995923dc013366c Mon Sep 17 00:00:00 2001 From: depate Date: Tue, 2 Oct 2018 12:39:52 +0200 Subject: [PATCH 5/8] hopefully fixes things --- contents/bubble_sort/code/fortran/bubble.f90 | 22 -------------------- 1 file changed, 22 deletions(-) diff --git a/contents/bubble_sort/code/fortran/bubble.f90 b/contents/bubble_sort/code/fortran/bubble.f90 index 001ce6f94..fb903f0d3 100644 --- a/contents/bubble_sort/code/fortran/bubble.f90 +++ b/contents/bubble_sort/code/fortran/bubble.f90 @@ -1,24 +1,3 @@ -<<<<<<< HEAD -SUBROUTINE bubblesort(array) - IMPLICIT NONE - INTEGER :: array_length, array_shape - REAL(8), ALLOCATABLE, DIMENSION(:,:) :: array - - len_array = size(array) - - DO - - END DO -END SUBROUTINE bubblesort - -PROGRAM main - -IMPLICIT NONE -INTEGER :: cols, rows - - -END PROGRAMM -======= PROGRAM main IMPLICIT NONE @@ -61,4 +40,3 @@ SUBROUTINE bubblesort(array) END SUBROUTINE bubblesort END PROGRAM main ->>>>>>> 44181dc533101507167ae8fe2c97329100941098 From b1f271bef64b316b9ab69de50cd81984d0be62bb Mon Sep 17 00:00:00 2001 From: depate Date: Tue, 2 Oct 2018 22:18:52 +0200 Subject: [PATCH 6/8] initial commit --- contents/bogo_sort/code/fortran/bogo.f90 | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 contents/bogo_sort/code/fortran/bogo.f90 diff --git a/contents/bogo_sort/code/fortran/bogo.f90 b/contents/bogo_sort/code/fortran/bogo.f90 new file mode 100644 index 000000000..e59ff228c --- /dev/null +++ b/contents/bogo_sort/code/fortran/bogo.f90 @@ -0,0 +1,47 @@ +program bogo + implicit none + real(8), dimension(:), allocatable :: array + + array = [1, 1, 0, 3, 7] + + call bogo_sort(array) +contains + + logical function is_sorted(array) + real(8), dimension(:), intent(in) :: array + integer :: i + + do i = 1, size(array) + if (array(i+1) > array(i)) then + is_sorted = .false. + end if + end do + end function is_sorted + + subroutine bogo_sort(array) + real(8), dimension(:), intent(inout) :: array + integer :: i + logical :: is_sorted + + do while (is_sorted(array) = .FALSE. ) + + CALL shuffle(array) + + end do + end subroutine bogo_sort + + subroutine shuffle(array) + real(8), dimension(:), intent(inout) :: array + integer :: i, randpos, temp + real(8) :: r + + do i = size(array), 2, -1 + call random_number(r) + randpos = int(r * i) + 1 + temp = array(randpos) + array(randpos) = array(i) + array(i) = temp + end do + + end subroutine shuffle +end program bogo From b8f152de115b396beed817d328419297a5b5e18a Mon Sep 17 00:00:00 2001 From: depate Date: Tue, 2 Oct 2018 23:01:28 +0200 Subject: [PATCH 7/8] final implementation and documentation --- contents/bogo_sort/bogo_sort.md | 7 +++++-- contents/bogo_sort/code/fortran/bogo.f90 | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/contents/bogo_sort/bogo_sort.md b/contents/bogo_sort/bogo_sort.md index d46241c06..0a3c4a51f 100644 --- a/contents/bogo_sort/bogo_sort.md +++ b/contents/bogo_sort/bogo_sort.md @@ -43,14 +43,15 @@ In code, it looks something like this: [import:16-18, lang:"nim"](code/nim/bogo_sort.nim) {% sample lang="ruby" %} [import:12-16, lang:"ruby"](code/ruby/bogo.rb) +{% sample lang="f90" %} +[import:24-32, lang:"fortran"](code/fortran/bogo.f90) {% endmethod %} That's it. Ship it! We are done here! -## Example Code - +## Example Code {% method %} {% sample lang="jl" %} [import, lang:"julia"](code/julia/bogo.jl) @@ -85,6 +86,8 @@ We are done here! [import, lang:"nim"](code/nim/bogo_sort.nim) {% sample lang="ruby" %} [import, lang:"ruby"](code/ruby/bogo.rb) +{% sample lang="f90" %} +[import, lang:"fortran"](code/fortran/bogo.f90) {% endmethod %} diff --git a/contents/bogo_sort/code/fortran/bogo.f90 b/contents/bogo_sort/code/fortran/bogo.f90 index e59ff228c..74050d566 100644 --- a/contents/bogo_sort/code/fortran/bogo.f90 +++ b/contents/bogo_sort/code/fortran/bogo.f90 @@ -1,10 +1,13 @@ program bogo implicit none - real(8), dimension(:), allocatable :: array + real(8), dimension(5) :: array - array = [1, 1, 0, 3, 7] + array = (/ 1, 1, 0, 3, 7 /) call bogo_sort(array) + + WRITE(*,*) array + contains logical function is_sorted(array) @@ -12,7 +15,7 @@ logical function is_sorted(array) integer :: i do i = 1, size(array) - if (array(i+1) > array(i)) then + if (array(i+1) < array(i)) then is_sorted = .false. end if end do @@ -20,20 +23,18 @@ end function is_sorted subroutine bogo_sort(array) real(8), dimension(:), intent(inout) :: array - integer :: i - logical :: is_sorted - do while (is_sorted(array) = .FALSE. ) + do while (is_sorted(array) .eqv. .false.) + + call shuffle(array) - CALL shuffle(array) - end do end subroutine bogo_sort subroutine shuffle(array) real(8), dimension(:), intent(inout) :: array - integer :: i, randpos, temp - real(8) :: r + integer :: i, randpos + real(8) :: r, temp do i = size(array), 2, -1 call random_number(r) From 82aad3be71b9799ae81d1bb106cb781019551a54 Mon Sep 17 00:00:00 2001 From: depate Date: Thu, 4 Oct 2018 22:31:53 +0200 Subject: [PATCH 8/8] capitalising the syntax --- contents/bogo_sort/code/fortran/bogo.f90 | 64 ++++++++++++------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/contents/bogo_sort/code/fortran/bogo.f90 b/contents/bogo_sort/code/fortran/bogo.f90 index 74050d566..87a7ab9ff 100644 --- a/contents/bogo_sort/code/fortran/bogo.f90 +++ b/contents/bogo_sort/code/fortran/bogo.f90 @@ -1,48 +1,48 @@ -program bogo - implicit none - real(8), dimension(5) :: array +PROGRAM bogo + IMPLICIT NONE + REAL(8), DIMENSION(5) :: array - array = (/ 1, 1, 0, 3, 7 /) + array = (/ 1d0, 1d0, 0d0, 3d0, 7d0 /) - call bogo_sort(array) + CALL bogo_sort(array) WRITE(*,*) array -contains +contaINs - logical function is_sorted(array) - real(8), dimension(:), intent(in) :: array - integer :: i + LOGICAL FUNCTION is_sorted(array) + REAL(8), DIMENSION(:), INTENT(IN) :: array + INTEGER :: i - do i = 1, size(array) - if (array(i+1) < array(i)) then - is_sorted = .false. - end if - end do - end function is_sorted + DO i = 1, SIZE(array) + IF (array(i+1) < array(i)) THEN + is_sorted = .FALSE. + END IF + END DO + END FUNCTION is_sorted - subroutine bogo_sort(array) - real(8), dimension(:), intent(inout) :: array + SUBROUTINE bogo_sort(array) + REAL(8), DIMENSION(:), INTENT(INOUT) :: array - do while (is_sorted(array) .eqv. .false.) + DO WHILE (is_sorted(array) .EQV. .FALSE.) - call shuffle(array) + CALL shuffle(array) - end do - end subroutine bogo_sort + END DO + END SUBROUTINE bogo_sort - subroutine shuffle(array) - real(8), dimension(:), intent(inout) :: array - integer :: i, randpos - real(8) :: r, temp - - do i = size(array), 2, -1 - call random_number(r) - randpos = int(r * i) + 1 + SUBROUTINE shuffle(array) + REAL(8), DIMENSION(:), INTENT(INOUT) :: array + INTEGER :: i, randpos + REAL(8) :: r, temp + + DO i = size(array), 2, -1 + CALL RANDOM_NUMBER(r) + randpos = INT(r * i) + 1 temp = array(randpos) array(randpos) = array(i) array(i) = temp - end do + END DO - end subroutine shuffle -end program bogo + END SUBROUTINE shuffle +END PROGRAM bogo