Skip to content

Instantly share code, notes, and snippets.

@t-nissie
Last active March 17, 2016 10:05
Show Gist options
  • Save t-nissie/15689902c40e74f81774 to your computer and use it in GitHub Desktop.
Save t-nissie/15689902c40e74f81774 to your computer and use it in GitHub Desktop.
dot_product()とかを使ってできるだけFortran風に書いた「ズンドコキヨシ in Fortran」(1行169バイトのzz.fもあるヨ!)
! zundoko.f -*-f90-*-
!「ズン」「ドコ」のいずれかをランダムで出力し続けて
!「ズン」「ズン」「ズン」「ズン」「ドコ」の配列が出たら
!「キ・ヨ・シ!」って出力した後終了
! Ref1: https://twitter.com/kumiromilk/status/707437861881180160
! Ref2: http://qiita.com/shunsugai@github/items/971a15461de29563bf90
!!
subroutine kiyoshi(c)
implicit none
integer,intent(in) :: c
integer :: seed(100)
integer :: memo(5) = (/ 0,0,0,0,0/)
integer, parameter :: chkr(5) = (/-1,1,1,1,1/)
real :: x(1)
call random_seed(get=seed)
seed(:) = seed(:) + c
call random_seed(put=seed)
do while (dot_product(memo(:),chkr(:)).ne.5)
memo(2:5) = memo(1:4)
call random_number(x)
if (x(1)<0.5) then
write(6,'(a,$)') 'ズン'
memo(1) = 1
else
write(6,'(a,$)') 'ドコ'
memo(1) = -1
end if
end do
write(6,'(a)') 'キ・ヨ・シ!'
end subroutine kiyoshi
program zundoko
implicit none
integer :: c
call system_clock(count=c)
call kiyoshi(c)
end program zundoko
!Local variables:
! compile-command: "gfortran -Wall -ffree-form -o zundoko zundoko.f && ./zundoko"
!End:
call system_clock(count=i);call srand(i);i=0;do;if(rand()<.5)then;i=i+1;print*,'ズン';else;print*,'ドコ';if(i>3)exit;i=0;endif;enddo;print*,'キ・ヨ・シ!';end
!Local variables:
! compile-command: "gfortran -Wall -ffree-form -ffree-line-length-none -o zz zz.f && head -1 zz.f | wc -c && ./zz"
!End:
@t-nissie
Copy link
Author

バグ: pgfortranではcが常に0になってしまう。http://www.pgroup.com/userforum/viewtopic.php?t=187&sid=c1ef7a38d16aa7aea815a4426accfab9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment