Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Translate the given D code snippet into Go without altering its behavior. | import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
char checksum(in char[] sedol) pure @safe
in {
assert(sedol.length == 6);
foreach (immutable c; sedol)
assert(c.isDigit || (c.isUpper && !"AEIOU".canFind(c)));
} out (result) {
assert(result.isDigit);
} body {
static immutabl... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Write the same code in C as shown below in Delphi. | program Sedol;
uses
SysUtils;
const
SEDOL_CHR_COUNT = 6;
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
VOWELS = ['A', 'E', 'I', 'O', 'U'];
ACCEPTABLE_CHRS = DIGITS + LETTERS - VOWELS;
WEIGHTS : ARRAY [1..SEDOL_CHR_COUNT] of integer = (1, 3, 1, 7, 3, 9);
LETTER_OFFSET = 9;
function AddSedolCheckDigit... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Write the same code in C# as shown below in Delphi. | program Sedol;
uses
SysUtils;
const
SEDOL_CHR_COUNT = 6;
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
VOWELS = ['A', 'E', 'I', 'O', 'U'];
ACCEPTABLE_CHRS = DIGITS + LETTERS - VOWELS;
WEIGHTS : ARRAY [1..SEDOL_CHR_COUNT] of integer = (1, 3, 1, 7, 3, 9);
LETTER_OFFSET = 9;
function AddSedolCheckDigit... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Convert this Delphi block to C++, preserving its control flow and logic. | program Sedol;
uses
SysUtils;
const
SEDOL_CHR_COUNT = 6;
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
VOWELS = ['A', 'E', 'I', 'O', 'U'];
ACCEPTABLE_CHRS = DIGITS + LETTERS - VOWELS;
WEIGHTS : ARRAY [1..SEDOL_CHR_COUNT] of integer = (1, 3, 1, 7, 3, 9);
LETTER_OFFSET = 9;
function AddSedolCheckDigit... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Write the same code in Java as shown below in Delphi. | program Sedol;
uses
SysUtils;
const
SEDOL_CHR_COUNT = 6;
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
VOWELS = ['A', 'E', 'I', 'O', 'U'];
ACCEPTABLE_CHRS = DIGITS + LETTERS - VOWELS;
WEIGHTS : ARRAY [1..SEDOL_CHR_COUNT] of integer = (1, 3, 1, 7, 3, 9);
LETTER_OFFSET = 9;
function AddSedolCheckDigit... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Preserve the algorithm and functionality while converting the code from Delphi to Python. | program Sedol;
uses
SysUtils;
const
SEDOL_CHR_COUNT = 6;
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
VOWELS = ['A', 'E', 'I', 'O', 'U'];
ACCEPTABLE_CHRS = DIGITS + LETTERS - VOWELS;
WEIGHTS : ARRAY [1..SEDOL_CHR_COUNT] of integer = (1, 3, 1, 7, 3, 9);
LETTER_OFFSET = 9;
function AddSedolCheckDigit... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Transform the following Delphi implementation into Go, maintaining the same output and logic. | program Sedol;
uses
SysUtils;
const
SEDOL_CHR_COUNT = 6;
DIGITS = ['0'..'9'];
LETTERS = ['A'..'Z'];
VOWELS = ['A', 'E', 'I', 'O', 'U'];
ACCEPTABLE_CHRS = DIGITS + LETTERS - VOWELS;
WEIGHTS : ARRAY [1..SEDOL_CHR_COUNT] of integer = (1, 3, 1, 7, 3, 9);
LETTER_OFFSET = 9;
function AddSedolCheckDigit... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Produce a language-to-language conversion: from Elixir to C, same semantics. | defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
defp char2value(c) do
unless c in @sedol_char, do: raise ArgumentError, "No vowels"
String.to_integer(c,36)
end
def checksum(sedol) do
if String.length(sedol) != length(@sedolwe... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Produce a language-to-language conversion: from Elixir to C#, same semantics. | defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
defp char2value(c) do
unless c in @sedol_char, do: raise ArgumentError, "No vowels"
String.to_integer(c,36)
end
def checksum(sedol) do
if String.length(sedol) != length(@sedolwe... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Convert this Elixir block to C++, preserving its control flow and logic. | defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
defp char2value(c) do
unless c in @sedol_char, do: raise ArgumentError, "No vowels"
String.to_integer(c,36)
end
def checksum(sedol) do
if String.length(sedol) != length(@sedolwe... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Translate the given Elixir code snippet into Java without altering its behavior. | defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
defp char2value(c) do
unless c in @sedol_char, do: raise ArgumentError, "No vowels"
String.to_integer(c,36)
end
def checksum(sedol) do
if String.length(sedol) != length(@sedolwe... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Preserve the algorithm and functionality while converting the code from Elixir to Python. | defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
defp char2value(c) do
unless c in @sedol_char, do: raise ArgumentError, "No vowels"
String.to_integer(c,36)
end
def checksum(sedol) do
if String.length(sedol) != length(@sedolwe... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Generate an equivalent Go version of this Elixir code. | defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
defp char2value(c) do
unless c in @sedol_char, do: raise ArgumentError, "No vowels"
String.to_integer(c,36)
end
def checksum(sedol) do
if String.length(sedol) != length(@sedolwe... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Produce a functionally identical C code for the snippet given in F#. | open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
let Vowels = set ['A'; 'E'; 'I'; 'O'; 'U']
let Weights = [1; 3; 1; 7; 3; 9; 1]
let inline isVowel c = Vowels.Contains (Char.ToUpper c)
let char2value c =
if Char... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Write the same algorithm in C# as shown in this F# implementation. | open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
let Vowels = set ['A'; 'E'; 'I'; 'O'; 'U']
let Weights = [1; 3; 1; 7; 3; 9; 1]
let inline isVowel c = Vowels.Contains (Char.ToUpper c)
let char2value c =
if Char... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Produce a language-to-language conversion: from F# to C++, same semantics. | open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
let Vowels = set ['A'; 'E'; 'I'; 'O'; 'U']
let Weights = [1; 3; 1; 7; 3; 9; 1]
let inline isVowel c = Vowels.Contains (Char.ToUpper c)
let char2value c =
if Char... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Translate the given F# code snippet into Java without altering its behavior. | open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
let Vowels = set ['A'; 'E'; 'I'; 'O'; 'U']
let Weights = [1; 3; 1; 7; 3; 9; 1]
let inline isVowel c = Vowels.Contains (Char.ToUpper c)
let char2value c =
if Char... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Maintain the same structure and functionality when rewriting this code in Python. | open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
let Vowels = set ['A'; 'E'; 'I'; 'O'; 'U']
let Weights = [1; 3; 1; 7; 3; 9; 1]
let inline isVowel c = Vowels.Contains (Char.ToUpper c)
let char2value c =
if Char... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Convert the following code from F# to Go, ensuring the logic remains intact. | open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
let Vowels = set ['A'; 'E'; 'I'; 'O'; 'U']
let Weights = [1; 3; 1; 7; 3; 9; 1]
let inline isVowel c = Vowels.Contains (Char.ToUpper c)
let char2value c =
if Char... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Change the following Factor code into C without altering its purpose. | USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
<PRIVATE
CONSTANT: input {
"710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL"
"557910" "B0YBKR" "585284" "B0YBKT" "B00030" "AEIOUA"
"123" "" "B_7K90"
}
CONSTAN... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Produce a functionally identical C# code for the snippet given in Factor. | USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
<PRIVATE
CONSTANT: input {
"710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL"
"557910" "B0YBKR" "585284" "B0YBKT" "B00030" "AEIOUA"
"123" "" "B_7K90"
}
CONSTAN... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Change the following Factor code into C++ without altering its purpose. | USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
<PRIVATE
CONSTANT: input {
"710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL"
"557910" "B0YBKR" "585284" "B0YBKT" "B00030" "AEIOUA"
"123" "" "B_7K90"
}
CONSTAN... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Produce a functionally identical Java code for the snippet given in Factor. | USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
<PRIVATE
CONSTANT: input {
"710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL"
"557910" "B0YBKR" "585284" "B0YBKT" "B00030" "AEIOUA"
"123" "" "B_7K90"
}
CONSTAN... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Write the same code in Python as shown below in Factor. | USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
<PRIVATE
CONSTANT: input {
"710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL"
"557910" "B0YBKR" "585284" "B0YBKT" "B00030" "AEIOUA"
"123" "" "B_7K90"
}
CONSTAN... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Change the programming language of this snippet from Factor to Go without modifying what it does. | USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
<PRIVATE
CONSTANT: input {
"710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL"
"557910" "B0YBKR" "585284" "B0YBKT" "B00030" "AEIOUA"
"123" "" "B_7K90"
}
CONSTAN... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Produce a language-to-language conversion: from Forth to C, same semantics. | create weight 1 , 3 , 1 , 7 , 3 , 9 ,
: char>num
dup [char] 9 > 7 and - [char] 0 - ;
: check+
6 <> abort" wrong SEDOL length"
0
6 0 do
over I + c@ char>num
weight I cells + @ *
+
loop
10 mod 10 swap - 10 mod [char] 0 +
over 6 + c! 7 ;
: sedol" [char] " parse check+ type ;
sedol" 7... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Maintain the same structure and functionality when rewriting this code in C#. | create weight 1 , 3 , 1 , 7 , 3 , 9 ,
: char>num
dup [char] 9 > 7 and - [char] 0 - ;
: check+
6 <> abort" wrong SEDOL length"
0
6 0 do
over I + c@ char>num
weight I cells + @ *
+
loop
10 mod 10 swap - 10 mod [char] 0 +
over 6 + c! 7 ;
: sedol" [char] " parse check+ type ;
sedol" 7... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Ensure the translated C++ code behaves exactly like the original Forth snippet. | create weight 1 , 3 , 1 , 7 , 3 , 9 ,
: char>num
dup [char] 9 > 7 and - [char] 0 - ;
: check+
6 <> abort" wrong SEDOL length"
0
6 0 do
over I + c@ char>num
weight I cells + @ *
+
loop
10 mod 10 swap - 10 mod [char] 0 +
over 6 + c! 7 ;
: sedol" [char] " parse check+ type ;
sedol" 7... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Change the programming language of this snippet from Forth to Java without modifying what it does. | create weight 1 , 3 , 1 , 7 , 3 , 9 ,
: char>num
dup [char] 9 > 7 and - [char] 0 - ;
: check+
6 <> abort" wrong SEDOL length"
0
6 0 do
over I + c@ char>num
weight I cells + @ *
+
loop
10 mod 10 swap - 10 mod [char] 0 +
over 6 + c! 7 ;
: sedol" [char] " parse check+ type ;
sedol" 7... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Port the following code from Forth to Python with equivalent syntax and logic. | create weight 1 , 3 , 1 , 7 , 3 , 9 ,
: char>num
dup [char] 9 > 7 and - [char] 0 - ;
: check+
6 <> abort" wrong SEDOL length"
0
6 0 do
over I + c@ char>num
weight I cells + @ *
+
loop
10 mod 10 swap - 10 mod [char] 0 +
over 6 + c! 7 ;
: sedol" [char] " parse check+ type ;
sedol" 7... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Please provide an equivalent version of this Forth code in Go. | create weight 1 , 3 , 1 , 7 , 3 , 9 ,
: char>num
dup [char] 9 > 7 and - [char] 0 - ;
: check+
6 <> abort" wrong SEDOL length"
0
6 0 do
over I + c@ char>num
weight I cells + @ *
+
loop
10 mod 10 swap - 10 mod [char] 0 +
over 6 + c! 7 ;
: sedol" [char] " parse check+ type ;
sedol" 7... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Change the following Fortran code into C# without altering its purpose. | MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Keep all operations the same but rewrite the snippet in C++. | MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Preserve the algorithm and functionality while converting the code from Fortran to C. | MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Produce a functionally identical Java code for the snippet given in Fortran. | MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Preserve the algorithm and functionality while converting the code from Fortran to Python. | MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Generate an equivalent PHP version of this Fortran code. | MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i... | function char2value($c) {
assert(stripos('AEIOU', $c) === FALSE);
return intval($c, 36);
}
$sedolweight = array(1,3,1,7,3,9);
function checksum($sedol) {
global $sedolweight;
$tmp = array_sum(array_map(create_function('$ch, $weight', 'return char2value($ch) * $weight;'),
str... |
Please provide an equivalent version of this Groovy code in C. | def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Maintain the same structure and functionality when rewriting this code in C#. | def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Please provide an equivalent version of this Groovy code in C++. | def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Translate this program into Java but keep the logic exactly as in Groovy. | def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Produce a functionally identical Python code for the snippet given in Groovy. | def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Maintain the same structure and functionality when rewriting this code in Go. | def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Port the provided Haskell code into C while preserving the original functionality. | import Data.Char (isAsciiUpper, isDigit, ord)
checkSum :: String -> String
checkSum x =
case traverse sedolValue x of
Right xs -> (show . checkSumFromSedolValues) xs
Left annotated -> annotated
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
rem
( 10
- rem
( su... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Produce a language-to-language conversion: from Haskell to C++, same semantics. | import Data.Char (isAsciiUpper, isDigit, ord)
checkSum :: String -> String
checkSum x =
case traverse sedolValue x of
Right xs -> (show . checkSumFromSedolValues) xs
Left annotated -> annotated
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
rem
( 10
- rem
( su... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Generate an equivalent Java version of this Haskell code. | import Data.Char (isAsciiUpper, isDigit, ord)
checkSum :: String -> String
checkSum x =
case traverse sedolValue x of
Right xs -> (show . checkSumFromSedolValues) xs
Left annotated -> annotated
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
rem
( 10
- rem
( su... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Generate a Python translation of this Haskell snippet without changing its computational steps. | import Data.Char (isAsciiUpper, isDigit, ord)
checkSum :: String -> String
checkSum x =
case traverse sedolValue x of
Right xs -> (show . checkSumFromSedolValues) xs
Left annotated -> annotated
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
rem
( 10
- rem
( su... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Keep all operations the same but rewrite the snippet in Go. | import Data.Char (isAsciiUpper, isDigit, ord)
checkSum :: String -> String
checkSum x =
case traverse sedolValue x of
Right xs -> (show . checkSumFromSedolValues) xs
Left annotated -> annotated
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
rem
( 10
- rem
( su... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Transform the following Icon implementation into C, maintaining the same output and logic. | procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
end
procedure sedol(x)
static w,c
initial {
every (i := -1, c := table())[!(&digits||&ucase)] := i +:= 1
every c[!"AEIOU"] := &null
w := [1,3... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Write the same code in C# as shown below in Icon. | procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
end
procedure sedol(x)
static w,c
initial {
every (i := -1, c := table())[!(&digits||&ucase)] := i +:= 1
every c[!"AEIOU"] := &null
w := [1,3... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Change the programming language of this snippet from Icon to C++ without modifying what it does. | procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
end
procedure sedol(x)
static w,c
initial {
every (i := -1, c := table())[!(&digits||&ucase)] := i +:= 1
every c[!"AEIOU"] := &null
w := [1,3... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Generate a Java translation of this Icon snippet without changing its computational steps. | procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
end
procedure sedol(x)
static w,c
initial {
every (i := -1, c := table())[!(&digits||&ucase)] := i +:= 1
every c[!"AEIOU"] := &null
w := [1,3... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Change the programming language of this snippet from Icon to Python without modifying what it does. | procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
end
procedure sedol(x)
static w,c
initial {
every (i := -1, c := table())[!(&digits||&ucase)] := i +:= 1
every c[!"AEIOU"] := &null
w := [1,3... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Rewrite this program in Go while keeping its functionality equivalent to the Icon version. | procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
end
procedure sedol(x)
static w,c
initial {
every (i := -1, c := table())[!(&digits||&ucase)] := i +:= 1
every c[!"AEIOU"] := &null
w := [1,3... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Convert this J snippet to C and keep its semantics consistent. | sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
| #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Rewrite this program in C# while keeping its functionality equivalent to the J version. | sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
| static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Change the programming language of this snippet from J to C++ without modifying what it does. | sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
| #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Convert this J snippet to Java and keep its semantics consistent. | sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
| import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Transform the following J implementation into Python, maintaining the same output and logic. | sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
| def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Write the same code in Go as shown below in J. | sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)
| package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Write the same algorithm in C as shown in this Julia implementation. | using Base.Test
function appendchecksum(chars::AbstractString)
if !all(isalnum, chars) throw(ArgumentError("invalid SEDOL number '$chars'")) end
weights = [1, 3, 1, 7, 3, 9, 1]
s = 0
for (w, c) in zip(weights, chars)
s += w * parse(Int, c, 36)
end
return string(chars, (10 - s % 10) % 1... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Write a version of this Julia function in C# with identical behavior. | using Base.Test
function appendchecksum(chars::AbstractString)
if !all(isalnum, chars) throw(ArgumentError("invalid SEDOL number '$chars'")) end
weights = [1, 3, 1, 7, 3, 9, 1]
s = 0
for (w, c) in zip(weights, chars)
s += w * parse(Int, c, 36)
end
return string(chars, (10 - s % 10) % 1... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Ensure the translated C++ code behaves exactly like the original Julia snippet. | using Base.Test
function appendchecksum(chars::AbstractString)
if !all(isalnum, chars) throw(ArgumentError("invalid SEDOL number '$chars'")) end
weights = [1, 3, 1, 7, 3, 9, 1]
s = 0
for (w, c) in zip(weights, chars)
s += w * parse(Int, c, 36)
end
return string(chars, (10 - s % 10) % 1... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Port the following code from Julia to Java with equivalent syntax and logic. | using Base.Test
function appendchecksum(chars::AbstractString)
if !all(isalnum, chars) throw(ArgumentError("invalid SEDOL number '$chars'")) end
weights = [1, 3, 1, 7, 3, 9, 1]
s = 0
for (w, c) in zip(weights, chars)
s += w * parse(Int, c, 36)
end
return string(chars, (10 - s % 10) % 1... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Translate this program into Python but keep the logic exactly as in Julia. | using Base.Test
function appendchecksum(chars::AbstractString)
if !all(isalnum, chars) throw(ArgumentError("invalid SEDOL number '$chars'")) end
weights = [1, 3, 1, 7, 3, 9, 1]
s = 0
for (w, c) in zip(weights, chars)
s += w * parse(Int, c, 36)
end
return string(chars, (10 - s % 10) % 1... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Produce a functionally identical Go code for the snippet given in Julia. | using Base.Test
function appendchecksum(chars::AbstractString)
if !all(isalnum, chars) throw(ArgumentError("invalid SEDOL number '$chars'")) end
weights = [1, 3, 1, 7, 3, 9, 1]
s = 0
for (w, c) in zip(weights, chars)
s += w * parse(Int, c, 36)
end
return string(chars, (10 - s % 10) % 1... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Generate an equivalent C version of this Mathematica code. | SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUM... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Port the following code from Mathematica to C# with equivalent syntax and logic. | SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUM... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Keep all operations the same but rewrite the snippet in C++. | SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUM... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Translate the given Mathematica code snippet into Java without altering its behavior. | SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUM... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Rewrite this program in Python while keeping its functionality equivalent to the Mathematica version. | SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUM... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Write the same algorithm in Go as shown in this Mathematica implementation. | SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUM... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Please provide an equivalent version of this Nim code in C. | proc c2v(c: char): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Convert this Nim snippet to C# and keep its semantics consistent. | proc c2v(c: char): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Transform the following Nim implementation into C++, maintaining the same output and logic. | proc c2v(c: char): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Generate an equivalent Java version of this Nim code. | proc c2v(c: char): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Can you help me rewrite this code in Python instead of Nim, keeping it the same logically? | proc c2v(c: char): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Rewrite this program in Go while keeping its functionality equivalent to the Nim version. | proc c2v(c: char): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Write the same algorithm in C as shown in this OCaml implementation. | let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
| '0'..'9' -> int_of_char c - int_of_char '0'
| 'A'..'Z' -> int_of_char c - int_of_char 'A' + 10
| _ -> assert false
let sedolweight = [1;3;1;7;3;9]
let explode s =
s |> String.to_seq |> List.of_seq
let checksum sedol =
let tm... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Can you help me rewrite this code in C# instead of OCaml, keeping it the same logically? | let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
| '0'..'9' -> int_of_char c - int_of_char '0'
| 'A'..'Z' -> int_of_char c - int_of_char 'A' + 10
| _ -> assert false
let sedolweight = [1;3;1;7;3;9]
let explode s =
s |> String.to_seq |> List.of_seq
let checksum sedol =
let tm... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Ensure the translated C++ code behaves exactly like the original OCaml snippet. | let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
| '0'..'9' -> int_of_char c - int_of_char '0'
| 'A'..'Z' -> int_of_char c - int_of_char 'A' + 10
| _ -> assert false
let sedolweight = [1;3;1;7;3;9]
let explode s =
s |> String.to_seq |> List.of_seq
let checksum sedol =
let tm... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Generate a Java translation of this OCaml snippet without changing its computational steps. | let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
| '0'..'9' -> int_of_char c - int_of_char '0'
| 'A'..'Z' -> int_of_char c - int_of_char 'A' + 10
| _ -> assert false
let sedolweight = [1;3;1;7;3;9]
let explode s =
s |> String.to_seq |> List.of_seq
let checksum sedol =
let tm... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Produce a functionally identical Python code for the snippet given in OCaml. | let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
| '0'..'9' -> int_of_char c - int_of_char '0'
| 'A'..'Z' -> int_of_char c - int_of_char 'A' + 10
| _ -> assert false
let sedolweight = [1;3;1;7;3;9]
let explode s =
s |> String.to_seq |> List.of_seq
let checksum sedol =
let tm... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Convert this OCaml block to Go, preserving its control flow and logic. | let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
| '0'..'9' -> int_of_char c - int_of_char '0'
| 'A'..'Z' -> int_of_char c - int_of_char 'A' + 10
| _ -> assert false
let sedolweight = [1;3;1;7;3;9]
let explode s =
s |> String.to_seq |> List.of_seq
let checksum sedol =
let tm... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Produce a functionally identical C code for the snippet given in Pascal. | program Sedols(output);
function index(c: char): integer;
const
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i: integer;
begin
index := 0;
for i := low(alpha) to high(alpha) do
if c = alpha[i] then
index := i;
end;
function checkdigit(c: string): char;
const
weight: ... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Rewrite the snippet below in C# so it works the same as the original Pascal code. | program Sedols(output);
function index(c: char): integer;
const
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i: integer;
begin
index := 0;
for i := low(alpha) to high(alpha) do
if c = alpha[i] then
index := i;
end;
function checkdigit(c: string): char;
const
weight: ... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Port the following code from Pascal to C++ with equivalent syntax and logic. | program Sedols(output);
function index(c: char): integer;
const
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i: integer;
begin
index := 0;
for i := low(alpha) to high(alpha) do
if c = alpha[i] then
index := i;
end;
function checkdigit(c: string): char;
const
weight: ... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Convert this Pascal block to Java, preserving its control flow and logic. | program Sedols(output);
function index(c: char): integer;
const
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i: integer;
begin
index := 0;
for i := low(alpha) to high(alpha) do
if c = alpha[i] then
index := i;
end;
function checkdigit(c: string): char;
const
weight: ... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Generate an equivalent Python version of this Pascal code. | program Sedols(output);
function index(c: char): integer;
const
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i: integer;
begin
index := 0;
for i := low(alpha) to high(alpha) do
if c = alpha[i] then
index := i;
end;
function checkdigit(c: string): char;
const
weight: ... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Translate the given Pascal code snippet into Go without altering its behavior. | program Sedols(output);
function index(c: char): integer;
const
alpha = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i: integer;
begin
index := 0;
for i := low(alpha) to high(alpha) do
if c = alpha[i] then
index := i;
end;
function checkdigit(c: string): char;
const
weight: ... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Rewrite the snippet below in C so it works the same as the original Perl code. | use List::Util qw(sum);
use POSIX qw(strtol);
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
my @b = @{shift()};
my @result;
push(@result, $f->(shift @a, shift @b)) while @a && @b;
return @result;
}
my @weights = (1, 3, 1, 7, 3, 9);
sub sedan :prototype($) {
my $s = shift;
$s =~ /[AEIO... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Keep all operations the same but rewrite the snippet in C#. | use List::Util qw(sum);
use POSIX qw(strtol);
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
my @b = @{shift()};
my @result;
push(@result, $f->(shift @a, shift @b)) while @a && @b;
return @result;
}
my @weights = (1, 3, 1, 7, 3, 9);
sub sedan :prototype($) {
my $s = shift;
$s =~ /[AEIO... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Generate an equivalent C++ version of this Perl code. | use List::Util qw(sum);
use POSIX qw(strtol);
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
my @b = @{shift()};
my @result;
push(@result, $f->(shift @a, shift @b)) while @a && @b;
return @result;
}
my @weights = (1, 3, 1, 7, 3, 9);
sub sedan :prototype($) {
my $s = shift;
$s =~ /[AEIO... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Produce a functionally identical Java code for the snippet given in Perl. | use List::Util qw(sum);
use POSIX qw(strtol);
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
my @b = @{shift()};
my @result;
push(@result, $f->(shift @a, shift @b)) while @a && @b;
return @result;
}
my @weights = (1, 3, 1, 7, 3, 9);
sub sedan :prototype($) {
my $s = shift;
$s =~ /[AEIO... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Rewrite the snippet below in Python so it works the same as the original Perl code. | use List::Util qw(sum);
use POSIX qw(strtol);
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
my @b = @{shift()};
my @result;
push(@result, $f->(shift @a, shift @b)) while @a && @b;
return @result;
}
my @weights = (1, 3, 1, 7, 3, 9);
sub sedan :prototype($) {
my $s = shift;
$s =~ /[AEIO... | def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
sedolweight = [1,3,1,7,3,9]
def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
for sedol in .split():
print s... |
Convert the following code from Perl to Go, ensuring the logic remains intact. | use List::Util qw(sum);
use POSIX qw(strtol);
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
my @b = @{shift()};
my @result;
push(@result, $f->(shift @a, shift @b)) while @a && @b;
return @result;
}
my @weights = (1, 3, 1, 7, 3, 9);
sub sedan :prototype($) {
my $s = shift;
$s =~ /[AEIO... | package main
import (
"fmt"
"strings"
"strconv"
)
const input = `710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
B
B0003
B000300
A00030
E00030
I00030
O00030
U00030
β00030
β0003`
var weight = [...]int{1,3,1,7,3,9}
func csd(code string) string {
switch len(code) {
cas... |
Convert this PowerShell snippet to C and keep its semantics consistent. | function Add-SEDOLCheckDigit
{
Param (
[ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )]
[parameter ( Mandatory = $True ) ]
[string]
$SixDigitSEDOL )
$SEDOL = [string[]][char[]]$SixDigitSEDOL
$Weight = @( 1, 3, 1, 7, 3, 9 )
... | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int sedol_weights[] = {1, 3, 1, 7, 3, 9};
const char *reject = "AEIOUaeiou";
int sedol_checksum(const char *sedol6)
{
int len = strlen(sedol6);
int sum = 0, i;
if ( len == 7 ) {
fprintf(stderr, "SEDOL code already checksummed? (%s)\n", sedol6);
... |
Port the following code from PowerShell to C# with equivalent syntax and logic. | function Add-SEDOLCheckDigit
{
Param (
[ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )]
[parameter ( Mandatory = $True ) ]
[string]
$SixDigitSEDOL )
$SEDOL = [string[]][char[]]$SixDigitSEDOL
$Weight = @( 1, 3, 1, 7, 3, 9 )
... | static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
if (len == 7)
return (int)sedol[6];
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+"))
return -1;
for... |
Keep all operations the same but rewrite the snippet in C++. | function Add-SEDOLCheckDigit
{
Param (
[ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )]
[parameter ( Mandatory = $True ) ]
[string]
$SixDigitSEDOL )
$SEDOL = [string[]][char[]]$SixDigitSEDOL
$Weight = @( 1, 3, 1, 7, 3, 9 )
... | #include <numeric>
#include <cctype>
#include <iostream>
#include <string>
template<typename result_sink_t>
auto sedol_checksum(std::string const& sedol, result_sink_t result_sink)
{
if(sedol.size() != 6)
return result_sink(0, "length of sedol string != 6");
const char * valid_chars = "BCDF... |
Port the following code from PowerShell to Java with equivalent syntax and logic. | function Add-SEDOLCheckDigit
{
Param (
[ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )]
[parameter ( Mandatory = $True ) ]
[string]
$SixDigitSEDOL )
$SEDOL = [string[]][char[]]$SixDigitSEDOL
$Weight = @( 1, 3, 1, 7, 3, 9 )
... | import java.util.Scanner;
public class SEDOL{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String sedol = sc.next();
System.out.println(sedol + getSedolCheckDigit(sedol));
}
}
private static final int[] mult = {1, 3, 1, 7, 3, 9};
public static in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.