WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sorting algorithms_Stooge sort


C++: #include <iostream>
#include <time.h>


using namespace std;


class stooge
{
public:
    void sort( int* arr, int start, int end )
    {
        if( arr[start] > arr[end - 1] ) swap( arr[start], arr[end - 1] );
	int n = end - start; if( n > 2 )
	{
	    n /= 3; sort( arr, start, end - n );
	    sort( arr, start + n, end ); sort( arr, start, end - n );
        }
    }
};

int main( int argc, char* argv[] )
{
    srand( static_cast<unsigned int>( time( NULL ) ) ); stooge s; int a[80], m = 80; 
    cout << "before:\n";
    for( int x = 0; x < m; x++ ) { a[x] = rand() % 40 - 20;  cout << a[x] << " "; }
    s.sort( a, 0, m ); cout << "\n\nafter:\n"; 
    for( int x = 0; x < m; x++ ) cout << a[x] << " "; cout << "\n\n"; 
    return system( "pause" );
}









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: Sorting algorithms_Shell sort


C++: #include <time.h>
#include <iostream>


using namespace std;


const int MAX = 126;
class shell
{
public:
    shell() 
    { _gap[0] = 1750; _gap[1] = 701; _gap[2] = 301; _gap[3] = 132; _gap[4] = 57; _gap[5] = 23; _gap[6] = 10; _gap[7] = 4; _gap[8] = 1; }

    void sort( int* a, int count )
    {
	_cnt = count;
	for( int x = 0; x < 9; x++ )
	    if( count > _gap[x] )
	    { _idx = x; break; }

	sortIt( a );
    }

private:	
    void sortIt( int* arr )
    {
	bool sorted = false;
	while( true )
	{
	    sorted = true;
	    int st = 0;
	    for( int x = _gap[_idx]; x < _cnt; x += _gap[_idx] )
	    {
		if( arr[st] > arr[x] )
		{ swap( arr[st], arr[x] ); sorted = false; }
		st = x;
	    }
	    if( ++_idx >= 8 ) _idx = 8;
	    if( sorted && _idx == 8 ) break;
	}
    }

    void swap( int& a, int& b ) { int t = a; a = b; b = t; }

    int _gap[9], _idx, _cnt;
};

int main( int argc, char* argv[] )
{
    srand( static_cast<unsigned int>( time( NULL ) ) ); int arr[MAX];
    for( int x = 0; x < MAX; x++ )
	arr[x] = rand() % MAX - rand() % MAX;

    cout << " Before: \n=========\n";
    for( int x = 0; x < 7; x++ )
    {
	for( int a = 0; a < 18; a++ )
	{ cout << arr[x * 18 + a] << " "; }
	cout << endl;
    }
    cout << endl; shell s; s.sort( arr, MAX );
	
    cout << " After: \n========\n";
    for( int x = 0; x < 7; x++ )
    {
	for( int a = 0; a < 18; a++ )
	{ cout << arr[x * 18 + a] << " "; }
	cout << endl;
    }
    cout << endl << endl; return system( "pause" );
}










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: Inverted syntax


C++: class invertedAssign {
  int data;
public:
  invertedAssign(int data):data(data){}
  int getData(){return data;}
  void operator=(invertedAssign& other) const {
    other.data = this->data;
  }
};


#include <iostream>

int main(){
  invertedAssign a = 0;
  invertedAssign b = 42;
  std::cout << a.getData() << ' ' << b.getData() << '\n';

  b = a;

  std::cout << a.getData() << ' ' << b.getData() << '\n';
}









Fortran:       INQUIRE(FILE = FILENAME(1:L), EXIST = MAYBE, ERR = 666, IOSTAT = RESULT)
Task: Numeric error propagation


C++: #pragma once

#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>

class Approx {
public:
    Approx(double _v, double _s = 0.0) : v(_v), s(_s) {}

    operator std::string() const {
        std::ostringstream os("");
        os << std::setprecision(15) << v << " ±" << std::setprecision(15) << s << std::ends;
        return os.str();
    }

    Approx operator +(const Approx& a) const { return Approx(v + a.v, sqrt(s * s + a.s * a.s)); }
    Approx operator +(double d) const { return Approx(v + d, s); }
    Approx operator -(const Approx& a) const { return Approx(v - a.v, sqrt(s * s + a.s * a.s)); }
    Approx operator -(double d) const { return Approx(v - d, s); }

    Approx operator *(const Approx& a) const {
        const double t = v * a.v;
        return Approx(v, sqrt(t * t * s * s / (v * v) + a.s * a.s / (a.v * a.v)));
    }

    Approx operator *(double d) const { return Approx(v * d, fabs(d * s)); }

    Approx operator /(const Approx& a) const {
        const double t = v / a.v;
        return Approx(t, sqrt(t * t * s * s / (v * v) + a.s * a.s / (a.v * a.v)));
    }

    Approx operator /(double d) const { return Approx(v / d, fabs(d * s)); }

    Approx pow(double d) const {
        const double t = ::pow(v, d);
        return Approx(t, fabs(t * d * s / v));
    }

private:
    double v, s;
};









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


C++: #include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>

int main( ) {
   std::vector<double> input( 11 ) , results( 11 ) ;
   std::cout << "Please enter 11 numbers!\n" ;
   for ( int i = 0 ; i < input.size( ) ; i++ ) 
      std::cin >> input[i];
      
   std::transform( input.begin( ) , input.end( ) , results.begin( ) ,
	 [ ]( double n )-> double { return sqrt( abs( n ) ) + 5 * pow( n , 3 ) ; } ) ;
   for ( int i = 10 ; i > -1 ; i-- ) {
      std::cout << "f( " << std::setw( 3 ) << input[ i ] << " ) : " ; 
      if ( results[ i ] > 400 ) 
	 std::cout << "too large!" ;
      else 
	 std::cout << results[ i ] << " !" ;
      std::cout << std::endl ;
   }
   return 0 ;
}









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


C++: #include <iostream>
#include <ctime>



class CRateState
{
protected:
    time_t m_lastFlush;
    time_t m_period;
    size_t m_tickCount;
public:
    CRateState(time_t period);
    void Tick();
};

CRateState::CRateState(time_t period) : m_lastFlush(std::time(NULL)),
                                        m_period(period),
                                        m_tickCount(0)
{ }

void CRateState::Tick()
{
    m_tickCount++;

    time_t now = std::time(NULL);

    if((now - m_lastFlush) >= m_period)
    {
        
        size_t tps = 0.0;
        if(m_tickCount > 0)
            tps = m_tickCount / (now - m_lastFlush);

        std::cout << tps << " tics per second" << std::endl;

        
        m_tickCount = 0;
        m_lastFlush = now;
    }
}



void something_we_do()
{
    
    
    
    
    
    
    
    volatile size_t anchor = 0;
    for(size_t x = 0; x < 0xffff; ++x)
    {
        anchor = x;
    }
}

int main()
{
    time_t start = std::time(NULL);

    CRateState rateWatch(5);

    
    for(time_t latest = start; (latest - start) < 20; latest = std::time(NULL))
    {
        
        something_we_do();

        
        rateWatch.Tick();
    }

    return 0;
}









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


C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int topswops(int n) {
  std::vector<int> list(n);
  std::iota(std::begin(list), std::end(list), 1);
  int max_steps = 0;
  do {
    auto temp_list = list;
    for (int steps = 1; temp_list[0] != 1; ++steps) {
      std::reverse(std::begin(temp_list), std::begin(temp_list) + temp_list[0]);
      if (steps > max_steps) max_steps = steps;
    }
  } while (std::next_permutation(std::begin(list), std::end(list)));
  return max_steps;
}

int main() {
  for (int i = 1; i <= 10; ++i) {
    std::cout << i << ": " << topswops(i) << std::endl;
  }
  return 0;
}









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


C++: #include <iostream>
#include <cctype>
#include <functional>

using namespace std;

bool odd()
{
  function<void ()> prev = []{};
  while(true) {
    int c = cin.get();
    if (!isalpha(c)) {
      prev();
      cout.put(c);
      return c != '.';
    }
    prev = [=] { cout.put(c); prev();  };
  }
}

bool even() 
{
  while(true) {
    int c;
    cout.put(c = cin.get());
    if (!isalpha(c)) return c != '.';
  }
}


int main()
{
  bool e = false;
  while( e ? odd() : even() ) e = !e;
  return 0;
}









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
Task: Largest proper divisor of n


C++: #include <cassert>
#include <iomanip>
#include <iostream>

int largest_proper_divisor(int n) {
    assert(n > 0);
    if ((n & 1) == 0)
        return n >> 1;
    for (int p = 3; p * p <= n; p += 2) {
        if (n % p == 0)
            return n / p;
    }
    return 1;
}

int main() {
    for (int n = 1; n < 101; ++n) {
        std::cout << std::setw(2) << largest_proper_divisor(n)
            << (n % 10 == 0 ? '\n' : ' ');
    }
}









Fortran:        program LargestProperDivisors
       implicit none
       integer i, lpd
       do 10 i=1, 100
           write (*,'(I3)',advance='no') lpd(i)
 10        if (i/10*10 .eq. i) write (*,*)       
       end program
       
       integer function lpd(n)
       implicit none
       integer n, i
       if (n .le. 1) then
           lpd = 1
       else
           do 10 i=n-1, 1, -1
 10            if (n/i*i .eq. n) goto 20
 20        lpd = i
       end if
       end function
Task: Numbers with equal rises and falls


C++: #include <iomanip>
#include <iostream>

bool equal_rises_and_falls(int n) {
    int total = 0;
    for (int previous_digit = -1; n > 0; n /= 10) {
        int digit = n % 10;
        if (previous_digit > digit)
            ++total;
        else if (previous_digit >= 0 && previous_digit < digit)
            --total;
        previous_digit = digit;
    }
    return total == 0;
}

int main() {
    const int limit1 = 200;
    const int limit2 = 10000000;
    int n = 0;
    std::cout << "The first " << limit1 << " numbers in the sequence are:\n";
    for (int count = 0; count < limit2; ) {
        if (equal_rises_and_falls(++n)) {
            ++count;
            if (count <= limit1)
                std::cout << std::setw(3) << n << (count % 20 == 0 ? '\n' : ' ');
        }
    }
    std::cout << "\nThe " << limit2 << "th number in the sequence is " << n << ".\n";
}









Fortran:       PROGRAM A296712
          INTEGER IDX, NUM, I
*         Index and number start out at zero
          IDX = 0
          NUM = 0 
*         Find and write the first 200 numbers
          WRITE (*,'(A)') 'The first 200 numbers are: '
          DO 100 I = 1, 200
              CALL NEXT NUM(IDX, NUM)
              WRITE (*,'(I4)',ADVANCE='NO') NUM
              IF (MOD(I,20).EQ.0) WRITE (*,*)
  100     CONTINUE
*         Find the 10,000,000th number
          WRITE (*,*)
          WRITE (*,'(A)',ADVANCE='NO') 'The 10,000,000th number is: '
  200     CALL NEXT NUM(IDX, NUM)
          IF (IDX.NE.10000000) GOTO 200
          WRITE (*,'(I8)') NUM
          STOP
      END    

*     Given index and current number, retrieve the next number
*     in the sequence.
      SUBROUTINE NEXT NUM(IDX, NUM) 
          INTEGER IDX, NUM
          LOGICAL IN SEQ
  100     NUM = NUM + 1
          IF (.NOT. IN SEQ(NUM)) GOTO 100
          IDX = IDX + 1           
      END
    
