WeixiangYan/CodeTransOcean huggingface dataset:
Task: Ulam spiral (for primes)


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

class ulamSpiral {
public:
    void create( unsigned n, unsigned startWith = 1 ) {
        _lst.clear();
        if( !( n & 1 ) ) n++;
        _mx = n;
        unsigned v = n * n;
        _wd = static_cast<unsigned>( log10( static_cast<long double>( v ) ) ) + 1;
        for( unsigned u = 0; u < v; u++ )
            _lst.push_back( -1 );

        arrange( startWith );

    }
    void display( char c ) {
        if( !c ) displayNumbers();
        else displaySymbol( c );
    }

private:
    bool isPrime( unsigned u ) {
        if( u < 4 ) return u > 1;
        if( !( u % 2 ) || !( u % 3 ) ) return false;
 
        unsigned q = static_cast<unsigned>( sqrt( static_cast<long double>( u ) ) ),
                 c = 5;
        while( c <= q ) {
            if( !( u % c ) || !( u % ( c + 2 ) ) ) return false;
            c += 6;
        }
        return true;
    }
    void arrange( unsigned s ) {
        unsigned stp = 1, n = 1, posX = _mx >> 1, 
                 posY = posX, stC = 0;
        int dx = 1, dy = 0;
    
        while( posX < _mx && posY < _mx ) {
            _lst.at( posX + posY * _mx ) =  isPrime( s ) ? s : 0;
            s++;
        
            if( dx ) {
                posX += dx;
                if( ++stC == stp ) {
                    dy = -dx;
                    dx = stC = 0;
                }
            } else {
                posY += dy;
                if( ++stC == stp ) {
                    dx = dy;
                    dy = stC = 0;
                    stp++;
                }
            }
        }
    }
    void displayNumbers() {
        unsigned ct = 0;
        for( std::vector<unsigned>::iterator i = _lst.begin(); i != _lst.end(); i++ ) {
            if( *i ) std::cout << std::setw( _wd ) << *i << " ";
            else std::cout << std::string( _wd, '*' ) << " ";
            if( ++ct >= _mx ) {
                std::cout << "\n";
                ct = 0;
            }
        }
        std::cout << "\n\n";
    }
    void displaySymbol( char c ) {
        unsigned ct = 0;
        for( std::vector<unsigned>::iterator i = _lst.begin(); i != _lst.end(); i++ ) {
            if( *i ) std::cout << c;
            else std::cout << " ";
            if( ++ct >= _mx ) {
                std::cout << "\n";
                ct = 0;
            }
        }
        std::cout << "\n\n";
    }

    std::vector<unsigned> _lst;
    unsigned _mx, _wd;
};

int main( int argc, char* argv[] )
{
    ulamSpiral ulam;
    ulam.create( 9 );
    ulam.display( 0 );
    ulam.create( 35 );
    ulam.display( '#' );
    return 0;
}
Task: Fibonacci word


C++: #include <string>
#include <map>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

double log2( double number ) {
   return ( log( number ) / log( 2 ) ) ;
}

double find_entropy( std::string & fiboword ) {
   std::map<char , int> frequencies ;
   std::for_each( fiboword.begin( ) , fiboword.end( ) ,
	 [ & frequencies ]( char c ) { frequencies[ c ]++ ; } ) ; 
   int numlen = fiboword.length( ) ;
   double infocontent = 0 ;
   for ( std::pair<char , int> p : frequencies ) {
      double freq = static_cast<double>( p.second ) / numlen ;
      infocontent += freq * log2( freq ) ;
   }
   infocontent *= -1 ;
   return infocontent ;
}

void printLine( std::string &fiboword , int n ) {
   std::cout << std::setw( 5 ) << std::left << n ;
   std::cout << std::setw( 12 ) << std::right << fiboword.size( ) ;
   std::cout << "  " << std::setw( 16 ) << std::setprecision( 13 ) 
      << std::left << find_entropy( fiboword ) ;
   std::cout << "\n" ;
}

int main( ) {
   std::cout << std::setw( 5 ) << std::left << "N" ;
   std::cout << std::setw( 12 ) << std::right << "length" ;
   std::cout << "  " << std::setw( 16 ) << std::left << "entropy" ; 
   std::cout << "\n" ;
   std::string firststring ( "1" ) ;
   int n = 1 ;
   printLine( firststring , n ) ;
   std::string secondstring( "0" ) ;
   n++ ;
   printLine( secondstring , n ) ;
   while ( n < 37 ) {
      std::string resultstring = firststring + secondstring ;
      firststring.assign( secondstring ) ;
      secondstring.assign( resultstring ) ;
      n++ ;
      printLine( resultstring , n ) ;
   }
   return 0 ;
}
Task: Longest string challenge


C++: #include <iostream>
#include <string.h>
 
int main()
{
    std::string longLine, longestLines, newLine;

    while (std::cin >> newLine)
    {
        auto isNewLineShorter = longLine.c_str();
        auto isLongLineShorter = newLine.c_str(); 
        while (*isNewLineShorter && *isLongLineShorter)
        {
            
            
            
            isNewLineShorter = &isNewLineShorter[1];
            isLongLineShorter = &isLongLineShorter[1];
        }

        if(*isNewLineShorter) continue; 
        if(*isLongLineShorter)
        {
            
            longLine = newLine;
            longestLines = newLine;
        }
        else
        {
            
            longestLines+=newLine; 
        }
        longestLines+="\n"; 
    }

    std::cout << "\nLongest string:\n" << longestLines;
}
Task: Magic squares of odd order


C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <cassert>
#include <vector>
using namespace std;
 
class MagicSquare
{
public: 
    MagicSquare(int d) : sqr(d*d,0), sz(d)
    {
        assert(d&1);
        fillSqr();
    }
 
    void display()
    {
        cout << "Odd Magic Square: " << sz << " x " << sz << "\n";
        cout << "It's Magic Sum is: " << magicNumber() << "\n\n";
        ostringstream cvr;
        cvr << sz * sz;
        int l = cvr.str().size();
 
	for( int y = 0; y < sz; y++ )
	{
	    int yy = y * sz;
	    for( int x = 0; x < sz; x++ )
		cout << setw( l + 2 ) << sqr[yy + x];
	    cout << "\n";
	}
        cout << "\n\n";
    }
 
private:
    void fillSqr()
    {
	int sx = sz / 2, sy = 0, c = 0;
	while( c < sz * sz )
	{
	    if( !sqr[sx + sy * sz] )
	    {
		sqr[sx + sy * sz]= c + 1;
		inc( sx ); dec( sy ); 
		c++;
	    }
	    else
	    {
		dec( sx ); inc( sy ); inc( sy );
	    }
	}
    }
 
    int magicNumber()
    { return sz * ( ( sz * sz ) + 1 ) / 2; }
 
    void inc( int& a )
    { if( ++a == sz ) a = 0; }
 
    void dec( int& a )
    { if( --a < 0 ) a = sz - 1; }
 
    bool checkPos( int x, int y )
    { return( isInside( x ) && isInside( y ) && !sqr[sz * y + x] ); }
 
    bool isInside( int s )
    { return ( s < sz && s > -1 ); }
 
    vector<int> sqr;
    int sz;
};
 
int main()
{
    MagicSquare s(7);
    s.display();
    return 0;
}
Task: Find prime numbers of the form n_n_n+2


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

bool is_prime(unsigned int n) {
    if (n < 2)
        return false;
    if (n % 2 == 0)
        return n == 2;
    if (n % 3 == 0)
        return n == 3;
    for (unsigned int p = 5; p * p <= n; p += 4) {
        if (n % p == 0)
            return false;
        p += 2;
        if (n % p == 0)
            return false;
    }
    return true;
}

int main() {
    for (unsigned int n = 1; n < 200; n += 2) {
        auto p = n * n * n + 2;
        if (is_prime(p))
            std::cout << std::setw(3) << n << std::setw(9) << p << '\n';
    }
}
Task: Strange numbers


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

std::vector<int> digits(int n) {
    std::vector<int> result;
    while (n > 0) {
        auto rem = n % 10;
        result.push_back(rem);
        n /= 10;
    }
    std::reverse(result.begin(), result.end());
    return result;
}

bool is_strange(int n) {
    auto test = [](int a, int b) {
        auto v = std::abs(a - b);
        return v == 2 || v == 3 || v == 5 || v == 7;
    };

    auto xs = digits(n);
    for (size_t i = 1; i < xs.size(); i++) {
        if (!test(xs[i - 1], xs[i])) {
            return false;
        }
    }
    return true;
}

