Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Can you help me rewrite this code in Python instead of PowerShell, keeping it the same logically?
function Add-SEDOLCheckDigit { Param ( [ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )] [parameter ( Mandatory = $True ) ] [string] $SixDigitSEDOL ) $SEDOL = [string[]][char[]]$SixDigitSEDOL $Weight = @( 1, 3, 1, 7, 3, 9 ) ...
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 this program into Go but keep the logic exactly as in PowerShell.
function Add-SEDOLCheckDigit { Param ( [ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )] [parameter ( Mandatory = $True ) ] [string] $SixDigitSEDOL ) $SEDOL = [string[]][char[]]$SixDigitSEDOL $Weight = @( 1, 3, 1, 7, 3, 9 ) ...
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 Racket block to C, preserving its control flow and logic.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
#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 Racket implementation.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
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 Racket code in C++.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
#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...
Ensure the translated Java code behaves exactly like the original Racket snippet.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
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 Racket code.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
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...
Preserve the algorithm and functionality while converting the code from Racket to Go.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
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 COBOL to C, same semantics.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
#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 COBOL.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
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 COBOL implementation into C++, maintaining the same output and logic.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
#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 COBOL block to Java, preserving its control flow and logic.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
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...
Ensure the translated Python code behaves exactly like the original COBOL snippet.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
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 COBOL code.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
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 REXX snippet to C and keep its semantics consistent.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
#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); ...
Translate this program into C# but keep the logic exactly as in REXX.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
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 REXX code into C++ without altering its purpose.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
#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 REXX block to Java, preserving its control flow and logic.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
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...
Convert the following code from REXX to Python, ensuring the logic remains intact.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
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...
Ensure the translated Go code behaves exactly like the original REXX snippet.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
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 Ruby implementation.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
#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 Ruby to C#, same semantics.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
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...
Rewrite the snippet below in C++ so it works the same as the original Ruby code.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
#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 Ruby to Java with equivalent syntax and logic.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
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 Ruby.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
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 this program into Go but keep the logic exactly as in Ruby.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
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 Scala implementation into C, maintaining the same output and logic.
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
#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 Scala, keeping it the same logically?
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
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 a C++ translation of this Scala snippet without changing its computational steps.
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
#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...
Transform the following Scala implementation into Java, maintaining the same output and logic.
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
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...
Ensure the translated Python code behaves exactly like the original Scala snippet.
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
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 language-to-language conversion: from Scala to Go, same semantics.
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
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...
Preserve the algorithm and functionality while converting the code from Tcl to C.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
#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); ...
Change the following Tcl code into C# without altering its purpose.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
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 a C++ translation of this Tcl snippet without changing its computational steps.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
#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 Tcl.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
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...
Convert the following code from Tcl to Python, ensuring the logic remains intact.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
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...
Port the following code from Tcl to Go with equivalent syntax and logic.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
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 this program in PHP while keeping its functionality equivalent to the Rust version.
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
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...
Write a version of this Ada function in PHP with identical behavior.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_SEDOL is subtype SEDOL_String is String (1..6); type SEDOL_Sum is range 0..9; function Check (SEDOL : SEDOL_String) return SEDOL_Sum is Weight : constant array (SEDOL_String'Range) of Integer := (1,3,1,7,3,9); Sum : Integer := 0; Item ...
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...
Generate a PHP translation of this Arturo snippet without changing its computational steps.
ord0: to :integer `0` ord7: to :integer `7` c2v: function [c][ ordC: to :integer c if? c < `A` -> return ordC - ord0 else -> return ordC - ord7 ] weight: [1 3 1 7 3 9] checksum: function [sedol][ val: new 0 loop .with:'i sedol 'ch -> 'val + weight\[i] * c2v ch return to :char ord0 + (1...
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...
Can you help me rewrite this code in PHP instead of AutoHotKey, keeping it the same logically?
codes = 710889,B0YBKJ,406566,B0YBLH,228276,B0YBKL,557910,B0YBKR,585284,B0YBKT,B00030,ABCDEF,BBBBBBB Loop, Parse, codes, `, output .= A_LoopField "`t-> " SEDOL(A_LoopField) "`n" Msgbox %output% SEDOL(code) { Static weight1:=1, weight2:=3, weight3:=1, weight4:=7, weight5:=3, weight6:=9 If (StrLen(code) != 6)...
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...
Ensure the translated PHP code behaves exactly like the original AWK snippet.
function ord(a) { return amap[a] } function sedol_checksum(sed) { sw[1] = 1; sw[2] = 3; sw[3] = 1 sw[4] = 7; sw[5] = 3; sw[6] = 9 sum = 0 for(i=1; i <= 6; i++) { c = substr(toupper(sed), i, 1) if ( c ~ /[[:digit:]]/ ) { sum += c*sw[i] } else { sum += (ord(c)-ord("A")+10)*sw[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...
Change the following BBC_Basic code into PHP without altering its purpose.
PRINT FNsedol("710889") PRINT FNsedol("B0YBKJ") PRINT FNsedol("406566") PRINT FNsedol("B0YBLH") PRINT FNsedol("228276") PRINT FNsedol("B0YBKL") PRINT FNsedol("557910") PRINT FNsedol("B0YBKR") PRINT FNsedol("585284") PRINT FNsedol("B0YBKT") PRINT FNsedol(...
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...
Rewrite this program in PHP while keeping its functionality equivalent to the Clojure version.
(defn sedols [xs] (letfn [(sedol [ys] (let [weights [1 3 1 7 3 9] convtonum (map #(Character/getNumericValue %) ys) check (-> (reduce + (map * weights convtonum)) (rem 10) (->> (- 10)) (rem 10))] (str ys check)))] (map #(sedol %) xs))...
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...
Convert this Common_Lisp snippet to PHP and keep its semantics consistent.
(defun append-sedol-check-digit (sedol &key (start 0) (end (+ start 6))) (assert (<= 0 start end (length sedol))) (assert (= (- end start) 6)) (loop :with checksum = 0 :for weight :in '(1 3 1 7 3 9) :for index :upfrom start :do (incf checksum (* weight (digit-char-p (char sedol index)...
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...
Keep all operations the same but rewrite the snippet in PHP.
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...
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...
Produce a functionally identical PHP code for the snippet given 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...
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...
Produce a functionally identical PHP code for the snippet given in Elixir.
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...
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...
Rewrite the snippet below in PHP so it works the same as the original F# code.
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...
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...
Write the same code in PHP 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...
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...
Rewrite the snippet below in PHP so it works the same as the original Forth code.
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...
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...
Convert this Fortran snippet to PHP and keep its semantics consistent.
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...
Maintain the same structure and functionality when rewriting this code in PHP.
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...
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...
Rewrite this program in PHP while keeping its functionality equivalent to the Haskell version.
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...
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...
Convert this Icon block to PHP, preserving its control flow 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...
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...
Port the provided J code into PHP while preserving the original functionality.
sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn 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...
Port the provided Julia code into PHP while preserving the original functionality.
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...
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...
Rewrite the snippet below in PHP so it works the same as the original 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...
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...
Rewrite this program in PHP 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...
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...
Maintain the same structure and functionality when rewriting this code in PHP.
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...
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...
Can you help me rewrite this code in PHP instead of Pascal, keeping it the same logically?
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: ...
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...
Keep all operations the same but rewrite the snippet in PHP.
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...
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...
Write the same code in PHP as shown below in PowerShell.
function Add-SEDOLCheckDigit { Param ( [ValidatePattern( "^[0123456789bcdfghjklmnpqrstvwxyz]{6}$" )] [parameter ( Mandatory = $True ) ] [string] $SixDigitSEDOL ) $SEDOL = [string[]][char[]]$SixDigitSEDOL $Weight = @( 1, 3, 1, 7, 3, 9 ) ...
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...
Ensure the translated PHP code behaves exactly like the original Racket snippet.
#lang racket (define output-SEDOLS (list "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300")) (define (output->input-SEDOL S) (substring S 0 6)) (define input-SEDOLS (map output->input-SEDOL output-SEDOLS)) (define (SEDOL-characte...
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...
Rewrite the snippet below in PHP so it works the same as the original COBOL code.
>>SOURCE FREE IDENTIFICATION DIVISION. PROGRAM-ID. sedol. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sedol-file ASSIGN "sedol.txt" ORGANIZATION LINE SEQUENTIAL FILE STATUS sedol-file-status. DATA DIVISION. FILE SECTION. FD sedol-file. 01 sedol ...
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...
Port the following code from REXX to PHP with equivalent syntax and logic.
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alphaDigs= '0123456789'@abcU allowable=space(translate(alphaDigs,,'AEIOU'),0) weights = 1317391 @.= arg @.1 . if @.1=='' then do...
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...
Generate an equivalent PHP version of this Ruby code.
Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" Sedolweight = [1,3,1,7,3,9] def char2value(c) raise ArgumentError, "Invalid char c.to_i(36) end def checksum(sedol) raise ArgumentError, "Invalid length" unless sedol.size == Sedolweight.size sum = sedol.chars.zip(Sedolweight).sum{|ch, weight| char2value(ch) * ...
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...
Write the same algorithm in PHP as shown in this Scala implementation.
val weights = listOf(1, 3, 1, 7, 3, 9, 1) fun sedol7(sedol6: String): String { if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6") var sum = 0 for (i in 0..5) { val c = sedol6[i] val v = when (c) { in '0'..'9' -> c.toInt() - 48 ...
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...
Port the provided Tcl code into PHP while preserving the original functionality.
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1} proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [strin...
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...
Rewrite this program in Rust while keeping its functionality equivalent to the C version.
#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); ...
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
Port the following code from C++ to Rust with equivalent syntax and logic.
#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...
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
Produce a language-to-language conversion: from C# to Rust, same semantics.
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...
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
Generate a Rust translation of this Java snippet without changing its computational steps.
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...
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
Rewrite the snippet below in Python so it works the same as the original Rust code.
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
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 following Go code into Rust without altering its purpose.
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...
fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ"; if input.len() != 6 { return None; } for c in input.chars() { if !valid_chars.contains(c) { return None; } } let...
Rewrite the snippet below in C# so it works the same as the original Ada code.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
using System; using static System.Linq.Enumerable; public class Program { static void Main() { SqueezeAndPrint("", ' '); SqueezeAndPrint("\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", '-'); SqueezeAndPrint("..11111111111111111111111111111111111111111111111...
Please provide an equivalent version of this Ada code in C#.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
using System; using static System.Linq.Enumerable; public class Program { static void Main() { SqueezeAndPrint("", ' '); SqueezeAndPrint("\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", '-'); SqueezeAndPrint("..11111111111111111111111111111111111111111111111...
Produce a functionally identical C code for the snippet given in Ada.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
#include<string.h> #include<stdlib.h> #include<stdio.h> #define COLLAPSE 0 #define SQUEEZE 1 typedef struct charList{ char c; struct charList *next; } charList; int strcmpi(char str1[100],char str2[100]){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } ...
Translate this program into C but keep the logic exactly as in Ada.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
#include<string.h> #include<stdlib.h> #include<stdio.h> #define COLLAPSE 0 #define SQUEEZE 1 typedef struct charList{ char c; struct charList *next; } charList; int strcmpi(char str1[100],char str2[100]){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } ...
Write a version of this Ada function in C++ with identical behavior.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
#include <algorithm> #include <string> #include <iostream> template<typename char_type> std::basic_string<char_type> squeeze(std::basic_string<char_type> str, char_type ch) { auto i = std::unique(str.begin(), str.end(), [ch](char_type a, char_type b) { return a == ch && b == ch; }); str.erase(i, str.en...
Generate an equivalent C++ version of this Ada code.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
#include <algorithm> #include <string> #include <iostream> template<typename char_type> std::basic_string<char_type> squeeze(std::basic_string<char_type> str, char_type ch) { auto i = std::unique(str.begin(), str.end(), [ch](char_type a, char_type b) { return a == ch && b == ch; }); str.erase(i, str.en...
Convert the following code from Ada to Go, ensuring the logic remains intact.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
package main import "fmt" func squeeze(s string, c rune) (string, int, int) { r := []rune(s) le, del := len(r), 0 for i := le - 2; i >= 0; i-- { if r[i] == c && r[i] == r[i+1] { copy(r[i:], r[i+1:]) del++ } } if del == 0 { return s, le, le } ...
Port the provided Ada code into Go while preserving the original functionality.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
package main import "fmt" func squeeze(s string, c rune) (string, int, int) { r := []rune(s) le, del := len(r), 0 for i := le - 2; i >= 0; i-- { if r[i] == c && r[i] == r[i+1] { copy(r[i:], r[i+1:]) del++ } } if del == 0 { return s, le, le } ...
Translate the given Ada code snippet into Java without altering its behavior.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
public class StringSqueezable { public static void main(String[] args) { String[] testStrings = new String[] { "", "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", "..11111111111111111111111111111111111111111111111111111111111...
Translate the given Ada code snippet into Java without altering its behavior.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
public class StringSqueezable { public static void main(String[] args) { String[] testStrings = new String[] { "", "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", "..11111111111111111111111111111111111111111111111111111111111...
Change the programming language of this snippet from Ada to Python without modifying what it does.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
from itertools import groupby def squeezer(s, txt): return ''.join(item if item == s else ''.join(grp) for item, grp in groupby(txt)) if __name__ == '__main__': strings = [ "", '"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', "....
Produce a language-to-language conversion: from Ada to Python, same semantics.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
from itertools import groupby def squeezer(s, txt): return ''.join(item if item == s else ''.join(grp) for item, grp in groupby(txt)) if __name__ == '__main__': strings = [ "", '"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', "....
Transform the following Ada implementation into VB, maintaining the same output and logic.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
Imports System.Linq.Enumerable Module Module1 Function Squeeze(s As String, c As Char) As String If String.IsNullOrEmpty(s) Then Return "" End If Return s(0) + New String(Range(1, s.Length - 1).Where(Function(i) s(i) <> c OrElse s(i) <> s(i - 1)).Select(Function(i) s(i)).ToArra...
Transform the following Ada implementation into VB, maintaining the same output and logic.
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Squeezable is procedure Squeeze (S : in String; C : in Character) is Res : String (1 .. S'Length); Len : Natural := 0; begin Put_Line ("Character to be squeezed: '" & C & "'"); Put_Line ("Input = <<<" & S & ">>>, length =" & S'Length'Image...
Imports System.Linq.Enumerable Module Module1 Function Squeeze(s As String, c As Char) As String If String.IsNullOrEmpty(s) Then Return "" End If Return s(0) + New String(Range(1, s.Length - 1).Where(Function(i) s(i) <> c OrElse s(i) <> s(i - 1)).Select(Function(i) s(i)).ToArra...
Generate a C translation of this AutoHotKey snippet without changing its computational steps.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
#include<string.h> #include<stdlib.h> #include<stdio.h> #define COLLAPSE 0 #define SQUEEZE 1 typedef struct charList{ char c; struct charList *next; } charList; int strcmpi(char str1[100],char str2[100]){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } ...
Write a version of this AutoHotKey function in C with identical behavior.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
#include<string.h> #include<stdlib.h> #include<stdio.h> #define COLLAPSE 0 #define SQUEEZE 1 typedef struct charList{ char c; struct charList *next; } charList; int strcmpi(char str1[100],char str2[100]){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } ...
Produce a functionally identical C# code for the snippet given in AutoHotKey.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
using System; using static System.Linq.Enumerable; public class Program { static void Main() { SqueezeAndPrint("", ' '); SqueezeAndPrint("\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", '-'); SqueezeAndPrint("..11111111111111111111111111111111111111111111111...
Convert this AutoHotKey snippet to C# and keep its semantics consistent.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
using System; using static System.Linq.Enumerable; public class Program { static void Main() { SqueezeAndPrint("", ' '); SqueezeAndPrint("\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", '-'); SqueezeAndPrint("..11111111111111111111111111111111111111111111111...
Port the provided AutoHotKey code into C++ while preserving the original functionality.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
#include <algorithm> #include <string> #include <iostream> template<typename char_type> std::basic_string<char_type> squeeze(std::basic_string<char_type> str, char_type ch) { auto i = std::unique(str.begin(), str.end(), [ch](char_type a, char_type b) { return a == ch && b == ch; }); str.erase(i, str.en...
Generate an equivalent C++ version of this AutoHotKey code.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
#include <algorithm> #include <string> #include <iostream> template<typename char_type> std::basic_string<char_type> squeeze(std::basic_string<char_type> str, char_type ch) { auto i = std::unique(str.begin(), str.end(), [ch](char_type a, char_type b) { return a == ch && b == ch; }); str.erase(i, str.en...
Rewrite this program in Java while keeping its functionality equivalent to the AutoHotKey version.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
public class StringSqueezable { public static void main(String[] args) { String[] testStrings = new String[] { "", "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", "..11111111111111111111111111111111111111111111111111111111111...
Convert this AutoHotKey snippet to Java and keep its semantics consistent.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
public class StringSqueezable { public static void main(String[] args) { String[] testStrings = new String[] { "", "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", "..11111111111111111111111111111111111111111111111111111111111...
Produce a language-to-language conversion: from AutoHotKey to Python, same semantics.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
from itertools import groupby def squeezer(s, txt): return ''.join(item if item == s else ''.join(grp) for item, grp in groupby(txt)) if __name__ == '__main__': strings = [ "", '"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', "....
Change the following AutoHotKey code into Python without altering its purpose.
squeezable_string(str, char){ for i, ch in StrSplit(str){ if (ch <> prev) || !InStr(ch, char) res .= ch prev := ch } result := " (ltrim Original string:`t" StrLen(str) " characters`t«««" str "»»» Squeezable Character «««" char "»»» Resultant string:`t" StrLen(res)...
from itertools import groupby def squeezer(s, txt): return ''.join(item if item == s else ''.join(grp) for item, grp in groupby(txt)) if __name__ == '__main__': strings = [ "", '"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', "....