Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Keep all operations the same but rewrite the snippet in PHP.
function bitwiseOps(a,b) disp(sprintf(' disp(sprintf(' disp(sprintf(' disp(sprintf(' disp(sprintf(' end
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Convert the following code from Nim to PHP, ensuring the logic remains intact.
proc bitwise(a, b) = echo "a and b: " , a and b echo "a or b: ", a or b echo "a xor b: ", a xor b echo "not a: ", not a echo "a << b: ", a shl b echo "a >> b: ", a shr b
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Change the following OCaml code into PHP without altering its purpose.
let bitwise a b = Printf.printf "a and b: %d\n" (a land b); Printf.printf "a or b: %d\n" (a lor b); Printf.printf "a xor b: %d\n" (a lxor b); Printf.printf "not a: %d\n" (lnot a); Printf.printf "a lsl b: %d\n" (a lsl b); Printf.printf "a asr b: %d\n" (a asr b); Printf.printf "a lsr b: %d\n" (a lsr b);...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Produce a language-to-language conversion: from Pascal to PHP, same semantics.
program Bitwise; var x:shortint = 2; y:ShortInt = 3; begin Writeln('2 and 3 = ', x and y); Writeln('2 or 3 = ', x or y); Writeln('2 xor 3 = ', x xor y); Writeln('not 2 = ', not x); Writeln('2 shl 3 = ', x >> y); Writeln('2 shr 3 = ', x << y); writeln('2 rol 3 = ', rolbyte(x,y)); writeln('2 ro...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Write a version of this Perl function in PHP with identical behavior.
use integer; sub bitwise :prototype($$) { ($a, $b) = @_; print 'a and b: '. ($a & $b) ."\n"; print 'a or b: '. ($a | $b) ."\n"; print 'a xor b: '. ($a ^ $b) ."\n"; print 'not a: '. (~$a) ."\n"; print 'a >> b: ', $a >> $b, "\n"; use integer; print "after use integer:\n"; print 'a <...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Maintain the same structure and functionality when rewriting this code in PHP.
$X -band $Y $X -bor $Y $X -bxor $Y -bnot $X
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Transform the following Racket implementation into PHP, maintaining the same output and logic.
#lang racket (define a 255) (define b 5) (list (bitwise-and a b) (bitwise-ior a b) (bitwise-xor a b) (bitwise-not a) (arithmetic-shift a b) (arithmetic-shift a (- b)))
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Generate a PHP translation of this COBOL snippet without changing its computational steps.
IDENTIFICATION DIVISION. PROGRAM-ID. bitwise-ops. DATA DIVISION. LOCAL-STORAGE SECTION. 01 a PIC 1(32) USAGE BIT. 01 b PIC 1(32) USAGE BIT. 01 result PIC 1(32) USAGE BIT. 01 result-disp ...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Convert this REXX snippet to PHP and keep its semantics consistent.
/ Bit Operations work as in Rexx (of course) * Bit operations are performed up to the length of the shorter string. * The rest of the longer string is copied to the result. * ooRexx introduces the possibility to specify a padding character * to be used for expanding the shorter string. * 10.11.2012 Walter Pachl taken ...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Rewrite this program in PHP while keeping its functionality equivalent to the Ruby version.
def bitwise(a, b) form = "%1$7s:%2$6d %2$016b" puts form % ["a", a] puts form % ["b", b] puts form % ["a and b", a & b] puts form % ["a or b ", a | b] puts form % ["a xor b", a ^ b] puts form % ["not a ", ~a] puts form % ["a << b ", a << b] puts form % ["a >> b ", a >> b] end bitwise(14,3)
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Rewrite this program in PHP while keeping its functionality equivalent to the Scala version.
def bitwise(a: Int, b: Int) { println("a and b: " + (a & b)) println("a or b: " + (a | b)) println("a xor b: " + (a ^ b)) println("not a: " + (~a)) println("a << b: " + (a << b)) println("a >> b: " + (a >> b)) println("a >>> b: " + (a >>> b)) println("a rot b: " + Integer.rotateLeft(a, b)) println...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Write the same algorithm in PHP as shown in this Swift implementation.
func bitwise(a: Int, b: Int) { println("a AND b: \(a & b)") println("a OR b: \(a | b)") println("a XOR b: \(a ^ b)") println("NOT a: \(~a)") println("a << b: \(a << b)") println("a >> b: \(a >> b)") println("a lsr b: \(Int(bitPattern: UInt(bitPattern: a) >> UInt(bitPattern: b)))") } bitwis...
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Keep all operations the same but rewrite the snippet in PHP.
proc bitwise {a b} { puts [format "a and b: % puts [format "a or b: % puts [format "a xor b: % puts [format "not a: % puts [format "a << b: % puts [format "a >> b: % }
function bitwise($a, $b) { function zerofill($a,$b) { if($a>=0) return $a>>$b; if($b==0) return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); // this line shifts a 0 into the sign bit for compatibility, replace with "if($b==0) return $a;" if you need $b=0 to mean that nothing happens return ((~$a)>>...
Write the same code in Rust as shown below in Java.
module BitwiseOps { @Inject Console console; void run() { for ((Int64 n1, Int64 n2) : [0=7, 1=5, 42=2, 0x123456789ABCDEF=0xFF]) { static String hex(Int64 n) { return n.toByteArray() [(n.leadingZeroCount / 8).minOf(...
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
Produce a functionally identical Python code for the snippet given in Rust.
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
def bitwise_built_ins(width, a, b): mask = (1 << width) - 1 print(f) def rotr(width, a, n): "Rotate a, n times to the right" if n < 0: return rotl(width, a, -n) elif n == 0: return a else: mask = (1 << width) - 1 a, n = a & mask, n % width return ((a >> n...
Rewrite this program in VB while keeping its functionality equivalent to the Rust version.
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
Debug.Print Hex(&HF0F0 And &HFF00) Debug.Print Hex(&HF0F0 Or &HFF00) Debug.Print Hex(&HF0F0 Xor &HFF00) Debug.Print Hex(Not &HF0F0) Debug.Print Hex(&HF0F0 Eqv &HFF00) Debug.Print Hex(&HF0F0 Imp &HFF00)
Generate an equivalent Rust version of this C code.
void bitwise(int a, int b) { printf("a and b: %d\n", a & b); printf("a or b: %d\n", a | b); printf("a xor b: %d\n", a ^ b); printf("not a: %d\n", ~a); printf("a << n: %d\n", a << b); printf("a >> n: %d\n", a >> b); unsigned int c = a; printf("c >> b: %d\n", c >> b); return 0; }
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
Can you help me rewrite this code in Rust instead of C++, keeping it the same logically?
#include <iostream> void bitwise(int a, int b) { std::cout << "a and b: " << (a & b) << '\n'; std::cout << "a or b: " << (a | b) << '\n'; std::cout << "a xor b: " << (a ^ b) << '\n'; std::cout << "not a: " << ~a << '\n'; std::cout << "a shl b: " << (a << b) << '\n'; std::cout << "a shr...
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
Ensure the translated Rust code behaves exactly like the original C# snippet.
static void bitwise(int a, int b) { Console.WriteLine("a and b is {0}", a & b); Console.WriteLine("a or b is {0}", a | b); Console.WriteLine("a xor b is {0}", a ^ b); Console.WriteLine("not a is {0}", ~a); Console.WriteLine("a lshift b is {0}", a << b)...
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
Preserve the algorithm and functionality while converting the code from Go to Rust.
package main import "fmt" func bitwise(a, b int16) { fmt.Printf("a: %016b\n", uint16(a)) fmt.Printf("b: %016b\n", uint16(b)) fmt.Printf("and: %016b\n", uint16(a&b)) fmt.Printf("or: %016b\n", uint16(a|b)) fmt.Printf("xor: %016b\n", uint16(a^b)) fmt.Printf("not: %016b\n", uint16(^a)) if b < 0 { fmt.Pr...
fn main() { let a: u8 = 105; let b: u8 = 91; println!("a = {:0>8b}", a); println!("b = {:0>8b}", b); println!("a | b = {:0>8b}", a | b); println!("a & b = {:0>8b}", a & b); println!("a ^ b = {:0>8b}", a ^ b); println!("!a = {:0>8b}", !a); println!("a << 3 = {:0>8b}",...
Produce a functionally identical C# code for the snippet given in Ada.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Translate this program into C but keep the logic exactly as in Ada.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Convert this Ada snippet to C++ and keep its semantics consistent.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Translate this program into Go but keep the logic exactly as in Ada.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Produce a language-to-language conversion: from Ada to Java, same semantics.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Please provide an equivalent version of this Ada code in Python.
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Convert this AutoHotKey block to C, preserving its control flow and logic.
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Translate the given AutoHotKey code snippet into C# without altering its behavior.
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Transform the following AutoHotKey implementation into C++, maintaining the same output and logic.
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Translate this program into Java but keep the logic exactly as in AutoHotKey.
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Can you help me rewrite this code in Python instead of AutoHotKey, keeping it the same logically?
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Produce a language-to-language conversion: from AutoHotKey to Go, same semantics.
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Change the programming language of this snippet from AWK to C without modifying what it does.
BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 " \ "105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 " \ "109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Keep all operations the same but rewrite the snippet in C#.
BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 " \ "105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 " \ "109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Keep all operations the same but rewrite the snippet in C++.
BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 " \ "105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 " \ "109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Convert the following code from AWK to Java, ensuring the logic remains intact.
BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 " \ "105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 " \ "109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Port the provided AWK code into Python while preserving the original functionality.
BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 " \ "105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 " \ "109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Keep all operations the same but rewrite the snippet in Go.
BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 " \ "105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 " \ "109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Convert the following code from BBC_Basic to C, ensuring the logic remains intact.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0) DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23,...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Rewrite the snippet below in C# so it works the same as the original BBC_Basic code.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0) DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23,...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Generate an equivalent C++ version of this BBC_Basic code.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0) DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23,...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Produce a functionally identical Java code for the snippet given in BBC_Basic.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0) DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23,...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Rewrite the snippet below in Python so it works the same as the original BBC_Basic code.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0) DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23,...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Convert this BBC_Basic snippet to Go and keep its semantics consistent.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0) DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23,...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Maintain the same structure and functionality when rewriting this code in C.
(def data [12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 146 52 71 118 11...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Write a version of this Clojure function in C# with identical behavior.
(def data [12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 146 52 71 118 11...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Port the following code from Clojure to C++ with equivalent syntax and logic.
(def data [12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 146 52 71 118 11...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Port the following code from Clojure to Java with equivalent syntax and logic.
(def data [12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 146 52 71 118 11...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Convert the following code from Clojure to Python, ensuring the logic remains intact.
(def data [12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 146 52 71 118 11...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Translate the given Clojure code snippet into Go without altering its behavior.
(def data [12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 146 52 71 118 11...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Produce a functionally identical C code for the snippet given in Common_Lisp.
(defun insert (x xs) (cond ((endp xs) (list x)) ((> x (first xs)) (cons (first xs) (insert x (rest xs)))) (t (cons x xs)))) (defun isort (xs) (if (endp xs) nil (insert (first xs) (isort (rest xs))))) (defun stem-and-leaf-bins (xs bin curr) (cond ((endp xs) (list curr...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Write the same algorithm in C# as shown in this Common_Lisp implementation.
(defun insert (x xs) (cond ((endp xs) (list x)) ((> x (first xs)) (cons (first xs) (insert x (rest xs)))) (t (cons x xs)))) (defun isort (xs) (if (endp xs) nil (insert (first xs) (isort (rest xs))))) (defun stem-and-leaf-bins (xs bin curr) (cond ((endp xs) (list curr...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Can you help me rewrite this code in C++ instead of Common_Lisp, keeping it the same logically?
(defun insert (x xs) (cond ((endp xs) (list x)) ((> x (first xs)) (cons (first xs) (insert x (rest xs)))) (t (cons x xs)))) (defun isort (xs) (if (endp xs) nil (insert (first xs) (isort (rest xs))))) (defun stem-and-leaf-bins (xs bin curr) (cond ((endp xs) (list curr...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Maintain the same structure and functionality when rewriting this code in Java.
(defun insert (x xs) (cond ((endp xs) (list x)) ((> x (first xs)) (cons (first xs) (insert x (rest xs)))) (t (cons x xs)))) (defun isort (xs) (if (endp xs) nil (insert (first xs) (isort (rest xs))))) (defun stem-and-leaf-bins (xs bin curr) (cond ((endp xs) (list curr...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Ensure the translated Python code behaves exactly like the original Common_Lisp snippet.
(defun insert (x xs) (cond ((endp xs) (list x)) ((> x (first xs)) (cons (first xs) (insert x (rest xs)))) (t (cons x xs)))) (defun isort (xs) (if (endp xs) nil (insert (first xs) (isort (rest xs))))) (defun stem-and-leaf-bins (xs bin curr) (cond ((endp xs) (list curr...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Write the same code in C as shown below in D.
import std.stdio, std.algorithm; void main() { enum data = [12,127,28,42,39,113,42,18,44,118,44,37,113,124,37,48, 127,36,29,31,125,139,131,115,105,132,104,123,35,113,122,42,117, 119,58,109,23,105,63,27,44,105,99,41,128,121,116,125,32,61,37, 127,29,113,121,58,114,126,53,114,96,25,109,7,31,14...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Convert the following code from D to C#, ensuring the logic remains intact.
import std.stdio, std.algorithm; void main() { enum data = [12,127,28,42,39,113,42,18,44,118,44,37,113,124,37,48, 127,36,29,31,125,139,131,115,105,132,104,123,35,113,122,42,117, 119,58,109,23,105,63,27,44,105,99,41,128,121,116,125,32,61,37, 127,29,113,121,58,114,126,53,114,96,25,109,7,31,14...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Change the following D code into C++ without altering its purpose.
import std.stdio, std.algorithm; void main() { enum data = [12,127,28,42,39,113,42,18,44,118,44,37,113,124,37,48, 127,36,29,31,125,139,131,115,105,132,104,123,35,113,122,42,117, 119,58,109,23,105,63,27,44,105,99,41,128,121,116,125,32,61,37, 127,29,113,121,58,114,126,53,114,96,25,109,7,31,14...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Translate the given D code snippet into Java without altering its behavior.
import std.stdio, std.algorithm; void main() { enum data = [12,127,28,42,39,113,42,18,44,118,44,37,113,124,37,48, 127,36,29,31,125,139,131,115,105,132,104,123,35,113,122,42,117, 119,58,109,23,105,63,27,44,105,99,41,128,121,116,125,32,61,37, 127,29,113,121,58,114,126,53,114,96,25,109,7,31,14...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Can you help me rewrite this code in Python instead of D, keeping it the same logically?
import std.stdio, std.algorithm; void main() { enum data = [12,127,28,42,39,113,42,18,44,118,44,37,113,124,37,48, 127,36,29,31,125,139,131,115,105,132,104,123,35,113,122,42,117, 119,58,109,23,105,63,27,44,105,99,41,128,121,116,125,32,61,37, 127,29,113,121,58,114,126,53,114,96,25,109,7,31,14...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Generate an equivalent Go version of this D code.
import std.stdio, std.algorithm; void main() { enum data = [12,127,28,42,39,113,42,18,44,118,44,37,113,124,37,48, 127,36,29,31,125,139,131,115,105,132,104,123,35,113,122,42,117, 119,58,109,23,105,63,27,44,105,99,41,128,121,116,125,32,61,37, 127,29,113,121,58,114,126,53,114,96,25,109,7,31,14...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Convert this Elixir block to C, preserving its control flow and logic.
defmodule Stem_and_leaf do def plot(data, leaf_digits\\1) do multiplier = Enum.reduce(1..leaf_digits, 1, fn _,acc -> acc*10 end) Enum.group_by(data, fn x -> div(x, multiplier) end) |> Map.new(fn {k,v} -> {k, Enum.map(v, &rem(&1, multiplier)) |> Enum.sort} end) |> print(leaf_digits) end defp pri...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Produce a language-to-language conversion: from Elixir to C++, same semantics.
defmodule Stem_and_leaf do def plot(data, leaf_digits\\1) do multiplier = Enum.reduce(1..leaf_digits, 1, fn _,acc -> acc*10 end) Enum.group_by(data, fn x -> div(x, multiplier) end) |> Map.new(fn {k,v} -> {k, Enum.map(v, &rem(&1, multiplier)) |> Enum.sort} end) |> print(leaf_digits) end defp pri...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Produce a language-to-language conversion: from Elixir to Java, same semantics.
defmodule Stem_and_leaf do def plot(data, leaf_digits\\1) do multiplier = Enum.reduce(1..leaf_digits, 1, fn _,acc -> acc*10 end) Enum.group_by(data, fn x -> div(x, multiplier) end) |> Map.new(fn {k,v} -> {k, Enum.map(v, &rem(&1, multiplier)) |> Enum.sort} end) |> print(leaf_digits) end defp pri...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Preserve the algorithm and functionality while converting the code from Elixir to Python.
defmodule Stem_and_leaf do def plot(data, leaf_digits\\1) do multiplier = Enum.reduce(1..leaf_digits, 1, fn _,acc -> acc*10 end) Enum.group_by(data, fn x -> div(x, multiplier) end) |> Map.new(fn {k,v} -> {k, Enum.map(v, &rem(&1, multiplier)) |> Enum.sort} end) |> print(leaf_digits) end defp pri...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Produce a language-to-language conversion: from Elixir to Go, same semantics.
defmodule Stem_and_leaf do def plot(data, leaf_digits\\1) do multiplier = Enum.reduce(1..leaf_digits, 1, fn _,acc -> acc*10 end) Enum.group_by(data, fn x -> div(x, multiplier) end) |> Map.new(fn {k,v} -> {k, Enum.map(v, &rem(&1, multiplier)) |> Enum.sort} end) |> print(leaf_digits) end defp pri...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Translate this program into C but keep the logic exactly as in F#.
open System let data = [ 12; 127; 28; 42; 39; 113; 42; 18; 44; 118; 44; 37; 113; 124; 37; 48; 127; 36; 29; 31; 125; 139; 131; 115; 105; 132; 104; 123; 35; 113; 122; 42; 117; 119; 58; 109; 23; 105; 63; 27; 44; 105; 99; 41; 128; 121; 116; 125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114;...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Generate a C# translation of this F# snippet without changing its computational steps.
open System let data = [ 12; 127; 28; 42; 39; 113; 42; 18; 44; 118; 44; 37; 113; 124; 37; 48; 127; 36; 29; 31; 125; 139; 131; 115; 105; 132; 104; 123; 35; 113; 122; 42; 117; 119; 58; 109; 23; 105; 63; 27; 44; 105; 99; 41; 128; 121; 116; 125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114;...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Write the same algorithm in C++ as shown in this F# implementation.
open System let data = [ 12; 127; 28; 42; 39; 113; 42; 18; 44; 118; 44; 37; 113; 124; 37; 48; 127; 36; 29; 31; 125; 139; 131; 115; 105; 132; 104; 123; 35; 113; 122; 42; 117; 119; 58; 109; 23; 105; 63; 27; 44; 105; 99; 41; 128; 121; 116; 125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114;...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Can you help me rewrite this code in Java instead of F#, keeping it the same logically?
open System let data = [ 12; 127; 28; 42; 39; 113; 42; 18; 44; 118; 44; 37; 113; 124; 37; 48; 127; 36; 29; 31; 125; 139; 131; 115; 105; 132; 104; 123; 35; 113; 122; 42; 117; 119; 58; 109; 23; 105; 63; 27; 44; 105; 99; 41; 128; 121; 116; 125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114;...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Produce a language-to-language conversion: from F# to Python, same semantics.
open System let data = [ 12; 127; 28; 42; 39; 113; 42; 18; 44; 118; 44; 37; 113; 124; 37; 48; 127; 36; 29; 31; 125; 139; 131; 115; 105; 132; 104; 123; 35; 113; 122; 42; 117; 119; 58; 109; 23; 105; 63; 27; 44; 105; 99; 41; 128; 121; 116; 125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114;...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Preserve the algorithm and functionality while converting the code from F# to Go.
open System let data = [ 12; 127; 28; 42; 39; 113; 42; 18; 44; 118; 44; 37; 113; 124; 37; 48; 127; 36; 29; 31; 125; 139; 131; 115; 105; 132; 104; 123; 35; 113; 122; 42; 117; 119; 58; 109; 23; 105; 63; 27; 44; 105; 99; 41; 128; 121; 116; 125; 32; 61; 37; 127; 29; 113; 121; 58; 114; 126; 53; 114;...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Ensure the translated C code behaves exactly like the original Factor snippet.
USING: assocs formatting grouping.extras io kernel math prettyprint sequences sorting ; : leaf-plot ( seq -- ) natural-sort [ 10 /i ] group-by dup keys last 1 + [ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with each-integer ; { 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Keep all operations the same but rewrite the snippet in C#.
USING: assocs formatting grouping.extras io kernel math prettyprint sequences sorting ; : leaf-plot ( seq -- ) natural-sort [ 10 /i ] group-by dup keys last 1 + [ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with each-integer ; { 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Maintain the same structure and functionality when rewriting this code in C++.
USING: assocs formatting grouping.extras io kernel math prettyprint sequences sorting ; : leaf-plot ( seq -- ) natural-sort [ 10 /i ] group-by dup keys last 1 + [ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with each-integer ; { 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Translate the given Factor code snippet into Java without altering its behavior.
USING: assocs formatting grouping.extras io kernel math prettyprint sequences sorting ; : leaf-plot ( seq -- ) natural-sort [ 10 /i ] group-by dup keys last 1 + [ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with each-integer ; { 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Convert this Factor snippet to Python and keep its semantics consistent.
USING: assocs formatting grouping.extras io kernel math prettyprint sequences sorting ; : leaf-plot ( seq -- ) natural-sort [ 10 /i ] group-by dup keys last 1 + [ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with each-integer ; { 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Convert the following code from Factor to Go, ensuring the logic remains intact.
USING: assocs formatting grouping.extras io kernel math prettyprint sequences sorting ; : leaf-plot ( seq -- ) natural-sort [ 10 /i ] group-by dup keys last 1 + [ dup "%2d | " printf of [ 10 mod pprint bl ] each nl ] with each-integer ; { 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Generate a C translation of this Forth snippet without changing its computational steps.
create data 12 , 127 , 28 , 42 , 39 , 113 , 42 , 18 , 44 , 118 , 44 , 37 , 113 , 124 , 37 , 48 , 127 , 36 , 29 , 31 , 125 , 139 , 131 , 115 , 105 , 132 , 104 , 123 , 35 , 113 , 122 , 42 , 117 , 119 , 58 , 109 , 23 , 105 , 63 , 27 , 44 , 105 , 99 , 41 , 128 , 121 , 116 , 125 , 32 , 61 ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Rewrite the snippet below in C# so it works the same as the original Forth code.
create data 12 , 127 , 28 , 42 , 39 , 113 , 42 , 18 , 44 , 118 , 44 , 37 , 113 , 124 , 37 , 48 , 127 , 36 , 29 , 31 , 125 , 139 , 131 , 115 , 105 , 132 , 104 , 123 , 35 , 113 , 122 , 42 , 117 , 119 , 58 , 109 , 23 , 105 , 63 , 27 , 44 , 105 , 99 , 41 , 128 , 121 , 116 , 125 , 32 , 61 ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Translate the given Forth code snippet into C++ without altering its behavior.
create data 12 , 127 , 28 , 42 , 39 , 113 , 42 , 18 , 44 , 118 , 44 , 37 , 113 , 124 , 37 , 48 , 127 , 36 , 29 , 31 , 125 , 139 , 131 , 115 , 105 , 132 , 104 , 123 , 35 , 113 , 122 , 42 , 117 , 119 , 58 , 109 , 23 , 105 , 63 , 27 , 44 , 105 , 99 , 41 , 128 , 121 , 116 , 125 , 32 , 61 ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Port the provided Forth code into Java while preserving the original functionality.
create data 12 , 127 , 28 , 42 , 39 , 113 , 42 , 18 , 44 , 118 , 44 , 37 , 113 , 124 , 37 , 48 , 127 , 36 , 29 , 31 , 125 , 139 , 131 , 115 , 105 , 132 , 104 , 123 , 35 , 113 , 122 , 42 , 117 , 119 , 58 , 109 , 23 , 105 , 63 , 27 , 44 , 105 , 99 , 41 , 128 , 121 , 116 , 125 , 32 , 61 ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Rewrite the snippet below in Python so it works the same as the original Forth code.
create data 12 , 127 , 28 , 42 , 39 , 113 , 42 , 18 , 44 , 118 , 44 , 37 , 113 , 124 , 37 , 48 , 127 , 36 , 29 , 31 , 125 , 139 , 131 , 115 , 105 , 132 , 104 , 123 , 35 , 113 , 122 , 42 , 117 , 119 , 58 , 109 , 23 , 105 , 63 , 27 , 44 , 105 , 99 , 41 , 128 , 121 , 116 , 125 , 32 , 61 ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Maintain the same structure and functionality when rewriting this code in Go.
create data 12 , 127 , 28 , 42 , 39 , 113 , 42 , 18 , 44 , 118 , 44 , 37 , 113 , 124 , 37 , 48 , 127 , 36 , 29 , 31 , 125 , 139 , 131 , 115 , 105 , 132 , 104 , 123 , 35 , 113 , 122 , 42 , 117 , 119 , 58 , 109 , 23 , 105 , 63 , 27 , 44 , 105 , 99 , 41 , 128 , 121 , 116 , 125 , 32 , 61 ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Generate a C# translation of this Fortran snippet without changing its computational steps.
SUBROUTINE COMBSORT(A,N) INTEGER A(*) INTEGER N INTEGER H,T LOGICAL CURSE H = N - 1 1 H = MAX(1,H*10/13) IF (H.EQ.9 .OR. H.EQ.10) H = 11 CURSE = .FALSE. DO I = N - H,1,-1 IF (A(I) .GT. A(I + H)) THEN T=A(I); A(I)=A(...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Convert this Fortran block to C++, preserving its control flow and logic.
SUBROUTINE COMBSORT(A,N) INTEGER A(*) INTEGER N INTEGER H,T LOGICAL CURSE H = N - 1 1 H = MAX(1,H*10/13) IF (H.EQ.9 .OR. H.EQ.10) H = 11 CURSE = .FALSE. DO I = N - H,1,-1 IF (A(I) .GT. A(I + H)) THEN T=A(I); A(I)=A(...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Can you help me rewrite this code in C instead of Fortran, keeping it the same logically?
SUBROUTINE COMBSORT(A,N) INTEGER A(*) INTEGER N INTEGER H,T LOGICAL CURSE H = N - 1 1 H = MAX(1,H*10/13) IF (H.EQ.9 .OR. H.EQ.10) H = 11 CURSE = .FALSE. DO I = N - H,1,-1 IF (A(I) .GT. A(I + H)) THEN T=A(I); A(I)=A(...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Convert the following code from Fortran to Java, ensuring the logic remains intact.
SUBROUTINE COMBSORT(A,N) INTEGER A(*) INTEGER N INTEGER H,T LOGICAL CURSE H = N - 1 1 H = MAX(1,H*10/13) IF (H.EQ.9 .OR. H.EQ.10) H = 11 CURSE = .FALSE. DO I = N - H,1,-1 IF (A(I) .GT. A(I + H)) THEN T=A(I); A(I)=A(...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Write the same algorithm in Python as shown in this Fortran implementation.
SUBROUTINE COMBSORT(A,N) INTEGER A(*) INTEGER N INTEGER H,T LOGICAL CURSE H = N - 1 1 H = MAX(1,H*10/13) IF (H.EQ.9 .OR. H.EQ.10) H = 11 CURSE = .FALSE. DO I = N - H,1,-1 IF (A(I) .GT. A(I + H)) THEN T=A(I); A(I)=A(...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Port the provided Haskell code into C while preserving the original functionality.
import Data.List import Control.Arrow import Control.Monad nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31 ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Convert the following code from Haskell to C#, ensuring the logic remains intact.
import Data.List import Control.Arrow import Control.Monad nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31 ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Rewrite the snippet below in C++ so it works the same as the original Haskell code.
import Data.List import Control.Arrow import Control.Monad nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31 ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Port the following code from Haskell to Java with equivalent syntax and logic.
import Data.List import Control.Arrow import Control.Monad nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31 ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Translate the given Haskell code snippet into Python without altering its behavior.
import Data.List import Control.Arrow import Control.Monad nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31 ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Port the provided Haskell code into Go while preserving the original functionality.
import Data.List import Control.Arrow import Control.Monad nlsRaw = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31" ++ " 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63" ++ " 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53" ++ " 114 96 25 109 7 31 ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Produce a language-to-language conversion: from J to C, same semantics.
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ] showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Translate the given J code snippet into C# without altering its behavior.
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ] showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Port the following code from J to C++ with equivalent syntax and logic.
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ] showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Produce a language-to-language conversion: from J to Java, same semantics.
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ] showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Maintain the same structure and functionality when rewriting this code in Python.
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ] showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...