WeixiangYan/CodeTransOcean huggingface dataset:
Task: Benford's law





Java: import java.math.BigInteger;
import java.util.Locale;

public class BenfordsLaw {

    private static BigInteger[] generateFibonacci(int n) {
        BigInteger[] fib = new BigInteger[n];
        fib[0] = BigInteger.ONE;
        fib[1] = BigInteger.ONE;
        for (int i = 2; i < fib.length; i++) {
            fib[i] = fib[i - 2].add(fib[i - 1]);
        }
        return fib;
    }

    public static void main(String[] args) {
        BigInteger[] numbers = generateFibonacci(1000);

        int[] firstDigits = new int[10];
        for (BigInteger number : numbers) {
            firstDigits[Integer.valueOf(number.toString().substring(0, 1))]++;
        }

        for (int i = 1; i < firstDigits.length; i++) {
            System.out.printf(Locale.ROOT, "%d %10.6f %10.6f%n",
                    i, (double) firstDigits[i] / numbers.length, Math.log10(1.0 + 1.0 / i));
        }
    }
}






Fortran: -*- mode: compilation; default-directory: "/tmp/" -*-
Compilation started at Sat May 18 01:13:00

a=./f && make $a && $a
f95 -Wall -ffree-form f.F -o f
  0.301030010      0.176091254      0.124938756       9.69100147E-02   7.91812614E-02   6.69467747E-02   5.79919666E-02   5.11525236E-02   4.57575098E-02 THE LAW
  0.300999999      0.177000001      0.125000000       9.60000008E-02   7.99999982E-02   6.70000017E-02   5.70000000E-02   5.29999994E-02   4.50000018E-02 LEADING FIBONACCI DIGIT

Compilation finished at Sat May 18 01:13:00
Task: Hickerson series of almost integers





Java: import java.math.*;

public class Hickerson {

    final static String LN2 = "0.693147180559945309417232121458";

    public static void main(String[] args) {
        for (int n = 1; n <= 17; n++)
            System.out.printf("%2s is almost integer: %s%n", n, almostInteger(n));
    }

    static boolean almostInteger(int n) {
        BigDecimal a = new BigDecimal(LN2);
        a = a.pow(n + 1).multiply(BigDecimal.valueOf(2));

        long f = n;
        while (--n > 1)
            f *= n;

        BigDecimal b = new BigDecimal(f);
        b = b.divide(a, MathContext.DECIMAL128);

        BigInteger c = b.movePointRight(1).toBigInteger().mod(BigInteger.TEN);

        return c.toString().matches("0|9");
    }
}






Fortran: program hickerson
    implicit none
    integer, parameter :: q = selected_real_kind(30)
    integer, parameter :: l = selected_int_kind(15)
    real(q) :: s, l2
    integer :: i, n, k

    l2 = log(2.0_q)
    do n = 1, 17
        s = 0.5_q / l2
        do i = 1, n
            s = (s * i) / l2
        end do

        k = floor((s - floor(s, l)) * 10)
        if (k == 0 .or. k == 9) then
            print 1, n, s, ""
        else
            print 1, n, s, " NOT"
        endif
    end do
  1 format('h(',I2,') = ',F23.3,' is',A,' an almost-integer')
end program
Task: Case-sensitivity of identifiers





Java: String dog = "Benjamin"; 
String Dog = "Samba";    
String DOG = "Bernie";   
@Inject Console console;
console.print($"There are three dogs named {dog}, {Dog}, and {DOG}");






Fortran: program Example
  implicit none

  character(8) :: dog, Dog, DOG

  dog = "Benjamin"
  Dog = "Samba"
  DOG = "Bernie"

  if (dog == DOG) then
    write(*,*) "There is just one dog named ", dog
  else
    write(*,*) "The three dogs are named ", dog, Dog, " and ", DOG
  end if

end program Example
Task: Sorting algorithms_Stooge sort





Java: import java.util.Arrays;

public class Stooge {
    public static void main(String[] args) {
        int[] nums = {1, 4, 5, 3, -6, 3, 7, 10, -2, -5};
        stoogeSort(nums);
        System.out.println(Arrays.toString(nums));
    }

    public static void stoogeSort(int[] L) {
        stoogeSort(L, 0, L.length - 1);
    }

    public static void stoogeSort(int[] L, int i, int j) {
        if (L[j] < L[i]) {
            int tmp = L[i];
            L[i] = L[j];
            L[j] = tmp;
        }
        if (j - i > 1) {
            int t = (j - i + 1) / 3;
            stoogeSort(L, i, j - t);
            stoogeSort(L, i + t, j);
            stoogeSort(L, i, j - t);
        }
    }
}






Fortran: program Stooge
  implicit none

  integer :: i
  integer :: array(50) = (/ (i, i = 50, 1, -1) /) 
  
  call Stoogesort(array)
  write(*,"(10i5)") array

contains

recursive subroutine Stoogesort(a)
  integer, intent(in out) :: a(:)
  integer :: j, t, temp
 
   j = size(a)
   if(a(j) < a(1)) then
     temp = a(j)
     a(j) = a(1)
     a(1) = temp
   end if

  if(j > 2) then
    t = j / 3
    call Stoogesort(a(1:j-t))
    call Stoogesort(a(1+t:j))
    call Stoogesort(a(1:j-t)) 
  end if

end subroutine
end program
Task: Truncate a file





Java: import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class TruncFile {
	public static void main(String[] args) throws IOException{
		if(args.length < 2){
			System.out.println("Usage: java TruncFile fileName newSize");
			return;
		}
		
		FileChannel outChan = new FileOutputStream(args[0], true).getChannel();
		long newSize = Long.parseLong(args[1]);
		outChan.truncate(newSize);
		outChan.close();
	}
}






Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,NB)
       CHARACTER*(*) FNAME	
       INTEGER NB		
       INTEGER L		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST		
       CHARACTER*1 B		
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (NB.LE.0)     CALL CROAK("Chop must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READWRITE",	
     1   FORM="UNFORMATTED",RECL=1,ACCESS="DIRECT")		
        OPEN (T,STATUS="SCRATCH",FORM="UNFORMATTED",RECL=1)	

Copy the desired "records" to the temporary file.
   10   DO L = 1,NB	
          READ  (F,REC = L,ERR = 20) B	
          WRITE (T) B			
        END DO		
   20   IF (L.LE.NB) CALL CROAK("Short file
Convert from input to output...
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
        DO L = 1,NB	
          READ  (T) B		
          WRITE (F,"(A1,$)") B	
        END DO		
Completed.
   30   CLOSE(T)	
        CLOSE(F)	
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",12)
      END
Task: Sorting algorithms_Shell sort





Java: public static void shell(int[] a) {
	int increment = a.length / 2;
	while (increment > 0) {
		for (int i = increment; i < a.length; i++) {
			int j = i;
			int temp = a[i];
			while (j >= increment && a[j - increment] > temp) {
				a[j] = a[j - increment];
				j = j - increment;
			}
			a[j] = temp;
		}
		if (increment == 2) {
			increment = 1;
		} else {
			increment *= (5.0 / 11);
		}
	}
}






Fortran: MODULE sort

CONTAINS

SUBROUTINE Shell_Sort(a)

  IMPLICIT NONE
  INTEGER :: i, j, increment
  REAL :: temp
  REAL, INTENT(in out) :: a(:)
	
  increment = SIZE(a) / 2
  DO WHILE (increment > 0)
      DO i = increment+1, SIZE(a)
         j = i
         temp = a(i)
         DO WHILE (j >= increment+1 .AND. a(j-increment) > temp)
            a(j) = a(j-increment)
            j = j - increment
         END DO
         a(j) = temp
      END DO
      IF (increment == 2) THEN
   	  increment = 1
      ELSE
         increment = increment * 5 / 11
      END IF      
  END DO
 
END SUBROUTINE Shell_Sort

END MODULE sort

PROGRAM Shellsort

USE sort

  IMPLICIT NONE
  REAL :: array(1000)
     
  CALL RANDOM_SEED
  CALL RANDOM_NUMBER(array)
 
  WRITE (*,*) "Unsorted array"
  WRITE (*,*) array
  WRITE (*,*) 
  CALL Shell_Sort(array)
  WRITE (*,*) "Sorted array"
  WRITE (*,*) array
  
END PROGRAM Shellsort
Task: Deconvolution_1D





Java: import java.util.Arrays;

public class Deconvolution1D {
    public static int[] deconv(int[] g, int[] f) {
        int[] h = new int[g.length - f.length + 1];
        for (int n = 0; n < h.length; n++) {
            h[n] = g[n];
            int lower = Math.max(n - f.length + 1, 0);
            for (int i = lower; i < n; i++)
                h[n] -= h[i] * f[n - i];
            h[n] /= f[0];
        }
        return h;
    }

    public static void main(String[] args) {
        int[] h = { -8, -9, -3, -1, -6, 7 };
        int[] f = { -3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1 };
        int[] g = { 24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96,
                96, 31, 55, 36, 29, -43, -7 };

        StringBuilder sb = new StringBuilder();
        sb.append("h = " + Arrays.toString(h) + "\n");
        sb.append("deconv(g, f) = " + Arrays.toString(deconv(g, f)) + "\n");
        sb.append("f = " + Arrays.toString(f) + "\n");
        sb.append("deconv(g, h) = " + Arrays.toString(deconv(g, h)) + "\n");
        System.out.println(sb.toString());
    }
}






Fortran: 



program deconv
  
  use mkl95_lapack, only : gelsd

  implicit none
  real(8), allocatable :: g(:), href(:), A(:,:), f(:)
  real(8), pointer     :: h(:), r(:)
  integer              :: N
  character(len=16)    :: cbuff
  integer              :: i
  intrinsic            :: nint

  
  allocate(g(21),f(16))
  g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7]
  f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1]

  
  h => deco(f, g)

  
  N = size(h)
  allocate(href(N))
  href = [-8,-9,-3,-1,-6,7]
  cbuff = ' '
  write(cbuff,'(a,i0,a)') '(a,',N,'(i0,a),i0)'
  if (any(abs(h-href) > 1.0d-4)) then
     write(*,'(a)') 'deconv(f, g) - FAILED'
  else
     write(*,cbuff) 'deconv(f, g) = ',(nint(h(i)),', ',i=1,N-1),nint(h(N))
  end if

  
  r => deco(h, g)

  cbuff = ' '
  N = size(r)
  write(cbuff,'(a,i0,a)') '(a,',N,'(i0,a),i0)'
  if (any(abs(r-f) > 1.0d-4)) then
     write(*,'(a)') 'deconv(h, g) - FAILED'
  else
     write(*,cbuff) 'deconv(h, g) = ',(nint(r(i)),', ',i=1,N-1),nint(r(N))
  end if

