Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Generate an equivalent Haskell version of this C code.
#include <stdio.h> #include "achain.c" typedef struct {double u, v;} cplx; inline cplx c_mul(cplx a, cplx b) { cplx c; c.u = a.u * b.u - a.v * b.v; c.v = a.u * b.v + a.v * b.u; return c; } cplx chain_expo(cplx x, int n) { int i, j, k, l, e[32]; cplx v[32]; l = seq(n, 0, e); puts("Exponents:"); for (i =...
dichotomicChain :: Integral a => a -> [a] dichotomicChain n | n == 3 = [3, 2, 1] | n == 2 ^ log2 n = takeWhile (> 0) $ iterate (`div` 2) n | otherwise = let k = n `div` (2 ^ ((log2 n + 1) `div` 2)) in chain n k where chain n1 n2 | n2 <= 1 = dichotomicChain n1 | otherwise = case...
Write the same algorithm in Haskell as shown in this C implementation.
#include <ctype.h> #include <locale.h> #include <stdbool.h> #include <stdio.h> #include <stdint.h> #include <glib.h> typedef uint64_t integer; typedef struct number_names_tag { const char* cardinal; const char* ordinal; } number_names; const number_names small[] = { { "zero", "zeroth" }, { "one", "first"...
import Data.Char sentence = start ++ foldMap add (zip [2..] $ tail $ words sentence) where start = "Four is the number of letters in the first word of this sentence, " add (i, w) = unwords [spellInteger (alphaLength w), "in the", spellOrdinal i ++ ", "] alphaLength w = fromIntegral $ length $ filter isAlpha...
Produce a language-to-language conversion: from C to Haskell, same semantics.
#include <stdio.h> #include <stdlib.h> #include <string.h> void wordle(const char *answer, const char *guess, int *result) { int i, ix, n = strlen(guess); char *ptr; if (n != strlen(answer)) { printf("The words must be of the same length.\n"); exit(1); } char answer2[n+1]; strcp...
import Data.Bifunctor (first) import Data.List (intercalate, mapAccumL) import qualified Data.Map.Strict as M import Data.Maybe (fromMaybe) type Tally = M.Map Char Int wordleScore :: String -> String -> [Int] wordleScore target guess = snd $ uncurry (mapAccumL amber) $ first charCounts $ mapAccu...
Rewrite the snippet below in BBC_Basic so it works the same as the original C++ code.
#include <conio.h> #include <iostream> using namespace std; int main() { char ch; _cputs( "Yes or no?" ); do { ch = _getch(); ch = toupper( ch ); } while(ch!='Y'&&ch!='N'); if(ch=='N') { cout << "You said no" << endl; } else { cout << "You said yes" << endl; } return 0; }
REPEAT UNTIL INKEY$(0) = "" PRINT "Press Y or N to continue" REPEAT key$ = GET$ UNTIL key$="Y" OR key$="N" PRINT "The response was " key$
Generate an equivalent BBC_Basic version of this C++ code.
#include <algorithm> #include <iostream> #include <sstream> #include <string> template <typename T> void demo_compare(const T &a, const T &b, const std::string &semantically) { std::cout << a << " and " << b << " are " << ((a == b) ? "" : "not ") << "exactly " << semantically << " equal." << std::end...
shav$ = "Shaw, George Bernard" shakes$ = "Shakespeare, William" : IF shav$ = shakes$ THEN PRINT "The two strings are equal" ELSE PRINT "The two strings are not equal" : IF shav$ <> shakes$ THEN PRINT "The two strings are unequal" ELSE PRINT "The two strings are not unequal" : IF shav$ > shakes$ THEN PRINT shav$; " ...
Generate a BBC_Basic translation of this C++ snippet without changing its computational steps.
#include <map> #include <iostream> #include <cmath> template<typename F> bool test_distribution(F f, int calls, double delta) { typedef std::map<int, int> distmap; distmap dist; for (int i = 0; i < calls; ++i) ++dist[f()]; double mean = 1.0/dist.size(); bool good = true; for (distmap::iterator i =...
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice5, 10^r%, 0.05) PRINT "Over "; 10^r% " runs dice5 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT...
Port the provided C++ code into BBC_Basic while preserving the original functionality.
#ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> class QPaintEvent ; class MyWidget : public QWidget { public : MyWidget( ) ; protected : void paintEvent( QPaintEvent * ) ; private : int width ; int height ; const int colornumber ; } ; #endif
SW_MAXIMIZE = 3 SYS "ShowWindow", @hwnd%, SW_MAXIMIZE VDU 26 W% = @vdu%!208 / 4 H% = @vdu%!212 * 2 COLOUR 1,9 COLOUR 2,10 COLOUR 3,12 COLOUR 4,13 COLOUR 5,14 COLOUR 6,11 COLOUR 7,15 FOR C% = 0 TO 7 GCOL C% ...
Produce a functionally identical BBC_Basic code for the snippet given in C++.
#ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> class QPaintEvent ; class MyWidget : public QWidget { public : MyWidget( ) ; protected : void paintEvent( QPaintEvent * ) ; private : int width ; int height ; const int colornumber ; } ; #endif
SW_MAXIMIZE = 3 SYS "ShowWindow", @hwnd%, SW_MAXIMIZE VDU 26 W% = @vdu%!208 / 4 H% = @vdu%!212 * 2 COLOUR 1,9 COLOUR 2,10 COLOUR 3,12 COLOUR 4,13 COLOUR 5,14 COLOUR 6,11 COLOUR 7,15 FOR C% = 0 TO 7 GCOL C% ...
Port the following code from C++ to BBC_Basic with equivalent syntax and logic.
#include <algorithm> #include <array> #include <chrono> #include <iostream> #include <mutex> #include <random> #include <string> #include <string_view> #include <thread> const int timeScale = 42; void Message(std::string_view message) { static std::mutex cout_mutex; std::scoped_lock cout_lock(cout_mute...
INSTALL @lib$+"TIMERLIB" nSeats% = 5 DIM Name$(nSeats%-1), Fork%(nSeats%-1), tID%(nSeats%-1), Leftie%(nSeats%-1) Name$() = "Aristotle", "Kant", "Spinoza", "Marx", "Russell" Fork%() = TRUE : Leftie%(RND(nSeats%)-1) = TRUE : tID%(0) = FN_ontimer(10, PROCphi...
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C++ version.
struct MyException { };
ON ERROR PROCerror(ERR, REPORT$) : END ERROR 100, "User-generated exception" END DEF PROCerror(er%, rpt$) PRINT "Exception occurred" PRINT "Error number was " ; er% PRINT "Error string was " rpt$ ENDPROC
Rewrite the snippet below in BBC_Basic so it works the same as the original C++ code.
#include <random> #include <iostream> #include <stack> #include <set> #include <string> #include <functional> using namespace std; class RPNParse { public: stack<double> stk; multiset<int> digits; void op(function<double(double,double)> f) { if(stk.size() < 2) throw "Improperly written expression"; ...
DIM digits%(4), check%(4) FOR choice% = 1 TO 4 digits%(choice%) = RND(9) NEXT choice% PRINT "Enter an equation (using all of, and only, the single digits "; FOR index% = 1 TO 4 PRINT ; digits%(index%) ; IF index%<>4 PRINT " " ; NEXT ...
Translate this program into BBC_Basic but keep the logic exactly as in C++.
#include <random> #include <iostream> #include <stack> #include <set> #include <string> #include <functional> using namespace std; class RPNParse { public: stack<double> stk; multiset<int> digits; void op(function<double(double,double)> f) { if(stk.size() < 2) throw "Improperly written expression"; ...
DIM digits%(4), check%(4) FOR choice% = 1 TO 4 digits%(choice%) = RND(9) NEXT choice% PRINT "Enter an equation (using all of, and only, the single digits "; FOR index% = 1 TO 4 PRINT ; digits%(index%) ; IF index%<>4 PRINT " " ; NEXT ...
Produce a functionally identical BBC_Basic code for the snippet given in C++.
#include <iostream> class MyOtherClass { public: const int m_x; MyOtherClass(const int initX = 0) : m_x(initX) { } }; int main() { MyOtherClass mocA, mocB(7); std::cout << mocA.m_x << std::endl; std::cout << mocB.m_x << std::endl; return 0; }
DEF FNconst = 2.71828182845905 PRINT FNconst FNconst = 1.234 :
Keep all operations the same but rewrite the snippet in BBC_Basic.
#include <string> #include <iostream> int main() { char* data = new char[sizeof(std::string)]; std::string* stringPtr = new (data) std::string("ABCD"); std::cout << *stringPtr << " 0x" << stringPtr << std::endl; stringPtr->~basic_string(); stringPtr = new (data) std::string("...
anInteger% = 12345678 PRINT "Original value =", anInteger% address% = ^anInteger% PRINT "Hexadecimal address = ";~address% !address% = 87654321 PRINT "New value =", anInteger% anInteger% = 55555555 ...
Preserve the algorithm and functionality while converting the code from C++ to BBC_Basic.
#include <iostream> int main() { const int size = 100000; int hofstadters[size] = { 1, 1 }; for (int i = 3 ; i < size; i++) hofstadters[ i - 1 ] = hofstadters[ i - 1 - hofstadters[ i - 1 - 1 ]] + hofstadters[ i - 1 - hofstadters[ i - 2 - 1 ]]; std::cout << "The first ...
PRINT "First 10 terms of Q = " ; FOR i% = 1 TO 10 : PRINT ;FNq(i%, c%) " "; : NEXT : PRINT PRINT "1000th term = " ; FNq(1000, c%) PRINT "100000th term = " ; FNq(100000, c%) PRINT "Term is less than preceding term " ; c% " times" END DEF FNq(n%, RETURN c%) LOCAL i%,...
Port the following code from C++ to BBC_Basic with equivalent syntax and logic.
#include <iostream> int main() { const int size = 100000; int hofstadters[size] = { 1, 1 }; for (int i = 3 ; i < size; i++) hofstadters[ i - 1 ] = hofstadters[ i - 1 - hofstadters[ i - 1 - 1 ]] + hofstadters[ i - 1 - hofstadters[ i - 2 - 1 ]]; std::cout << "The first ...
PRINT "First 10 terms of Q = " ; FOR i% = 1 TO 10 : PRINT ;FNq(i%, c%) " "; : NEXT : PRINT PRINT "1000th term = " ; FNq(1000, c%) PRINT "100000th term = " ; FNq(100000, c%) PRINT "Term is less than preceding term " ; c% " times" END DEF FNq(n%, RETURN c%) LOCAL i%,...
Produce a language-to-language conversion: from C++ to BBC_Basic, same semantics.
#include <iostream> #include <string> int countSubstring(const std::string& str, const std::string& sub) { if (sub.length() == 0) return 0; int count = 0; for (size_t offset = str.find(sub); offset != std::string::npos; offset = str.find(sub, offset + sub.length())) { ++count; } retu...
tst$ = "the three truths" sub$ = "th" PRINT ; FNcountSubstring(tst$, sub$) " """ sub$ """ in """ tst$ """" tst$ = "ababababab" sub$ = "abab" PRINT ; FNcountSubstring(tst$, sub$) " """ sub$ """ in """ tst$ """" END DEF FNcountSubstring(A$, B$) LOCAL I%, N% ...
Translate this program into BBC_Basic but keep the logic exactly as in C++.
#ifndef TASK_H #define TASK_H #include <QWidget> class QLabel ; class QLineEdit ; class QVBoxLayout ; class QHBoxLayout ; class EntryWidget : public QWidget { Q_OBJECT public : EntryWidget( QWidget *parent = 0 ) ; private : QHBoxLayout *upperpart , *lowerpart ; QVBoxLayout *entryLayout ; QLineEdit *...
INSTALL @lib$+"WINLIB2" INSTALL @lib$+"WINLIB5" ES_NUMBER = 8192 form% = FN_newdialog("Rosetta Code", 100, 100, 100, 64, 8, 1000) PROC_static(form%, "String:", 100, 8, 8, 30, 14, 0) PROC_editbox(form%, "Example", 101, 40, 6, 52, 14, 0) PROC_static(form%, "Number:", 102, ...
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C++ version.
#include <iostream> #include <iomanip> inline int sign(int i) { return i < 0 ? -1 : i > 0; } inline int& E(int *x, int row, int col) { return x[row * (row + 1) / 2 + col]; } int iter(int *v, int *diff) { E(v, 0, 0) = 151; E(v, 2, 0) = 40; E(v, 4, 1) = 11; E(v, 4, 3) = 4; for (a...
INSTALL @lib$ + "ARRAYLIB" DIM matrix(10,10), vector(10) matrix() = \ a, b, c, d, e, f, g, h, x, y, z \ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ \ 1, 0,-1, 0, 0, ...
Transform the following C++ implementation into BBC_Basic, maintaining the same output and logic.
#include <iostream> #include <iomanip> inline int sign(int i) { return i < 0 ? -1 : i > 0; } inline int& E(int *x, int row, int col) { return x[row * (row + 1) / 2 + col]; } int iter(int *v, int *diff) { E(v, 0, 0) = 151; E(v, 2, 0) = 40; E(v, 4, 1) = 11; E(v, 4, 3) = 4; for (a...
INSTALL @lib$ + "ARRAYLIB" DIM matrix(10,10), vector(10) matrix() = \ a, b, c, d, e, f, g, h, x, y, z \ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ \ 1, 0,-1, 0, 0, ...
Generate an equivalent BBC_Basic version of this C++ code.
#include <windows.h> #include <string> #include <math.h> using namespace std; const float PI = 3.1415926536f; class myBitmap { public: myBitmap() : pen( NULL ) {} ~myBitmap() { DeleteObject( pen ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( int w, int h ) { BITMAPINFO bi; v...
Spread = 25 Scale = 0.76 SizeX% = 400 SizeY% = 300 Depth% = 10
Write the same code in BBC_Basic as shown below in C++.
#include <windows.h> #include <iostream> #include <string> using namespace std; enum choices { ROCK, SPOCK, PAPER, LIZARD, SCISSORS, MX_C }; enum indexes { PLAYER, COMPUTER, DRAW }; class stats { public: stats() : _draw( 0 ) { ZeroMemory( _moves, sizeof( _moves ) ); ZeroMemory( _win, sizeof( _win...
PRINT"Welcome to the game of rock-paper-scissors" PRINT "Each player guesses one of these three, and reveals it at the same time." PRINT "Rock blunts scissors, which cut paper, which wraps stone." PRINT "If both players choose the same, it is a draw!" PRINT "When you've had enough, choose Q." DIM rps%(2),g$(3) g$()="ro...
Transform the following C++ implementation into BBC_Basic, maintaining the same output and logic.
#include "stdafx.h" #include <iostream> #include <fstream> #include <vector> #include <string> #include <boost/tokenizer.hpp> #include <boost/algorithm/string/case_conv.hpp> using namespace std; using namespace boost; typedef boost::tokenizer<boost::char_separator<char> > Tokenizer; static const char_separator<char> s...
BOOL = 1 NAME = 2 ARRAY = 3 optfile$ = "options.cfg" fullname$ = FNoption(optfile$, "FULLNAME", NAME) favouritefruit$ = FNoption(optfile$, "FAVOURITEFRUIT", NAME) needspeeling% = FNoption(optfile$, "NEEDSPEELING", BOOL) seeds !^otherfamily$() = FNoptio...
Please provide an equivalent version of this C++ code in BBC_Basic.
#include <iostream> #include <string> using namespace std; int main() { string dog = "Benjamin", Dog = "Samba", DOG = "Bernie"; cout << "The three dogs are named " << dog << ", " << Dog << ", and " << DOG << endl; }
dog$ = "Benjamin" Dog$ = "Samba" DOG$ = "Bernie" PRINT "The three dogs are " dog$ ", " Dog$ " and " DOG$ "."
Ensure the translated BBC_Basic code behaves exactly like the original C++ snippet.
#include <iostream> #include <time.h> using namespace std; class stooge { public: void sort( int* arr, int start, int end ) { if( arr[start] > arr[end - 1] ) swap( arr[start], arr[end - 1] ); int n = end - start; if( n > 2 ) { n /= 3; sort( arr, start, end - n ); sort( arr, start + n, en...
DIM test%(9) test%() = 4, 65, 2, -31, 0, 99, 2, 83, 782, 1 PROCstoogesort(test%(), 0, DIM(test%(),1)) FOR i% = 0 TO 9 PRINT test%(i%) ; NEXT PRINT END DEF PROCstoogesort(l%(), i%, j%) LOCAL t% IF l%(j%) < l%(i%) SWAP l%(i%), l%(j%) IF j% -...
Keep all operations the same but rewrite the snippet in BBC_Basic.
#include <time.h> #include <iostream> using namespace std; const int MAX = 126; class shell { public: shell() { _gap[0] = 1750; _gap[1] = 701; _gap[2] = 301; _gap[3] = 132; _gap[4] = 57; _gap[5] = 23; _gap[6] = 10; _gap[7] = 4; _gap[8] = 1; } void sort( int* a, int count ) { _cnt = count; for( i...
DIM test(9) test() = 4, 65, 2, -31, 0, 99, 2, 83, 782, 1 PROCshellsort(test(), 10) FOR i% = 0 TO 9 PRINT test(i%) ; NEXT PRINT END DEF PROCshellsort(a(), n%) LOCAL h%, i%, j%, k h% = n% WHILE h% IF h% = 2 h% = 1 ELSE h% DIV= 2.2 ...
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C++ version.
#include <string> #include <fstream> #include <iostream> int main( ) { std::cout << "Which file do you want to look at ?\n" ; std::string input ; std::getline( std::cin , input ) ; std::ifstream infile( input.c_str( ) , std::ios::in ) ; std::string file( input ) ; std::cout << "Which file line do you...
filepath$ = @lib$ + "..\licence.txt" requiredline% = 7 file% = OPENIN(filepath$) IF file%=0 ERROR 100, "File could not be opened" FOR i% = 1 TO requiredline% IF EOF#file% ERROR 100, "File contains too few lines" INPUT #file%, text$ NEXT CLOSE #file% ...
Produce a functionally identical BBC_Basic code for the snippet given in C++.
#include <string> #include <fstream> #include <iostream> int main( ) { std::cout << "Which file do you want to look at ?\n" ; std::string input ; std::getline( std::cin , input ) ; std::ifstream infile( input.c_str( ) , std::ios::in ) ; std::string file( input ) ; std::cout << "Which file line do you...
filepath$ = @lib$ + "..\licence.txt" requiredline% = 7 file% = OPENIN(filepath$) IF file%=0 ERROR 100, "File could not be opened" FOR i% = 1 TO requiredline% IF EOF#file% ERROR 100, "File contains too few lines" INPUT #file%, text$ NEXT CLOSE #file% ...
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C++ version.
#include <QByteArray> #include <iostream> int main( ) { QByteArray text ( "http: QByteArray encoded( text.toPercentEncoding( ) ) ; std::cout << encoded.data( ) << '\n' ; return 0 ; }
PRINT FNurlencode("http://foo bar/") END DEF FNurlencode(url$) LOCAL c%, i% WHILE i% < LEN(url$) i% += 1 c% = ASCMID$(url$, i%) IF c%<&30 OR c%>&7A OR c%>&39 AND c%<&41 OR c%>&5A AND c%<&61 THEN url$ = LEFT$(url$,i%-1) + "%" + RIGHT$("0"+STR$~c%,2) ...
Port the following code from C++ to BBC_Basic with equivalent syntax and logic.
#include <QByteArray> #include <iostream> int main( ) { QByteArray text ( "http: QByteArray encoded( text.toPercentEncoding( ) ) ; std::cout << encoded.data( ) << '\n' ; return 0 ; }
PRINT FNurlencode("http://foo bar/") END DEF FNurlencode(url$) LOCAL c%, i% WHILE i% < LEN(url$) i% += 1 c% = ASCMID$(url$, i%) IF c%<&30 OR c%>&7A OR c%>&39 AND c%<&41 OR c%>&5A AND c%<&61 THEN url$ = LEFT$(url$,i%-1) + "%" + RIGHT$("0"+STR$~c%,2) ...
Preserve the algorithm and functionality while converting the code from C++ to BBC_Basic.
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <numeric> #include <sstream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} ...
DIM A1(2,2) A1() = 1, 3, 5, 2, 4, 7, 1, 1, 0 PROCLUdecomposition(A1(), L1(), U1(), P1()) PRINT "L1:" ' FNshowmatrix(L1()) PRINT "U1:" ' FNshowmatrix(U1()) PRINT "P1:" ' FNshowmatrix(P1()) DIM A2(3,3) A2() = 11, 9, 24, 2, 1, 5, 2, 6, 3, 17, 18, 1, 2, 5, 7, 1 P...
Convert the following code from C++ to BBC_Basic, ensuring the logic remains intact.
#include <vector> #include <algorithm> #include <string> template <class T> struct sort_table_functor { typedef bool (*CompFun)(const T &, const T &); const CompFun ordering; const int column; const bool reverse; sort_table_functor(CompFun o, int c, bool r) : ordering(o), column(c), reverse(r) { } boo...
DIM table$(100,100) PROCsort_default(table$()) PROCsort_options(table$(), TRUE, 1, FALSE) END DEF PROCsort_options(table$(), ordering%, column%, reverse%) DEF PROCsort_default(table$()) : LOCAL ordering%, column%, reverse% ENDPROC
Translate the given C++ code snippet into BBC_Basic without altering its behavior.
#include <iostream> #include <ctime> class CRateState { protected: time_t m_lastFlush; time_t m_period; size_t m_tickCount; public: CRateState(time_t period); void Tick(); }; CRateState::CRateState(time_t period) : m_lastFlush(std::time(NULL)), m_period(pe...
PRINT "Method 1: Calculate reciprocal of elapsed time:" FOR trial% = 1 TO 3 start% = TIME PROCtasktomeasure finish% = TIME PRINT "Rate = "; 100 / (finish%-start%) " per second" NEXT trial% PRINT '"Method 2: Count completed tasks in one second:" FOR tr...
Generate an equivalent BBC_Basic version of this C++ code.
#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> std::map<char, int> _map; std::vector<std::string> _result; size_t longest = 0; void make_sequence( std::string n ) { _map.clear(); for( std::string::iterator i = n.begin(); i != n.end(); i++ ) _map.insert( std...
*FLOAT64 DIM list$(30) maxiter% = 0 maxseed% = 0 FOR seed% = 0 TO 999999 list$(0) = STR$(seed%) iter% = 0 REPEAT list$(iter%+1) = FNseq(list$(iter%)) IF VALlist$(iter%+1) <= VALlist$(iter%) THEN FOR try% = iter% TO 0 STEP -1 ...
Translate the given C++ code snippet into BBC_Basic without altering its behavior.
#include <iostream> typedef unsigned long long bigint; using namespace std; class sdn { public: bool check( bigint n ) { int cc = digitsCount( n ); return compare( n, cc ); } void displayAll( bigint s ) { for( bigint y = 1; y < s; y++ ) if( check( y ) ) cout << y << " is a Self-...
FOR N = 1 TO 5E7 IF FNselfdescribing(N) PRINT N NEXT END DEF FNselfdescribing(N%) LOCAL D%(), I%, L%, O% DIM D%(9) O% = N% L% = LOG(N%) WHILE N% I% = N% MOD 10 D%(I%) += 10^(L%-I%) N% DIV=10 ENDWHILE = O% = SUM(D%()...
Convert the following code from C++ to BBC_Basic, ensuring the logic remains intact.
#include <time.h> #include <iostream> #include <string> #include <iomanip> #include <cstdlib> typedef unsigned int uint; using namespace std; enum movDir { UP, DOWN, LEFT, RIGHT }; class tile { public: tile() : val( 0 ), blocked( false ) {} uint val; bool blocked; }; class g2048 { public: g2048() : d...
SIZE = 4 : MAX = SIZE-1 Won% = FALSE : Lost% = FALSE @% = 5 DIM Board(MAX,MAX),Stuck% 3 PROCBreed PROCPrint REPEAT Direction = GET-135 IF Direction > 0 AND Direction < 5 THEN Moved% = FALSE PROCShift PROCMerge PROCShi...
Write a version of this C++ function in BBC_Basic with identical behavior.
inline double multiply(double a, double b) { return a*b; }
PRINT FNmultiply(6,7) END DEF FNmultiply(a,b) = a * b
Translate the given C++ code snippet into BBC_Basic without altering its behavior.
void runCode(string code) { int c_len = code.length(); unsigned accumulator=0; int bottles; for(int i=0;i<c_len;i++) { switch(code[i]) { case 'Q': cout << code << endl; break; case 'H': cout << "Hello, world!" <...
PROChq9plus("hq9+HqQ+Qq") END DEF PROChq9plus(code$) LOCAL accumulator%, i%, bottles% FOR i% = 1 TO LEN(code$) CASE MID$(code$, i%, 1) OF WHEN "h","H": PRINT "Hello, world!" WHEN "q","Q": PRINT code$ WHEN "9": bottles% = 99 ...
Keep all operations the same but rewrite the snippet in BBC_Basic.
void runCode(string code) { int c_len = code.length(); unsigned accumulator=0; int bottles; for(int i=0;i<c_len;i++) { switch(code[i]) { case 'Q': cout << code << endl; break; case 'H': cout << "Hello, world!" <...
PROChq9plus("hq9+HqQ+Qq") END DEF PROChq9plus(code$) LOCAL accumulator%, i%, bottles% FOR i% = 1 TO LEN(code$) CASE MID$(code$, i%, 1) OF WHEN "h","H": PRINT "Hello, world!" WHEN "q","Q": PRINT code$ WHEN "9": bottles% = 99 ...
Translate the given C++ code snippet into BBC_Basic without altering its behavior.
#include <deque> #include <algorithm> #include <ostream> #include <iterator> namespace cards { class card { public: enum pip_type { two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace, pip_count }; enum suite_type { hearts, spades, diamonds, clubs, suite_count }; ...
DIM Deck{ncards%, card&(51)}, Suit$(3), Rank$(12) Suit$() = "Clubs", "Diamonds", "Hearts", "Spades" Rank$() = "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", \ \ "Eight", "Nine", "Ten", "Jack", "Queen", "King" PRINT "Creating a new deck..." PROCnewdeck(deck1{}) ...
Rewrite the snippet below in BBC_Basic so it works the same as the original C++ code.
#include <algorithm> template<typename ForwardIterator> void permutation_sort(ForwardIterator begin, ForwardIterator end) { while (std::next_permutation(begin, end)) { } }
DIM test(9) test() = 4, 65, 2, 31, 0, 99, 2, 83, 782, 1 perms% = 0 WHILE NOT FNsorted(test()) perms% += 1 PROCnextperm(test()) ENDWHILE PRINT ;perms% " permutations required to sort "; DIM(test(),1)+1 " items." END DEF PROCnextperm(a()) ...
Produce a functionally identical BBC_Basic code for the snippet given in C++.
#include <windows.h> #include <iostream> #include <string> using namespace std; class lastSunday { public: lastSunday() { m[0] = "JANUARY: "; m[1] = "FEBRUARY: "; m[2] = "MARCH: "; m[3] = "APRIL: "; m[4] = "MAY: "; m[5] = "JUNE: "; m[6] = "JULY: "; m[7] = "AUGUST: ";...
INSTALL @lib$+"DATELIB" INPUT "What year to calculate (YYYY)? " Year% PRINT '"Last Sundays in ";Year%;" are on:" FOR Month%=1 TO 12 PRINT Year% "-" RIGHT$("0"+STR$Month%,2) "-";FN_dim(Month%,Year%)-FN_dow(FN_mjd(FN_dim(Month%,Year%),Month%,Year%)) NEXT END
Convert this C++ snippet to BBC_Basic and keep its semantics consistent.
#include <windows.h> #include <iostream> #include <string> using namespace std; class lastSunday { public: lastSunday() { m[0] = "JANUARY: "; m[1] = "FEBRUARY: "; m[2] = "MARCH: "; m[3] = "APRIL: "; m[4] = "MAY: "; m[5] = "JUNE: "; m[6] = "JULY: "; m[7] = "AUGUST: ";...
INSTALL @lib$+"DATELIB" INPUT "What year to calculate (YYYY)? " Year% PRINT '"Last Sundays in ";Year%;" are on:" FOR Month%=1 TO 12 PRINT Year% "-" RIGHT$("0"+STR$Month%,2) "-";FN_dim(Month%,Year%)-FN_dow(FN_mjd(FN_dim(Month%,Year%),Month%,Year%)) NEXT END
Rewrite this program in BBC_Basic while keeping its functionality equivalent to the C++ version.
#include <iostream> #include <vector> using namespace std; vector<int> UpTo(int n, int offset = 0) { vector<int> retval(n); for (int ii = 0; ii < n; ++ii) retval[ii] = ii + offset; return retval; } struct JohnsonTrotterState_ { vector<int> values_; vector<int> positions_; vector<bool> directions_; int sign...
PROCperms(3) PRINT PROCperms(4) END DEF PROCperms(n%) LOCAL p%(), i%, k%, s% DIM p%(n%) FOR i% = 1 TO n% p%(i%) = -i% NEXT s% = 1 REPEAT PRINT "Perm: [ "; FOR i% = 1 TO n% PRINT ;ABSp%(i%) " "; NEXT ...
Produce a functionally identical BBC_Basic code for the snippet given in C++.
#include "stdafx.h" #include <windows.h> #include <stdlib.h> const int BMP_WID = 410, BMP_HEI = 230, MAX_BALLS = 120; class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObject(...
maxBalls% = 10 DIM ballX%(maxBalls%), ballY%(maxBalls%) VDU 23,22,180;400;8,16,16,128 ORIGIN 180,0 OFF GCOL 9 FOR row% = 1 TO 7 FOR col% = 1 TO row% CIRCLE FILL 40*col% - 20*row% - 20, 800 - 40*row%, 12 NEXT NEXT row% ...
Ensure the translated BBC_Basic code behaves exactly like the original C++ snippet.
using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; [STAThreadAttribute] int main() { Point^ MousePoint = gcnew Point(); Control^ TempControl = gcnew Control(); MousePoint = TempControl->MousePosition; Bitmap^ TempBitmap = gcnew Bitmap(1,1); Graphics^ g = Graphics::Fro...
palette_index% = POINT(x%, y%) RGB24b_colour% = TINT(x%, y%)
Change the programming language of this snippet from C++ to BBC_Basic without modifying what it does.
#include <iostream> #include <string> #include <windows.h> #include <mmsystem.h> #pragma comment ( lib, "winmm.lib" ) using namespace std; class recorder { public: void start() { paused = rec = false; action = "IDLE"; while( true ) { cout << endl << "==" << action << "==" << endl << endl; cout <<...
wavfile$ = @dir$ + "capture.wav" bitspersample% = 16 channels% = 2 samplespersec% = 44100 alignment% = bitspersample% * channels% / 8 bytespersec% = alignment% * samplespersec% params$ = " bitspersample " + STR$(bitspersample%) + \ \ " channels " + STR$(channe...
Produce a language-to-language conversion: from C++ to BBC_Basic, same semantics.
#include <time.h> #include <iostream> #include <string> using namespace std; class penney { public: penney() { pW = cW = 0; } void gameLoop() { string a; while( true ) { playerChoice = computerChoice = ""; if( rand() % 2 ) { computer(); player(); } else { player(); comput...
PRINT "*** Penney's Game ***" REPEAT PRINT ' "Heads you pick first, tails I pick first." PRINT "And it is... "; WAIT 100 ht% = RND(0 - TIME) AND 1 IF ht% THEN PRINT "heads!" PROC_player_chooses(player$) computer$ = FN_optimal(player$) PRINT "I choose "; computer$; "." ELSE PRINT "tails!...
Convert this C++ block to BBC_Basic, preserving its control flow and logic.
#include <windows.h> #include <string> #include <iostream> const int BMP_SIZE = 612; class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( ...
order% = 8 size% = 2^order% VDU 23,22,size%;size%;8,8,16,128 FOR Y% = 0 TO size%-1 FOR X% = 0 TO size%-1 IF (X% AND Y%)=0 PLOT X%*2,Y%*2 NEXT NEXT Y%
Change the programming language of this snippet from C++ to BBC_Basic without modifying what it does.
#include <windows.h> #include <string> #include <iostream> const int BMP_SIZE = 612; class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( ...
order% = 8 size% = 2^order% VDU 23,22,size%;size%;8,8,16,128 FOR Y% = 0 TO size%-1 FOR X% = 0 TO size%-1 IF (X% AND Y%)=0 PLOT X%*2,Y%*2 NEXT NEXT Y%
Ensure the translated BBC_Basic code behaves exactly like the original C++ snippet.
#include <iostream> #include <sstream> int main(int argc, char *argv[]) { using namespace std; #if _WIN32 if (argc != 5) { cout << "Usage : " << argv[0] << " (type) (id) (source string) (description>)\n"; cout << " Valid types: SUCCESS, ERROR, WARNING, INFORMATION\n"; } else { ...
INSTALL @lib$+"COMLIB" PROC_cominitlcid(1033) WshShell% = FN_createobject("WScript.Shell") PROC_callmethod(WshShell%, "LogEvent(0, ""Test from BBC BASIC"")") PROC_releaseobject(WshShell%) PROC_comexit
Generate an equivalent BBC_Basic version of this C++ code.
#include <boost/spirit.hpp> #include <boost/spirit/tree/ast.hpp> #include <string> #include <cassert> #include <iostream> #include <istream> #include <ostream> using boost::spirit::rule; using boost::spirit::parser_tag; using boost::spirit::ch_p; using boost::spirit::real_p; using boost::spirit::tree_no...
Expr$ = "1 + 2 * (3 + (4 * 5 + 6 * 7 * 8) - 9) / 10" PRINT "Input = " Expr$ AST$ = FNast(Expr$) PRINT "AST = " AST$ PRINT "Value = " ;EVAL(AST$) END DEF FNast(RETURN in$) LOCAL ast$, oper$ REPEAT ast$ += FNast1(in$) WHILE ASC(in$)=32 in$ = M...
Translate the given C++ code snippet into BBC_Basic without altering its behavior.
#include <boost/spirit.hpp> #include <boost/spirit/tree/ast.hpp> #include <string> #include <cassert> #include <iostream> #include <istream> #include <ostream> using boost::spirit::rule; using boost::spirit::parser_tag; using boost::spirit::ch_p; using boost::spirit::real_p; using boost::spirit::tree_no...
Expr$ = "1 + 2 * (3 + (4 * 5 + 6 * 7 * 8) - 9) / 10" PRINT "Input = " Expr$ AST$ = FNast(Expr$) PRINT "AST = " AST$ PRINT "Value = " ;EVAL(AST$) END DEF FNast(RETURN in$) LOCAL ast$, oper$ REPEAT ast$ += FNast1(in$) WHILE ASC(in$)=32 in$ = M...
Port the provided C++ code into BBC_Basic while preserving the original functionality.
#include <stdio.h> #include <stdlib.h> void clear() { for(int n = 0;n < 10; n++) { printf("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\r\n\r\n\r\n"); } } #define UP "00^00\r\n00|00\r\n00000\r\n" #define DOWN "00000\r\n00|00\r\n00v00\r\n" #define LEFT "00000\r\n<--00\r\n00000\r\n" #define RIGHT "00000\r\n00-->\r\n00000\r\...
VDU 23,22,512;512;8,16,16,0 VDU 5 GCOL 4,15 REPEAT B% = ADVAL(0) X% = ADVAL(1) / 64 Y% = 1023 - ADVAL(2) / 64 PROCjoy(B%,X%,Y%) WAIT 4 PROCjoy(B%,X%,Y%) UNTIL FALSE END DEF PROCjoy(B%,X%,Y%) LOCAL I% LINE...
Generate an equivalent BBC_Basic version of this C++ code.
#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 ...
INSTALL @lib$+"BB4WMAPMLIB" : PROCMAPM_Init : MAPM_Dec%=200 Result$="0" : A$="1" FOR I%=0 TO 10000 IF I% Result$=FNMAPM_Add(Result$,A$) : A$=FNMAPM_Multiply(A$,STR$I%) IF I% < 111 IF I% MOD 10 = 0 OR I% < 11 PRINT "!";I% " = " FNMAPM_FormatDec(Result$,0) IF I% > 999 IF I...
Transform the following C++ implementation into BBC_Basic, maintaining the same output and logic.
#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 ...
INSTALL @lib$+"BB4WMAPMLIB" : PROCMAPM_Init : MAPM_Dec%=200 Result$="0" : A$="1" FOR I%=0 TO 10000 IF I% Result$=FNMAPM_Add(Result$,A$) : A$=FNMAPM_Multiply(A$,STR$I%) IF I% < 111 IF I% MOD 10 = 0 OR I% < 11 PRINT "!";I% " = " FNMAPM_FormatDec(Result$,0) IF I% > 999 IF I...
Can you help me rewrite this code in BBC_Basic instead of C++, keeping it the same logically?
#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 ) {} ...
@% = &90E PROColdrus(1, "meter") PRINT PROColdrus(10, "arshin") END : DEF PROColdrus(length, unit$) LOCAL units$(), values(), unit%, i% DIM units$(12) DIM values(12) units$() = "kilometer", "meter", "centimeter", "milia", "versta", "sazhen", "arshin", "fut", "piad", "vershok", "diuym", "liniya", "tochka" values() = 10...
Translate the given C++ code snippet into BBC_Basic without altering its behavior.
#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, ...
HIMEM = PAGE + 3000000 INSTALL @lib$+"HIMELIB" PROC_himeinit("HIMEkey") DIM old$(20000), new$(20000) h1% = 1 : h2% = 2 : h3% = 3 : h4% = 4 FOR base% = 3 TO 17 PRINT "Base "; base% " : " FN_largest_left_truncated_prime(base%) NEXT END DEF...
Rewrite the snippet below in BBC_Basic so it works the same as the original C++ code.
#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::...
PROCsolve24("1234") PROCsolve24("6789") PROCsolve24("1127") PROCsolve24("5566") END DEF PROCsolve24(s$) LOCAL F%, I%, J%, K%, L%, P%, T%, X$, o$(), p$(), t$() DIM o$(4), p$(24,4), t$(11) o$() = "", "+", "-", "*", "/" RESTORE FOR T% = 1 TO 11 ...
Rewrite the snippet below in BBC_Basic so it works the same as the original C++ code.
#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::...
PROCsolve24("1234") PROCsolve24("6789") PROCsolve24("1127") PROCsolve24("5566") END DEF PROCsolve24(s$) LOCAL F%, I%, J%, K%, L%, P%, T%, X$, o$(), p$(), t$() DIM o$(4), p$(24,4), t$(11) o$() = "", "+", "-", "*", "/" RESTORE FOR T% = 1 TO 11 ...
Convert this C++ block to BBC_Basic, preserving its control flow and logic.
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...
DIM table&(7,15), test%(1) table&() = 4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3, \ \ 14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9, \ \ 5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11, \ \ 7, 13, 10, 1, 0, ...
Change the programming language of this snippet from PHP to REXX without modifying what it does.
define("PI", 3.14159265358); define("MSG", "Hello World");
call immutable '$=1' call immutable ' pi = 3.14159' call immutable 'radius= 2*pi/4 ' call immutable ' r=13/2 ' call immutable ' d=0002 * r' call immutable ' f.1 = 12**2 ' say ' $ =' ...
Change the programming language of this snippet from PHP to REXX without modifying what it does.
<?php echo substr_count("the three truths", "th"), PHP_EOL; // prints "3" echo substr_count("ababababab", "abab"), PHP_EOL; // prints "2"
options replace format comments java crossref symbols nobinary -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method countSubstring(inStr, findStr) public static return inStr.countstr(findStr) -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method ...
Produce a language-to-language conversion: from PHP to REXX, same semantics.
<?php header("Content-type: image/png"); $width = 512; $height = 512; $img = imagecreatetruecolor($width,$height); $bg = imagecolorallocate($img,255,255,255); imagefilledrectangle($img, 0, 0, $width, $width, $bg); $depth = 8; function drawTree($x1, $y1, $angle, $depth){ global $img; if ($depth != 0)...
options replace format comments java crossref symbols binary import java.awt.Color import java.awt.Graphics import javax.swing.JFrame class RFractalTree public extends JFrame properties constant isTrue = (1 == 1) isFalse = \isTrue -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ...
Write the same algorithm in REXX as shown in this PHP implementation.
<?php echo "<h1>" . "Choose: ROCK - PAPER - SCISSORS" . "</h1>"; echo "<h2>"; echo ""; $player = strtoupper( $_GET["moves"] ); $wins = [ 'ROCK' => 'SCISSORS', 'PAPER' => 'ROCK', 'SCISSORS' => 'PAPER' ]; $a_i = array_rand($wins); echo "<br>"; echo "Player chooses " . "<i style=\"color:blue\">" . $player ....
!= '────────'; err=! "***error***"; @.=0 prompt= ! 'Please enter one of: Rock Paper Scissors (or Quit)' $.p= 'paper' ; $.s= "scissors"; $.r= 'rock' t.p= $.r ; t.s= $.p ; t.r= $.s w.p= $.s ; w.s= $.r ; w.r= $.p b.p= 'covers'; b.s= "cuts" ; b.r= 'br...
Write a version of this PHP function in REXX with identical behavior.
<?php $conf = file_get_contents('parse-conf-file.txt'); $conf = preg_replace('/^([a-z]+)/mi', '$1 =', $conf); $conf = preg_replace_callback( '/^([a-z]+)\s*=((?=.*\,.*).*)$/mi', function ($matches) { $r = ''; foreach (explode(',', $matches[2]) AS $val) { $r .= $matches[1] . '[]...
#!/usr/bin/rexx call usage arg(1) trace normal signal on any name error keywords = 'FULLNAME FAVOURITEFRUIT NEEDSPEELING SEEDSREMOVED OTHERFAMILY' config_single?. = 1 config. = '' config.NEEDSPEELING = 0 config.SEEDSREMOVED = 1 parse arg configfilename if length(co...
Can you help me rewrite this code in REXX instead of PHP, keeping it the same logically?
<?php $dog = 'Benjamin'; $Dog = 'Samba'; $DOG = 'Bernie'; echo "There are 3 dogs named {$dog}, {$Dog} and {$DOG}\n"; function DOG() { return 'Bernie'; } echo 'There is only 1 dog named ' . dog() . "\n";
options replace format comments java crossref symbols nobinary dog = "Benjamin"; Dog = "Samba"; DOG = "Bernie"; if dog == Dog & Dog == DOG & dog == DOG then do say 'There is just one dog named' dog'.' end else do say 'The three dogs are named' dog',' Dog 'and' DOG'.' end return
Port the following code from PHP to REXX with equivalent syntax and logic.
$commands = 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase ...
parse arg uw if uw='' then uw= 'riG rePEAT copies put mo rest types fup. 6 poweRin' say 'user words: ' uw @= 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy' , 'COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPa...
Please provide an equivalent version of this PHP code in REXX.
$commands = 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput Join SPlit SPLTJOIN LOAD Locate CLocate LOWercase UPPercase ...
parse arg uw if uw='' then uw= 'riG rePEAT copies put mo rest types fup. 6 poweRin' say 'user words: ' uw @= 'Add ALTer BAckup Bottom CAppend Change SCHANGE CInsert CLAst COMPress COpy' , 'COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPa...
Write a version of this PHP function in REXX with identical behavior.
function stoogeSort(&$arr, $i, $j) { if($arr[$j] < $arr[$i]) { list($arr[$j],$arr[$i]) = array($arr[$i], $arr[$j]); } if(($j - $i) > 1) { $t = ($j - $i + 1) / 3; stoogesort($arr, $i, $j - $t); stoogesort($arr, $i + $t, $j); stoogesort($arr, $i, $j - $t); } }
options replace format comments java crossref savelog symbols binary iList = [int 1, 4, 5, 3, -6, 3, 7, 10, -2, -5, 7, 5, 9, -3, 7] sList = Arrays.copyOf(iList, iList.length) sList = stoogeSort(sList) lists = [iList, sList] loop ln = 0 to lists.length - 1 cl = lists[ln] rpt = Rexx('') loop ct = 0 to cl.length...
Maintain the same structure and functionality when rewriting this code in REXX.
function shellSort($arr) { $inc = round(count($arr)/2); while($inc > 0) { for($i = $inc; $i < count($arr);$i++){ $temp = $arr[$i]; $j = $i; while($j >= $inc && $arr[$j-$inc] > $temp) { $arr[$j] = $arr[$j - $inc]; $j -= $inc; } $arr[$j] = $temp; } $inc = round($inc/2.2); } return $ar...
options replace format comments java crossref savelog symbols binary placesList = [String - "UK London", "US New York", "US Boston", "US Washington" - , "UK Washington", "US Birmingham", "UK Birmingham", "UK Boston" - ] sortedList = shellSort(String[] Arrays.copyOf(placesList, placesList.l...
Convert this PHP snippet to REXX and keep its semantics consistent.
<?php $DOCROOT = $_SERVER['DOCUMENT_ROOT']; function fileLine ($lineNum, $file) { $count = 0; while (!feof($file)) { $count++; $line = fgets($file); if ($count == $lineNum) return $line; } die("Requested file has fewer than ".$lineNum." lines!"); } @ $fp = fopen("$DOC...
options replace format comments java crossref symbols nobinary parse arg inFileName lineNr . if inFileName = '' | inFileName = '.' then inFileName = './data/input.txt' if lineNr = '' | lineNr = '.' then lineNr = 7 do lineTxt = readLine(inFileName, lineNr) say '<textline number="'lineNr.right(5, 0)'"...
Write a version of this PHP function in REXX with identical behavior.
<?php $DOCROOT = $_SERVER['DOCUMENT_ROOT']; function fileLine ($lineNum, $file) { $count = 0; while (!feof($file)) { $count++; $line = fgets($file); if ($count == $lineNum) return $line; } die("Requested file has fewer than ".$lineNum." lines!"); } @ $fp = fopen("$DOC...
options replace format comments java crossref symbols nobinary parse arg inFileName lineNr . if inFileName = '' | inFileName = '.' then inFileName = './data/input.txt' if lineNr = '' | lineNr = '.' then lineNr = 7 do lineTxt = readLine(inFileName, lineNr) say '<textline number="'lineNr.right(5, 0)'"...
Rewrite this program in REXX while keeping its functionality equivalent to the PHP version.
<?php $s = 'http://foo/bar/'; $s = rawurlencode($s); ?>
options replace format comments java crossref symbols nobinary testcase() say say 'RFC3986' testcase('RFC3986') say say 'HTML5' testcase('HTML5') say return method encode(url, varn) public static variation = varn.upper opts = '' opts['RFC3986'] = '-._~' opts['HTML5'] = '-._*' rp = ...
Change the programming language of this snippet from PHP to REXX without modifying what it does.
<?php $s = 'http://foo/bar/'; $s = rawurlencode($s); ?>
options replace format comments java crossref symbols nobinary testcase() say say 'RFC3986' testcase('RFC3986') say say 'HTML5' testcase('HTML5') say return method encode(url, varn) public static variation = varn.upper opts = '' opts['RFC3986'] = '-._~' opts['HTML5'] = '-._*' rp = ...
Can you help me rewrite this code in REXX instead of PHP, keeping it the same logically?
<?php function f($n) { return sqrt(abs($n)) + 5 * $n * $n * $n; } $sArray = []; echo "Enter 11 numbers.\n"; for ($i = 0; $i <= 10; $i++) { echo $i + 1, " - Enter number: "; array_push($sArray, (float)fgets(STDIN)); } echo PHP_EOL; $sArray = array_reverse($sArray); foreach ($sArray as $s) { $r = ...
numeric digits 200 parse arg N .; if N=='' | N=="," then N=11 maxValue= 400 wid= 20 frac= 5 say ' _____' say 'function: ...
Rewrite the snippet below in REXX so it works the same as the original PHP code.
$odd = function ($prev) use ( &$odd ) { $a = fgetc(STDIN); if (!ctype_alpha($a)) { $prev(); fwrite(STDOUT, $a); return $a != '.'; } $clos = function () use ($a , $prev) { fwrite(STDOUT, $a); $prev(); }; return $odd($clos); }; $even = function () { while (true) { $c = fgetc(STDIN); fwrite(STDOUT, $c...
iFID_ = 'ODDWORD.IN' oFID_ = 'ODDWORD.' do case=1 for 2; #= 0 iFID= iFID_ || case oFID= oFID_ || case say; say; say '════════ reading file: ' iFID ...
Please provide an equivalent version of this PHP code in REXX.
<?php function is_describing($number) { foreach (str_split((int) $number) as $place => $value) { if (substr_count($number, $place) != $value) { return false; } } return true; } for ($i = 0; $i <= 50000000; $i += 10) { if (is_describing($i)) { echo $i . PHP_EOL;...
-- REXX program to check if a number (base 10) is self-describing. parse arg x y . if x=='' then exit if y=='' then y=x -- 10 digits is the maximum size number that works here, so cap it numeric digits 10 y=min(y, 9999999999) loop number = x to y loop i = 1 to number~length digit = number~subchar(i) -- r...
Write the same algorithm in REXX as shown in this PHP implementation.
<?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";
parse arg $ minL iFID . if $=='' | $=="," then $= 'the' if minL=='' | minL=="," then minL= 12 if iFID=='' | iFID=="," then iFID='unixdict.txt' tell= minL>0; minL= abs(minL) @.= do #=1 ...
Maintain the same structure and functionality when rewriting this code in REXX.
$address = <<<END 1, High Street, $town_name, West Midlands. WM4 5HD. END;
parse arg doc . do j=1 for sourceline() if sourceline(j)\=='◄◄'doc then iterate do !=j+1 to sourceline() while sourceline(!)\=='◄◄.' say sourceline(!) end exit end say doc '"here" document not f...
Change the following PHP code into REXX without altering its purpose.
$address = <<<END 1, High Street, $town_name, West Midlands. WM4 5HD. END;
parse arg doc . do j=1 for sourceline() if sourceline(j)\=='◄◄'doc then iterate do !=j+1 to sourceline() while sourceline(!)\=='◄◄.' say sourceline(!) end exit end say doc '"here" document not f...
Please provide an equivalent version of this PHP code in REXX.
<?php $game = new Game(); while(true) { $game->cycle(); } class Game { private $field; private $fieldSize; private $command; private $error; private $lastIndexX, $lastIndexY; private $score; private $finishScore; function __construct() { $this->field = array(); $this->fieldSize = 4; $this->finishS...
parse arg N win seed . if N=='' | N=="," then N= 4 if win=='' | win=="," then win= 2**11 if datatype(seed, 'W') then call random ,,seed L= length(win) + 2 eye=copies("─", 8); pad=left('', length(eye)+2) b= ' ' ...
Produce a language-to-language conversion: from PHP to REXX, same semantics.
while(1) echo "SPAM\n";
options replace format comments java crossref savelog symbols nobinary say say 'Loops/Infinite' loop label spam forever say 'SPAM' end spam
Change the programming language of this snippet from PHP to REXX without modifying what it does.
function multiply( $a, $b ) { return $a * $b; }
options replace format comments java crossref savelog symbols binary pi = 3.14159265358979323846264338327950 radiusY = 10 in2ft = 12 ft2yds = 3 in2mm = 25.4 mm2m = 1 / 1000 radiusM = multiply(multiply(radiusY, multiply(multiply(ft2yds, in2ft), in2mm)), mm2m) say "Area of a circle" radiusY "yds radius: "...
Write a version of this PHP function in REXX with identical behavior.
function sattoloCycle($items) { for ($i = 0; $i < count($items); $i++) { $j = floor((mt_rand() / mt_getrandmax()) * $i); $tmp = $items[$i]; $items[$i] = $items[$j]; $items[$j] = $tmp; } return $items; }
parse arg a; say 'original:' space(a) do x=0 for words(a); @.x= word(a, x+1); end do #=x-1 by -1 to 1; j= random(0, #-1) parse value @.# @.j with @.j @.# end $= ...
Maintain the same structure and functionality when rewriting this code in REXX.
function sattoloCycle($items) { for ($i = 0; $i < count($items); $i++) { $j = floor((mt_rand() / mt_getrandmax()) * $i); $tmp = $items[$i]; $items[$i] = $items[$j]; $items[$j] = $tmp; } return $items; }
parse arg a; say 'original:' space(a) do x=0 for words(a); @.x= word(a, x+1); end do #=x-1 by -1 to 1; j= random(0, #-1) parse value @.# @.j with @.j @.# end $= ...
Port the provided PHP code into REXX while preserving the original functionality.
<?php $db = new SQLite3(':memory:'); $db->exec(" CREATE TABLE address ( addrID INTEGER PRIMARY KEY AUTOINCREMENT, addrStreet TEXT NOT NULL, addrCity TEXT NOT NULL, addrState TEXT NOT NULL, addrZIP TEXT NOT NULL ) "); ?>
options replace format comments java crossref symbols binary import java.sql.Connection import java.sql.Statement import java.sql.SQLException import java.sql.DriverManager class RTableCreate01 public properties private constant addressDDL = String '' - ' create table Address' - ' (' - ' addrID ...
Keep all operations the same but rewrite the snippet in REXX.
<?php $a = array(); array_push($a, 0); $used = array(); array_push($used, 0); $used1000 = array(); array_push($used1000, 0); $foundDup = false; $n = 1; while($n <= 15 || !$foundDup || count($used1000) < 1001) { $next = $a[$n - 1] - $n; if ($next < 1 || in_array($next, $used)) { $next += 2 * $n; } $alreadyUsed...
parse arg N h . if N=='' | N=="," then N= 15 if h=='' | h=="," then h= 1000 say "Recamán's sequence for the first " N " numbers: " recaman(N) say; say "The first duplicate number in the Recamán's sequence is: " ...
Change the programming language of this snippet from PHP to REXX without modifying what it does.
<?php $a = array(); array_push($a, 0); $used = array(); array_push($used, 0); $used1000 = array(); array_push($used1000, 0); $foundDup = false; $n = 1; while($n <= 15 || !$foundDup || count($used1000) < 1001) { $next = $a[$n - 1] - $n; if ($next < 1 || in_array($next, $used)) { $next += 2 * $n; } $alreadyUsed...
parse arg N h . if N=='' | N=="," then N= 15 if h=='' | h=="," then h= 1000 say "Recamán's sequence for the first " N " numbers: " recaman(N) say; say "The first duplicate number in the Recamán's sequence is: " ...
Preserve the algorithm and functionality while converting the code from PHP to REXX.
<?php function Y($f) { $g = function($w) use($f) { return $f(function() use($w) { return call_user_func_array($w($w), func_get_args()); }); }; return $g($g); } $fibonacci = Y(function($f) { return function($i) use($f) { return ($i <= 1) ? $i : ($f($i-1) + $f($i-2)); }; }); echo $fibonacci(10), "...
numeric digits 1000 say ' fib' Y(fib (50) ) say ' fib' Y(fib (12 11 10 9 8 7 6 5 4 3 2 1 0) ) say ' fact' Y(fact (60) ) say ' fact' Y(fact (0 1 2 3 4 5 6 7 8 9 10 ...
Maintain the same structure and functionality when rewriting this code in REXX.
<?php function columns($arr) { if (count($arr) == 0) return array(); else if (count($arr) == 1) return array_chunk($arr[0], 1); array_unshift($arr, NULL); $transpose = call_user_func_array('array_map', $arr); return array_map('array_filter', $transpose); } function beadsort($arr) ...
options replace format comments java crossref symbols nobinary runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method bead_sort(harry = Rexx[]) public static binary returns Rexx[] MIN_ = 'MIN' MAX_ = 'MAX' beads = Rexx 0 beads[MIN_] = 0 beads[MAX_] = 0...
Translate this program into REXX but keep the logic exactly as in PHP.
$accumulator = 0; echo 'HQ9+: '; $program = trim(fgets(STDIN)); foreach (str_split($program) as $chr) { switch ($chr) { case 'H': case 'h': printHelloWorld(); break; case 'Q': case 'q': printSource($program); break; case '9': ...
arg pgm . accumulator=0 do instructions=1 for length(pgm); ?=substr(pgm, instructions, 1) select when ?=='H' then say "Hello, world!" when ?=='Q' then...
Can you help me rewrite this code in REXX instead of PHP, keeping it the same logically?
$accumulator = 0; echo 'HQ9+: '; $program = trim(fgets(STDIN)); foreach (str_split($program) as $chr) { switch ($chr) { case 'H': case 'h': printHelloWorld(); break; case 'Q': case 'q': printSource($program); break; case '9': ...
arg pgm . accumulator=0 do instructions=1 for length(pgm); ?=substr(pgm, instructions, 1) select when ?=='H' then say "Hello, world!" when ?=='Q' then...
Preserve the algorithm and functionality while converting the code from PHP to REXX.
<?php function brainfuck_interpret(&$s, &$_s, &$d, &$_d, &$i, &$_i, &$o) { do { switch($s[$_s]) { case '+': $d[$_d] = chr(ord($d[$_d]) + 1); break; case '-': $d[$_d] = chr(ord($d[$_d]) - 1); break; case '>': $_d++; if(!isset($d[$_d])) $d[$_d] = chr(0); break; case '<': $_d--; break; ...
@.=0 p =0 ! =0 parse arg $ if $='' then $=, "++++++++++ ...
Rewrite this program in REXX while keeping its functionality equivalent to the PHP version.
<?php function brainfuck_interpret(&$s, &$_s, &$d, &$_d, &$i, &$_i, &$o) { do { switch($s[$_s]) { case '+': $d[$_d] = chr(ord($d[$_d]) + 1); break; case '-': $d[$_d] = chr(ord($d[$_d]) - 1); break; case '>': $_d++; if(!isset($d[$_d])) $d[$_d] = chr(0); break; case '<': $_d--; break; ...
@.=0 p =0 ! =0 parse arg $ if $='' then $=, "++++++++++ ...
Port the provided PHP code into REXX while preserving the original functionality.
class Card { protected static $suits = array( '♠', '♥', '♦', '♣' ); protected static $pips = array( '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' ); protected $suit; protected $suitOrder; protected $pip; protected $pipOrder; protected $order; public function __c...
* 1) Build ordered Card deck * 2) Create shuffled stack * 3) Deal 5 cards to 4 players each * 4) show what cards have been dealt and what's left on the stack * 05.07.2012 Walter Pachl **********************************************************************/ colors='S H C D' ranks ='A 2 3 4 5 6 7 8 9 T J Q K' i=0 cards='...
Generate a REXX translation of this PHP snippet without changing its computational steps.
function inOrder($arr){ for($i=0;$i<count($arr);$i++){ if(isset($arr[$i+1])){ if($arr[$i] > $arr[$i+1]){ return false; } } } return true; } function permute($items, $perms = array( )) { if (empty($items)) { if(inOrder($perms)){ return $perms; } } else { for ($i = count($items) ...
options replace format comments java crossref symbols nobinary import java.util.List import java.util.ArrayList numeric digits 20 class RSortingPermutationsort public properties private static iterations maxIterations -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ met...
Generate an equivalent REXX version of this PHP code.
<?php function meaning_of_life() { return 42; } function main($args) { echo "Main: The meaning of life is " . meaning_of_life() . "\n"; } if (preg_match("/scriptedmain/", $_SERVER["SCRIPT_NAME"])) { main($argv); } ?>
parse source . howInvoked @fn say 'This program ('@fn") was invoked as a: " howInvoked if howInvoked\=='COMMAND' then do say 'This program ('@fn") wasn't invoked via a command." exit 12 end ...
Port the provided PHP code into REXX while preserving the original functionality.
<?php function meaning_of_life() { return 42; } function main($args) { echo "Main: The meaning of life is " . meaning_of_life() . "\n"; } if (preg_match("/scriptedmain/", $_SERVER["SCRIPT_NAME"])) { main($argv); } ?>
parse source . howInvoked @fn say 'This program ('@fn") was invoked as a: " howInvoked if howInvoked\=='COMMAND' then do say 'This program ('@fn") wasn't invoked via a command." exit 12 end ...
Convert the following code from PHP to REXX, ensuring the logic remains intact.
<?php function printLastSundayOfAllMonth($year) { $months = array( 'January', 'February', 'March', 'April', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); foreach ($months as $month) { echo $month . ': ' . date('Y-m-d', strtotime('last sunday of ' . $month ...
parse arg yyyy do j=1 for 12 _ = lastDOW('Sunday', j, yyyy) say right(_,4)'-'right(j,2,0)"-"left(word(_,2),2) end exit │ lastDOW: procedure to return the date of the last day-of-week of │ │ ...