WeixiangYan/CodeTransOcean huggingface dataset:
Task: Mutual recursion





Java: import java.util.HashMap;
import java.util.Map;

public class MutualRecursion {

    public static void main(final String args[]) {
        int max = 20;
        System.out.printf("First %d values of the Female sequence:  %n", max);
        for (int i = 0; i < max; i++) {
            System.out.printf("  f(%d) = %d%n", i, f(i));
        }
        System.out.printf("First %d values of the Male sequence:  %n", max);
        for (int i = 0; i < 20; i++) {
            System.out.printf("  m(%d) = %d%n", i, m(i));
        }
    }

    private static Map<Integer,Integer> F_MAP = new HashMap<>();

    private static int f(final int n) {
        if ( F_MAP.containsKey(n) ) {
            return F_MAP.get(n);
        }
        int fn = n == 0 ? 1 : n - m(f(n - 1));
        F_MAP.put(n, fn);
        return fn;
    }

    private static Map<Integer,Integer> M_MAP = new HashMap<>();

    private static int m(final int n) {
        if ( M_MAP.containsKey(n) ) {
            return M_MAP.get(n);
        }
        int mn = n == 0 ? 0 : n - f(m(n - 1));
        M_MAP.put(n, mn);
        return mn;
    }
     

}






Fortran: module MutualRec
  implicit none
contains
  pure recursive function m(n) result(r)
    integer :: r
    integer, intent(in) :: n
    if ( n == 0 ) then
       r = 0
       return
    end if
    r = n - f(m(n-1))
  end function m
  
  pure recursive function f(n) result(r)
    integer :: r
    integer, intent(in) :: n
    if ( n == 0 ) then
       r = 1
       return
    end if
    r = n - m(f(n-1))
  end function f

end module
Task: Mutual recursion







Python: def F(n): return 1 if n == 0 else n - M(F(n-1))
def M(n): return 0 if n == 0 else n - F(M(n-1))

print ([ F(n) for n in range(20) ])
print ([ M(n) for n in range(20) ])




Fortran: module MutualRec
  implicit none
contains
  pure recursive function m(n) result(r)
    integer :: r
    integer, intent(in) :: n
    if ( n == 0 ) then
       r = 0
       return
    end if
    r = n - f(m(n-1))
  end function m
  
  pure recursive function f(n) result(r)
    integer :: r
    integer, intent(in) :: n
    if ( n == 0 ) then
       r = 1
       return
    end if
    r = n - m(f(n-1))
  end function f

end module
Task: Mutual recursion






PHP: <?php
function F($n)
{
  if ( $n == 0 ) return 1;
  return $n - M(F($n-1));
}

function M($n)
{
  if ( $n == 0) return 0;
  return $n - F(M($n-1));
}

$ra = array();
$rb = array();
for($i=0; $i < 20; $i++)
{
  array_push($ra, F($i));
  array_push($rb, M($i));
}
echo implode(" ", $ra) . "\n";
echo implode(" ", $rb) . "\n";
?>





Fortran: module MutualRec
  implicit none
contains
  pure recursive function m(n) result(r)
    integer :: r
    integer, intent(in) :: n
    if ( n == 0 ) then
       r = 0
       return
    end if
    r = n - f(m(n-1))
  end function m
  
  pure recursive function f(n) result(r)
    integer :: r
    integer, intent(in) :: n
    if ( n == 0 ) then
       r = 1
       return
    end if
    r = n - m(f(n-1))
  end function f

end module
Task: Mutual recursion






PHP: <?php
function F($n)
{
  if ( $n == 0 ) return 1;
  return $n - M(F($n-1));
}

function M($n)
{
  if ( $n == 0) return 0;
  return $n - F(M($n-1));
}

$ra = array();
$rb = array();
for($i=0; $i < 20; $i++)
{
  array_push($ra, F($i));
  array_push($rb, M($i));
}
echo implode(" ", $ra) . "\n";
echo implode(" ", $rb) . "\n";
?>
Task: Mutual recursion






PHP: <?php
function F($n)
{
  if ( $n == 0 ) return 1;
  return $n - M(F($n-1));
}