contains
  function deco(p, q)
    real(8), pointer    :: deco(:)
    real(8), intent(in) :: p(:), q(:)

    real(8), allocatable, target :: r(:)
    real(8), allocatable         :: A(:,:)
    integer :: N

    
    N = size(q) - size(p) + 1
    allocate(A(size(q),N),r(size(q)))
    A = 0.0d0
    do i=1,N
       A(i:i+size(p)-1,i) = p
    end do
    
    
    r = q
    call gelsd(A, r)

    deco => r(1:N)
  end function deco

end program deconv
Task: Optional parameters





Java: module OptionalParameters
    {
    typedef Type<String  >.Orderer as ColumnOrderer;
    typedef Type<String[]>.Orderer as RowOrderer;

    static String[][] sort(String[][]     table,
                           ColumnOrderer? orderer = Null,
                           Int            column  = 0,
                           Boolean        reverse = False,
                          )
        {
        
        orderer ?:= (s1, s2) -> s1 <=> s2;

        
        ColumnOrderer byString = reverse
                ? ((s1, s2) -> orderer(s1, s2).reversed)
                : orderer;

        
        RowOrderer byColumn = (row1, row2) -> byString(row1[column], row2[column]);

        return table.sorted(byColumn);
        }

    void run()
        {
        String[][] table =
            [
            ["c", "x", "i"],
            ["a", "y", "p"],
            ["b", "z", "a"],
            ];

        show("original input", table);
        show("by default sort on column 0", sort(table));
        show("by column 2", sort(table, column=2));
        show("by column 2 reversed", sort(table, column=2, reverse=True));
        }

    void show(String title, String[][] table)
        {
        @Inject Console console;
        console.print($"{title}:");
        for (val row : table)
            {
            console.print($"  {row}");
            }
        console.print();
        }
    }






Fortran: module ExampleOptionalParameter
  
  
  implicit none
contains

  subroutine sort_table(table, ordering, column, reverse)
    type(table_type), intent(inout) :: table
    integer, optional :: column
    logical, optional :: reverse
    optional :: ordering
    interface
       integer function ordering(a, b)
         type(table_element), intent(in) :: a, b
       end function ordering
    end interface

    integer :: the_column, i
    logical :: reversing
    type(table_row) :: rowA, rowB

    if ( present(column) ) then
       if ( column > get_num_of_columns(table) ) then
          
       else
          the_column = column
       end if
    else
       the_column = 1   
    end if

    reversing = .false.  
    if ( present(reverse) ) reversing = reverse

    do
       
       
       
       
       ea = get_element(rowA, the_column)
       eb = get_element(rowB, the_column)
       if ( present(ordering) ) then
          if ( .not. reversing ) then
             if ( ordering(ea, eb) > 0 ) then
                
             end if
          else   
             if ( ordering(ea, eb) < 0 ) then
                
             end if
          end if
       else
          if ( .not. reversing ) then
             if ( lexinternal(ea, eb) > 0 ) then
                
             end if
          else   
             if ( lexinternal(ea, eb) < 0 ) then
                
             end if
          end if
       end if
       
       
    end do

  end subroutine sort_table

end module ExampleOptionalParameter
Task: Numeric error propagation





Java: public class Approx {
    private double value;
    private double error;
    
    public Approx(){this.value = this.error = 0;}
    
    public Approx(Approx b){
        this.value = b.value;
        this.error = b.error;
    }
    
    public Approx(double value, double error){
        this.value = value;
        this.error = error;
    }
    
    public Approx add(Approx b){
        value+= b.value;
        error = Math.sqrt(error * error + b.error * b.error);
        return this;
    }
    
    public Approx add(double b){
        value+= b;
        return this;
    }
    
    public Approx sub(Approx b){
        value-= b.value;
        error = Math.sqrt(error * error + b.error * b.error);
        return this;
    }
    
    public Approx sub(double b){
        value-= b;
        return this;
    }
    
    public Approx mult(Approx b){
        double oldVal = value;
        value*= b.value;
        error = Math.sqrt(value * value * (error*error) / (oldVal*oldVal) +
                                  (b.error*b.error) / (b.value*b.value));
        return this;
    }

    public Approx mult(double b){
        value*= b;
        error = Math.abs(b * error);
        return this;
    }
    
    public Approx div(Approx b){
        double oldVal = value;
        value/= b.value;
        error = Math.sqrt(value * value * (error*error) / (oldVal*oldVal) +
                                  (b.error*b.error) / (b.value*b.value));
        return this;
    }

    public Approx div(double b){
        value/= b;
        error = Math.abs(b * error);
        return this;
    }
    
    public Approx pow(double b){
        double oldVal = value;
        value = Math.pow(value, b);
        error = Math.abs(value * b * (error / oldVal));
        return this;
    }
    
    @Override
    public String toString(){return value+"±"+error;}
    
    public static void main(String[] args){
        Approx x1 = new Approx(100, 1.1);
        Approx y1 = new Approx(50, 1.2);
        Approx x2 = new Approx(200, 2.2);
        Approx y2 = new Approx(100, 2.3);
        
        x1.sub(x2).pow(2).add(y1.sub(y2).pow(2)).pow(0.5);
        
        System.out.println(x1);
    }
}






Fortran:       PROGRAM CALCULATE	
      REAL X1, Y1, X2, Y2	
      REAL X1E,Y1E,X2E,Y2E	
      DATA X1, Y1 ,X2, Y2 /100., 50., 200.,100./	
      DATA X1E,Y1E,X2E,Y2E/  1.1, 1.2,  2.2, 2.3/	
      REAL DX,DY,D2,D,DXE,DYE,E	
      CHARACTER*1 C			
      PARAMETER (C = CHAR(241))		
      REAL SD	
      SD(X,P,S) = P*ABS(X)**(P - 1)*S	
      WRITE (6,1) X1,C,X1E,Y1,C,Y1E,	
     1            X2,C,X2E,Y2,C,Y2E	
    1 FORMAT ("Euclidean distance between two points:"/	
     1 ("(",F5.1,A1,F3.1,",",F5.1,A1,F3.1,")"))		
      DX = (X1 - X2)			
      DXE = SQRT(X1E**2 + X2E**2)	
      DY = (Y1 - Y2)			
      DYE = SQRT(Y1E**2 + Y2E**2)	
      D2 = DX**2 + DY**2		
      DXE = SD(DX,2,DXE)		
      DYE = SD(DY,2,DYE)		
      E = SQRT(DXE**2 + DYE**2)		
      D = SQRT(D2)			
      E = SD(D2,0.5,E)			
      WRITE (6,2) D,C,E			
    2 FORMAT ("Distance",F6.1,A1,F4.2)	
      END
