Last active
April 1, 2019 22:32
-
-
Save roblogic/d1175fa16fb4540910cc389a1e5374e6 to your computer and use it in GitHub Desktop.
(Draft) Fortran solution for code golf challenge: https://codegolf.stackexchange.com/questions/182363/rotate-a-column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! source file: "rotcol.f" | |
! compile command: | |
! gfortran -std=gnu -Wextra -Wall -pedantic -ffree-form -fcheck=all -fbacktrace rotcol.f -o rotcol.app | |
! executable: "rotcol.app" | |
! read from file "rotateme.txt": | |
! K : column to rotate | |
! Z : number of rows to input | |
program main | |
implicit none | |
integer z,i,k | |
character(128), allocatable :: A(:) | |
character(1) :: r,s | |
! read data | |
open(unit=8,file='rotateme.txt') | |
read(8,*) k,z | |
allocate(A(z)) | |
! loop over Z | |
do i=1,z | |
read(8,'(a)') A(i) | |
r=A(i)(k:k) | |
if (r.ne.'' .or. r.ne.' ') then | |
A(i)(k:k)=s | |
s=r | |
endif | |
enddo | |
A(1)(k:k)=s | |
print '(A)',A | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires input file
rotateme.txt
with following format: