Skip to content

Instantly share code, notes, and snippets.

@roblogic
Last active April 1, 2019 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roblogic/d1175fa16fb4540910cc389a1e5374e6 to your computer and use it in GitHub Desktop.
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
! 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
Copy link
Author

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