function M($n)
{
  if ( $n == 0) return 0;
  return $n - F(M($n-1));
}

$ra = array();
$rb = array();
for($i=0; $i < 20; $i++)
{
  array_push($ra, F($i));
  array_push($rb, M($i));
}
echo implode(" ", $ra) . "\n";
echo implode(" ", $rb) . "\n";
?>






Ada: with Ada.Text_Io; use Ada.Text_Io; 
procedure Mutual_Recursion is
   function M(N : Integer) return Integer;
   function F(N : Integer) return Integer is
   begin
      if N = 0 then
         return 1;
      else
         return N - M(F(N - 1));
      end if;
   end F;
   function M(N : Integer) return Integer is
   begin
      if N = 0 then
         return 0;
      else
         return N - F(M(N-1));
      end if;
   end M;
begin
   for I in 0..19 loop
      Put_Line(Integer'Image(F(I)));
   end loop;
   New_Line;
   for I in 0..19 loop
      Put_Line(Integer'Image(M(I)));
   end loop;
end Mutual_recursion;
Task: Narcissistic decimal number



C#: using System;

namespace Narcissistic
{
    class Narcissistic
    {
        public bool isNarcissistic(int z)
        {
            if (z < 0) return false;
            string n = z.ToString();
            int t = 0, l = n.Length;
            foreach (char c in n)
                t += Convert.ToInt32(Math.Pow(Convert.ToDouble(c - 48), l));

            return t == z;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Narcissistic n = new Narcissistic();
            int c = 0, x = 0;
            while (c < 25)
            {
                if (n.isNarcissistic(x))
                {
                    if (c % 5 == 0) Console.WriteLine();
                    Console.Write("{0,7} ", x);
                    c++;
                }
                x++;
            }
            Console.WriteLine("\n\nPress any key to continue...");
            Console.ReadKey();
        }
    }
}









Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number

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

#define MAX_LEN 81

mpz_t power[10];
mpz_t dsum[MAX_LEN + 1];
int cnt[10], len;

void check_perm(void)
{
	char s[MAX_LEN + 1];
	int i, c, out[10] = { 0 };

	mpz_get_str(s, 10, dsum[0]);
	for (i = 0; s[i]; i++) {
		c = s[i]-'0';
		if (++out[c] > cnt[c]) return;
	}

	if (i == len)
		gmp_printf(" %Zd", dsum[0]);
}

void narc_(int pos, int d)
{
	if (!pos) {
		check_perm();
		return;
	}

	do {
		mpz_add(dsum[pos-1], dsum[pos], power[d]);
		++cnt[d];
		narc_(pos - 1, d);
		--cnt[d];
	} while (d--);
}

void narc(int n)
{
	int i;
	len = n;
	for (i = 0; i < 10; i++)
		mpz_ui_pow_ui(power[i], i, n);

	mpz_init_set_ui(dsum[n], 0);

	printf("length %d:", n);
	narc_(n, 9);
	putchar('\n');
}

int main(void)
{
	int i;

	for (i = 0; i <= 10; i++)
		mpz_init(power[i]);
	for (i = 1; i <= MAX_LEN; i++) narc(i);

	return 0;
}











Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number


C++: #include <iostream>
#include <vector>
using namespace std;
typedef unsigned int uint;

class NarcissisticDecs
{
public:
    void makeList( int mx )
    {
	uint st = 0, tl; int pwr = 0, len;
        while( narc.size() < mx )
	{
	    len = getDigs( st );
	    if( pwr != len )
	    {
		pwr = len;
		fillPower( pwr );
	    }
            tl = 0;
	    for( int i = 1; i < 10; i++ )
		tl += static_cast<uint>( powr[i] * digs[i] );

	    if( tl == st ) narc.push_back( st );
	    st++;
	}
    }

    void display()
    {
	for( vector<uint>::iterator i = narc.begin(); i != narc.end(); i++ )
	    cout << *i << " ";
	cout << "\n\n";
    }

private:
    int getDigs( uint st )
    {
	memset( digs, 0, 10 * sizeof( int ) );
	int r = 0;
	while( st )
	{
	    digs[st % 10]++;
	    st /= 10;
	    r++;
	}
        return r;
    }

    void fillPower( int z )
    {
	for( int i = 1; i < 10; i++ )
	    powr[i] = pow( static_cast<float>( i ), z );
    }

    vector<uint> narc;
    uint powr[10];
    int digs[10];
};

int main( int argc, char* argv[] )
{
    NarcissisticDecs n;
    n.makeList( 25 );
    n.display();
    return system( "pause" );
}










Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number




Go: package main

import "fmt"

func narc(n int) []int {
	power := [...]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	limit := 10
	result := make([]int, 0, n)
	for x := 0; len(result) < n; x++ {
		if x >= limit {
			for i := range power {
				power[i] *= i 
			}
			limit *= 10
		}
		sum := 0
		for xx := x; xx > 0; xx /= 10 {
			sum += power[xx%10]
		}
		if sum == x {
			result = append(result, x)
		}
	}
	return result
}

func main() {
	fmt.Println(narc(25))
}








Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number





Java: public class Narc{
	public static boolean isNarc(long x){
		if(x < 0) return false;
		
		String xStr = Long.toString(x);
		int m = xStr.length();
		long sum = 0;
		
		for(char c : xStr.toCharArray()){
			sum += Math.pow(Character.digit(c, 10), m);
		}
		return sum == x;
	}

	public static void main(String[] args){
		for(long x = 0, count = 0; count < 25; x++){
			if(isNarc(x)){
				System.out.print(x + " ");
				count++;
			}
		}
	}
}







Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number







Python: from __future__ import print_function
from itertools import count, islice

def narcissists():
    for digits in count(0):
        digitpowers = [i**digits for i in range(10)]
        for n in range(int(10**(digits-1)), 10**digits):
            div, digitpsum = n, 0
            while div:
                div, mod = divmod(div, 10)
                digitpsum += digitpowers[mod]
            if n == digitpsum:
                yield n

for i, n in enumerate(islice(narcissists(), 25), 1):
    print(n, end=' ')
    if i % 5 == 0: print() 
print()





Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number








VB: Private Function narcissistic(n As Long) As Boolean
    Dim d As String: d = CStr(n)
    Dim l As Integer: l = Len(d)
    Dim sumn As Long: sumn = 0
    For i = 1 To l
        sumn = sumn + (Mid(d, i, 1) - "0") ^ l
    Next i
    narcissistic = sumn = n
End Function

Public Sub main()
    Dim s(24) As String
    Dim n As Long: n = 0
    Dim found As Integer: found = 0
    Do While found < 25
        If narcissistic(n) Then
            s(found) = CStr(n)
            found = found + 1
        End If
        n = n + 1
    Loop
    Debug.Print Join(s, ", ")
End Sub




Ada: with Ada.Text_IO;

procedure Narcissistic is
   
   function Is_Narcissistic(N: Natural) return Boolean is
      Decimals: Natural := 1;
      M: Natural := N;
      Sum: Natural := 0;
   begin
      while M >= 10 loop
	 M := M / 10;
	 Decimals := Decimals + 1;
      end loop;
      M := N;
      while M >= 1 loop
	 Sum := Sum + (M mod 10) ** Decimals;
	 M := M/10;
      end loop;
      return Sum=N;
   end Is_Narcissistic;
   
   Count, Current: Natural := 0;
   
begin
   while Count < 25 loop
      if Is_Narcissistic(Current) then
	 Ada.Text_IO.Put(Integer'Image(Current));
	 Count := Count + 1;
      end if;
      Current := Current + 1;
   end loop;
end Narcissistic;
Task: Narcissistic decimal number

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

#define MAX_LEN 81

mpz_t power[10];
mpz_t dsum[MAX_LEN + 1];
int cnt[10], len;

void check_perm(void)
{
	char s[MAX_LEN + 1];
	int i, c, out[10] = { 0 };

	mpz_get_str(s, 10, dsum[0]);
	for (i = 0; s[i]; i++) {
		c = s[i]-'0';
		if (++out[c] > cnt[c]) return;
	}

	if (i == len)
		gmp_printf(" %Zd", dsum[0]);
}

void narc_(int pos, int d)
{
	if (!pos) {
		check_perm();
		return;
	}

	do {
		mpz_add(dsum[pos-1], dsum[pos], power[d]);
		++cnt[d];
		narc_(pos - 1, d);
		--cnt[d];
	} while (d--);
}

void narc(int n)
{
	int i;
	len = n;
	for (i = 0; i < 10; i++)
		mpz_ui_pow_ui(power[i], i, n);

	mpz_init_set_ui(dsum[n], 0);

	printf("length %d:", n);
	narc_(n, 9);
	putchar('\n');
}

int main(void)
{
	int i;

	for (i = 0; i <= 10; i++)
		mpz_init(power[i]);
	for (i = 1; i <= MAX_LEN; i++) narc(i);

	return 0;
}
Task: Narcissistic decimal number



C#: using System;

namespace Narcissistic
{
    class Narcissistic
    {
        public bool isNarcissistic(int z)
        {
            if (z < 0) return false;
            string n = z.ToString();
            int t = 0, l = n.Length;
            foreach (char c in n)
                t += Convert.ToInt32(Math.Pow(Convert.ToDouble(c - 48), l));

            return t == z;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Narcissistic n = new Narcissistic();
            int c = 0, x = 0;
            while (c < 25)
            {
                if (n.isNarcissistic(x))
                {
                    if (c % 5 == 0) Console.WriteLine();
                    Console.Write("{0,7} ", x);
                    c++;
                }
                x++;
            }
            Console.WriteLine("\n\nPress any key to continue...");
            Console.ReadKey();
        }
    }
}
Task: Narcissistic decimal number


C++: #include <iostream>
#include <vector>
using namespace std;
typedef unsigned int uint;

class NarcissisticDecs
{
public:
    void makeList( int mx )
    {
	uint st = 0, tl; int pwr = 0, len;
        while( narc.size() < mx )
	{
	    len = getDigs( st );
	    if( pwr != len )
	    {
		pwr = len;
		fillPower( pwr );
	    }
            tl = 0;
	    for( int i = 1; i < 10; i++ )
		tl += static_cast<uint>( powr[i] * digs[i] );

	    if( tl == st ) narc.push_back( st );
	    st++;
	}
    }

    void display()
    {
	for( vector<uint>::iterator i = narc.begin(); i != narc.end(); i++ )
	    cout << *i << " ";
	cout << "\n\n";
    }

private:
    int getDigs( uint st )
    {
	memset( digs, 0, 10 * sizeof( int ) );
	int r = 0;
	while( st )
	{
	    digs[st % 10]++;
	    st /= 10;
	    r++;
	}
        return r;
    }

    void fillPower( int z )
    {
	for( int i = 1; i < 10; i++ )
	    powr[i] = pow( static_cast<float>( i ), z );
    }

    vector<uint> narc;
    uint powr[10];
    int digs[10];
};

int main( int argc, char* argv[] )
{
    NarcissisticDecs n;
    n.makeList( 25 );
    n.display();
    return system( "pause" );
}
Task: Narcissistic decimal number





Java: public class Narc{
	public static boolean isNarc(long x){
		if(x < 0) return false;
		
		String xStr = Long.toString(x);
		int m = xStr.length();
		long sum = 0;
		
		for(char c : xStr.toCharArray()){
			sum += Math.pow(Character.digit(c, 10), m);
		}
		return sum == x;
	}

	public static void main(String[] args){
		for(long x = 0, count = 0; count < 25; x++){
			if(isNarc(x)){
				System.out.print(x + " ");
				count++;
			}
		}
	}
}
Task: Narcissistic decimal number







Python: from __future__ import print_function
from itertools import count, islice

def narcissists():
    for digits in count(0):
        digitpowers = [i**digits for i in range(10)]
        for n in range(int(10**(digits-1)), 10**digits):
            div, digitpsum = n, 0
            while div:
                div, mod = divmod(div, 10)
                digitpsum += digitpowers[mod]
            if n == digitpsum:
                yield n

for i, n in enumerate(islice(narcissists(), 25), 1):
    print(n, end=' ')
    if i % 5 == 0: print() 
print()
Task: Narcissistic decimal number








VB: Private Function narcissistic(n As Long) As Boolean
    Dim d As String: d = CStr(n)
    Dim l As Integer: l = Len(d)
    Dim sumn As Long: sumn = 0
    For i = 1 To l
        sumn = sumn + (Mid(d, i, 1) - "0") ^ l
    Next i
    narcissistic = sumn = n
End Function

Public Sub main()
    Dim s(24) As String
    Dim n As Long: n = 0
    Dim found As Integer: found = 0
    Do While found < 25
        If narcissistic(n) Then
            s(found) = CStr(n)
            found = found + 1
        End If
        n = n + 1
    Loop
    Debug.Print Join(s, ", ")
End Sub
Task: Narcissistic decimal number




Go: package main

import "fmt"

func narc(n int) []int {
	power := [...]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	limit := 10
	result := make([]int, 0, n)
	for x := 0; len(result) < n; x++ {
		if x >= limit {
			for i := range power {
				power[i] *= i 
			}
			limit *= 10
		}
		sum := 0
		for xx := x; xx > 0; xx /= 10 {
			sum += power[xx%10]
		}
		if sum == x {
			result = append(result, x)
		}
	}
	return result
}

func main() {
	fmt.Println(narc(25))
}
Task: Narcissistic decimal number

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

#define MAX_LEN 81

mpz_t power[10];
mpz_t dsum[MAX_LEN + 1];
int cnt[10], len;

void check_perm(void)
{
	char s[MAX_LEN + 1];
	int i, c, out[10] = { 0 };

	mpz_get_str(s, 10, dsum[0]);
	for (i = 0; s[i]; i++) {
		c = s[i]-'0';
		if (++out[c] > cnt[c]) return;
	}

	if (i == len)
		gmp_printf(" %Zd", dsum[0]);
}

void narc_(int pos, int d)
{
	if (!pos) {
		check_perm();
		return;
	}

	do {
		mpz_add(dsum[pos-1], dsum[pos], power[d]);
		++cnt[d];
		narc_(pos - 1, d);
		--cnt[d];
	} while (d--);
}

void narc(int n)
{
	int i;
	len = n;
	for (i = 0; i < 10; i++)
		mpz_ui_pow_ui(power[i], i, n);

	mpz_init_set_ui(dsum[n], 0);

	printf("length %d:", n);
	narc_(n, 9);
	putchar('\n');
}

int main(void)
{
	int i;

	for (i = 0; i <= 10; i++)
		mpz_init(power[i]);
	for (i = 1; i <= MAX_LEN; i++) narc(i);

	return 0;
}









COBOL:        PROGRAM-ID. NARCISSIST-NUMS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
 
           01 num-length PIC 9(2) value 0.
           01 in-sum PIC  9(9) value 0.
           01 counter PIC  9(9) value 0.
           01 current-number PIC  9(9) value 0.
           01 narcissist PIC Z(9).
           01 temp PIC  9(9) value 0.
           01 modulo PIC  9(9) value 0.
           01 answer PIC  9 .
 
       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
           DISPLAY "the first 20 narcissist numbers:" .
 
           MOVE 20 TO counter.
           PERFORM UNTIL counter=0
 
               PERFORM 000-NARCISSIST-PARA
 
                   IF answer = 1 
                       SUBTRACT 1 from counter
                       GIVING counter
                       MOVE current-number TO narcissist
                       DISPLAY narcissist
                   END-IF
 
                   ADD 1 TO current-number
 
               END-PERFORM
 
            STOP RUN.
 
       000-NARCISSIST-PARA.
 
             MOVE ZERO TO in-sum.
             MOVE current-number TO temp.
             COMPUTE num-length =1+  FUNCTION Log10(temp)
 
             PERFORM  UNTIL temp=0
 
                  DIVIDE temp BY 10 GIVING temp
                            REMAINDER  modulo
 
                  COMPUTE modulo=modulo**num-length
                  ADD modulo to in-sum GIVING in-sum
 
            END-PERFORM.
 
               IF current-number=in-sum
                   MOVE 1 TO answer
                   ELSE MOVE 0 TO answer
               END-IF.
 
       END PROGRAM NARCISSIST-NUMS.