Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <iostream>
#include <map>
#include <random>
std::default_random_engine generator;
std::uniform_int_distribution<int> dice(1, 6);
int rollDice() {
return dice(generator);
}
const bool sixesThrowAgain = true;
const std::map<int, int> snl{
{4, 14},
{9, 31},
{17, 7},
{20, 38},
{28, 84},
... |
import java.util.Random
val rand = Random()
val snl = mapOf(
4 to 14, 9 to 31, 17 to 7, 20 to 38, 28 to 84, 40 to 59, 51 to 67, 54 to 34,
62 to 19, 63 to 81, 64 to 60, 71 to 91, 87 to 24, 93 to 73, 95 to 75, 99 to 78
)
val sixThrowsAgain = true
fun turn(player: Int, square: Int): Int {
var square2 ... |
Write a version of this C++ function in Scala with identical behavior. | #include <iostream>
#include <map>
#include <random>
std::default_random_engine generator;
std::uniform_int_distribution<int> dice(1, 6);
int rollDice() {
return dice(generator);
}
const bool sixesThrowAgain = true;
const std::map<int, int> snl{
{4, 14},
{9, 31},
{17, 7},
{20, 38},
{28, 84},
... |
import java.util.Random
val rand = Random()
val snl = mapOf(
4 to 14, 9 to 31, 17 to 7, 20 to 38, 28 to 84, 40 to 59, 51 to 67, 54 to 34,
62 to 19, 63 to 81, 64 to 60, 71 to 91, 87 to 24, 93 to 73, 95 to 75, 99 to 78
)
val sixThrowsAgain = true
fun turn(player: Int, square: Int): Int {
var square2 ... |
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <iostream>
struct fraction {
fraction(int n, int d) : numerator(n), denominator(d) {}
int numerator;
int denominator;
};
std::ostream& operator<<(std::ostream& out, const fraction& f) {
out << f.numerator << '/' << f.denominator;
return out;
}
class farey_sequence {
public:
explicit ... |
fun farey(n: Int): List<String> {
var a = 0
var b = 1
var c = 1
var d = n
val f = mutableListOf("$a/$b")
while (c <= n) {
val k = (n + b) / d
val aa = a
val bb = b
a = c
b = d
c = k * c - aa
d = k * d - bb
f.add("$a/$b")
}
... |
Change the following C++ code into Scala without altering its purpose. | #include <iostream>
struct fraction {
fraction(int n, int d) : numerator(n), denominator(d) {}
int numerator;
int denominator;
};
std::ostream& operator<<(std::ostream& out, const fraction& f) {
out << f.numerator << '/' << f.denominator;
return out;
}
class farey_sequence {
public:
explicit ... |
fun farey(n: Int): List<String> {
var a = 0
var b = 1
var c = 1
var d = n
val f = mutableListOf("$a/$b")
while (c <= n) {
val k = (n + b) / d
val aa = a
val bb = b
a = c
b = d
c = k * c - aa
d = k * d - bb
f.add("$a/$b")
}
... |
Can you help me rewrite this code in Scala instead of C++, keeping it the same logically? | #include <cstdint>
#include <iostream>
#include <string>
using integer = uint64_t;
integer divisor_sum(integer n) {
integer total = 1, power = 2;
for (; n % 2 == 0; power *= 2, n /= 2)
total += power;
for (integer p = 3; p * p <= n; p += 2) {
integer sum = 1;
for (power ... |
data class Classification(val sequence: List<Long>, val aliquot: String)
const val THRESHOLD = 1L shl 47
fun sumProperDivisors(n: Long): Long {
if (n < 2L) return 0L
val sqrt = Math.sqrt(n.toDouble()).toLong()
var sum = 1L + (2L..sqrt)
.filter { n % it == 0L }
.map { it + n / it }
... |
Maintain the same structure and functionality when rewriting this code in Scala. | #include <cstdint>
#include <iostream>
#include <string>
using integer = uint64_t;
integer divisor_sum(integer n) {
integer total = 1, power = 2;
for (; n % 2 == 0; power *= 2, n /= 2)
total += power;
for (integer p = 3; p * p <= n; p += 2) {
integer sum = 1;
for (power ... |
data class Classification(val sequence: List<Long>, val aliquot: String)
const val THRESHOLD = 1L shl 47
fun sumProperDivisors(n: Long): Long {
if (n < 2L) return 0L
val sqrt = Math.sqrt(n.toDouble()).toLong()
var sum = 1L + (2L..sqrt)
.filter { n % it == 0L }
.map { it + n / it }
... |
Rewrite this program in Scala while keeping its functionality equivalent to the C++ version. | #include <iostream>
#include <math.h>
struct PolarPoint;
struct CartesianPoint
{
double x;
double y;
operator PolarPoint();
};
struct PolarPoint
{
double rho;
double theta;
operator CartesianPoint();
};
CartesianPoint::operator PolarPoint()
{
return PolarPoint
... |
open class C(val x: Int)
class D(x: Int) : C(x)
fun main(args: Array<String>) {
val c: C = D(42)
println(c.x)
val b: Byte = 100
println(b)
val s: Short = 32000
println(s)
val l: Long = 1_000_000
println(l)
val n : Int? = c.x
println(n)
}
|
Maintain the same structure and functionality when rewriting this code in Scala. | #include <iostream>
#include <math.h>
struct PolarPoint;
struct CartesianPoint
{
double x;
double y;
operator PolarPoint();
};
struct PolarPoint
{
double rho;
double theta;
operator CartesianPoint();
};
CartesianPoint::operator PolarPoint()
{
return PolarPoint
... |
open class C(val x: Int)
class D(x: Int) : C(x)
fun main(args: Array<String>) {
val c: C = D(42)
println(c.x)
val b: Byte = 100
println(b)
val s: Short = 32000
println(s)
val l: Long = 1_000_000
println(l)
val n : Int? = c.x
println(n)
}
|
Rewrite the snippet below in Scala so it works the same as the original C++ code. | #include <iostream>
bool isPrime(uint64_t n) {
if (n < 2) return false;
if (n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
uint64_t test = 5;
while (test * test < n) {
if (n % test == 0) return false;
test += 2;
if (n % test == 0) return false;
test += 4;... |
import java.math.BigInteger
const val MAX = 20
val bigOne = BigInteger.ONE
val bigTwo = 2.toBigInteger()
fun isPrime(n: Int): Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d == 0) return false
... |
Rewrite the snippet below in Scala so it works the same as the original C++ code. | #include <iostream>
bool isPrime(uint64_t n) {
if (n < 2) return false;
if (n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
uint64_t test = 5;
while (test * test < n) {
if (n % test == 0) return false;
test += 2;
if (n % test == 0) return false;
test += 4;... |
import java.math.BigInteger
const val MAX = 20
val bigOne = BigInteger.ONE
val bigTwo = 2.toBigInteger()
fun isPrime(n: Int): Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d == 0) return false
... |
Can you help me rewrite this code in Scala instead of C++, keeping it the same logically? | #include <array>
#include <iostream>
#include <vector>
#include <boost/circular_buffer.hpp>
#include "prime_sieve.hpp"
int main() {
using std::cout;
using std::vector;
using boost::circular_buffer;
using group_buffer = circular_buffer<vector<int>>;
const int max = 1000035;
const int max_group_... |
fun sieve(lim: Int): BooleanArray {
var limit = lim + 1
val c = BooleanArray(limit)
c[0] = true
c[1] = true
var p = 3
while (true) {
val p2 = p * p
if (p2 >= limit) break
for (i in p2 until limit step 2 * p) c[i] = true
while (true) {
p... |
Convert the following code from C++ to Scala, ensuring the logic remains intact. | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
template <typename T>
size_t indexOf(const std::vector<T> &v, const T &k) {
auto it = std::find(v.cbegin(), v.cend(), k);
if (it != v.cend()) {
return it - v.cbegin();
}
return -1;
}... |
import java.util.PriorityQueue
class CubeSum(val x: Long, val y: Long) : Comparable<CubeSum> {
val value: Long = x * x * x + y * y * y
override fun toString() = String.format("%4d^3 + %3d^3", x, y)
override fun compareTo(other: CubeSum) = value.compareTo(other.value)
}
class SumIterator : Iterator<Cu... |
Translate this program into Scala but keep the logic exactly as in C++. | #include <algorithm>
#include <iostream>
#include <iterator>
#include <locale>
#include <vector>
#include "prime_sieve.hpp"
const int limit1 = 1000000;
const int limit2 = 10000000;
class prime_info {
public:
explicit prime_info(int max) : max_print(max) {}
void add_prime(int prime);
void print(std::ostrea... | private const val MAX = 10000000 + 1000
private val primes = BooleanArray(MAX)
fun main() {
sieve()
println("First 36 strong primes:")
displayStrongPrimes(36)
for (n in intArrayOf(1000000, 10000000)) {
System.out.printf("Number of strong primes below %,d = %,d%n", n, strongPrimesBelow(n))
... |
Convert the following code from C++ to Scala, ensuring the logic remains intact. | #include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
#if 1
typedef unsigned long usingle;
typedef unsigned long long udouble;
const int word_len = 32;
#else
typedef unsigned short usingle;
typedef unsigned long udouble;
const int word_len = 16;
#endif
... |
import java.math.BigInteger
fun leftFactorial(n: Int): BigInteger {
if (n == 0) return BigInteger.ZERO
var fact = BigInteger.ONE
var sum = fact
for (i in 1 until n) {
fact *= BigInteger.valueOf(i.toLong())
sum += fact
}
return sum
}
fun main(args: Array<String... |
Convert the following code from C++ to Scala, ensuring the logic remains intact. | #include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
#if 1
typedef unsigned long usingle;
typedef unsigned long long udouble;
const int word_len = 32;
#else
typedef unsigned short usingle;
typedef unsigned long udouble;
const int word_len = 16;
#endif
... |
import java.math.BigInteger
fun leftFactorial(n: Int): BigInteger {
if (n == 0) return BigInteger.ZERO
var fact = BigInteger.ONE
var sum = fact
for (i in 1 until n) {
fact *= BigInteger.valueOf(i.toLong())
sum += fact
}
return sum
}
fun main(args: Array<String... |
Generate an equivalent Scala version of this C++ code. | #include <iomanip>
#include <iostream>
#include <vector>
std::vector<bool> prime_sieve(size_t limit) {
std::vector<bool> sieve(limit, true);
if (limit > 0)
sieve[0] = false;
if (limit > 1)
sieve[1] = false;
for (size_t i = 4; i < limit; i += 2)
sieve[i] = false;
for (size_t ... | val primeStream5 = LazyList.from(5, 6)
.flatMap(n => Seq(n, n + 2))
.filter(p => (5 to math.sqrt(p).floor.toInt by 6).forall(a => p % a > 0 && p % (a + 2) > 0))
val primes = LazyList(2, 3) ++ primeStream5
def isPrime(n: Int): Boolean =
if (n < 5) (n | 1) == 3
else primes.takeWhile(_ <= math.sqrt(n)).... |
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <iomanip>
#include <iostream>
#include <vector>
std::vector<bool> prime_sieve(size_t limit) {
std::vector<bool> sieve(limit, true);
if (limit > 0)
sieve[0] = false;
if (limit > 1)
sieve[1] = false;
for (size_t i = 4; i < limit; i += 2)
sieve[i] = false;
for (size_t ... | val primeStream5 = LazyList.from(5, 6)
.flatMap(n => Seq(n, n + 2))
.filter(p => (5 to math.sqrt(p).floor.toInt by 6).forall(a => p % a > 0 && p % (a + 2) > 0))
val primes = LazyList(2, 3) ++ primeStream5
def isPrime(n: Int): Boolean =
if (n < 5) (n | 1) == 3
else primes.takeWhile(_ <= math.sqrt(n)).... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <iostream>
#include <vector>
const std::vector<bool> p{
false, false, true, true, false,
true, false, true, false, false,
false, true, false, true, false,
false, false, true, false
};
bool isStrange(long n) {
if (n < 10) {
return false;
}
for (; n >= 10; n /= 10) {
... | val p = arrayOf(
false, false, true, true, false,
true, false, true, false, false,
false, true, false, true, false,
false, false, true, false
)
fun isStrange(n: Long): Boolean {
if (n < 10) {
return false
}
var nn = n
while (nn >= 10) {
if (!p[(nn % 10 + (nn / 10) % 10)... |
Translate this program into Scala but keep the logic exactly as in C++. | #include <iostream>
#include <vector>
const std::vector<bool> p{
false, false, true, true, false,
true, false, true, false, false,
false, true, false, true, false,
false, false, true, false
};
bool isStrange(long n) {
if (n < 10) {
return false;
}
for (; n >= 10; n /= 10) {
... | val p = arrayOf(
false, false, true, true, false,
true, false, true, false, false,
false, true, false, true, false,
false, false, true, false
)
fun isStrange(n: Long): Boolean {
if (n < 10) {
return false
}
var nn = n
while (nn >= 10) {
if (!p[(nn % 10 + (nn / 10) % 10)... |
Translate this program into Scala but keep the logic exactly as in C++. | #include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
class magicSqr
{
public:
magicSqr( int d ) {
while( d % 4 > 0 ) { d++; }
sz = d;
sqr = new int[sz * sz];
fillSqr();
}
~magicSqr() { delete [] sqr; }
void display() const {
cout << "D... |
fun magicSquareDoublyEven(n: Int): Array<IntArray> {
if ( n < 4 || n % 4 != 0)
throw IllegalArgumentException("Base must be a positive multiple of 4")
val bits = 0b1001_0110_0110_1001
val size = n * n
val mult = n / 4
val result = Array(n) { IntArray(n) }
var i = 0
for (r ... |
Port the following code from C++ to Scala with equivalent syntax and logic. | #include <windows.h>
#include <math.h>
#include <string>
const int BMP_SIZE = 240, MY_TIMER = 987654;
class myBitmap {
public:
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
~myBitmap() {
DeleteObject( pen ); DeleteObject( brush );
DeleteDC( hdc ); DeleteObject( bmp );
}
... |
import java.awt.*
import java.awt.image.BufferedImage
import javax.swing.*
class PlasmaEffect : JPanel() {
private val plasma: Array<FloatArray>
private var hueShift = 0.0f
private val img: BufferedImage
init {
val dim = Dimension(640, 640)
preferredSize = dim
background = Co... |
Write the same code in Scala as shown below in C++. | #include <cstdint>
#include <iostream>
#include <string>
using integer = uint64_t;
bool square_free(integer n) {
if (n % 4 == 0)
return false;
for (integer p = 3; p * p <= n; p += 2) {
integer count = 0;
for (; n % p == 0; n /= p) {
if (++count > 1)
return f... |
import kotlin.math.sqrt
fun sieve(limit: Long): List<Long> {
val primes = mutableListOf(2L)
val c = BooleanArray(limit.toInt() + 1)
var p = 3
while (true) {
val p2 = p * p
if (p2 > limit) break
for (i in p2..limit step 2L * p) c[i.toInt()] = true
do { p += 2 } wh... |
Keep all operations the same but rewrite the snippet in Scala. | #include <array>
#include <iomanip>
#include <iostream>
const int MC = 103 * 1000 * 10000 + 11 * 9 + 1;
std::array<bool, MC + 1> SV;
void sieve() {
std::array<int, 10000> dS;
for (int a = 9, i = 9999; a >= 0; a--) {
for (int b = 9; b >= 0; b--) {
for (int c = 9, s = a + b; c >= 0; c--) {
... | private const val MC = 103 * 1000 * 10000 + 11 * 9 + 1
private val SV = BooleanArray(MC + 1)
private fun sieve() {
val dS = IntArray(10000)
run {
var a = 9
var i = 9999
while (a >= 0) {
for (b in 9 downTo 0) {
var c = 9
val s = a + b
... |
Translate the given C++ code snippet into Scala without altering its behavior. | #include <iostream>
#include <iomanip>
using namespace std;
class ormConverter
{
public:
ormConverter() : AR( 0.7112f ), CE( 0.01f ), DI( 0.0254f ), FU( 0.3048f ), KI( 1000.0f ), LI( 0.00254f ), ME( 1.0f ),
MI( 7467.6f ), PI( 0.1778f ), SA( 2.1336f ), TO( 0.000254f ), VE( 0.04445f ), VR( 1066.8f ) {}
... |
fun cls() = ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor()
fun main(args: Array<String>) {
val units = listOf("tochka", "liniya", "dyuim", "vershok", "piad", "fut",
"arshin", "sazhen", "versta", "milia",
"centimeter", "meter", "kilometer")
val ... |
Generate an equivalent Scala version of this C++ code. | #include <iostream>
#include <vector>
constexpr int N = 2200;
constexpr int N2 = 2 * N * N;
int main() {
using namespace std;
vector<bool> found(N + 1);
vector<bool> aabb(N2 + 1);
int s = 3;
for (int a = 1; a < N; ++a) {
int aa = a * a;
for (int b = 1; b < N; ++b) {
... |
const val MAX = 2200
const val MAX2 = MAX * MAX - 1
fun main(args: Array<String>) {
val found = BooleanArray(MAX + 1)
val p2 = IntArray(MAX + 1) { it * it }
val dc = mutableMapOf<Int, MutableList<Int>>()
for (d in 1..MAX) {
for (c in 1 until d) {
val diff = p2[d] - ... |
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
std::ostream &operator<<(std::ostream &os, std::vector<std::pair<int, int>> &v) {
for (auto &p : v) {
auto sum = p.first + p.second;
auto prod = p.first * p.second;
os << '[' << p.first << ", " << p.second << "] S=" <... |
data class P(val x: Int, val y: Int, val sum: Int, val prod: Int)
fun main(args: Array<String>) {
val candidates = mutableListOf<P>()
for (x in 2..49) {
for (y in x + 1..100 - x) {
candidates.add(P(x, y, x + y, x * y))
}
}
val sums = candidates.groupBy { it.sum }
... |
Convert this C++ snippet to Scala and keep its semantics consistent. | #include <array>
#include <iostream>
#include <vector>
constexpr int MAX = 12;
static std::vector<char> sp;
static std::array<int, MAX> count;
static int pos = 0;
int factSum(int n) {
int s = 0;
int x = 0;
int f = 1;
while (x < n) {
f *= ++x;
s += f;
}
return s;
}
bool r(int ... |
const val MAX = 12
var sp = CharArray(0)
val count = IntArray(MAX)
var pos = 0
fun factSum(n: Int): Int {
var s = 0
var x = 0
var f = 1
while (x < n) {
f *= ++x
s += f
}
return s
}
fun r(n: Int): Boolean {
if (n == 0) return false
val c = sp[pos - n]
if (--co... |
Convert this C++ snippet to Scala and keep its semantics consistent. | #include <complex>
#include <math.h>
#include <iostream>
template<class Type>
struct Precision
{
public:
static Type GetEps()
{
return eps;
}
static void SetEps(Type e)
{
eps = e;
}
private:
static Type eps;
};
template<class Type> Type Precision<Type>::eps = static_cast<Type>(1E-7);
template<class DigT... |
import java.math.BigInteger
import java.math.BigDecimal
fun Double.isLong(tolerance: Double = 0.0) =
(this - Math.floor(this)) <= tolerance || (Math.ceil(this) - this) <= tolerance
fun BigDecimal.isBigInteger() =
try {
this.toBigIntegerExact()
true
}
catch (ex: ArithmeticException) ... |
Change the following C++ code into Scala without altering its purpose. | #include <fstream>
#include <iostream>
#include <numeric>
#include <unistd.h>
#include <vector>
std::vector<size_t> get_cpu_times() {
std::ifstream proc_stat("/proc/stat");
proc_stat.ignore(5, ' ');
std::vector<size_t> times;
for (size_t time; proc_stat >> time; times.push_back(time));
return time... |
import java.io.FileReader
import java.io.BufferedReader
fun main(args: Array<String>) {
println("CPU usage % at 1 second intervals:\n")
var prevIdleTime = 0L
var prevTotalTime = 0L
repeat(10) {
val br = BufferedReader(FileReader("/proc/stat"))
val firstLine = br.readLine().drop(5)
... |
Transform the following C++ implementation into Scala, maintaining the same output and logic. | #include <iostream>
template <typename T>
auto typeString(const T&) {
return typeid(T).name();
}
class C {};
struct S {};
int main() {
std::cout << typeString(1) << '\n';
std::cout << typeString(1L) << '\n';
std::cout << typeString(1.0f) << '\n';
std::cout << typeString(1.0) << '\n';
std::cou... |
fun showType(a: Any) = when (a) {
is Int -> println("'$a' is an integer")
is Double -> println("'$a' is a double")
is Char -> println("'$a' is a character")
else -> println("'$a' is some other type")
}
fun main(args: Array<String>) {
showType(5)
showType(7.5)
... |
Change the following C++ code into Scala without altering its purpose. | #include <algorithm>
#include <iostream>
#include <iterator>
#include <locale>
#include <vector>
#include "prime_sieve.hpp"
const int limit1 = 1000000;
const int limit2 = 10000000;
class prime_info {
public:
explicit prime_info(int max) : max_print(max) {}
void add_prime(int prime);
void print(std::ostrea... |
fun sieve(limit: Int): BooleanArray {
val c = BooleanArray(limit + 1)
c[0] = true
c[1] = true
for (i in 4..limit step 2) c[i] = true
var p = 3
while (true) {
val p2 = p * p
if (p2 > limit) break
for (i in p2..limit step 2 * p) c[i] = true
while (true... |
Transform the following C++ implementation into Scala, maintaining the same output and logic. | #include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using tab_t = std::vector<std::vector<std::string>>;
tab_t tab1 {
{"27", "Jonah"}
, {"18", "Alan"}
, {"28", "Glory"}
, {"18", "Popeye"}
, {"28", "Alan"}
};
tab_t tab2 {
{"Jonah", "Whales"}
, {"Jonah", "Spiders"}
, {"Alan", "Ghosts"... | data class A(val age: Int, val name: String)
data class B(val character: String, val nemesis: String)
data class C(val rowA: A, val rowB: B)
fun hashJoin(tableA: List<A>, tableB: List<B>): List<C> {
val mm = tableB.groupBy { it.character }
val tableC = mutableListOf<C>()
for (a in tableA) {
val v... |
Convert this C++ snippet to Scala and keep its semantics consistent. | #include <gmpxx.h>
#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <vector>
using big_int = mpz_class;
const unsigned int small_primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23,
29, 31, 37, 41, 43, 47, 53, 59, 61,
... |
import java.math.BigInteger
fun nextLeftTruncatablePrimes(n: BigInteger, radix: Int, certainty: Int): List<BigInteger> {
val probablePrimes = mutableListOf<BigInteger>()
val baseString = if (n == BigInteger.ZERO) "" else n.toString(radix)
for (i in 1 until radix) {
val p = BigInteger(i.toString(r... |
Write the same code in Scala as shown below in C++. | #include <iostream>
#include <ratio>
#include <array>
#include <algorithm>
#include <random>
typedef short int Digit;
constexpr Digit nDigits{4};
constexpr Digit maximumDigit{9};
constexpr short int gameGoal{24};
typedef std::array<Digit, nDigits> digitSet;
digitSet d;
void printTrivialOperation(std::... |
import java.util.Random
const val N_CARDS = 4
const val SOLVE_GOAL = 24
const val MAX_DIGIT = 9
class Frac(val num: Int, val den: Int)
enum class OpType { NUM, ADD, SUB, MUL, DIV }
class Expr(
var op: OpType = OpType.NUM,
var left: Expr? = null,
var right: Expr? = null,
var value: Int = 0... |
Transform the following C++ implementation into Scala, maintaining the same output and logic. | #include <iostream>
#include <ratio>
#include <array>
#include <algorithm>
#include <random>
typedef short int Digit;
constexpr Digit nDigits{4};
constexpr Digit maximumDigit{9};
constexpr short int gameGoal{24};
typedef std::array<Digit, nDigits> digitSet;
digitSet d;
void printTrivialOperation(std::... |
import java.util.Random
const val N_CARDS = 4
const val SOLVE_GOAL = 24
const val MAX_DIGIT = 9
class Frac(val num: Int, val den: Int)
enum class OpType { NUM, ADD, SUB, MUL, DIV }
class Expr(
var op: OpType = OpType.NUM,
var left: Expr? = null,
var right: Expr? = null,
var value: Int = 0... |
Translate the given C++ code snippet into Scala without altering its behavior. | UINT_64 TGost::SWAP32(UINT_32 N1, UINT_32 N2)
{
UINT_64 N;
N = N1;
N = (N<<32)|N2;
return UINT_64(N);
}
UINT_32 TGost::ReplaceBlock(UINT_32 x)
{
register i;
UINT_32 res = 0UL;
for(i=7;i>=0;i--)
{
ui4_0 = x>>(i*4);
ui4_0 = BS[ui4_0][i];
res = (res<<4)|ui4_0;
}
retu... |
fun Byte.toUInt() = java.lang.Byte.toUnsignedInt(this)
fun Byte.toULong() = java.lang.Byte.toUnsignedLong(this)
fun Int.toULong() = java.lang.Integer.toUnsignedLong(this)
val s = arrayOf(
byteArrayOf( 4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3),
byteArrayOf(14, 11, 4, 12, 6, 13, 15, ... |
Please provide an equivalent version of this C++ code in Scala. | #include <iostream>
#include <list>
int main ()
{
std::list<int> numbers {1, 5, 7, 0, 3, 2};
numbers.insert(numbers.begin(), 9);
numbers.insert(numbers.end(), 4);
auto it = std::next(numbers.begin(), numbers.size() / 2);
numbers.insert(it, 6);
for(const auto& i: numbers)
std::cout <... |
class LinkedList<E> {
class Node<E>(var data: E, var prev: Node<E>? = null, var next: Node<E>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.dat... |
Write the same algorithm in Scala as shown in this C++ implementation. | #include <iostream>
#include <stack>
#include <string>
#include <sstream>
#include <vector>
struct var {
char name;
bool value;
};
std::vector<var> vars;
template<typename T>
T pop(std::stack<T> &s) {
auto v = s.top();
s.pop();
return v;
}
bool is_operator(char c) {
return c == '&' || c == '|... |
import java.util.Stack
class Variable(val name: Char, var value: Boolean = false)
lateinit var expr: String
var variables = mutableListOf<Variable>()
fun Char.isOperator() = this in "&|!^"
fun Char.isVariable() = this in variables.map { it.name }
fun evalExpression(): Boolean {
val stack = Stack<Boolean>()
... |
Transform the following C++ implementation into Scala, maintaining the same output and logic. | #include <iostream>
#include <stack>
#include <string>
#include <sstream>
#include <vector>
struct var {
char name;
bool value;
};
std::vector<var> vars;
template<typename T>
T pop(std::stack<T> &s) {
auto v = s.top();
s.pop();
return v;
}
bool is_operator(char c) {
return c == '&' || c == '|... |
import java.util.Stack
class Variable(val name: Char, var value: Boolean = false)
lateinit var expr: String
var variables = mutableListOf<Variable>()
fun Char.isOperator() = this in "&|!^"
fun Char.isVariable() = this in variables.map { it.name }
fun evalExpression(): Boolean {
val stack = Stack<Boolean>()
... |
Convert this C++ snippet to Scala and keep its semantics consistent. | #include <cassert>
#include <functional>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
enum RangeType {
CLOSED,
BOTH_OPEN,
LEFT_OPEN,
RIGHT_OPEN
};
class RealSet {
private:
double low, high;
double interval = 0.00001;
std::function<bool(double)> predicate;
public:
R... |
typealias RealPredicate = (Double) -> Boolean
enum class RangeType { CLOSED, BOTH_OPEN, LEFT_OPEN, RIGHT_OPEN }
class RealSet(val low: Double, val high: Double, val predicate: RealPredicate) {
constructor (start: Double, end: Double, rangeType: RangeType): this(start, end,
when (rangeType) {
... |
Produce a functionally identical Scala code for the snippet given in C++. | #include <cassert>
#include <functional>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
enum RangeType {
CLOSED,
BOTH_OPEN,
LEFT_OPEN,
RIGHT_OPEN
};
class RealSet {
private:
double low, high;
double interval = 0.00001;
std::function<bool(double)> predicate;
public:
R... |
typealias RealPredicate = (Double) -> Boolean
enum class RangeType { CLOSED, BOTH_OPEN, LEFT_OPEN, RIGHT_OPEN }
class RealSet(val low: Double, val high: Double, val predicate: RealPredicate) {
constructor (start: Double, end: Double, rangeType: RangeType): this(start, end,
when (rangeType) {
... |
Ensure the translated Scala code behaves exactly like the original C++ snippet. | #include <algorithm>
#include <iostream>
#include <string>
#include <array>
#include <vector>
template<typename T>
T unique(T&& src)
{
T retval(std::move(src));
std::sort(retval.begin(), retval.end(), std::less<typename T::value_type>());
retval.erase(std::unique(retval.begin(), retval.end()), retval.end()... |
fun solve(states: List<String>) {
val dict = mutableMapOf<String, String>()
for (state in states) {
val key = state.toLowerCase().replace(" ", "")
if (dict[key] == null) dict.put(key, state)
}
val keys = dict.keys.toList()
val solutions = mutableListOf<String>()
val duplicates ... |
Write the same code in Scala as shown below in C++. | #include <iostream>
#include <sstream>
#include <vector>
uint64_t ipow(uint64_t base, uint64_t exp) {
uint64_t result = 1;
while (exp) {
if (exp & 1) {
result *= base;
}
exp >>= 1;
base *= base;
}
return result;
}
int main() {
using namespace std;
v... | import java.math.BigInteger
fun superD(d: Int, max: Int) {
val start = System.currentTimeMillis()
var test = ""
for (i in 0 until d) {
test += d
}
var n = 0
var i = 0
println("First $max super-$d numbers:")
while (n < max) {
i++
val value: Any = BigInteger.value... |
Maintain the same structure and functionality when rewriting this code in Scala. | #include <iostream>
#include <sstream>
#include <vector>
uint64_t ipow(uint64_t base, uint64_t exp) {
uint64_t result = 1;
while (exp) {
if (exp & 1) {
result *= base;
}
exp >>= 1;
base *= base;
}
return result;
}
int main() {
using namespace std;
v... | import java.math.BigInteger
fun superD(d: Int, max: Int) {
val start = System.currentTimeMillis()
var test = ""
for (i in 0 until d) {
test += d
}
var n = 0
var i = 0
println("First $max super-$d numbers:")
while (n < max) {
i++
val value: Any = BigInteger.value... |
Write the same algorithm in Scala as shown in this C++ implementation. | #include <iostream>
#include <cmath>
#include <optional>
#include <vector>
using namespace std;
template <typename T>
auto operator>>(const optional<T>& monad, auto f)
{
if(!monad.has_value())
{
return optional<remove_reference_t<decltype(*f(*monad))>>();
}
return f(*monad)... |
import java.util.Optional
fun getOptionalInt(i: Int) = Optional.of(2 * i)
fun getOptionalString(i: Int) = Optional.of("A".repeat(i))
fun getOptionalString2(i: Int) =
Optional.ofNullable(if (i > 0) "A".repeat(i) else null)
fun main(args: Array<String>) {
println(getOptionalInt(5).flatMap(::getOption... |
Write the same algorithm in Scala as shown in this C++ implementation. | #include <iostream>
#include <vector>
using namespace std;
template <typename T>
auto operator>>(const vector<T>& monad, auto f)
{
vector<remove_reference_t<decltype(f(monad.front()).front())>> result;
for(auto& item : monad)
{
const auto r = f(item);
resul... |
class MList<T : Any> private constructor(val value: List<T>) {
fun <U : Any> bind(f: (List<T>) -> MList<U>) = f(this.value)
companion object {
fun <T : Any> unit(lt: List<T>) = MList<T>(lt)
}
}
fun doubler(li: List<Int>) = MList.unit(li.map { 2 * it } )
fun letters(li: List<Int>) = MList.unit(l... |
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
struct Textonym_Checker {
private:
int total;
int elements;
int textonyms;
int max_found;
std::vector<std::string> max_strings;
std::unordered_map<std::string, std::vector<std::string>> values;
int get_mappin... |
import java.io.File
val wordList = "unixdict.txt"
val url = "http:
const val DIGITS = "22233344455566677778889999"
val map = mutableMapOf<String, MutableList<String>>()
fun processList() {
var countValid = 0
val f = File(wordList)
val sb = StringBuilder()
f.forEachLine { word->
var valid ... |
Convert the following code from C++ to Scala, ensuring the logic remains intact. | #include <iostream>
struct SpecialVariables
{
int i = 0;
SpecialVariables& operator++()
{
this->i++;
return *this;
}
};
int main()
{
SpecialVariables sv;
auto sv2 = ++sv;
std::cout << " sv :" << sv.i << "\n sv2:" << sv2.i << "\n... |
class President(val name: String) {
var age: Int = 0
set(value) {
if (value in 0..125) field = value
else throw IllegalArgumentException("$name's age must be between 0 and 125")
}
}
fun main(args: Array<String>) {
val pres = President("Donald")
pres.age = 69
... |
Convert the following code from C++ to Scala, ensuring the logic remains intact. | #include <cstdint>
#include <iostream>
#include <sstream>
#include <gmpxx.h>
typedef mpz_class integer;
bool is_probably_prime(const integer& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 25) != 0;
}
bool is_prime(unsigned int n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2;
... |
import java.math.BigInteger
const val LIMIT = 20
fun isPrime(n: Int): Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d == 0) return false
d += 2
if (n % d == 0) return false
... |
Convert this C++ block to Scala, preserving its control flow and logic. | #include <boost/multiprecision/gmp.hpp>
#include <iostream>
using namespace boost::multiprecision;
mpz_int p(uint n, uint p) {
mpz_int r = 1;
mpz_int k = n - p;
while (n > k)
r *= n--;
return r;
}
mpz_int c(uint n, uint k) {
mpz_int r = p(n, k);
while (k)
r /= k--;
return ... |
import java.math.BigInteger
fun perm(n: Int, k: Int): BigInteger {
require(n > 0 && k >= 0)
return (n - k + 1 .. n).fold(BigInteger.ONE) { acc, i -> acc * BigInteger.valueOf(i.toLong()) }
}
fun comb(n: Int, k: Int): BigInteger {
require(n > 0 && k >= 0)
val fact = (2..k).fold(BigInteger.ONE) { acc, ... |
Generate an equivalent Scala version of this C++ code. | #include <gmpxx.h>
#include <chrono>
using namespace std;
using namespace chrono;
void agm(mpf_class& rop1, mpf_class& rop2, const mpf_class& op1,
const mpf_class& op2)
{
rop1 = (op1 + op2) / 2;
rop2 = op1 * op2;
mpf_sqrt(rop2.get_mpf_t(), rop2.get_mpf_t());
}
int main(void)
{
auto st = ste... | import java.math.BigDecimal
import java.math.MathContext
val con1024 = MathContext(1024)
val bigTwo = BigDecimal(2)
val bigFour = bigTwo * bigTwo
fun bigSqrt(bd: BigDecimal, con: MathContext): BigDecimal {
var x0 = BigDecimal.ZERO
var x1 = BigDecimal.valueOf(Math.sqrt(bd.toDouble()))
while (x0 != x1) {
... |
Translate this program into Scala but keep the logic exactly as in C++. | #include <gmpxx.h>
#include <chrono>
using namespace std;
using namespace chrono;
void agm(mpf_class& rop1, mpf_class& rop2, const mpf_class& op1,
const mpf_class& op2)
{
rop1 = (op1 + op2) / 2;
rop2 = op1 * op2;
mpf_sqrt(rop2.get_mpf_t(), rop2.get_mpf_t());
}
int main(void)
{
auto st = ste... | import java.math.BigDecimal
import java.math.MathContext
val con1024 = MathContext(1024)
val bigTwo = BigDecimal(2)
val bigFour = bigTwo * bigTwo
fun bigSqrt(bd: BigDecimal, con: MathContext): BigDecimal {
var x0 = BigDecimal.ZERO
var x1 = BigDecimal.valueOf(Math.sqrt(bd.toDouble()))
while (x0 != x1) {
... |
Port the following code from C++ to Scala with equivalent syntax and logic. | #include <iomanip>
#include <iostream>
#include <list>
using namespace std;
void sieve(int limit, list<int> &primes)
{
bool *c = new bool[limit + 1];
for (int i = 0; i <= limit; i++)
c[i] = false;
int p = 3, n = 0;
int p2 = p * p;
while (p2 <= limit)
{
for (int i = p2; i <= limit; i += 2 * p)
... |
fun sieve(limit: Int): List<Int> {
val primes = mutableListOf<Int>()
val c = BooleanArray(limit + 1)
var p = 3
var p2 = p * p
while (p2 <= limit) {
for (i in p2..limit step 2 * p) c[i] = true
do {
p += 2
} while (c[p])
p2 = p * p
}
for (i... |
Maintain the same structure and functionality when rewriting this code in Scala. | using System;
class Program {
static int l;
static int[] gp(int n) {
var c = new bool[n]; var r = new int[(int)(1.28 * n)];
l = 0; r[l++] = 2; r[l++] = 3; int j, d, lim = (int)Math.Sqrt(n);
for (int i = 9; i < n; i += 6) c[i] = true;
for (j = 5, d = 4; j < lim; j += (d = 6 - ... |
import java.math.BigInteger
const val LIMIT = 1000000
fun isPrime(n: Int): Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d == 0) return false
d += 2
if (n % d == 0) return fals... |
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <iostream>
#include <optional>
#include <vector>
#include <string>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int integer;
struct fraction {
fraction(const integer& n, const integer& d) : numerator(n), denominator(d) {}
integer numerator;
int... |
import java.math.BigInteger
import java.math.BigDecimal
import java.math.MathContext
val bigZero = BigInteger.ZERO
val bigOne = BigInteger.ONE
val bdZero = BigDecimal.ZERO
val context = MathContext.UNLIMITED
fun gcd(a: BigInteger, b: BigInteger): BigInteger
= if (b == bigZero) a else gcd(b, a % b)
class Frac... |
Please provide an equivalent version of this C++ code in Scala. | #include <iostream>
#include <optional>
#include <vector>
#include <string>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int integer;
struct fraction {
fraction(const integer& n, const integer& d) : numerator(n), denominator(d) {}
integer numerator;
int... |
import java.math.BigInteger
import java.math.BigDecimal
import java.math.MathContext
val bigZero = BigInteger.ZERO
val bigOne = BigInteger.ONE
val bdZero = BigDecimal.ZERO
val context = MathContext.UNLIMITED
fun gcd(a: BigInteger, b: BigInteger): BigInteger
= if (b == bigZero) a else gcd(b, a % b)
class Frac... |
Change the following C++ code into Scala without altering its purpose. | #include <iostream>
#include <iomanip>
#include <cmath>
namespace Rosetta {
template <int N>
class GaussLegendreQuadrature {
public:
enum {eDEGREE = N};
template <typename Function>
double integrate(double a, double b, Function f) {
double p = (b - a) / 2... | import java.lang.Math.*
class Legendre(val N: Int) {
fun evaluate(n: Int, x: Double) = (n downTo 1).fold(c[n][n]) { s, i -> s * x + c[n][i - 1] }
fun diff(n: Int, x: Double) = n * (x * evaluate(n, x) - evaluate(n - 1, x)) / (x * x - 1)
fun integrate(f: (Double) -> Double, a: Double, b: Double): Double {
... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <random>
#include <vector>
template<typename coordinate_type, size_t dimensions>
class point {
public:
point(std::array<coordinate_type, dimensions> c) : coords_(c) {}
point(std::initializer_list<coordinate_type> list) {
... |
import java.util.Random
typealias Point = DoubleArray
fun Point.sqd(p: Point) = this.zip(p) { a, b -> (a - b) * (a - b) }.sum()
class HyperRect (val min: Point, val max: Point) {
fun copy() = HyperRect(min.copyOf(), max.copyOf())
}
data class NearestNeighbor(val nearest: Point?, val distSqd: Double, val nodes... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <random>
#include <vector>
template<typename coordinate_type, size_t dimensions>
class point {
public:
point(std::array<coordinate_type, dimensions> c) : coords_(c) {}
point(std::initializer_list<coordinate_type> list) {
... |
import java.util.Random
typealias Point = DoubleArray
fun Point.sqd(p: Point) = this.zip(p) { a, b -> (a - b) * (a - b) }.sum()
class HyperRect (val min: Point, val max: Point) {
fun copy() = HyperRect(min.copyOf(), max.copyOf())
}
data class NearestNeighbor(val nearest: Point?, val distSqd: Double, val nodes... |
Generate an equivalent Scala version of this C++ code. | #include <iostream>
#include <string>
#include <random>
int main()
{
std::random_device rd;
std::uniform_int_distribution<int> dist(1, 10);
std::mt19937 mt(rd());
std::cout << "Random Number (hardware): " << dist(rd) << std::endl;
std::cout << "Mersenne twister (hardware seeded): " << dist(mt... | import scala.util.Random
object Throws extends App {
Stream.continually(Random.nextInt(6) + Random.nextInt(6) + 2)
.take(200).groupBy(identity).toList.sortBy(_._1)
.foreach {
case (a, b) => println(f"$a%2d:" + "X" * b.size)
}
}
|
Ensure the translated Scala code behaves exactly like the original C++ snippet. | #include <iostream>
#include <string>
#include <random>
int main()
{
std::random_device rd;
std::uniform_int_distribution<int> dist(1, 10);
std::mt19937 mt(rd());
std::cout << "Random Number (hardware): " << dist(rd) << std::endl;
std::cout << "Mersenne twister (hardware seeded): " << dist(mt... | import scala.util.Random
object Throws extends App {
Stream.continually(Random.nextInt(6) + Random.nextInt(6) + 2)
.take(200).groupBy(identity).toList.sortBy(_._1)
.foreach {
case (a, b) => println(f"$a%2d:" + "X" * b.size)
}
}
|
Keep all operations the same but rewrite the snippet in Scala. | #include <array>
#include <iostream>
#include <stack>
#include <vector>
const std::array<std::pair<int, int>, 4> DIRS = {
std::make_pair(0, -1),
std::make_pair(-1, 0),
std::make_pair(0, 1),
std::make_pair(1, 0),
};
void printResult(const std::vector<std::vector<int>> &v) {
for (auto &row : v) {... |
object RectangleCutter {
private var w: Int = 0
private var h: Int = 0
private var len: Int = 0
private var cnt: Long = 0
private lateinit var grid: ByteArray
private val next = IntArray(4)
private val dir = arrayOf(
intArrayOf(0, -1),
intArrayOf(-1, 0),
intArrayOf... |
Change the programming language of this snippet from C++ to Scala without modifying what it does. | #include <array>
#include <iostream>
#include <stack>
#include <vector>
const std::array<std::pair<int, int>, 4> DIRS = {
std::make_pair(0, -1),
std::make_pair(-1, 0),
std::make_pair(0, 1),
std::make_pair(1, 0),
};
void printResult(const std::vector<std::vector<int>> &v) {
for (auto &row : v) {... |
object RectangleCutter {
private var w: Int = 0
private var h: Int = 0
private var len: Int = 0
private var cnt: Long = 0
private lateinit var grid: ByteArray
private val next = IntArray(4)
private val dir = arrayOf(
intArrayOf(0, -1),
intArrayOf(-1, 0),
intArrayOf... |
Please provide an equivalent version of this C++ code in Scala. | #include <iostream>
#include <vector>
#include <chrono>
#include <climits>
#include <cmath>
using namespace std;
vector <long long> primes{ 3, 5 };
int main()
{
cout.imbue(locale(""));
const int cutOff = 200, bigUn = 100000,
chunks = 50, little = bigUn / chunks;
const char tn[] = " cuban prime";
... | import kotlin.math.ceil
import kotlin.math.sqrt
fun main() {
val primes = mutableListOf(3L, 5L)
val cutOff = 200
val bigUn = 100_000
val chunks = 50
val little = bigUn / chunks
println("The first $cutOff cuban primes:")
var showEach = true
var c = 0
var u = 0L
var v = 1L
va... |
Produce a language-to-language conversion: from C++ to Scala, same semantics. | #include <windows.h>
#include <ctime>
#include <string>
#include <iostream>
const int BMP_SIZE = 600;
class myBitmap {
public:
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
~myBitmap() {
DeleteObject( pen ); DeleteObject( brush );
DeleteDC( hdc ); DeleteObject( bmp );
}
... |
import java.awt.*
import java.util.Stack
import java.util.Random
import javax.swing.JPanel
import javax.swing.JFrame
import javax.swing.Timer
import javax.swing.SwingUtilities
class ChaosGame : JPanel() {
class ColoredPoint(x: Int, y: Int, val colorIndex: Int) : Point(x, y)
val stack = Stack<ColoredPoint>(... |
Port the following code from C++ to Scala with equivalent syntax and logic. | #include <windows.h>
#include <ctime>
#include <string>
#include <iostream>
const int BMP_SIZE = 600;
class myBitmap {
public:
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
~myBitmap() {
DeleteObject( pen ); DeleteObject( brush );
DeleteDC( hdc ); DeleteObject( bmp );
}
... |
import java.awt.*
import java.util.Stack
import java.util.Random
import javax.swing.JPanel
import javax.swing.JFrame
import javax.swing.Timer
import javax.swing.SwingUtilities
class ChaosGame : JPanel() {
class ColoredPoint(x: Int, y: Int, val colorIndex: Int) : Point(x, y)
val stack = Stack<ColoredPoint>(... |
Keep all operations the same but rewrite the snippet in Scala. | #include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <sstream>
std::array<std::string, 6> games{ "12", "13", "14", "23", "24", "34" };
std::string results = "000000";
int fromBase3(std::string num) {
int out = 0;
for (auto c : num) {
int d = c - '0';
out = 3 * ... |
val games = arrayOf("12", "13", "14", "23", "24", "34")
var results = "000000"
fun nextResult(): Boolean {
if (results == "222222") return false
val res = results.toInt(3) + 1
results = res.toString(3).padStart(6, '0')
return true
}
fun main(args: Array<String>) {
val points = Array(4) { IntArra... |
Write a version of this C++ function in Scala with identical behavior. | #include <ciso646>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using std::vector;
using std::string;
#include <exception>
#include <stdexcept>
template <typename...Args> std::runtime_error error( Args...args )
{
return st... |
import java.util.Stack
const val OPS = "-+/*^"
fun infixToPostfix(infix: String): String {
val sb = StringBuilder()
val s = Stack<Int>()
val rx = Regex("""\s""")
for (token in infix.split(rx)) {
if (token.isEmpty()) continue
val c = token[0]
val idx = OPS.indexOf(c)
... |
Convert this C++ snippet to Scala and keep its semantics consistent. |
template<uint _N, uint _G> class Nonogram {
enum class ng_val : char {X='#',B='.',V='?'};
template<uint _NG> struct N {
N() {}
N(std::vector<int> ni,const int l) : X{},B{},Tx{},Tb{},ng(ni),En{},gNG(l){}
std::bitset<_NG> X, B, T, Tx, Tb;
std::vector<int> ng;
int En, gNG;
void fn (con... |
import java.util.BitSet
typealias BitSets = List<MutableList<BitSet>>
val rx = Regex("""\s""")
fun newPuzzle(data: List<String>) {
val rowData = data[0].split(rx)
val colData = data[1].split(rx)
val rows = getCandidates(rowData, colData.size)
val cols = getCandidates(colData, rowData.size)
do ... |
Convert this C++ block to Scala, preserving its control flow and logic. |
template<uint _N, uint _G> class Nonogram {
enum class ng_val : char {X='#',B='.',V='?'};
template<uint _NG> struct N {
N() {}
N(std::vector<int> ni,const int l) : X{},B{},Tx{},Tb{},ng(ni),En{},gNG(l){}
std::bitset<_NG> X, B, T, Tx, Tb;
std::vector<int> ng;
int En, gNG;
void fn (con... |
import java.util.BitSet
typealias BitSets = List<MutableList<BitSet>>
val rx = Regex("""\s""")
fun newPuzzle(data: List<String>) {
val rowData = data[0].split(rx)
val colData = data[1].split(rx)
val rows = getCandidates(rowData, colData.size)
val cols = getCandidates(colData, rowData.size)
do ... |
Write the same algorithm in Scala as shown in this C++ implementation. | #include <iostream>
#include <map>
#include <vector>
#include <gmpxx.h>
using integer = mpz_class;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
void print_vector(const std::vector<integer>& vec) {
if (vec.empty()... |
import java.math.BigInteger
const val ITERATIONS = 500
const val LIMIT = 10000
val bigLimit = BigInteger.valueOf(LIMIT.toLong())
val lychrelSieve = IntArray(LIMIT + 1)
val seedLychrels = mutableListOf<Int>()
val relatedLychrels = mutableSetOf<BigInteger>()
fun isPalindrome(bi: BigInteger): Boolean {
... |
Transform the following C++ implementation into Scala, maintaining the same output and logic. | #include <iostream>
#include <map>
#include <vector>
#include <gmpxx.h>
using integer = mpz_class;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
void print_vector(const std::vector<integer>& vec) {
if (vec.empty()... |
import java.math.BigInteger
const val ITERATIONS = 500
const val LIMIT = 10000
val bigLimit = BigInteger.valueOf(LIMIT.toLong())
val lychrelSieve = IntArray(LIMIT + 1)
val seedLychrels = mutableListOf<Int>()
val relatedLychrels = mutableSetOf<BigInteger>()
fun isPalindrome(bi: BigInteger): Boolean {
... |
Produce a language-to-language conversion: from C++ to Scala, same semantics. | #include <iomanip>
#include <iostream>
#include <sstream>
using namespace std;
enum CipherMode {ENCRYPT, DECRYPT};
uint32_t randRsl[256];
uint32_t randCnt;
uint32_t mm[256];
uint32_t aa = 0, bb = 0, cc = 0;
void isaac()
{
++cc;
bb += cc;
for (uint32_t i = 0; i < 256; ++i)
{
uin... |
val randrsl = IntArray(256)
var randcnt = 0
val mm = IntArray(256)
var aa = 0
var bb = 0
var cc = 0
const val GOLDEN_RATIO = 0x9e3779b9.toInt()
fun isaac() {
cc++
bb += cc
for (i in 0..255) {
val x = mm[i]
when (i % 4) {
0 -> aa = aa xor (aa shl 13)
... |
Maintain the same structure and functionality when rewriting this code in Scala. | #include <iomanip>
#include <iostream>
#include <sstream>
using namespace std;
enum CipherMode {ENCRYPT, DECRYPT};
uint32_t randRsl[256];
uint32_t randCnt;
uint32_t mm[256];
uint32_t aa = 0, bb = 0, cc = 0;
void isaac()
{
++cc;
bb += cc;
for (uint32_t i = 0; i < 256; ++i)
{
uin... |
val randrsl = IntArray(256)
var randcnt = 0
val mm = IntArray(256)
var aa = 0
var bb = 0
var cc = 0
const val GOLDEN_RATIO = 0x9e3779b9.toInt()
fun isaac() {
cc++
bb += cc
for (i in 0..255) {
val x = mm[i]
when (i % 4) {
0 -> aa = aa xor (aa shl 13)
... |
Maintain the same structure and functionality when rewriting this code in Scala. |
#include <string>
#include <chrono>
#include <cmath>
#include <locale>
using namespace std;
using namespace chrono;
unsigned int js(int l, int n) {
unsigned int res = 0, f = 1;
double lf = log(2) / log(10), ip;
for (int i = l; i > 10; i /= 10) f *= 10;
while (n > 0)
if ((int)(f * pow(10, modf(++res * ... | import kotlin.math.ln
import kotlin.math.pow
fun main() {
runTest(12, 1)
runTest(12, 2)
runTest(123, 45)
runTest(123, 12345)
runTest(123, 678910)
}
private fun runTest(l: Int, n: Int) {
println("p($l, $n) = %,d".format(p(l, n)))
}
fun p(l: Int, n: Int): Int {
var m = n
var test = 0
... |
Rewrite the snippet below in Scala so it works the same as the original C++ code. |
#include <string>
#include <chrono>
#include <cmath>
#include <locale>
using namespace std;
using namespace chrono;
unsigned int js(int l, int n) {
unsigned int res = 0, f = 1;
double lf = log(2) / log(10), ip;
for (int i = l; i > 10; i /= 10) f *= 10;
while (n > 0)
if ((int)(f * pow(10, modf(++res * ... | import kotlin.math.ln
import kotlin.math.pow
fun main() {
runTest(12, 1)
runTest(12, 2)
runTest(123, 45)
runTest(123, 12345)
runTest(123, 678910)
}
private fun runTest(l: Int, n: Int) {
println("p($l, $n) = %,d".format(p(l, n)))
}
fun p(l: Int, n: Int): Int {
var m = n
var test = 0
... |
Produce a language-to-language conversion: from C++ to Scala, same semantics. | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>
using integer = mpz_class;
class stirling2 {
public:
integer get(int n, int k);
private:
std::map<std::pair<int, int>, integer> cache_;
};
integer stirling2::get(int n, int k) {
if (k == n)
return 1;
... | import java.math.BigInteger
fun main() {
println("Stirling numbers of the second kind:")
val max = 12
print("n/k")
for (n in 0..max) {
print("%10d".format(n))
}
println()
for (n in 0..max) {
print("%-3d".format(n))
for (k in 0..n) {
print("%10s".format(st... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>
using integer = mpz_class;
class stirling2 {
public:
integer get(int n, int k);
private:
std::map<std::pair<int, int>, integer> cache_;
};
integer stirling2::get(int n, int k) {
if (k == n)
return 1;
... | import java.math.BigInteger
fun main() {
println("Stirling numbers of the second kind:")
val max = 12
print("n/k")
for (n in 0..max) {
print("%10d".format(n))
}
println()
for (n in 0..max) {
print("%-3d".format(n))
for (k in 0..n) {
print("%10s".format(st... |
Convert this C++ snippet to Scala and keep its semantics consistent. | #include <cassert>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#include <gmpxx.h>
using big_int = mpz_class;
bool is_prime(const big_int& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 25);
}
template <typename integer>
class n_smooth_generator {
public:
explicit n_smooth_gen... | import java.math.BigInteger
import kotlin.math.min
val one: BigInteger = BigInteger.ONE
val two: BigInteger = BigInteger.valueOf(2)
val three: BigInteger = BigInteger.valueOf(3)
fun pierpont(n: Int): List<List<BigInteger>> {
val p = List(2) { MutableList(n) { BigInteger.ZERO } }
p[0][0] = two
var count = ... |
Change the following C++ code into Scala without altering its purpose. | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<uint64_t> primes;
std::vector<uint64_t> smallPrimes;
template <typename T>
std::ostream &operator <<(std::ostream &os, const std::vector<T> &v) {
auto it = v.cbegin();
auto end = v.cend();
os << '[';
if (it != end) {
os <... | import java.math.BigInteger
var primes = mutableListOf<BigInteger>()
var smallPrimes = mutableListOf<Int>()
fun init() {
val two = BigInteger.valueOf(2)
val three = BigInteger.valueOf(3)
val p521 = BigInteger.valueOf(521)
val p29 = BigInteger.valueOf(29)
primes.add(two)
smallPrimes.add(2)
... |
Convert this C++ snippet to Scala and keep its semantics consistent. | #include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
std::vector<int> primes;
struct Seq {
public:
bool empty() {
return p < 0;
}
int front() {
return p;
}
void popFront() {
if (p == 2) {
p++;
} else {
p += 2;
... |
import kotlin.coroutines.experimental.*
val primes = generatePrimes().take(50_000).toList()
var foundCombo = false
fun isPrime(n: Int) : Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d ==... |
Write the same algorithm in Scala as shown in this C++ implementation. |
#include <iostream>
enum class zd {N00,N01,N10,N11};
class N {
private:
int dVal = 0, dLen;
void _a(int i) {
for (;; i++) {
if (dLen < i) dLen = i;
switch ((zd)((dVal >> (i*2)) & 3)) {
case zd::N00: case zd::N01: return;
case zd::N10: if (((dVal >> ((i+1)*2)) & 1) != 1) return;... |
class Zeckendorf(x: String = "0") : Comparable<Zeckendorf> {
var dVal = 0
var dLen = 0
private fun a(n: Int) {
var i = n
while (true) {
if (dLen < i) dLen = i
val j = (dVal shr (i * 2)) and 3
when (j) {
0, 1 -> return
2... |
Write the same code in Scala as shown below in C++. | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>
using integer = mpz_class;
class unsigned_stirling1 {
public:
integer get(int n, int k);
private:
std::map<std::pair<int, int>, integer> cache_;
};
integer unsigned_stirling1::get(int n, int k) {
if (k == 0)
... | import java.math.BigInteger
fun main() {
println("Unsigned Stirling numbers of the first kind:")
val max = 12
print("n/k")
for (n in 0..max) {
print("%10d".format(n))
}
println()
for (n in 0..max) {
print("%-3d".format(n))
for (k in 0..n) {
print("%10s".f... |
Translate the given C++ code snippet into Scala without altering its behavior. | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>
using integer = mpz_class;
class unsigned_stirling1 {
public:
integer get(int n, int k);
private:
std::map<std::pair<int, int>, integer> cache_;
};
integer unsigned_stirling1::get(int n, int k) {
if (k == 0)
... | import java.math.BigInteger
fun main() {
println("Unsigned Stirling numbers of the first kind:")
val max = 12
print("n/k")
for (n in 0..max) {
print("%10d".format(n))
}
println()
for (n in 0..max) {
print("%-3d".format(n))
for (k in 0..n) {
print("%10s".f... |
Rewrite this program in Scala while keeping its functionality equivalent to the C++ version. | #include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <stdexcept>
using namespace std;
typedef std::pair<double, double> Point;
double PerpendicularDistance(const Point &pt, const Point &lineStart, const Point &lineEnd)
{
double dx = lineEnd.first - lineStart.first;
double dy = lineEnd.... |
typealias Point = Pair<Double, Double>
fun perpendicularDistance(pt: Point, lineStart: Point, lineEnd: Point): Double {
var dx = lineEnd.first - lineStart.first
var dy = lineEnd.second - lineStart.second
val mag = Math.hypot(dx, dy)
if (mag > 0.0) { dx /= mag; dy /= mag }
val pvx = pt.first... |
Rewrite this program in Scala while keeping its functionality equivalent to the C++ version. | #include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <stdexcept>
using namespace std;
typedef std::pair<double, double> Point;
double PerpendicularDistance(const Point &pt, const Point &lineStart, const Point &lineEnd)
{
double dx = lineEnd.first - lineStart.first;
double dy = lineEnd.... |
typealias Point = Pair<Double, Double>
fun perpendicularDistance(pt: Point, lineStart: Point, lineEnd: Point): Double {
var dx = lineEnd.first - lineStart.first
var dy = lineEnd.second - lineStart.second
val mag = Math.hypot(dx, dy)
if (mag > 0.0) { dx /= mag; dy /= mag }
val pvx = pt.first... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
#define PI 3.14159265359
class Vector
{
public:
Vector(double ix, double iy, char mode)
{
if(mode=='a')
{
x=ix*cos(iy);
y=ix*sin(iy);
}
else
{
x=ix;
... |
class Vector2D(val x: Double, val y: Double) {
operator fun plus(v: Vector2D) = Vector2D(x + v.x, y + v.y)
operator fun minus(v: Vector2D) = Vector2D(x - v.x, y - v.y)
operator fun times(s: Double) = Vector2D(s * x, s * y)
operator fun div(s: Double) = Vector2D(x / s, y / s)
override fun toStr... |
Preserve the algorithm and functionality while converting the code from C++ to Scala. | #include <cmath>
#include <iostream>
using namespace std;
class EllipticPoint
{
double m_x, m_y;
static constexpr double ZeroThreshold = 1e20;
static constexpr double B = 7;
void Double() noexcept
{
if(IsZero())
{
... |
const val C = 7
class Pt(val x: Double, val y: Double) {
val zero get() = Pt(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
val isZero get() = x > 1e20 || x < -1e20
fun dbl(): Pt {
if (isZero) return this
val l = 3.0 * x * x / (2.0 * y)
val t = l * l - 2.0 * x
retur... |
Generate an equivalent Scala version of this C++ code. | #include <cmath>
#include <iostream>
using namespace std;
class EllipticPoint
{
double m_x, m_y;
static constexpr double ZeroThreshold = 1e20;
static constexpr double B = 7;
void Double() noexcept
{
if(IsZero())
{
... |
const val C = 7
class Pt(val x: Double, val y: Double) {
val zero get() = Pt(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
val isZero get() = x > 1e20 || x < -1e20
fun dbl(): Pt {
if (isZero) return this
val l = 3.0 * x * x / (2.0 * y)
val t = l * l - 2.0 * x
retur... |
Transform the following C++ implementation into Scala, maintaining the same output and logic. | #include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <utility>
#include <vector>
using namespace std;
static const double PI = acos(-1.0);
double affine_remap(const pair<double, double>& from, double x, const pair<double, double>& to)
{
return to.first + (x - from.first) * (to.second -... |
typealias DFunc = (Double) -> Double
fun mapRange(x: Double, min: Double, max: Double, minTo: Double, maxTo:Double): Double {
return (x - min) / (max - min) * (maxTo - minTo) + minTo
}
fun chebCoeffs(func: DFunc, n: Int, min: Double, max: Double): DoubleArray {
val coeffs = DoubleArray(n)
for (i in 0 un... |
Maintain the same structure and functionality when rewriting this code in Scala. | #include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <utility>
#include <vector>
using namespace std;
static const double PI = acos(-1.0);
double affine_remap(const pair<double, double>& from, double x, const pair<double, double>& to)
{
return to.first + (x - from.first) * (to.second -... |
typealias DFunc = (Double) -> Double
fun mapRange(x: Double, min: Double, max: Double, minTo: Double, maxTo:Double): Double {
return (x - min) / (max - min) * (maxTo - minTo) + minTo
}
fun chebCoeffs(func: DFunc, n: Int, min: Double, max: Double): DoubleArray {
val coeffs = DoubleArray(n)
for (i in 0 un... |
Rewrite this program in Scala while keeping its functionality equivalent to the C++ version. | #include <algorithm>
#include <iostream>
#include <vector>
const int STX = 0x02;
const int ETX = 0x03;
void rotate(std::string &a) {
char t = a[a.length() - 1];
for (int i = a.length() - 1; i > 0; i--) {
a[i] = a[i - 1];
}
a[0] = t;
}
std::string bwt(const std::string &s) {
for (char c : ... |
const val STX = "\u0002"
const val ETX = "\u0003"
fun bwt(s: String): String {
if (s.contains(STX) || s.contains(ETX)) {
throw RuntimeException("String can't contain STX or ETX")
}
val ss = STX + s + ETX
val table = Array<String>(ss.length) { ss.substring(it) + ss.substring(0, it) }
table... |
Keep all operations the same but rewrite the snippet in Scala. | #include <algorithm>
#include <iostream>
#include <vector>
const int STX = 0x02;
const int ETX = 0x03;
void rotate(std::string &a) {
char t = a[a.length() - 1];
for (int i = a.length() - 1; i > 0; i--) {
a[i] = a[i - 1];
}
a[0] = t;
}
std::string bwt(const std::string &s) {
for (char c : ... |
const val STX = "\u0002"
const val ETX = "\u0003"
fun bwt(s: String): String {
if (s.contains(STX) || s.contains(ETX)) {
throw RuntimeException("String can't contain STX or ETX")
}
val ss = STX + s + ETX
val table = Array<String>(ss.length) { ss.substring(it) + ss.substring(0, it) }
table... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <time.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <deque>
class riffle
{
public:
void shuffle( std::deque<int>* v, int tm )
{
std::deque<int> tmp;
bool fl;
size_t len;
std::deque<int>::iterator it;
copyTo( v, &tmp );
for( int t = 0; t < tm; t++ )
{
std:... |
import java.util.Random
import java.util.Collections.shuffle
val r = Random()
fun riffle(deck: List<Int>, iterations: Int): List<Int> {
val pile = deck.toMutableList()
repeat(iterations) {
val mid = deck.size / 2
val tenpc = mid / 10
val cut = mid - tenpc + r.nextInt(2 * te... |
Keep all operations the same but rewrite the snippet in Scala. | #include <time.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <deque>
class riffle
{
public:
void shuffle( std::deque<int>* v, int tm )
{
std::deque<int> tmp;
bool fl;
size_t len;
std::deque<int>::iterator it;
copyTo( v, &tmp );
for( int t = 0; t < tm; t++ )
{
std:... |
import java.util.Random
import java.util.Collections.shuffle
val r = Random()
fun riffle(deck: List<Int>, iterations: Int): List<Int> {
val pile = deck.toMutableList()
repeat(iterations) {
val mid = deck.size / 2
val tenpc = mid / 10
val cut = mid - tenpc + r.nextInt(2 * te... |
Ensure the translated Scala code behaves exactly like the original C++ snippet. | #include <exception>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
class Frac {
public:
Frac() : num(0), denom(1) {}
Frac(int n, int d) {
if (d == 0) {
throw std::runtime_error("d must not be zero");
}
int sign_of_d = d < 0 ? -1 : 1;
int g = std::gcd(n,... |
import java.math.BigDecimal
import java.math.MathContext
val mc = MathContext(256)
fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
class Frac : Comparable<Frac> {
val num: Long
val denom: Long
companion object {
val ZERO = Frac(0, 1)
val ONE = Frac(1, 1)
}
... |
Generate a Scala translation of this C++ snippet without changing its computational steps. | #include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
class Frac {
public:
Frac(long n, long d) {
if (d == 0) {
throw new std::runtime_error("d must not be zero");
}
long nn = n;
long dd = d;
if (nn == 0) {
dd = 1;
} else if (dd < 0) {
nn = -nn;
dd = -dd;
}
long g =... |
fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
class Frac : Comparable<Frac> {
val num: Long
val denom: Long
companion object {
val ZERO = Frac(0, 1)
val ONE = Frac(1, 1)
}
constructor(n: Long, d: Long) {
require(d != 0L)
var nn = n
... |
Change the programming language of this snippet from C++ to Scala without modifying what it does. | #include <vector>
#include <iostream>
#include <cmath>
#include <utility>
#include <map>
#include <iomanip>
bool isPrime( int i ) {
int stop = std::sqrt( static_cast<double>( i ) ) ;
for ( int d = 2 ; d <= stop ; d++ )
if ( i % d == 0 )
return false ;
return true ;
}
class Compare {
public :
Compa... |
import kotlin.coroutines.experimental.*
typealias Transition = Pair<Int, Int>
fun isPrime(n: Int) : Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d == 0) return false
d += 2
if (... |
Convert this C++ block to Scala, preserving its control flow and logic. | #include <iostream>
#include <vector>
std::vector<long> TREE_LIST;
std::vector<int> OFFSET;
void init() {
for (size_t i = 0; i < 32; i++) {
if (i == 1) {
OFFSET.push_back(1);
} else {
OFFSET.push_back(0);
}
}
}
void append(long t) {
TREE_LIST.push_back(1 | ... |
typealias Tree = Long
val treeList = mutableListOf<Tree>()
val offset = IntArray(32) { if (it == 1) 1 else 0 }
fun append(t: Tree) {
treeList.add(1L or (t shl 1))
}
fun show(t: Tree, l: Int) {
var tt = t
var ll = l
while (ll-- > 0) {
print(if (tt % 2L == 1L) "(" else ")")
tt = tt u... |
Convert this C++ block to Scala, preserving its control flow and logic. | #include <bitset>
#include <stdio.h>
#define SIZE 80
#define RULE 30
#define RULE_TEST(x) (RULE & 1 << (7 & (x)))
void evolve(std::bitset<SIZE> &s) {
int i;
std::bitset<SIZE> t(0);
t[SIZE-1] = RULE_TEST( s[0] << 2 | s[SIZE-1] << 1 | s[SIZE-2] );
t[ 0] = RULE_TEST( s[... |
const val N = 64
fun pow2(x: Int) = 1L shl x
fun evolve(state: Long, rule: Int) {
var state2 = state
for (p in 0..9) {
var b = 0
for (q in 7 downTo 0) {
val st = state2
b = (b.toLong() or ((st and 1L) shl q)).toInt()
state2 = 0L
for (i in 0 unt... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.