*     See whether N is in the sequence
      LOGICAL FUNCTION IN SEQ(N)
          INTEGER N, DL, DR, VAL, HEIGHT
*         Get first digit and divide value by 10
          DL = MOD(N, 10)
          VAL = N / 10
          HEIGHT = 0
  100     IF (VAL.NE.0) THEN
*             Retrieve digits by modulo and division
              DR = DL
              DL = MOD(VAL, 10)
              VAL = VAL / 10
*             Record rise or fall
              IF (DL.LT.DR) HEIGHT = HEIGHT + 1
              IF (DL.GT.DR) HEIGHT = HEIGHT - 1
              GOTO 100
          END IF
*         N is in the sequence if the final height is 0
          IN SEQ = HEIGHT.EQ.0
          RETURN
      END
Task: Length of an arc between two angles


C++: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}









Fortran: *-----------------------------------------------------------------------
* given:  polar coordinates of two points on a circle of known radius
* find:  length of the major arc between these points
*
*___Name_____Type___I/O___Description___________________________________
*   RAD      Real   In    Radius of circle, any unit of measure
*   ANG1     Real   In    Angle of first point, degrees
*   ANG2     Real   In    Angle of second point, degrees
*   MAJARC   Real   Out   Length of major arc, same units as RAD
*-----------------------------------------------------------------------
      FUNCTION MAJARC (RAD, ANG1, ANG2)
       IMPLICIT NONE
       REAL RAD, ANG1, ANG2, MAJARC

       REAL FACT                          
       PARAMETER (FACT = 3.1415926536 / 180.)
       REAL DIF

*       Begin
       MAJARC = 0.
       IF (RAD .LE. 0.) RETURN
       DIF = MOD(ABS(ANG1 - ANG2), 360.)   
       DIF = MAX(DIF, 360. - DIF)          
       MAJARC = RAD * DIF * FACT           
       RETURN
      END  

*-----------------------------------------------------------------------
      PROGRAM TMA
       IMPLICIT NONE
       INTEGER J
       REAL ANG1, ANG2, RAD, MAJARC, ALENG
       REAL DATARR(3,3)     
       DATA DATARR / 120.,  10., 10.,
     $                10., 120., 10.,
     $               180., 270., 10. /

       DO J = 1, 3
         ANG1 = DATARR(1,J)
         ANG2 = DATARR(2,J)
         RAD = DATARR(3,J)
         ALENG = MAJARC (RAD, ANG1, ANG2)        
         PRINT *, 'first angle: ', ANG1, ' second angle: ', ANG2, 
     $     ' radius: ', RAD, ' Length of major arc: ', ALENG
       END DO
      END
Task: Here document


C++: #include <iostream> 

int main()
{
  std::cout <<
R"EOF(  A  raw  string  begins  with  R,  then a double-quote ("),  then an optional
identifier (here I've used "EOF"),  then an opening parenthesis ('(').  If you
use  an  identifier,  it  cannot  be longer than 16 characters,  and it cannot
contain a space,  either opening or closing parentheses, a backslash, a tab, a
vertical tab, a form feed, or a newline.

  It  ends with a closing parenthesis (')'),  the identifer (if you used one),
and a double-quote.

  All  characters are okay in a raw string,  no escape sequences are necessary
or recognized, and all whitespace is preserved.
)EOF";
}









Fortran:       INTEGER I         
      CHARACTER*666 I AM    
      I AM =                                                           "<col72
C              111111111122222222223333333333444444444455555555556666666666
C     123456789012345678901234567890123456789012345678901234567890123456789
     1                                                                  <col72
     2              I AM                                                <col72
     3                                                                  <col72
     4           THAT I AM                                              <col72
     5"

Chug through the text blob.
      DO I = 0,600,66   
        WRITE (6,1) I AM(I + 1:I + 66)  
    1   FORMAT (A66)            
      END DO                
      END
