WeixiangYan/CodeTransOcean huggingface dataset:
Task: Gapful numbers



C#: using System;

namespace GapfulNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("The first 30 gapful numbers are: ");
            
            FindGap(100, 30);

            Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ");
            FindGap(1000000, 15);

            Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ");
            FindGap(1000000000, 10);

            Console.Read();
        }

        public static int firstNum(int n)
        {
            
            while (n >= 10)
            {
                n /= 10;
            }
            return (n);
        }

        public static int lastNum(int n)
        {
            
            return (n % 10);
        }

        static void FindGap(int n, int gaps)
        {
            int count = 0;
            while (count < gaps)
            {

                
                string concat = firstNum(n).ToString() + lastNum(n).ToString();
                
                int i = Convert.ToInt32(concat);

                
                if (n % i == 0)
                {
                    Console.Write(n + " ");
                    count++;
                    n++;
                }
                else
                {
                    n++;
                    continue;
                }
            }
        }
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers

C: #include<stdio.h>

void generateGaps(unsigned long long int start,int count){
    
    int counter = 0;
    unsigned long long int i = start;
    char str[100];
    
    printf("\nFirst %d Gapful numbers >= %llu :\n",count,start);

    while(counter<count){
        sprintf(str,"%llu",i);
        if((i%(10*(str[0]-'0') + i%10))==0L){
            printf("\n%3d : %llu",counter+1,i);
            counter++;
        }
        i++;
    }
}