Task: Trabb Pardo–Knuth algorithm





Java: 
import java.util.*;
import java.io.*; 

public class TPKA {
	public static void main(String... args) {
		double[] input = new double[11];
		double userInput = 0.0;
		Scanner in = new Scanner(System.in);
		for(int i = 0; i < 11; i++) {
			System.out.print("Please enter a number: ");
			String s = in.nextLine();
			try {
				userInput = Double.parseDouble(s);
			} catch (NumberFormatException e) { 
				System.out.println("You entered invalid input, exiting");
				System.exit(1);
			}
			input[i] = userInput;
		}
		for(int j = 10; j >= 0; j--) {
			double x = input[j]; double y = f(x);
			if( y < 400.0) {
				System.out.printf("f( %.2f ) = %.2f\n", x, y);
			} else {
				System.out.printf("f( %.2f ) = %s\n", x, "TOO LARGE");
			}
		}
	}

	private static double f(double x) {
		return Math.pow(Math.abs(x), 0.5) + (5*(Math.pow(x, 3)));
	}
}






Fortran: program tpk
  implicit none
  
  real, parameter :: overflow = 400.0
  real :: a(11), res
  integer :: i
 
  write(*,*) "Input eleven numbers:"
  read(*,*) a
 
  a = a(11:1:-1)
  do i = 1, 11
    res = f(a(i))
    write(*, "(a, f0.3, a)", advance = "no") "f(", a(i), ") = "
    if(res > overflow) then
      write(*, "(a)") "overflow
    else
       write(*, "(f0.3)") res
    end if
  end do  
      
contains

real function f(x)
  real, intent(in) :: x
  
  f = sqrt(abs(x)) + 5.0*x**3

end function  
end program
Task: Rate counter





Java: import java.util.function.Consumer;

public class RateCounter {

    public static void main(String[] args) {
        for (double d : benchmark(10, x -> System.out.print(""), 10))
            System.out.println(d);
    }

    static double[] benchmark(int n, Consumer<Integer> f, int arg) {
        double[] timings = new double[n];
        for (int i = 0; i < n; i++) {
            long time = System.nanoTime();
            f.accept(arg);
            timings[i] = System.nanoTime() - time;
        }
        return timings;
    }
}






Fortran:       DO I = FIRST,LAST
        IF (PROGRESSNOTE((I - FIRST)/(LAST - FIRST + 1.0))) WRITE (6,*) "Reached ",I,", towards ",LAST
        ...much computation...
      END DO
Task: Topswops





Java: public class Topswops {
    static final int maxBest = 32;
    static int[] best;

    static private void trySwaps(int[] deck, int f, int d, int n) {
        if (d > best[n])
            best[n] = d;

        for (int i = n - 1; i >= 0; i--) {
            if (deck[i] == -1 || deck[i] == i)
                break;
            if (d + best[i] <= best[n])
                return;
        }

        int[] deck2 = deck.clone();
        for (int i = 1; i < n; i++) {
            final int k = 1 << i;
            if (deck2[i] == -1) {
                if ((f & k) != 0)
                    continue;
            } else if (deck2[i] != i)
                continue;

            deck2[0] = i;
            for (int j = i - 1; j >= 0; j--)
                deck2[i - j] = deck[j]; 
            trySwaps(deck2, f | k, d + 1, n);
        }
    }

    static int topswops(int n) {
        assert(n > 0 && n < maxBest);
        best[n] = 0;
        int[] deck0 = new int[n + 1];
        for (int i = 1; i < n; i++)
            deck0[i] = -1;
        trySwaps(deck0, 1, 0, n);
        return best[n];
    }

    public static void main(String[] args) {
        best = new int[maxBest];
        for (int i = 1; i < 11; i++)
            System.out.println(i + ": " + topswops(i));
    }
}