Task: 15 puzzle solver


C++: 
class fifteenSolver{
  const int Nr[16]{3,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3}, Nc[16]{3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2};
  int n{},_n{}, N0[100]{},N3[100]{},N4[100]{};
  unsigned long N2[100]{};
  const bool fY(){
    if (N4[n]<_n) return fN();
    if (N2[n]==0x123456789abcdef0) {std::cout<<"Solution found in "<<n<<" moves :"; for (int g{1};g<=n;++g) std::cout<<(char)N3[g]; std::cout<<std::endl; return true;};
    if (N4[n]==_n) return fN(); else return false;
  }
  const bool                     fN(){
    if (N3[n]!='u' && N0[n]/4<3){fI(); ++n; if (fY()) return true; --n;}
    if (N3[n]!='d' && N0[n]/4>0){fG(); ++n; if (fY()) return true; --n;}
    if (N3[n]!='l' && N0[n]%4<3){fE(); ++n; if (fY()) return true; --n;}
    if (N3[n]!='r' && N0[n]%4>0){fL(); ++n; if (fY()) return true; --n;}
    return false;
  }
  void fI(){
    const int           g = (11-N0[n])*4;
    const unsigned long a = N2[n]&((unsigned long)15<<g);
    N0[n+1]=N0[n]+4; N2[n+1]=N2[n]-a+(a<<16); N3[n+1]='d'; N4[n+1]=N4[n]+(Nr[a>>g]<=N0[n]/4?0:1);
  } 
  void fG(){
    const int           g = (19-N0[n])*4;
    const unsigned long a = N2[n]&((unsigned long)15<<g);
    N0[n+1]=N0[n]-4; N2[n+1]=N2[n]-a+(a>>16); N3[n+1]='u'; N4[n+1]=N4[n]+(Nr[a>>g]>=N0[n]/4?0:1);
  } 
  void fE(){
    const int           g = (14-N0[n])*4;
    const unsigned long a = N2[n]&((unsigned long)15<<g);
    N0[n+1]=N0[n]+1; N2[n+1]=N2[n]-a+(a<<4); N3[n+1]='r'; N4[n+1]=N4[n]+(Nc[a>>g]<=N0[n]%4?0:1);
  } 
  void fL(){
    const int           g = (16-N0[n])*4;
    const unsigned long a = N2[n]&((unsigned long)15<<g);
    N0[n+1]=N0[n]-1; N2[n+1]=N2[n]-a+(a>>4); N3[n+1]='l'; N4[n+1]=N4[n]+(Nc[a>>g]>=N0[n]%4?0:1);
  }
public:
  fifteenSolver(int n, unsigned long g){N0[0]=n; N2[0]=g;}
  void Solve(){for(;not fY();++_n);}
};









Fortran: IF (NR.EQ.4) THEN
 code specialised for NR = 4
ELSE IF (NR.EQ.3) THEN
 code specialised for NR = 3
END IF
Task: Address of a variable


C++: int i;
void* address_of_i = &i;









Fortran: program test_loc
  implicit none

  integer :: i
  real    :: r

  i = loc(r)
  print *, i
end program
Task: Loops_Infinite


C++: while (true)
  std::cout << "SPAM\n";









Fortran:       
   10 WRITE(*,*) 'SPAM'
      GO TO 10
      END
Task: Arena storage pool


C++: T* foo = new(arena) T;









Fortran:       SUBROUTINE CHECK(A,N)	
       REAL A(:,:)	
       INTEGER N	
       REAL B(N,N)	
       INTEGER, ALLOCATABLE::TROUBLE(:)	
       INTEGER M

        M = COUNT(A(1:N,1:N).LE.0)	

        ALLOCATE (TROUBLE(1:M**3))	

        DEALLOCATE(TROUBLE)		
      END SUBROUTINE CHECK