WeixiangYan/CodeTransOcean huggingface dataset:
Task: Comma quibbling

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

char *quib(const char **strs, size_t size)
{

    size_t len = 3 + ((size > 1) ? (2 * size + 1) : 0);
    size_t i;

    for (i = 0; i < size; i++)
        len += strlen(strs[i]);

    char *s = malloc(len * sizeof(*s));
    if (!s)
    {
        perror("Can't allocate memory!\n");
        exit(EXIT_FAILURE);
    }

    strcpy(s, "{");
    switch (size) {
        case 0:  break;
        case 1:  strcat(s, strs[0]);
                 break;
        default: for (i = 0; i < size - 1; i++)
                 {
                     strcat(s, strs[i]);
                     if (i < size - 2)
                         strcat(s, ", ");
                     else
                         strcat(s, " and ");
                 }
                 strcat(s, strs[i]);
                 break;
    }  
    strcat(s, "}");
    return s;
}

int main(void)
{
    const char *test[] = {"ABC", "DEF", "G", "H"};
    char *s;

    for (size_t i = 0; i < 5; i++)
    {
        s = quib(test, i);
        printf("%s\n", s);
        free(s);
    }
    return EXIT_SUCCESS;
}






PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}
Task: Comma quibbling



C#: using System;
using System.Linq;

namespace CommaQuibbling
{
    internal static class Program
    {
        #region Static Members
	private static string Quibble(string[] input)
	{
            return
                String.Format("{{{0}}}",
                    String.Join("",
                        input.Reverse().Zip(
                            new [] { "", " and " }.Concat(Enumerable.Repeat(", ", int.MaxValue)),
                            (x, y) => x + y).Reverse()));
	}


        private static void Main()
        {
            Console.WriteLine( Quibble( new string[] {} ) );
            Console.WriteLine( Quibble( new[] {"ABC"} ) );
            Console.WriteLine( Quibble( new[] {"ABC", "DEF"} ) );
            Console.WriteLine( Quibble( new[] {"ABC", "DEF", "G", "H"} ) );

            Console.WriteLine( "< Press Any Key >" );
            Console.ReadKey();
        }

        #endregion
    }
}




PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}
Task: Comma quibbling


C++: #include <iostream>

template<class T>
void quibble(std::ostream& o, T i, T e) {
  o << "{";
  if (e != i) {
    T n = i++;
    const char* more = "";
    while (e != i) {
      o << more << *n;
      more = ", ";
      n = i++;
    }
    o << (*more?" and ":"") << *n;
  }
  o << "}";
}

int main(int argc, char** argv) {
  char const* a[] = {"ABC","DEF","G","H"};
  for (int i=0; i<5; i++) {
    quibble(std::cout, a, a+i);
    std::cout << std::endl;
  }
  return 0;
}





PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}
Task: Comma quibbling




Go: package main

import (
    "fmt"
    "strings"
)

func q(s []string) string {
    switch len(s) {
    case 0:
        return "{}"
    case 1:
        return "{" + s[0] + "}"
    case 2:
        return "{" + s[0] + " and " + s[1] + "}"
    default:
        return "{" +
            strings.Join(s[:len(s)-1], ", ") +
            " and " +
            s[len(s)-1] +
            "}"
    }
}

func main() {
    fmt.Println(q([]string{}))
    fmt.Println(q([]string{"ABC"}))
    fmt.Println(q([]string{"ABC", "DEF"}))
    fmt.Println(q([]string{"ABC", "DEF", "G", "H"}))
}



PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}
Task: Comma quibbling





Java: public class Quibbler {

	public static String quibble(String[] words) {
		String qText = "{";
		for(int wIndex = 0; wIndex < words.length; wIndex++) {
			qText += words[wIndex] + (wIndex == words.length-1 ? "" : 
						  wIndex == words.length-2 ? " and " :
						  ", ";
		}
		qText += "}";
		return qText;
	}
	
	public static void main(String[] args) {
		System.out.println(quibble(new String[]{}));
		System.out.println(quibble(new String[]{"ABC"}));
		System.out.println(quibble(new String[]{"ABC", "DEF"}));
		System.out.println(quibble(new String[]{"ABC", "DEF", "G"}));
		System.out.println(quibble(new String[]{"ABC", "DEF", "G", "H"}));
	}
}


PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}
Task: Comma quibbling






PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}


Python: fun quibble(s):
    let result = s.join(' and ').replace(|| and ||, ", ", length(s) - 1)
    return "{ $result }"

let s = [
    []
    ["ABC"]
    ["ABC", "DEF"]
    ["ABC", "DEF", "G", "H"]
]

for i in s:
    print(quibble i)
Task: Comma quibbling






PHP: <?php

function quibble($arr){

  $words = count($arr);

  if($words == 0){
    return '{}';
  }elseif($words == 1){
    return '{'.$arr[0].'}';
  }elseif($words == 2){
    return '{'.$arr[0].' and '.$arr[1].'}';
  }else{
    return '{'.implode(', ',  array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
  }

}


$tests = [
  [],
  ["ABC"],
  ["ABC", "DEF"],
  ["ABC", "DEF", "G", "H"] 
];

foreach ($tests as $test) {
  echo quibble($test) . PHP_EOL;
}



VB: Option Explicit

Sub Main()
   Debug.Print Quibbling("")
   Debug.Print Quibbling("ABC")
   Debug.Print Quibbling("ABC, DEF")
   Debug.Print Quibbling("ABC, DEF, G, H")
   Debug.Print Quibbling("ABC, DEF, G, H, IJKLM, NO, PQRSTUV")
End Sub

Private Function Quibbling(MyString As String) As String
Dim s As String, n As Integer
   s = "{" & MyString & "}": n = InStrRev(s, ",")
   If n > 0 Then s = Left(s, n - 1) & " and " & Right(s, Len(s) - (n + 1))
   Quibbling = s
End Function
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(CheckISBN13("978-1734314502"));
        Console.WriteLine(CheckISBN13("978-1734314509"));
        Console.WriteLine(CheckISBN13("978-1788399081"));
        Console.WriteLine(CheckISBN13("978-1788399083"));

        static bool CheckISBN13(string code) {
            code = code.Replace("-", "").Replace(" ", "");
            if (code.Length != 13) return false;
            int sum = 0;
            foreach (var (index, digit) in code.Select((digit, index) => (index, digit))) {
                if (char.IsDigit(digit)) sum += (digit - '0') * (index % 2 == 0 ? 1 : 3);
                else return false;
            }
            return sum % 10 == 0;
        }
    }
}
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}


C++: #include <iostream>

bool check_isbn13(std::string isbn) {
    int count = 0;
    int sum = 0;

    for (auto ch : isbn) {
        
        if (ch == ' ' || ch == '-') {
            continue;
        }
        if (ch < '0' || ch > '9') {
            return false;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
        count++;
    }

    if (count != 13) {
        return false;
    }
    return sum % 10 == 0;
}

int main() {
    auto isbns = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" };
    for (auto isbn : isbns) {
        std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
    }

    return 0;
}
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}




Go: package main

import (
    "fmt"
    "strings"
    "unicode/utf8"
)

func checkIsbn13(isbn string) bool {
    
    isbn = strings.ReplaceAll(strings.ReplaceAll(isbn, "-", ""), " ", "")
    
    le := utf8.RuneCountInString(isbn)
    if le != 13 {
        return false
    }
    
    sum := int32(0)
    for i, c := range isbn {
        if c < '0' || c > '9' {
            return false
        }
        if i%2 == 0 {
            sum += c - '0'
        } else {
            sum += 3 * (c - '0')
        }
    }
    return sum%10 == 0
}

func main() {
    isbns := []string{"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
    for _, isbn := range isbns {
        res := "bad"
        if checkIsbn13(isbn) {
            res = "good"
        }
        fmt.Printf("%s: %s\n", isbn, res)
    }
}
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}





Java: public static void main(){
        System.out.println(isISBN13("978-1734314502"));
        System.out.println(isISBN13("978-1734314509"));
        System.out.println(isISBN13("978-1788399081"));
        System.out.println(isISBN13("978-1788399083"));
    }
public static boolean isISBN13(String in){
        int pre = Integer.parseInt(in.substring(0,3));
        if (pre!=978)return false;
        String postStr = in.substring(4);
        if (postStr.length()!=10)return false;
        int post = Integer.parseInt(postStr);
        int sum = 38;
        for(int x = 0; x<10;x+=2)
        sum += (postStr.charAt(x)-48)*3 + ((postStr.charAt(x+1)-48));
        if(sum%10==0) return true;
        return false;
    }
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}