int main() {
    std::vector<int> xs;
    for (int i = 100; i <= 500; i++) {
        if (is_strange(i)) {
            xs.push_back(i);
        }
    }

    std::cout << "Strange numbers in range [100..500]\n";
    std::cout << "(Total: " << xs.size() << ")\n\n";

    for (size_t i = 0; i < xs.size(); i++) {
        std::cout << xs[i];
        if ((i + 1) % 10 == 0) {
            std::cout << '\n';
        } else {
            std::cout << ' ';
        }
    }

    return 0;
}
Task: Arithmetic numbers


C++: #include <cstdio>

void divisor_count_and_sum(unsigned int n,
			   unsigned int& divisor_count,
			   unsigned int& divisor_sum)
{
  divisor_count = 0;
  divisor_sum = 0;
  for (unsigned int i = 1;; i++)
  {
    unsigned int j = n / i;
    if (j < i)
      break;
    if (i * j != n)
      continue;
    divisor_sum += i;
    divisor_count += 1;
    if (i != j)
    {
      divisor_sum += j;
      divisor_count += 1;
    }
  }
}

int main()
{
  unsigned int arithmetic_count = 0;
  unsigned int composite_count = 0;

  for (unsigned int n = 1; arithmetic_count <= 1000000; n++)
  {
    unsigned int divisor_count;
    unsigned int divisor_sum;
    divisor_count_and_sum(n, divisor_count, divisor_sum);
    unsigned int mean = divisor_sum / divisor_count;
    if (mean * divisor_count != divisor_sum)
      continue;
    arithmetic_count++;
    if (divisor_count > 2)
      composite_count++;
    if (arithmetic_count <= 100)
    {
      
      std::printf("%3u ", n);
      if (arithmetic_count % 10 == 0)
	std::printf("\n");
    }
    if ((arithmetic_count == 1000) || (arithmetic_count == 10000) ||
	(arithmetic_count == 100000) || (arithmetic_count == 1000000))
    {
      std::printf("\n%uth arithmetic number is %u\n", arithmetic_count, n);
      std::printf("Number of composite arithmetic numbers <= %u: %u\n", n, composite_count);
    }
  }
  return 0;
}
Task: Digit fifth powers


C++: #include <iostream>
#include <cmath>
#include <chrono>

using namespace std;
using namespace chrono;

int main() {
  auto st = high_resolution_clock::now();
  const uint i5 = 100000, i4 = 10000, i3 = 1000, i2 = 100, i1 = 10;
  uint p4[] = { 0, 1, 32, 243 }, nums[10], p5[10], t = 0, 
    m5, m4, m3, m2, m1, m0; m5 = m4 = m3 = m2 = m1 = m0 = 0;
  for (uint i = 0; i < 10; i++) p5[i] = pow(nums[i] = i, 5);
  for (auto i : p4) { auto im =      m5, ip =      i; m4 = 0;
  for (auto j : p5) { auto jm = im + m4, jp = ip + j; m3 = 0;
  for (auto k : p5) { auto km = jm + m3, kp = jp + k; m2 = 0;
  for (auto l : p5) { auto lm = km + m2, lp = kp + l; m1 = 0;
  for (auto m : p5) { auto mm = lm + m1, mp = lp + m; m0 = 0;
  for (auto n : p5) { auto nm = mm + m0++;
    if (nm == mp + n && nm > 1) t += nm;
  } m1 += i1; } m2 += i2; } m3 += i3; } m4 += i4; } m5 += i5; }
  auto et = high_resolution_clock::now();
  std::cout << t << " " <<
    duration_cast<nanoseconds>(et - st).count() / 1000.0 << " μs";
}
Task: Sum data type


C++: #include <iostream>
#include <optional>
#include <string>
#include <variant>
#include <vector>


std::variant<int, std::string, bool, int> myVariant{"Ukraine"}; 

struct Tree
{
  
  
  
  std::variant<std::vector<Tree>, int> Nodes;
};

Tree tree1; 
Tree tree2{2}; 


Tree tree3{std::vector{Tree{3}, Tree{std::vector{Tree{2}, Tree{7}}}, Tree{8}}};


std::optional<int> maybeInt1;    
std::optional<int> maybeInt2{2}; 


int* intPtr1 = nullptr;  

int value = 3;
int* intPtr2 = &value; 


void PrintTree(const Tree& tree)
{
  std::cout << "(";
  if(holds_alternative<int>(tree.Nodes))
  {
    std::cout << get<1>(tree.Nodes);
  }
  else
  {
    for(const auto& subtree : get<0>(tree.Nodes)) PrintTree(subtree);
  }
  std::cout <<")";
}

int main()
{
  std::cout << "myVariant: " << get<std::string>(myVariant) << "\n";

  PrintTree(tree1); std::cout << "\n";
  PrintTree(tree2); std::cout << "\n";
  PrintTree(tree3); std::cout << "\n";

  std::cout << "*maybeInt2: " << *maybeInt2 << "\n";
  std::cout << "intPtr1: " << intPtr1 << "\n";
  std::cout << "*intPtr2: " << *intPtr2 << "\n";
}
Task: Water collected between towers








VB: 
Module Module1
    Sub Main(Args() As String)
        Dim shoTow As Boolean = Environment.GetCommandLineArgs().Count > 1  
        Dim wta As Integer()() = {                       
            New Integer() {1, 5, 3, 7, 2}, New Integer() {5, 3, 7, 2, 6, 4, 5, 9, 1, 2},
            New Integer() {2, 6, 3, 5, 2, 8, 1, 4, 2, 2, 5, 3, 5, 7, 4, 1},
            New Integer() {5, 5, 5, 5}, New Integer() {5, 6, 7, 8},
            New Integer() {8, 7, 7, 6}, New Integer() {6, 7, 10, 7, 6}}
        Dim blk As String,                   
            lf As String = vbLf,      
            tb = "██", wr = "≈≈", mt = "  "    
        For i As Integer = 0 To wta.Length - 1
            Dim bpf As Integer                    
            blk = ""
            Do
                bpf = 0 : Dim floor As String = ""  
                For j As Integer = 0 To wta(i).Length - 1
                    If wta(i)(j) > 0 Then      
                        floor &= tb : wta(i)(j) -= 1 : bpf += 1    
                    Else  
                        floor &= If(j > 0 AndAlso j < wta(i).Length - 1, wr, mt)
                    End If
                Next
                If bpf > 0 Then blk = floor & lf & blk 
            Loop Until bpf = 0                       
            
            While blk.Contains(mt & wr) : blk = blk.Replace(mt & wr, mt & mt) : End While
            While blk.Contains(wr & mt) : blk = blk.Replace(wr & mt, mt & mt) : End While
            
            If shoTow Then Console.Write("{0}{1}", lf, blk)
            
            Console.Write("Block {0} retains {1,2} water units.{2}", i + 1,
                                     (blk.Length - blk.Replace(wr, "").Length) \ 2, lf)
        Next
    End Sub
End Module
Task: Validate International Securities Identification Number








VB: 

buf=buf&test("US0378331005")&vbCrLf
buf=buf&test("US0373831005")&vbCrLf
buf=buf&test("U50378331005")&vbCrLf
buf=buf&test("US03378331005")&vbCrLf
buf=buf&test("AU0000XVGZA3")&vbCrLf
buf=buf&test("AU0000VXGZA3")&vbCrLf
buf=buf&test("FR0000988040")&vbCrLf
msgbox buf,,"Validate International Securities Identification Number"

function test(cc)
	dim err,c,r,s,i1,i2
	if len(cc)=12 then
		for i=1 to len(cc)
			p=instr("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",mid(cc,i,1))
			if p<>0 then c=c&(p-1) else err=1
		next 
		for i=1 to 2
			if instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",mid(cc,i,1))=0 then err=1 
		next 
		if err=0 then
			for i=len(c) to 1 step -1
				r=r&mid(c,i,1)
			next 
			for i=1 to len(r) step 2
				i1=i1+cint(mid(r,i,1))
			next 
			for i=2 to len(r) step 2
				ii=cint(mid(r,i,1))*2
				if ii>=10 then ii=ii-9
				i2=i2+ii
			next 
			s=cstr(i1+i2)
			if mid(s,len(s),1)="0" then
				msg="valid"
			else
				msg="invalid ??1"
			end if
		else
			msg="invalid ??2"
		end if
	else
		msg="invalid ??3"
	end if
	test=cc&" "&msg
end function
Task: Cycle detection








VB: Module Module1

    Function FindCycle(Of T As IEquatable(Of T))(x0 As T, yielder As Func(Of T, T)) As Tuple(Of Integer, Integer)
        Dim power = 1
        Dim lambda = 1
        Dim tortoise As T
        Dim hare As T

        tortoise = x0
        hare = yielder(x0)

        
        While Not tortoise.Equals(hare)
            If power = lambda Then
                tortoise = hare
                power *= 2
                lambda = 0
            End If
            hare = yielder(hare)
            lambda += 1
        End While

        
        Dim mu = 0
        tortoise = x0
        hare = x0
        For times = 1 To lambda
            hare = yielder(hare)
        Next

        While Not tortoise.Equals(hare)
            tortoise = yielder(tortoise)
            hare = yielder(hare)
            mu += 1
        End While

        Return Tuple.Create(lambda, mu)
    End Function

    Sub Main()
        
        Dim sequence = Function(_x As Integer) (_x * _x + 1) Mod 255

        
        Dim x = 3
        Console.Write(x)
        For times = 0 To 39
            x = sequence(x)
            Console.Write(",{0}", x)
        Next
        Console.WriteLine()

        
        Dim cycle = FindCycle(3, sequence)
        Console.WriteLine("Cycle length = {0}", cycle.Item1)
        Console.WriteLine("Start index = {0}", cycle.Item2)
    End Sub

End Module
Task: Gray code








VB: Function Encoder(ByVal n)
    Encoder = n Xor (n \ 2)
End Function

Function Decoder(ByVal n)
    Dim g : g = 0
    Do While n > 0
       g = g Xor n
       n = n \ 2
    Loop
    Decoder = g
End Function


Function Dec2bin(ByVal n, ByVal length)
    Dim i, strbin : strbin = ""
    For i = 1 to 5
        strbin = (n Mod 2) & strbin
        n = n \ 2
    Next
    Dec2Bin = strbin
End Function

WScript.StdOut.WriteLine("Binary -> Gray Code -> Binary")
For i = 0 to 31
    encoded = Encoder(i)
    decoded = Decoder(encoded)
    WScript.StdOut.WriteLine(Dec2Bin(i, 5) & " -> " & Dec2Bin(encoded, 5) & " -> " & Dec2Bin(decoded, 5))
Next
Task: LZW compression








VB: Option Explicit
Const numchars=127  

Function LZWCompress(si)
  Dim oDict,  intMaxCode, i,z,ii,ss,strCurrent,strNext,j
  Set oDict = CreateObject("Scripting.Dictionary")
  ReDim a(Len(si))
  
  intMaxCode = numchars
  For i = 0 To numchars
    oDict.Add Chr(i), i
  Next
  
  strCurrent = Left(si,1)
  j=0
  For ii=2 To Len(si)
    strNext = Mid(si,ii,1)
    ss=strCurrent & strNext
    If oDict.Exists(ss) Then
      strCurrent = ss
    Else
      a(j)=oDict.Item(strCurrent) :j=j+1
      intMaxCode = intMaxCode + 1
      oDict.Add ss, intMaxCode
      strCurrent = strNext
    End If
  Next
  a(j)=oDict.Item(strCurrent) 
  ReDim preserve a(j)
  LZWCompress=a
  Set oDict = Nothing
End Function

Function lzwUncompress(sc)
  Dim intNext, intCurrent, intMaxCode, i,ss,istr,s,j
  s=""     
  reDim dict(1000)
  intMaxCode = numchars
  For i = 0 To numchars : dict(i)= Chr(i) :  Next
    intCurrent=sc(0)
    
    For j=1 To UBound(sc)
      ss=dict(intCurrent)
      s= s & ss
      intMaxCode = intMaxCode + 1
      intnext=sc(j)
      If intNext<intMaxCode Then
        dict(intMaxCode)=ss & Left(dict(intNext), 1)
      Else
        dict(intMaxCode)=ss & Left(ss, 1) 
      End If
      intCurrent = intNext
    Next
    s= s & dict(intCurrent)
    lzwUncompress=s
End function

Sub printvec(a)
  Dim s,i,x
  s="("
  For i=0 To UBound (a)
   s=s & x & a(i)
   x=", "
  Next 
  WScript.echo s &")"
End sub

Dim a,b
b="TOBEORNOTTOBEORTOBEORNOT"
WScript.Echo b
a=LZWCompress (b)
printvec(a)
WScript.echo lzwUncompress (a )
wscript.quit 1
Task: Long year



C#: using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;

public static class Program
{
    public static void Main()
    {
        WriteLine("Long years in the 21st century:");
        WriteLine(string.Join(" ", 2000.To(2100).Where(y => ISOWeek.GetWeeksInYear(y) == 53)));
    }
    
    public static IEnumerable<int> To(this int start, int end) {
        for (int i = start; i < end; i++) yield return i;
    }
    
}








Fortran: program longyear
    use iso_fortran_env, only: output_unit, input_unit
    implicit none

    integer             :: start, ende, i, counter
    integer, parameter  :: line_break=10

    write(output_unit,*) "Enter beginning of interval"
    read(input_unit,*) start
    write(output_unit,*) "Enter end of interval"
    read(input_unit,*) ende

    if (start>=ende) error stop "Last year must be after first year

    counter = 0
    do i = start, ende
        if (is_long_year(i)) then
            write(output_unit,'(I0,x)', advance="no") i
            counter = counter + 1
            if (modulo(counter,line_break) == 0) write(output_unit,*)
        end if
    end do
contains
    pure function p(year)
        integer, intent(in) :: year
        integer             :: p

        p = modulo(year + year/4 - year/100 + year/400, 7)
    end function p

    pure function is_long_year(year)
        integer, intent(in) :: year
        logical             :: is_long_year

        is_long_year = p(year) == 4 .or. p(year-1) == 3
    end function is_long_year
end program longyear
Task: Magic 8-ball



C#: using System;

namespace newProg
{

    class Program
    {
        static void Main(string[] args)
        {
            string[] answers =
            {
                "It is certain.",
                "It is decidedly so.",
                "Without a doubt.",
                "Yes – definitely.",
                "You may rely on it.",
                "As I see it, yes.",
                "Most likely.",
                "Outlook good.",
                "Yes.",
                "Signs point to yes.",
                "Reply hazy, try again.",
                "Ask again later",
                "Better not tell you now.",
                "Cannot predict now.",
                "Concentrate and ask again.",
                "Don't count on it.",
                "My reply is no.",
                "My sources say no.",
                "Outlook not so good.",
                "Very doubtful."
            };

            while (true)
            {
                Random rnd = new Random();
                int result = rnd.Next(0, 19);

                Console.WriteLine("Magic 8 Ball! Ask question and hit a key for the answer!");

                string inp = Console.ReadLine();
                
                Console.WriteLine(answers[result]);

            }
        }
    }
}








Fortran: PROGRAM EIGHT_BALL
    CHARACTER(LEN=100) :: RESPONSE
    CHARACTER(LEN=100) :: QUESTION
    CHARACTER(LEN=100), DIMENSION(20) :: RESPONSES
    REAL :: R

    CALL RANDOM_SEED()

    RESPONSES(1) = "It is certain" 
    RESPONSES(2) = "It is decidedly so"
    RESPONSES(3) = "Without a doubt"
    RESPONSES(4) = "Yes, definitely"
    RESPONSES(5) = "You may rely on it"
    RESPONSES(6) = "As I see it, yes"
    RESPONSES(7) = "Most likely"
    RESPONSES(8) = "Outlook good"
    RESPONSES(9) = "Signs point to yes"
    RESPONSES(10) = "Yes"
    RESPONSES(11) = "Reply hazy, try again"
    RESPONSES(12) = "Ask again later"
    RESPONSES(13) = "Better not tell you now"
    RESPONSES(14) = "Cannot predict now"
    RESPONSES(15) = "Concentrate and ask again"
    RESPONSES(16) = "Don't bet on it"
    RESPONSES(17) = "My reply is no"
    RESPONSES(18) = "My sources say no"
    RESPONSES(19) = "Outlook not so good"
    RESPONSES(20) = "Very doubtful"

    WRITE(*,*) "Welcome to 8 Ball
    WRITE(*,*) "you seek, type either 'quit' or 'q' to exit", NEW_LINE('A')

    DO WHILE(.TRUE.)
        PRINT*, "Ask your question: "
        READ(*,*) QUESTION
        IF(QUESTION == "q" .OR. QUESTION == "quit") THEN
            CALL EXIT(0)
        ENDIF
        CALL RANDOM_NUMBER(R)
        PRINT*, "Response: ", TRIM(RESPONSES(FLOOR(R*20))), NEW_LINE('A')
    ENDDO
END PROGRAM EIGHT_BALL