Fortran: module top
implicit none
contains 
recursive function f(x) result(m)
  integer :: n, m, x(:),y(size(x)), fst
  fst = x(1)
  if (fst == 1) then
    m = 0
  else
    y(1:fst) = x(fst:1:-1)
    y(fst+1:) = x(fst+1:)
    m = 1 + f(y)
  end if
end function

recursive function perms(x) result(p)
integer, pointer     :: p(:,:), q(:,:)
integer              :: x(:), n, k, i
n = size(x)
if (n == 1) then
  allocate(p(1,1))
  p(1,:) = x
else
  q => perms(x(2:n))
  k = ubound(q,1)
  allocate(p(k*n,n))
  p = 0
  do i = 1,n
    p(1+k*(i-1):k*i,1:i-1) = q(:,1:i-1)
    p(1+k*(i-1):k*i,i) = x(1)
    p(1+k*(i-1):k*i,i+1:) = q(:,i:)
  end do
end if
end function
end module

program topswort
use top
implicit none
integer :: x(10)
integer, pointer  :: p(:,:)
integer :: i, j, m

forall(i=1:10)
  x(i) = i
end forall

do i = 1,10
  p=>perms(x(1:i))
  m = 0
  do j = 1, ubound(p,1)
    m = max(m, f(p(j,:)))
  end do
  print "(i3,a,i3)", i,": ",m
end do  
end program
Task: Odd word problem





Java: public class OddWord {
    interface CharHandler {
	CharHandler handle(char c) throws Exception;
    }
    final CharHandler fwd = new CharHandler() {
	public CharHandler handle(char c) {
	    System.out.print(c);
	    return (Character.isLetter(c) ? fwd : rev);
	}
    };
    class Reverser extends Thread implements CharHandler {
	Reverser() {
	    setDaemon(true);
	    start();
	}
	private Character ch; 
	private char recur() throws Exception {
	    notify();
	    while (ch == null) wait();
	    char c = ch, ret = c;
	    ch = null;
	    if (Character.isLetter(c)) {
		ret = recur();
		System.out.print(c);
	    }
	    return ret;
	}
	public synchronized void run() {
	    try {
		while (true) {
		    System.out.print(recur());
		    notify();
		}
	    } catch (Exception e) {}
	}
	public synchronized CharHandler handle(char c) throws Exception {
	    while (ch != null) wait();
	    ch = c;
	    notify();
	    while (ch != null) wait();
	    return (Character.isLetter(c) ? rev : fwd);
	}
    }
    final CharHandler rev = new Reverser();

    public void loop() throws Exception {
	CharHandler handler = fwd;
	int c;
	while ((c = System.in.read()) >= 0) {
	    handler = handler.handle((char) c);
	}
    }

    public static void main(String[] args) throws Exception {
	new OddWord().loop();
    }
}






Fortran:       MODULE ELUDOM	
       INTEGER MSG,INF	
       LOGICAL DEFER	
       CONTAINS
        CHARACTER*1 RECURSIVE FUNCTION GET(IN)	
         INTEGER IN	
         CHARACTER*1 C	
          READ (IN,1,ADVANCE="NO",EOR=3,END=4) C	
    1     FORMAT (A1,$)	
    2     IF (("A"<=C .AND. C<="Z").OR.("a"<=C .AND. C<="z")) THEN	
            IF (DEFER) THEN	
              GET = GET(IN)	
              WRITE (MSG,1) C	
              RETURN		
            END IF		
           ELSE		
            DEFER = .NOT. DEFER	
          END IF	
    3     GET = C	
          RETURN	
    4     GET = CHAR(0)	
        END FUNCTION GET
      END MODULE ELUDOM	

      PROGRAM CONFUSED	
      USE ELUDOM	
      CHARACTER*1 C	
      MSG = 6	
      INF = 10	
      OPEN (INF,NAME = "Confused.txt",STATUS="OLD",ACTION="READ")	

Chew through the input. A full stop marks the end.
   10 DEFER = .FALSE.	
   11 C = GET(INF)		
      IF (ICHAR(C).LE.0) STOP		
      IF (C.NE." ") WRITE (MSG,12) C	
   12 FORMAT (A1,$)			
      IF (C.NE.".") GO TO 11	
      WRITE (MSG,"('')")	
      GO TO 10		
      END