Python: def is_isbn13(n):
    n = n.replace('-','').replace(' ', '')
    if len(n) != 13:
        return False
    product = (sum(int(ch) for ch in n[::2]) 
               + sum(int(ch) * 3 for ch in n[1::2]))
    return product % 10 == 0

if __name__ == '__main__':
    tests = .strip().split()
    for t in tests:
        print(f"ISBN13 {t} validates {is_isbn13(t)}")
Task: ISBN13 check digit

C: #include <stdio.h>

int check_isbn13(const char *isbn) {
    int ch = *isbn, count = 0, sum = 0;
    
    for ( ; ch != 0; ch = *++isbn, ++count) {
        
        if (ch == ' ' || ch == '-') {
            --count;
            continue;
        }
        if (ch < '0' || ch > '9') {
            return 0;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
    }
    if (count != 13) return 0;
    return !(sum%10);
}

int main() {
    int i;
    const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
    for (i = 0; i < 4; ++i) {
        printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
    }
    return 0;
}








VB: Module Module1

    Function CheckISBN13(code As String) As Boolean
        code = code.Replace("-", "").Replace(" ", "")
        If code.Length <> 13 Then
            Return False
        End If
        Dim sum = 0
        For Each i_d In code.Select(Function(digit, index) (index, digit))
            Dim index = i_d.index
            Dim digit = i_d.digit
            If Char.IsDigit(digit) Then
                sum += (Asc(digit) - Asc("0")) * If(index Mod 2 = 0, 1, 3)
            Else
                Return False
            End If
        Next
        Return sum Mod 10 = 0
    End Function

    Sub Main()
        Console.WriteLine(CheckISBN13("978-1734314502"))
        Console.WriteLine(CheckISBN13("978-1734314509"))
        Console.WriteLine(CheckISBN13("978-1788399081"))
        Console.WriteLine(CheckISBN13("978-1788399083"))
    End Sub

End Module
Task: ISBN13 check digit


C++: #include <iostream>

bool check_isbn13(std::string isbn) {
    int count = 0;
    int sum = 0;

    for (auto ch : isbn) {
        
        if (ch == ' ' || ch == '-') {
            continue;
        }
        if (ch < '0' || ch > '9') {
            return false;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
        count++;
    }

    if (count != 13) {
        return false;
    }
    return sum % 10 == 0;
}

int main() {
    auto isbns = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" };
    for (auto isbn : isbns) {
        std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
    }

    return 0;
}


C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(CheckISBN13("978-1734314502"));
        Console.WriteLine(CheckISBN13("978-1734314509"));
        Console.WriteLine(CheckISBN13("978-1788399081"));
        Console.WriteLine(CheckISBN13("978-1788399083"));

        static bool CheckISBN13(string code) {
            code = code.Replace("-", "").Replace(" ", "");
            if (code.Length != 13) return false;
            int sum = 0;
            foreach (var (index, digit) in code.Select((digit, index) => (index, digit))) {
                if (char.IsDigit(digit)) sum += (digit - '0') * (index % 2 == 0 ? 1 : 3);
                else return false;
            }
            return sum % 10 == 0;
        }
    }
}
Task: ISBN13 check digit


C++: #include <iostream>

