Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Transform the following COBOL implementation into Java, maintaining the same output and logic.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Rewrite this program in Java while keeping its functionality equivalent to the COBOL version.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Transform the following COBOL implementation into Python, maintaining the same output and logic.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Translate the given COBOL code snippet into Python without altering its behavior.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Ensure the translated VB code behaves exactly like the original COBOL snippet.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Change the programming language of this snippet from COBOL to VB without modifying what it does.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Port the following code from COBOL to Go with equivalent syntax and logic.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Keep all operations the same but rewrite the snippet in Go.
IDENTIFICATION DIVISION. PROGRAM-ID. MUNCHAUSEN. DATA DIVISION. WORKING-STORAGE SECTION. 01 VARIABLES. 03 CANDIDATE PIC 9(4). 03 DIGITS PIC 9 OCCURS 4 TIMES, REDEFINES CANDIDATE. 03 DIGIT PIC 9. 03 POWER-SUM PIC 9(5). 0...
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Port the provided REXX code into C while preserving the original functionality.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Produce a functionally identical C code for the snippet given in REXX.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Preserve the algorithm and functionality while converting the code from REXX to C#.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Translate the given REXX code snippet into C# without altering its behavior.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Transform the following REXX implementation into C++, maintaining the same output and logic.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Convert this REXX snippet to C++ and keep its semantics consistent.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Write the same code in Java as shown below in REXX.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Convert this REXX snippet to Java and keep its semantics consistent.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Please provide an equivalent version of this REXX code in Python.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Convert this REXX block to Python, preserving its control flow and logic.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Port the following code from REXX to VB with equivalent syntax and logic.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Translate the given REXX code snippet into VB without altering its behavior.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Transform the following REXX implementation into Go, maintaining the same output and logic.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Translate this program into Go but keep the logic exactly as in REXX.
Do n=0 To 10000 If n=m(n) Then Say n End Exit m: Parse Arg z res=0 Do While z>'' Parse Var z c +1 z res=res+c**c End Return res
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Preserve the algorithm and functionality while converting the code from Ruby to C.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Port the following code from Ruby to C with equivalent syntax and logic.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Change the following Ruby code into C# without altering its purpose.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Convert this Ruby snippet to C# and keep its semantics consistent.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Keep all operations the same but rewrite the snippet in C++.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Transform the following Ruby implementation into C++, maintaining the same output and logic.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Translate this program into Java but keep the logic exactly as in Ruby.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Convert this Ruby block to Java, preserving its control flow and logic.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Keep all operations the same but rewrite the snippet in Python.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Translate this program into Python but keep the logic exactly as in Ruby.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Write the same code in VB as shown below in Ruby.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Port the following code from Ruby to VB with equivalent syntax and logic.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Keep all operations the same but rewrite the snippet in Go.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Preserve the algorithm and functionality while converting the code from Ruby to Go.
puts (1..5000).select{|n| n.digits.sum{|d| d**d} == n}
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Translate this program into C but keep the logic exactly as in Scala.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Produce a language-to-language conversion: from Scala to C, same semantics.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Convert this Scala snippet to C# and keep its semantics consistent.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Change the following Scala code into C# without altering its purpose.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Translate the given Scala code snippet into C++ without altering its behavior.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Transform the following Scala implementation into C++, maintaining the same output and logic.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Preserve the algorithm and functionality while converting the code from Scala to Java.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Produce a language-to-language conversion: from Scala to Java, same semantics.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Generate an equivalent Python version of this Scala code.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Preserve the algorithm and functionality while converting the code from Scala to Python.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Produce a language-to-language conversion: from Scala to VB, same semantics.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Change the following Scala code into VB without altering its purpose.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Maintain the same structure and functionality when rewriting this code in Go.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Translate the given Scala code snippet into Go without altering its behavior.
val powers = IntArray(10) fun isMunchausen(n: Int): Boolean { if (n < 0) return false var sum = 0L var nn = n while (nn > 0) { sum += powers[nn % 10] if (sum > n.toLong()) return false nn /= 10 } return sum == n.toLong() } fun main(args: Array<String>) { for ...
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Write a version of this Swift function in C with identical behavior.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Rewrite this program in C while keeping its functionality equivalent to the Swift version.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
#include <stdio.h> #include <math.h> int main() { for (int i = 1; i < 5000; i++) { int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; sum += pow(digit, digit); } if (sum == i) { ...
Convert this Swift block to C#, preserving its control flow and logic.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Ensure the translated C# code behaves exactly like the original Swift snippet.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
Func<char, int> toInt = c => c-'0'; foreach (var i in Enumerable.Range(1,5000) .Where(n => n == n.ToString() .Sum(x => Math.Pow(toInt(x), toInt(x))))) Console.WriteLine(i);
Can you help me rewrite this code in C++ instead of Swift, keeping it the same logically?
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Preserve the algorithm and functionality while converting the code from Swift to C++.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
Port the following code from Swift to Java with equivalent syntax and logic.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Write the same code in Java as shown below in Swift.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
public class Main { public static void main(String[] args) { for(int i = 0 ; i <= 5000 ; i++ ){ int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum(); if( i == val){ System.out.println( i + " (munchausen)"); } } } }
Change the following Swift code into Python without altering its purpose.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Produce a language-to-language conversion: from Swift to Python, same semantics.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
for i in range(5000): if i == sum(int(x) ** int(x) for x in str(i)): print(i)
Change the following Swift code into VB without altering its purpose.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Port the provided Swift code into VB while preserving the original functionality.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
Option Explicit Sub Main_Munchausen_numbers() Dim i& For i = 1 To 5000 If IsMunchausen(i) Then Debug.Print i & " is a munchausen number." Next i End Sub Function IsMunchausen(Number As Long) As Boolean Dim Digits, i As Byte, Tot As Long Digits = Split(StrConv(Number, vbUnicode), Chr(0)) For ...
Port the provided Swift code into Go while preserving the original functionality.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Generate a Go translation of this Swift snippet without changing its computational steps.
import Foundation func isMünchhausen(_ n: Int) -> Bool { let nums = String(n).map(String.init).compactMap(Int.init) return Int(nums.map({ pow(Double($0), Double($0)) }).reduce(0, +)) == n } for i in 1...5000 where isMünchhausen(i) { print(i) }
package main import( "fmt" "math" ) var powers [10]int func isMunchausen(n int) bool { if n < 0 { return false } n64 := int64(n) nn := n64 var sum int64 = 0 for nn > 0 { sum += int64(powers[nn % 10]) if sum > n64 { return false } nn /= 10 } return sum == n...
Rewrite the snippet below in PHP so it works the same as the original Rust code.
fn main() { let mut solutions = Vec::new(); for num in 1..5_000 { let power_sum = num.to_string() .chars() .map(|c| { let digit = c.to_digit(10).unwrap(); (digit as f64).powi(digit as i32) as usize }) .sum::<usize>(); ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Change the programming language of this snippet from Rust to PHP without modifying what it does.
fn main() { let mut solutions = Vec::new(); for num in 1..5_000 { let power_sum = num.to_string() .chars() .map(|c| { let digit = c.to_digit(10).unwrap(); (digit as f64).powi(digit as i32) as usize }) .sum::<usize>(); ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Rewrite the snippet below in PHP so it works the same as the original Ada code.
with Ada.Text_IO; procedure Munchausen is function Is_Munchausen (M : in Natural) return Boolean is Table : constant array (Character range '0' .. '9') of Natural := (0**0, 1**1, 2**2, 3**3, 4**4, 5**5, 6**6, 7**7, 8**8, 9**9); Image : constant String := M'Image; Sum : Natural ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Produce a language-to-language conversion: from Ada to PHP, same semantics.
with Ada.Text_IO; procedure Munchausen is function Is_Munchausen (M : in Natural) return Boolean is Table : constant array (Character range '0' .. '9') of Natural := (0**0, 1**1, 2**2, 3**3, 4**4, 5**5, 6**6, 7**7, 8**8, 9**9); Image : constant String := M'Image; Sum : Natural ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Convert this Arturo block to PHP, preserving its control flow and logic.
munchausen?: function [n][ n = sum map split to :string n 'digit [ d: to :integer digit d^d ] ] loop 1..5000 'x [ if munchausen? x -> print x ]
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Can you help me rewrite this code in PHP instead of Arturo, keeping it the same logically?
munchausen?: function [n][ n = sum map split to :string n 'digit [ d: to :integer digit d^d ] ] loop 1..5000 'x [ if munchausen? x -> print x ]
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Convert this AutoHotKey snippet to PHP and keep its semantics consistent.
Loop, 5000 { Loop, Parse, A_Index var += A_LoopField**A_LoopField if (var = A_Index) num .= var "`n" var := 0 } Msgbox, %num%
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write a version of this AutoHotKey function in PHP with identical behavior.
Loop, 5000 { Loop, Parse, A_Index var += A_LoopField**A_LoopField if (var = A_Index) num .= var "`n" var := 0 } Msgbox, %num%
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Generate an equivalent PHP version of this AWK code.
BEGIN { for (i=1; i<=5000; i++) { sum = 0 for (j=1; j<=length(i); j++) { digit = substr(i,j,1) sum += digit ^ digit } if (i == sum) { printf("%d\n",i) } } exit(0) }
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Keep all operations the same but rewrite the snippet in PHP.
BEGIN { for (i=1; i<=5000; i++) { sum = 0 for (j=1; j<=length(i); j++) { digit = substr(i,j,1) sum += digit ^ digit } if (i == sum) { printf("%d\n",i) } } exit(0) }
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Produce a language-to-language conversion: from BBC_Basic to PHP, same semantics.
FOR i% = 0 TO 5 FOR j% = 0 TO 5 FOR k% = 0 TO 5 FOR l% = 0 TO 5 m% = FNexp(i%) + FNexp(j%) + FNexp(k%) + FNexp(l%) n% = 1000 * i% + 100 * j% + 10 * k% + l% IF m% = n% AND m% > 0 THEN PRINT m% NEXT NEXT NEXT NEXT END : DEF FNexp(x%) IF x% = 0 THEN = 0 ELSE = x% ^ x%
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Convert the following code from BBC_Basic to PHP, ensuring the logic remains intact.
FOR i% = 0 TO 5 FOR j% = 0 TO 5 FOR k% = 0 TO 5 FOR l% = 0 TO 5 m% = FNexp(i%) + FNexp(j%) + FNexp(k%) + FNexp(l%) n% = 1000 * i% + 100 * j% + 10 * k% + l% IF m% = n% AND m% > 0 THEN PRINT m% NEXT NEXT NEXT NEXT END : DEF FNexp(x%) IF x% = 0 THEN = 0 ELSE = x% ^ x%
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write a version of this Common_Lisp function in PHP with identical behavior.
(ns async-example.core (:require [clojure.math.numeric-tower :as math]) (:use [criterium.core]) (:gen-class)) (defn get-digits [n] " Convert number of a list of digits (e.g. 545 -> ((5), (4), (5)) " (map #(Integer/valueOf (str %)) (String/valueOf n))) (defn sum-power [digits] " Convert digits such as abc...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Generate an equivalent PHP version of this Common_Lisp code.
(ns async-example.core (:require [clojure.math.numeric-tower :as math]) (:use [criterium.core]) (:gen-class)) (defn get-digits [n] " Convert number of a list of digits (e.g. 545 -> ((5), (4), (5)) " (map #(Integer/valueOf (str %)) (String/valueOf n))) (defn sum-power [digits] " Convert digits such as abc...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Produce a functionally identical PHP code for the snippet given in D.
import std.stdio; void main() { for (int i=1; i<5000; i++) { int sum = 0; for (int number=i; number>0; number/=10) { int digit = number % 10; sum += digit ^^ digit; } if (sum == i) { ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Change the programming language of this snippet from D to PHP without modifying what it does.
import std.stdio; void main() { for (int i=1; i<5000; i++) { int sum = 0; for (int number=i; number>0; number/=10) { int digit = number % 10; sum += digit ^^ digit; } if (sum == i) { ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write a version of this Elixir function in PHP with identical behavior.
defmodule Munchausen do @pow for i <- 0..9, into: %{}, do: {i, :math.pow(i,i) |> round} def number?(n) do n == Integer.digits(n) |> Enum.reduce(0, fn d,acc -> @pow[d] + acc end) end end Enum.each(1..5000, fn i -> if Munchausen.number?(i), do: IO.puts i end)
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Translate the given Elixir code snippet into PHP without altering its behavior.
defmodule Munchausen do @pow for i <- 0..9, into: %{}, do: {i, :math.pow(i,i) |> round} def number?(n) do n == Integer.digits(n) |> Enum.reduce(0, fn d,acc -> @pow[d] + acc end) end end Enum.each(1..5000, fn i -> if Munchausen.number?(i), do: IO.puts i end)
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Translate this program into PHP but keep the logic exactly as in F#.
let toFloat x = x |> int |> fun n -> n - 48 |> float let power x = toFloat x ** toFloat x |> int let isMunchausen n = n = (string n |> Seq.map char |> Seq.map power |> Seq.sum) printfn "%A" ([1..5000] |> List.filter isMunchausen)
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write the same code in PHP as shown below in F#.
let toFloat x = x |> int |> fun n -> n - 48 |> float let power x = toFloat x ** toFloat x |> int let isMunchausen n = n = (string n |> Seq.map char |> Seq.map power |> Seq.sum) printfn "%A" ([1..5000] |> List.filter isMunchausen)
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Translate this program into PHP but keep the logic exactly as in Factor.
USING: kernel math.functions math.ranges math.text.utils prettyprint sequences ; : munchausen? ( n -- ? ) dup 1 digit-groups dup [ ^ ] 2map sum = ; 5000 [1,b] [ munchausen? ] filter .
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Please provide an equivalent version of this Factor code in PHP.
USING: kernel math.functions math.ranges math.text.utils prettyprint sequences ; : munchausen? ( n -- ? ) dup 1 digit-groups dup [ ^ ] 2map sum = ; 5000 [1,b] [ munchausen? ] filter .
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Change the following Forth code into PHP without altering its purpose.
: dig.num dup 0 swap begin swap 1 + swap dup 10 >= while 10 / repeat drop ; : to.self dup 1 = if drop 1 else dup 0 <= if drop 0 else dup 1 do dup loop dup 1 do * ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write the same code in PHP as shown below in Forth.
: dig.num dup 0 swap begin swap 1 + swap dup 10 >= while 10 / repeat drop ; : to.self dup 1 = if drop 1 else dup 0 <= if drop 0 else dup 1 do dup loop dup 1 do * ...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Ensure the translated PHP code behaves exactly like the original Fortran snippet.
C MUNCHAUSEN NUMBERS - FORTRAN IV DO 2 I=1,5000 IS=0 II=I DO 1 J=1,4 ID=10**(4-J) N=II/ID IR=MOD(II,ID) IF(N.NE.0) IS=IS+N**N 1 II=IR 2 IF(IS.EQ.I) WRITE(*,*) I END
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Translate this program into PHP but keep the logic exactly as in Fortran.
C MUNCHAUSEN NUMBERS - FORTRAN IV DO 2 I=1,5000 IS=0 II=I DO 1 J=1,4 ID=10**(4-J) N=II/ID IR=MOD(II,ID) IF(N.NE.0) IS=IS+N**N 1 II=IR 2 IF(IS.EQ.I) WRITE(*,*) I END
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Port the following code from Haskell to PHP with equivalent syntax and logic.
import Control.Monad (join) import Data.List (unfoldr) isMunchausen :: Integer -> Bool isMunchausen = (==) <*> (sum . map (join (^)) . unfoldr digit) digit 0 = Nothing digit n = Just (r, q) where (q, r) = n `divMod` 10 main :: IO () main = print $ filter isMunchausen [1 .. 5000]
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Translate the given Haskell code snippet into PHP without altering its behavior.
import Control.Monad (join) import Data.List (unfoldr) isMunchausen :: Integer -> Bool isMunchausen = (==) <*> (sum . map (join (^)) . unfoldr digit) digit 0 = Nothing digit n = Just (r, q) where (q, r) = n `divMod` 10 main :: IO () main = print $ filter isMunchausen [1 .. 5000]
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Convert the following code from J to PHP, ensuring the logic remains intact.
munch=: +/@(^~@(10&#.inv)) (#~ ] = munch"0) 1+i.5000 1 3435
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Translate this program into PHP but keep the logic exactly as in J.
munch=: +/@(^~@(10&#.inv)) (#~ ] = munch"0) 1+i.5000 1 3435
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write the same code in PHP as shown below in Julia.
println([n for n = 1:5000 if sum(d^d for d in digits(n)) == n])
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Change the following Julia code into PHP without altering its purpose.
println([n for n = 1:5000 if sum(d^d for d in digits(n)) == n])
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Write the same algorithm in PHP as shown in this Lua implementation.
function isMunchausen (n) local sum, nStr, digit = 0, tostring(n) for pos = 1, #nStr do digit = tonumber(nStr:sub(pos, pos)) sum = sum + digit ^ digit end return sum == n end local function isMunchausen (n) local sum, digit, acc = 0, 0, n while acc > 0 do digit = acc %...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Generate an equivalent PHP version of this Lua code.
function isMunchausen (n) local sum, nStr, digit = 0, tostring(n) for pos = 1, #nStr do digit = tonumber(nStr:sub(pos, pos)) sum = sum + digit ^ digit end return sum == n end local function isMunchausen (n) local sum, digit, acc = 0, 0, n while acc > 0 do digit = acc %...
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Please provide an equivalent version of this Mathematica code in PHP.
Off[Power::indet]; Select[Range[5000], Total[IntegerDigits[#]^IntegerDigits[#]] == # &]
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...
Generate an equivalent PHP version of this Mathematica code.
Off[Power::indet]; Select[Range[5000], Total[IntegerDigits[#]^IntegerDigits[#]] == # &]
<?php $pwr = array_fill(0, 10, 0); function isMunchhausen($n) { global $pwr; $sm = 0; $temp = $n; while ($temp) { $sm= $sm + $pwr[($temp % 10)]; $temp = (int)($temp / 10); } return $sm == $n; } for ($i = 0; $i < 10; $i++) { $pwr[$i] = pow((float)($i), (float)($i)); } for...