Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Convert this Factor block to Python, preserving its control flow and logic.
USING: assocs formatting grouping io kernel math math.parser math.statistics sequences sequences.extras sorting.extras ; : bin ( data limits -- seq ) dup length 1 + [ 0 ] replicate -rot [ bisect-right over [ 1 + ] change-nth ] curry each ; : .bin ( {lo,hi} n i -- ) swap "%3d members in " printf zero? "(" ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Rewrite this program in Go while keeping its functionality equivalent to the Factor version.
USING: assocs formatting grouping io kernel math math.parser math.statistics sequences sequences.extras sorting.extras ; : bin ( data limits -- seq ) dup length 1 + [ 0 ] replicate -rot [ bisect-right over [ 1 + ] change-nth ] curry each ; : .bin ( {lo,hi} n i -- ) swap "%3d members in " printf zero? "(" ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Keep all operations the same but rewrite the snippet in Go.
USING: assocs formatting grouping io kernel math math.parser math.statistics sequences sequences.extras sorting.extras ; : bin ( data limits -- seq ) dup length 1 + [ 0 ] replicate -rot [ bisect-right over [ 1 + ] change-nth ] curry each ; : .bin ( {lo,hi} n i -- ) swap "%3d members in " printf zero? "(" ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Convert this Haskell block to C, preserving its control flow and logic.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Port the following code from Haskell to C with equivalent syntax and logic.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Maintain the same structure and functionality when rewriting this code in C#.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Keep all operations the same but rewrite the snippet in C++.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Transform the following Haskell implementation into C++, maintaining the same output and logic.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Write a version of this Haskell function in Java with identical behavior.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Can you help me rewrite this code in Java instead of Haskell, keeping it the same logically?
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Convert this Haskell snippet to Python and keep its semantics consistent.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Convert this Haskell snippet to Python and keep its semantics consistent.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Write a version of this Haskell function in Go with identical behavior.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Translate the given Haskell code snippet into Go without altering its behavior.
import Control.Monad (foldM) import Data.List (partition) binSplit :: Ord a => [a] -> [a] -> [[a]] binSplit lims ns = counts ++ [rest] where (counts, rest) = foldM split ns lims split l i = let (a, b) = partition (< i) l in ([a], b) binCounts :: Ord a => [a] -> [a] -> [Int] binCounts b = fmap length . binS...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Change the following J code into C without altering its purpose.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Rewrite the snippet below in C so it works the same as the original J code.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Rewrite the snippet below in C# so it works the same as the original J code.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Produce a functionally identical C# code for the snippet given in J.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Change the programming language of this snippet from J to C++ without modifying what it does.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Write a version of this J function in C++ with identical behavior.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Write the same algorithm in Java as shown in this J implementation.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Rewrite this program in Java while keeping its functionality equivalent to the J version.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Port the following code from J to Python with equivalent syntax and logic.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Translate this program into Python but keep the logic exactly as in J.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Generate a Go translation of this J snippet without changing its computational steps.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Rewrite this program in Go while keeping its functionality equivalent to the J version.
Idotr=: |.@[ (#@[ - I.) ] binnedData=: adverb define bidx=. i.@>:@# x x (Idotr (u@}./.)&(bidx&,) ]) y ) require 'format/printf' printBinCounts=: dyad define counts =. y '%2d in [ -∞, %3d)' printf ({. counts) , {. x '%2d in [%3d, %3d)' printf (}.}: counts) ,. 2 ]\ x ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Translate the given Julia code snippet into C without altering its behavior.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Convert the following code from Julia to C, ensuring the logic remains intact.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Translate this program into C# but keep the logic exactly as in Julia.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Write the same algorithm in C# as shown in this Julia implementation.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Write the same algorithm in C++ as shown in this Julia implementation.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Maintain the same structure and functionality when rewriting this code in C++.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Preserve the algorithm and functionality while converting the code from Julia to Java.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Keep all operations the same but rewrite the snippet in Java.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Maintain the same structure and functionality when rewriting this code in Python.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Change the programming language of this snippet from Julia to Python without modifying what it does.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Convert this Julia snippet to Go and keep its semantics consistent.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Produce a functionally identical Go code for the snippet given in Julia.
"""Add the function Python has in its bisect library""" function bisect_right(array, x, low = 1, high = length(array) + 1) while low < high middle = (low + high) ÷ 2 x < array[middle] ? (high = middle) : (low = middle + 1) end return low end """ Bin data according to (ascending) limits """ ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Port the following code from Lua to C with equivalent syntax and logic.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Please provide an equivalent version of this Lua code in C.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Convert this Lua snippet to C# and keep its semantics consistent.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Generate an equivalent C# version of this Lua code.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Produce a functionally identical C++ code for the snippet given in Lua.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Write a version of this Lua function in C++ with identical behavior.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Change the programming language of this snippet from Lua to Java without modifying what it does.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Write the same code in Java as shown below in Lua.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Translate this program into Python but keep the logic exactly as in Lua.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Rewrite the snippet below in Python so it works the same as the original Lua code.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Generate an equivalent Go version of this Lua code.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Maintain the same structure and functionality when rewriting this code in Go.
function binner(limits, data) local bins = setmetatable({}, {__index=function() return 0 end}) local n, flr = #limits+1, math.floor for _, x in ipairs(data) do local lo, hi = 1, n while lo < hi do local mid = flr((lo + hi) / 2) if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Produce a language-to-language conversion: from Mathematica to C, same semantics.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Transform the following Mathematica implementation into C, maintaining the same output and logic.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Translate the given Mathematica code snippet into C# without altering its behavior.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Generate a C# translation of this Mathematica snippet without changing its computational steps.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Write a version of this Mathematica function in C++ with identical behavior.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Write a version of this Mathematica function in C++ with identical behavior.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Change the following Mathematica code into Java without altering its purpose.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Convert the following code from Mathematica to Java, ensuring the logic remains intact.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Produce a language-to-language conversion: from Mathematica to Python, same semantics.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Please provide an equivalent version of this Mathematica code in Python.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Translate this program into Go but keep the logic exactly as in Mathematica.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Produce a functionally identical Go code for the snippet given in Mathematica.
limits = {23, 37, 43, 53, 67, 83}; data = {95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47, 16, 8, 9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55}; limits = {{-\[Infinity]}~Join~limits~Join~{\[Infinity]}}; BinCounts[da...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Generate an equivalent C version of this Nim code.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Write a version of this Nim function in C with identical behavior.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Port the provided Nim code into C# while preserving the original functionality.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Rewrite this program in C# while keeping its functionality equivalent to the Nim version.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Translate the given Nim code snippet into C++ without altering its behavior.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Generate a C++ translation of this Nim snippet without changing its computational steps.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Convert this Nim snippet to Java and keep its semantics consistent.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Change the following Nim code into Java without altering its purpose.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Write a version of this Nim function in Python with identical behavior.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Generate a Python translation of this Nim snippet without changing its computational steps.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Please provide an equivalent version of this Nim code in Go.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Convert this Nim block to Go, preserving its control flow and logic.
import algorithm, strformat func binIt(limits, data: openArray[int]): seq[Natural] = result.setLen(limits.len + 1) for d in data: inc result[limits.upperBound(d)] proc binPrint(limits: openArray[int]; bins: seq[Natural]) = echo &" < {limits[0]:3} := {bins[0]:3}" for i in 1..limits.high: echo ...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Write the same code in C as shown below in Perl.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Change the following Perl code into C without altering its purpose.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Preserve the algorithm and functionality while converting the code from Perl to C#.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Convert this Perl snippet to C# and keep its semantics consistent.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Write a version of this Perl function in C++ with identical behavior.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Translate this program into C++ but keep the logic exactly as in Perl.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Translate the given Perl code snippet into Java without altering its behavior.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Preserve the algorithm and functionality while converting the code from Perl to Java.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Can you help me rewrite this code in Python instead of Perl, keeping it the same logically?
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Keep all operations the same but rewrite the snippet in Python.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Convert the following code from Perl to Go, ensuring the logic remains intact.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Keep all operations the same but rewrite the snippet in Go.
use strict; use warnings; no warnings 'uninitialized'; use feature 'say'; use experimental 'signatures'; use constant Inf => 1e10; my @tests = ( { limits => [23, 37, 43, 53, 67, 83], data => [ 95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47, 16, 8...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Translate this program into C but keep the logic exactly as in Racket.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Translate this program into C but keep the logic exactly as in Racket.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Change the following Racket code into C# without altering its purpose.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Ensure the translated C# code behaves exactly like the original Racket snippet.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
using System; public class Program { static void Main() { PrintBins(new [] { 23, 37, 43, 53, 67, 83 }, 95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47, 16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55 ); Console.Wr...
Ensure the translated C++ code behaves exactly like the original Racket snippet.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Translate the given Racket code snippet into C++ without altering its behavior.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream> #include <vector> std::vector<int> bins(const std::vector<int>& limits, const std::vector<int>& data) { std::vector<int> result(limits.size() + 1, 0); for (int n : data) { auto i = std::upper_bound(limi...
Generate an equivalent Java version of this Racket code.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Write the same algorithm in Java as shown in this Racket implementation.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Bins { public static <T extends Comparable<? super T>> int[] bins( List<? extends T> limits, Iterable<? extends T> data) { int[] result = new int[limits.size() + 1]; for (T n : data) { ...
Maintain the same structure and functionality when rewriting this code in Python.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Convert this Racket snippet to Python and keep its semantics consistent.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
from bisect import bisect_right def bin_it(limits: list, data: list) -> list: "Bin data according to (ascending) limits." bins = [0] * (len(limits) + 1) for d in data: bins[bisect_right(limits, d)] += 1 return bins def bin_print(limits: list, bins: list) -> list: print(f" < ...
Change the following Racket code into Go without altering its purpose.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Port the provided Racket code into Go while preserving the original functionality.
#lang racket (define (find-bin-index limits v) (let inner ((l 0) (r (vector-length limits))) (let ((m (quotient (+ l r) 2))) (if (< v (vector-ref limits m)) (if (= m l) l (inner l m)) (if (= m (sub1 r)) r (inner m r)))))) (define ((bin-given-limits! limits) data (bins (make-vector (add...
package main import ( "fmt" "sort" ) func getBins(limits, data []int) []int { n := len(limits) bins := make([]int, n+1) for _, d := range data { index := sort.SearchInts(limits, d) if index < len(limits) && d == limits[index] { index++ } bins[index]++ ...
Keep all operations the same but rewrite the snippet in C.
lims= 23 37 43 53 67 83 data= 95 21 94 12 99 4 70 75 83 93 52 80 57 5 53 86 65 17 92 83 71 61 54 58 47 , 16 8 9 32 84 7 87 46 19 30 37 96 6 98 40 79 97 45 64 60 29 49 36 43 55 call lims lims; call bins data call show 'the 1st set of bin counts for the specified data:' ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...
Write a version of this REXX function in C with identical behavior.
lims= 23 37 43 53 67 83 data= 95 21 94 12 99 4 70 75 83 93 52 80 57 5 53 86 65 17 92 83 71 61 54 58 47 , 16 8 9 32 84 7 87 46 19 30 37 96 6 98 40 79 97 45 64 60 29 49 36 43 55 call lims lims; call bins data call show 'the 1st set of bin counts for the specified data:' ...
#include <stdio.h> #include <stdlib.h> size_t upper_bound(const int* array, size_t n, int value) { size_t start = 0; while (n > 0) { size_t step = n / 2; size_t index = start + step; if (value >= array[index]) { start = index + 1; n -= step + 1; } else { ...