bool check_isbn13(std::string isbn) {
    int count = 0;
    int sum = 0;

    for (auto ch : isbn) {
        
        if (ch == ' ' || ch == '-') {
            continue;
        }
        if (ch < '0' || ch > '9') {
            return false;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
        count++;
    }

    if (count != 13) {
        return false;
    }
    return sum % 10 == 0;
}

int main() {
    auto isbns = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" };
    for (auto isbn : isbns) {
        std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
    }

    return 0;
}



Go: package main

import (
    "fmt"
    "strings"
    "unicode/utf8"
)

func checkIsbn13(isbn string) bool {
    
    isbn = strings.ReplaceAll(strings.ReplaceAll(isbn, "-", ""), " ", "")
    
    le := utf8.RuneCountInString(isbn)
    if le != 13 {
        return false
    }
    
    sum := int32(0)
    for i, c := range isbn {
        if c < '0' || c > '9' {
            return false
        }
        if i%2 == 0 {
            sum += c - '0'
        } else {
            sum += 3 * (c - '0')
        }
    }
    return sum%10 == 0
}

func main() {
    isbns := []string{"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
    for _, isbn := range isbns {
        res := "bad"
        if checkIsbn13(isbn) {
            res = "good"
        }
        fmt.Printf("%s: %s\n", isbn, res)
    }
}
Task: ISBN13 check digit


C++: #include <iostream>

bool check_isbn13(std::string isbn) {
    int count = 0;
    int sum = 0;

    for (auto ch : isbn) {
        
        if (ch == ' ' || ch == '-') {
            continue;
        }
        if (ch < '0' || ch > '9') {
            return false;
        }
        if (count & 1) {
            sum += 3 * (ch - '0');
        } else {
            sum += ch - '0';
        }
        count++;
    }

    if (count != 13) {
        return false;
    }
    return sum % 10 == 0;
}

int main() {
    auto isbns = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" };
    for (auto isbn : isbns) {
        std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
    }

    return 0;
}






Python: def is_isbn13(n):
    n = n.replace('-','').replace(' ', '')
    if len(n) != 13:
        return False
    product = (sum(int(ch) for ch in n[::2]) 
               + sum(int(ch) * 3 for ch in n[1::2]))
    return product % 10 == 0

if __name__ == '__main__':
    tests = .strip().split()
    for t in tests:
        print(f"ISBN13 {t} validates {is_isbn13(t)}")
Task: ISBN13 check digit



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(CheckISBN13("978-1734314502"));
        Console.WriteLine(CheckISBN13("978-1734314509"));
        Console.WriteLine(CheckISBN13("978-1788399081"));
        Console.WriteLine(CheckISBN13("978-1788399083"));

        static bool CheckISBN13(string code) {
            code = code.Replace("-", "").Replace(" ", "");
            if (code.Length != 13) return false;
            int sum = 0;
            foreach (var (index, digit) in code.Select((digit, index) => (index, digit))) {
                if (char.IsDigit(digit)) sum += (digit - '0') * (index % 2 == 0 ? 1 : 3);
                else return false;
            }
            return sum % 10 == 0;
        }
    }
}


Go: package main

import (
    "fmt"
    "strings"
    "unicode/utf8"
)

func checkIsbn13(isbn string) bool {
    
    isbn = strings.ReplaceAll(strings.ReplaceAll(isbn, "-", ""), " ", "")
    
    le := utf8.RuneCountInString(isbn)
    if le != 13 {
        return false
    }
    
    sum := int32(0)
    for i, c := range isbn {
        if c < '0' || c > '9' {
            return false
        }
        if i%2 == 0 {
            sum += c - '0'
        } else {
            sum += 3 * (c - '0')
        }
    }
    return sum%10 == 0
}

func main() {
    isbns := []string{"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
    for _, isbn := range isbns {
        res := "bad"
        if checkIsbn13(isbn) {
            res = "good"
        }
        fmt.Printf("%s: %s\n", isbn, res)
    }
}
Task: ISBN13 check digit



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(CheckISBN13("978-1734314502"));
        Console.WriteLine(CheckISBN13("978-1734314509"));
        Console.WriteLine(CheckISBN13("978-1788399081"));
        Console.WriteLine(CheckISBN13("978-1788399083"));

        static bool CheckISBN13(string code) {
            code = code.Replace("-", "").Replace(" ", "");
            if (code.Length != 13) return false;
            int sum = 0;
            foreach (var (index, digit) in code.Select((digit, index) => (index, digit))) {
                if (char.IsDigit(digit)) sum += (digit - '0') * (index % 2 == 0 ? 1 : 3);
                else return false;
            }
            return sum % 10 == 0;
        }
    }
}



Java: public static void main(){
        System.out.println(isISBN13("978-1734314502"));
        System.out.println(isISBN13("978-1734314509"));
        System.out.println(isISBN13("978-1788399081"));
        System.out.println(isISBN13("978-1788399083"));
    }
public static boolean isISBN13(String in){
        int pre = Integer.parseInt(in.substring(0,3));
        if (pre!=978)return false;
        String postStr = in.substring(4);
        if (postStr.length()!=10)return false;
        int post = Integer.parseInt(postStr);
        int sum = 38;
        for(int x = 0; x<10;x+=2)
        sum += (postStr.charAt(x)-48)*3 + ((postStr.charAt(x+1)-48));
        if(sum%10==0) return true;
        return false;
    }