Skip to content

Instantly share code, notes, and snippets.

@roblogic

roblogic/rotcol.f

Last active Apr 1, 2019
Embed
What would you like to do?
(Draft) Fortran solution for code golf challenge: https://codegolf.stackexchange.com/questions/182363/rotate-a-column
! 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
@roblogic

This comment has been minimized.

Copy link
Owner Author

@roblogic roblogic commented Apr 1, 2019

requires input file rotateme.txt with following format:

20 8
A line with more than k characters.
A longer line with more than k character.
A short line.
Rotate here: ------v--
This is long enough.

This is not enough.
Wrapping around to the first line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment