WeixiangYan/CodeTransOcean huggingface dataset:
Task: Look-and-say sequence




Go: package main

import (
    "fmt"
    "strconv"
)

func lss(s string) (r string) {
    c := s[0]
    nc := 1
    for i := 1; i < len(s); i++ {
        d := s[i]
        if d == c {
            nc++
            continue
        }
        r += strconv.Itoa(nc) + string(c)
        c = d
        nc = 1
    }
    return r + strconv.Itoa(nc) + string(c)
}

func main() {
    s := "1"
    fmt.Println(s)
    for i := 0; i < 8; i++ {
        s = lss(s)
        fmt.Println(s)
    }
}








Ada: with Ada.Text_IO, Ada.Strings.Fixed;
use  Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed;

function "+" (S : String) return String is
   Item : constant Character := S (S'First);
begin
   for Index in S'First + 1..S'Last loop
      if Item /= S (Index) then
         return Trim (Integer'Image (Index - S'First), Both) & Item & (+(S (Index..S'Last)));
      end if;
   end loop;
   return Trim (Integer'Image (S'Length), Both) & Item;
end "+";
Task: Look-and-say sequence





Java: public static String lookandsay(String number){
	StringBuilder result= new StringBuilder();

	char repeat= number.charAt(0);
	number= number.substring(1) + " ";
	int times= 1;

	for(char actual: number.toCharArray()){
		if(actual != repeat){
			result.append(times + "" + repeat);
			times= 1;
			repeat= actual;
		}else{
			times+= 1;
		}
	}
	return result.toString();
}







Ada: with Ada.Text_IO, Ada.Strings.Fixed;
use  Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed;

function "+" (S : String) return String is
   Item : constant Character := S (S'First);
begin
   for Index in S'First + 1..S'Last loop
      if Item /= S (Index) then
         return Trim (Integer'Image (Index - S'First), Both) & Item & (+(S (Index..S'Last)));
      end if;
   end loop;
   return Trim (Integer'Image (S'Length), Both) & Item;
end "+";
Task: Look-and-say sequence







Python: def lookandsay(number):
    result = ""

    repeat = number[0]
    number = number[1:]+" "
    times = 1

    for actual in number:
        if actual != repeat:
            result += str(times)+repeat
            times = 1
            repeat = actual
        else:
            times += 1

    return result

num = "1"

for i in range(10):
    print num
    num = lookandsay(num)





Ada: with Ada.Text_IO, Ada.Strings.Fixed;
use  Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed;

function "+" (S : String) return String is
   Item : constant Character := S (S'First);
begin
   for Index in S'First + 1..S'Last loop
      if Item /= S (Index) then
         return Trim (Integer'Image (Index - S'First), Both) & Item & (+(S (Index..S'Last)));
      end if;
   end loop;
   return Trim (Integer'Image (S'Length), Both) & Item;
end "+";
Task: Look-and-say sequence








VB: function looksay( n )
	dim i
	dim accum
	dim res
	dim c
	res = vbnullstring
	do
		if n = vbnullstring then exit do
		accum = 0
		c = left( n,1 )
		do while left( n, 1 ) = c
			accum = accum + 1
			n = mid(n,2)
		loop
		if accum > 0 then 
			res = res & accum & c
		end if
	loop
	looksay = res
end function




Ada: with Ada.Text_IO, Ada.Strings.Fixed;
use  Ada.Text_IO, Ada.Strings, Ada.Strings.Fixed;

function "+" (S : String) return String is
   Item : constant Character := S (S'First);
begin
   for Index in S'First + 1..S'Last loop
      if Item /= S (Index) then
         return Trim (Integer'Image (Index - S'First), Both) & Item & (+(S (Index..S'Last)));
      end if;
   end loop;
   return Trim (Integer'Image (S'Length), Both) & Item;
end "+";
Task: Look-and-say sequence

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
	char *a = malloc(2), *b = 0, *x, c;
	int cnt, len = 1;

	for (sprintf(a, "1"); (b = realloc(b, len * 2 + 1)); a = b, b = x) {
		puts(x = a);
		for (len = 0, cnt = 1; (c = *a); ) {
			if (c == *++a)
				cnt++;
			else if (c) {
				len += sprintf(b + len, "%d%c", cnt, c);
				cnt = 1;
			}
		}
	}

	return 0;
}
Task: Look-and-say sequence



C#: using System;
using System.Text;
using System.Linq;

class Program
{
    static string lookandsay(string number)
    {
        StringBuilder result = new StringBuilder();

        char repeat = number[0];
        number = number.Substring(1, number.Length-1)+" ";
        int times = 1;
      
        foreach (char actual in number)
        {
            if (actual != repeat)
            {
                result.Append(Convert.ToString(times)+repeat);
                times = 1;
                repeat = actual;
            }
            else
            {
                times += 1;
            }
        }
        return result.ToString();
    }

    static void Main(string[] args)
    {
        string num = "1"; 

        foreach (int i in Enumerable.Range(1, 10)) {
             Console.WriteLine(num);
             num = lookandsay(num);             
        }
    }
}
Task: Look-and-say sequence


C++: #include <iostream>
#include <sstream>
#include <string>

std::string lookandsay(const std::string& s)
{
    std::ostringstream r;

    for (std::size_t i = 0; i != s.length();) {
        auto new_i = s.find_first_not_of(s[i], i + 1);

        if (new_i == std::string::npos)
            new_i = s.length();

        r << new_i - i << s[i];
        i = new_i;
    }
    return r.str();
}

int main()
{
    std::string laf = "1";

    std::cout << laf << '\n';
    for (int i = 0; i < 10; ++i) {
        laf = lookandsay(laf);
        std::cout << laf << '\n';
    }
}
Task: Look-and-say sequence





Java: public static String lookandsay(String number){
	StringBuilder result= new StringBuilder();

	char repeat= number.charAt(0);
	number= number.substring(1) + " ";
	int times= 1;

	for(char actual: number.toCharArray()){
		if(actual != repeat){
			result.append(times + "" + repeat);
			times= 1;
			repeat= actual;
		}else{
			times+= 1;
		}
	}
	return result.toString();
}
Task: Look-and-say sequence







Python: def lookandsay(number):
    result = ""

    repeat = number[0]
    number = number[1:]+" "
    times = 1

    for actual in number:
        if actual != repeat:
            result += str(times)+repeat
            times = 1
            repeat = actual
        else:
            times += 1

    return result

num = "1"

for i in range(10):
    print num
    num = lookandsay(num)
Task: Look-and-say sequence








VB: function looksay( n )
	dim i
	dim accum
	dim res
	dim c
	res = vbnullstring
	do
		if n = vbnullstring then exit do
		accum = 0
		c = left( n,1 )
		do while left( n, 1 ) = c
			accum = accum + 1
			n = mid(n,2)
		loop
		if accum > 0 then 
			res = res & accum & c
		end if
	loop
	looksay = res
end function
Task: Look-and-say sequence




Go: package main

import (
    "fmt"
    "strconv"
)

func lss(s string) (r string) {
    c := s[0]
    nc := 1
    for i := 1; i < len(s); i++ {
        d := s[i]
        if d == c {
            nc++
            continue
        }
        r += strconv.Itoa(nc) + string(c)
        c = d
        nc = 1
    }
    return r + strconv.Itoa(nc) + string(c)
}

func main() {
    s := "1"
    fmt.Println(s)
    for i := 0; i < 8; i++ {
        s = lss(s)
        fmt.Println(s)
    }
}
Task: Look-and-say sequence



C#: using System;
using System.Text;
using System.Linq;

class Program
{
    static string lookandsay(string number)
    {
        StringBuilder result = new StringBuilder();

        char repeat = number[0];
        number = number.Substring(1, number.Length-1)+" ";
        int times = 1;
      
        foreach (char actual in number)
        {
            if (actual != repeat)
            {
                result.Append(Convert.ToString(times)+repeat);
                times = 1;
                repeat = actual;
            }
            else
            {
                times += 1;
            }
        }
        return result.ToString();
    }

    static void Main(string[] args)
    {
        string num = "1"; 

        foreach (int i in Enumerable.Range(1, 10)) {
             Console.WriteLine(num);
             num = lookandsay(num);             
        }
    }
}








Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence


C++: #include <iostream>
#include <sstream>
#include <string>

std::string lookandsay(const std::string& s)
{
    std::ostringstream r;

    for (std::size_t i = 0; i != s.length();) {
        auto new_i = s.find_first_not_of(s[i], i + 1);

        if (new_i == std::string::npos)
            new_i = s.length();

        r << new_i - i << s[i];
        i = new_i;
    }
    return r.str();
}

int main()
{
    std::string laf = "1";

    std::cout << laf << '\n';
    for (int i = 0; i < 10; ++i) {
        laf = lookandsay(laf);
        std::cout << laf << '\n';
    }
}









Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
	char *a = malloc(2), *b = 0, *x, c;
	int cnt, len = 1;

	for (sprintf(a, "1"); (b = realloc(b, len * 2 + 1)); a = b, b = x) {
		puts(x = a);
		for (len = 0, cnt = 1; (c = *a); ) {
			if (c == *++a)
				cnt++;
			else if (c) {
				len += sprintf(b + len, "%d%c", cnt, c);
				cnt = 1;
			}
		}
	}

	return 0;
}










Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence





Java: public static String lookandsay(String number){
	StringBuilder result= new StringBuilder();

	char repeat= number.charAt(0);
	number= number.substring(1) + " ";
	int times= 1;

	for(char actual: number.toCharArray()){
		if(actual != repeat){
			result.append(times + "" + repeat);
			times= 1;
			repeat= actual;
		}else{
			times+= 1;
		}
	}
	return result.toString();
}






Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence







Python: def lookandsay(number):
    result = ""

    repeat = number[0]
    number = number[1:]+" "
    times = 1

    for actual in number:
        if actual != repeat:
            result += str(times)+repeat
            times = 1
            repeat = actual
        else:
            times += 1

    return result

num = "1"

for i in range(10):
    print num
    num = lookandsay(num)




Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence








VB: function looksay( n )
	dim i
	dim accum
	dim res
	dim c
	res = vbnullstring
	do
		if n = vbnullstring then exit do
		accum = 0
		c = left( n,1 )
		do while left( n, 1 ) = c
			accum = accum + 1
			n = mid(n,2)
		loop
		if accum > 0 then 
			res = res & accum & c
		end if
	loop
	looksay = res
end function



Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence






PHP: <?php

function lookAndSay($str) {

	return preg_replace_callback('#(.)\1*#', function($matches) {
	
		return strlen($matches[0]).$matches[1];
	}, $str);
}

$num = "1";

foreach(range(1,10) as $i) {

	echo $num."<br/>";
	$num = lookAndSay($num);
}

?>





Fortran: module LookAndSay
  implicit none

contains

  subroutine look_and_say(in, out)
    character(len=*), intent(in) :: in
    character(len=*), intent(out) :: out

    integer :: i, c
    character(len=1) :: x
    character(len=2) :: d

    out = ""
    c = 1
    x = in(1:1)
    do i = 2, len(trim(in))
       if ( x == in(i:i) ) then
          c = c + 1
       else
          write(d, "(I2)") c
          out = trim(out) // trim(adjustl(d)) // trim(x)
          c = 1
          x = in(i:i)
       end if
    end do
    write(d, "(I2)") c
    out = trim(out) // trim(adjustl(d)) // trim(x)
  end subroutine look_and_say

end module LookAndSay
Task: Look-and-say sequence

C: #include <stdio.h>
#include <stdlib.h>

int main()
{
	char *a = malloc(2), *b = 0, *x, c;
	int cnt, len = 1;

	for (sprintf(a, "1"); (b = realloc(b, len * 2 + 1)); a = b, b = x) {
		puts(x = a);
		for (len = 0, cnt = 1; (c = *a); ) {
			if (c == *++a)
				cnt++;
			else if (c) {
				len += sprintf(b + len, "%d%c", cnt, c);
				cnt = 1;
			}
		}
	}

	return 0;
}









COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Look-and-say sequence



C#: using System;
using System.Text;
using System.Linq;

class Program
{
    static string lookandsay(string number)
    {
        StringBuilder result = new StringBuilder();

        char repeat = number[0];
        number = number.Substring(1, number.Length-1)+" ";
        int times = 1;
      
        foreach (char actual in number)
        {
            if (actual != repeat)
            {
                result.Append(Convert.ToString(times)+repeat);
                times = 1;
                repeat = actual;
            }
            else
            {
                times += 1;
            }
        }
        return result.ToString();
    }

    static void Main(string[] args)
    {
        string num = "1"; 

        foreach (int i in Enumerable.Range(1, 10)) {
             Console.WriteLine(num);
             num = lookandsay(num);             
        }
    }
}







COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Look-and-say sequence


C++: #include <iostream>
#include <sstream>
#include <string>

std::string lookandsay(const std::string& s)
{
    std::ostringstream r;

    for (std::size_t i = 0; i != s.length();) {
        auto new_i = s.find_first_not_of(s[i], i + 1);

        if (new_i == std::string::npos)
            new_i = s.length();

        r << new_i - i << s[i];
        i = new_i;
    }
    return r.str();
}

int main()
{
    std::string laf = "1";

    std::cout << laf << '\n';
    for (int i = 0; i < 10; ++i) {
        laf = lookandsay(laf);
        std::cout << laf << '\n';
    }
}








COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.
Task: Look-and-say sequence





Java: public static String lookandsay(String number){
	StringBuilder result= new StringBuilder();

	char repeat= number.charAt(0);
	number= number.substring(1) + " ";
	int times= 1;

	for(char actual: number.toCharArray()){
		if(actual != repeat){
			result.append(times + "" + repeat);
			times= 1;
			repeat= actual;
		}else{
			times+= 1;
		}
	}
	return result.toString();
}





COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. LOOK-AND-SAY-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQUENCES.
           02 CUR-SEQ       PIC X(80) VALUE "1".
           02 CUR-CHARS     REDEFINES CUR-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY CI.
           02 CUR-LENGTH    PIC 99 COMP VALUE 1.
           02 NEXT-SEQ      PIC X(80).
           02 NEXT-CHARS    REDEFINES NEXT-SEQ 
                            PIC X OCCURS 80 TIMES INDEXED BY NI.
        01 ALG-STATE.
           02 STEP-AMOUNT   PIC 99 VALUE 14.
           02 ITEM-COUNT    PIC 9.
           
        PROCEDURE DIVISION.
        LOOK-AND-SAY.
            DISPLAY CUR-SEQ.
            SET CI TO 1.
            SET NI TO 1.
        MAKE-NEXT-ENTRY.
            MOVE 0 TO ITEM-COUNT.
            IF CI IS GREATER THAN CUR-LENGTH GO TO STEP-DONE.
        TALLY-ITEM.
            ADD 1 TO ITEM-COUNT.
            SET CI UP BY 1.
            IF CI IS NOT GREATER THAN CUR-LENGTH
               AND CUR-CHARS(CI) IS EQUAL TO CUR-CHARS(CI - 1) 
                GO TO TALLY-ITEM.
        INSERT-ENTRY.
            MOVE ITEM-COUNT TO NEXT-CHARS(NI).
            MOVE CUR-CHARS(CI - 1) TO NEXT-CHARS(NI + 1).
            SET NI UP BY 2.
            GO TO MAKE-NEXT-ENTRY.
        STEP-DONE.
            MOVE NEXT-SEQ TO CUR-SEQ.
            SET NI DOWN BY 1.
            SET CUR-LENGTH TO NI.
            SUBTRACT 1 FROM STEP-AMOUNT.
            IF STEP-AMOUNT IS NOT EQUAL TO ZERO GO TO LOOK-AND-SAY.
            STOP RUN.