int main()
{
    unsigned long long int i = 100;
    int count = 0;
    char str[21];

    generateGaps(100,30);
    printf("\n");
    generateGaps(1000000,15);
    printf("\n");
    generateGaps(1000000000,15);
    printf("\n");

    return 0;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers


C++: #include <iostream>

bool gapful(int n) {
    int m = n;
    while (m >= 10)
        m /= 10;
    return n % ((n % 10) + 10 * (m % 10)) == 0;
}

void show_gapful_numbers(int n, int count) {
    std::cout << "First " << count << " gapful numbers >= " << n << ":\n";
    for (int i = 0; i < count; ++n) {
        if (gapful(n)) {
            if (i != 0)
                std::cout << ", ";
            std::cout << n;
            ++i;
        }
    }
    std::cout << '\n';
}

int main() {
    show_gapful_numbers(100, 30);
    show_gapful_numbers(1000000, 15);
    show_gapful_numbers(1000000000, 10);
    return 0;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers




Go: package main

import "fmt"

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    starts := []uint64{1e2, 1e6, 1e7, 1e9, 7123}
    counts := []int{30, 15, 15, 10, 25}
    for i := 0; i < len(starts); i++ {
        count := 0
        j := starts[i]
        pow := uint64(100)
        for {
            if j < pow*10 {
                break
            }
            pow *= 10
        }
        fmt.Printf("First %d gapful numbers starting at %s:\n", counts[i], commatize(starts[i]))
        for count < counts[i] {
            fl := (j/pow)*10 + (j % 10)
            if j%fl == 0 {
                fmt.Printf("%d ", j)
                count++
            }
            j++
            if j >= 10*pow {
                pow *= 10
            }
        }
        fmt.Println("\n")
    }
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers





Java: import java.util.List;

public class GapfulNumbers {
    private static String commatize(long n) {
        StringBuilder sb = new StringBuilder(Long.toString(n));
        int le = sb.length();
        for (int i = le - 3; i >= 1; i -= 3) {
            sb.insert(i, ',');
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        List<Long> starts = List.of((long) 1e2, (long) 1e6, (long) 1e7, (long) 1e9, (long) 7123);
        List<Integer> counts = List.of(30, 15, 15, 10, 25);
        for (int i = 0; i < starts.size(); ++i) {
            int count = 0;
            Long j = starts.get(i);
            long pow = 100;
            while (j >= pow * 10) {
                pow *= 10;
            }
            System.out.printf("First %d gapful numbers starting at %s:\n", counts.get(i), commatize(starts.get(i)));
            while (count < counts.get(i)) {
                long fl = (j / pow) * 10 + (j % 10);
                if (j % fl == 0) {
                    System.out.printf("%d ", j);
                    count++;
                }
                j++;
                if (j >= 10 * pow) {
                    pow *= 10;
                }
            }
            System.out.println('\n');
        }
    }
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers







Python: from itertools import islice, count
for start, n in [(100, 30), (1_000_000, 15), (1_000_000_000, 10)]:
    print(f"\nFirst {n} gapful numbers from {start:_}")
    print(list(islice(( x for x in count(start) 
                        if (x % (int(str(x)[0]) * 10 + (x % 10)) == 0) )
                      , n)))





Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers








VB: Module Module1

    Function FirstNum(n As Integer) As Integer
        REM Divide by ten until the leading digit remains.
        While n >= 10
            n /= 10
        End While
        Return n
    End Function

    Function LastNum(n As Integer) As Integer
        REM Modulo gives you the last digit.
        Return n Mod 10
    End Function

    Sub FindGap(n As Integer, gaps As Integer)
        Dim count = 0
        While count < gaps
            Dim i = FirstNum(n) * 10 + LastNum(n)

            REM Modulo with our new integer and output the result.
            If n Mod i = 0 Then
                Console.Write("{0} ", n)
                count += 1
            End If

            n += 1
        End While
        Console.WriteLine()
        Console.WriteLine()
    End Sub

    Sub Main()
        Console.WriteLine("The first 30 gapful numbers are: ")
        FindGap(100, 30)

        Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ")
        FindGap(1000000, 15)

        Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ")
        FindGap(1000000000, 10)
    End Sub

End Module




Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Gapful_Numbers is

   function Divisor (N : in Positive) return Positive is
      NN : Positive := N;
   begin
      while NN >= 10 loop
         NN := NN / 10;
      end loop;
      return 10 * NN + (N mod 10);
   end Divisor;

   function Is_Gapful (N : in Positive) return Boolean is
   begin
      return N mod Divisor (N) = 0;
   end Is_Gapful;

   procedure Find_Gapful (Count : in Positive; From : in Positive) is
      Found : Natural := 0;
   begin
      for Candidate in From .. Positive'Last loop
         if Is_Gapful (Candidate) then
            Put (Candidate'Image);
            Found := Found + 1;
            exit when Found = Count;
         end if;
      end loop;
      New_Line;
   end Find_Gapful;

begin
   Put_Line ("First 30 gapful numbers over 100:");
   Find_Gapful (From => 100, Count => 30);
   New_Line;

   Put_Line ("First 15 gapful numbers over 1_000_000:");
   Find_Gapful (From => 1_000_000, Count => 15);
   New_Line;

   Put_Line ("First 10 gapful numbers over 1_000_000_000:");
   Find_Gapful (From => 1_000_000_000, Count => 10);
   New_Line;
end Gapful_Numbers;
Task: Gapful numbers

C: #include<stdio.h>

void generateGaps(unsigned long long int start,int count){
    
    int counter = 0;
    unsigned long long int i = start;
    char str[100];
    
    printf("\nFirst %d Gapful numbers >= %llu :\n",count,start);

    while(counter<count){
        sprintf(str,"%llu",i);
        if((i%(10*(str[0]-'0') + i%10))==0L){
            printf("\n%3d : %llu",counter+1,i);
            counter++;
        }
        i++;
    }
}

int main()
{
    unsigned long long int i = 100;
    int count = 0;
    char str[21];

    generateGaps(100,30);
    printf("\n");
    generateGaps(1000000,15);
    printf("\n");
    generateGaps(1000000000,15);
    printf("\n");

    return 0;
}
Task: Gapful numbers



C#: using System;

namespace GapfulNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("The first 30 gapful numbers are: ");
            
            FindGap(100, 30);

            Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ");
            FindGap(1000000, 15);

            Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ");
            FindGap(1000000000, 10);

            Console.Read();
        }

        public static int firstNum(int n)
        {
            
            while (n >= 10)
            {
                n /= 10;
            }
            return (n);
        }

        public static int lastNum(int n)
        {
            
            return (n % 10);
        }

        static void FindGap(int n, int gaps)
        {
            int count = 0;
            while (count < gaps)
            {

                
                string concat = firstNum(n).ToString() + lastNum(n).ToString();
                
                int i = Convert.ToInt32(concat);

                
                if (n % i == 0)
                {
                    Console.Write(n + " ");
                    count++;
                    n++;
                }
                else
                {
                    n++;
                    continue;
                }
            }
        }
    }
}
Task: Gapful numbers


C++: #include <iostream>

bool gapful(int n) {
    int m = n;
    while (m >= 10)
        m /= 10;
    return n % ((n % 10) + 10 * (m % 10)) == 0;
}

void show_gapful_numbers(int n, int count) {
    std::cout << "First " << count << " gapful numbers >= " << n << ":\n";
    for (int i = 0; i < count; ++n) {
        if (gapful(n)) {
            if (i != 0)
                std::cout << ", ";
            std::cout << n;
            ++i;
        }
    }
    std::cout << '\n';
}

int main() {
    show_gapful_numbers(100, 30);
    show_gapful_numbers(1000000, 15);
    show_gapful_numbers(1000000000, 10);
    return 0;
}
Task: Gapful numbers





Java: import java.util.List;

public class GapfulNumbers {
    private static String commatize(long n) {
        StringBuilder sb = new StringBuilder(Long.toString(n));
        int le = sb.length();
        for (int i = le - 3; i >= 1; i -= 3) {
            sb.insert(i, ',');
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        List<Long> starts = List.of((long) 1e2, (long) 1e6, (long) 1e7, (long) 1e9, (long) 7123);
        List<Integer> counts = List.of(30, 15, 15, 10, 25);
        for (int i = 0; i < starts.size(); ++i) {
            int count = 0;
            Long j = starts.get(i);
            long pow = 100;
            while (j >= pow * 10) {
                pow *= 10;
            }
            System.out.printf("First %d gapful numbers starting at %s:\n", counts.get(i), commatize(starts.get(i)));
            while (count < counts.get(i)) {
                long fl = (j / pow) * 10 + (j % 10);
                if (j % fl == 0) {
                    System.out.printf("%d ", j);
                    count++;
                }
                j++;
                if (j >= 10 * pow) {
                    pow *= 10;
                }
            }
            System.out.println('\n');
        }
    }
}
Task: Gapful numbers







Python: from itertools import islice, count
for start, n in [(100, 30), (1_000_000, 15), (1_000_000_000, 10)]:
    print(f"\nFirst {n} gapful numbers from {start:_}")
    print(list(islice(( x for x in count(start) 
                        if (x % (int(str(x)[0]) * 10 + (x % 10)) == 0) )
                      , n)))
Task: Gapful numbers








VB: Module Module1

    Function FirstNum(n As Integer) As Integer
        REM Divide by ten until the leading digit remains.
        While n >= 10
            n /= 10
        End While
        Return n
    End Function

    Function LastNum(n As Integer) As Integer
        REM Modulo gives you the last digit.
        Return n Mod 10
    End Function

    Sub FindGap(n As Integer, gaps As Integer)
        Dim count = 0
        While count < gaps
            Dim i = FirstNum(n) * 10 + LastNum(n)

            REM Modulo with our new integer and output the result.
            If n Mod i = 0 Then
                Console.Write("{0} ", n)
                count += 1
            End If

            n += 1
        End While
        Console.WriteLine()
        Console.WriteLine()
    End Sub

    Sub Main()
        Console.WriteLine("The first 30 gapful numbers are: ")
        FindGap(100, 30)

        Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ")
        FindGap(1000000, 15)

        Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ")
        FindGap(1000000000, 10)
    End Sub

End Module
Task: Gapful numbers




Go: package main

import "fmt"

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    starts := []uint64{1e2, 1e6, 1e7, 1e9, 7123}
    counts := []int{30, 15, 15, 10, 25}
    for i := 0; i < len(starts); i++ {
        count := 0
        j := starts[i]
        pow := uint64(100)
        for {
            if j < pow*10 {
                break
            }
            pow *= 10
        }
        fmt.Printf("First %d gapful numbers starting at %s:\n", counts[i], commatize(starts[i]))
        for count < counts[i] {
            fl := (j/pow)*10 + (j % 10)
            if j%fl == 0 {
                fmt.Printf("%d ", j)
                count++
            }
            j++
            if j >= 10*pow {
                pow *= 10
            }
        }
        fmt.Println("\n")
    }
}
Task: Gapful numbers

C: #include<stdio.h>

void generateGaps(unsigned long long int start,int count){
    
    int counter = 0;
    unsigned long long int i = start;
    char str[100];
    
    printf("\nFirst %d Gapful numbers >= %llu :\n",count,start);

    while(counter<count){
        sprintf(str,"%llu",i);
        if((i%(10*(str[0]-'0') + i%10))==0L){
            printf("\n%3d : %llu",counter+1,i);
            counter++;
        }
        i++;
    }
}

int main()
{
    unsigned long long int i = 100;
    int count = 0;
    char str[21];

    generateGaps(100,30);
    printf("\n");
    generateGaps(1000000,15);
    printf("\n");
    generateGaps(1000000000,15);
    printf("\n");

    return 0;
}









COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.