Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Write the same code in Go as shown below in AWK.
BEGIN { print(" for (fire=1; fire<=7; fire++) { for (police=1; police<=7; police++) { for (sanitation=1; sanitation<=7; sanitation++) { if (rules() ~ /^1+$/) { printf("%2d %2d %2d %2d\n",++count,fire,police,sanitation) } } } } exit(0) } function rules( stmt1,stmt2,stmt3) { stmt1 = fire != police && fire != sanitation && police != sanitation stmt2 = fire + police + sanitation == 12 stmt3 = police % 2 == 0 return(stmt1 stmt2 stmt3) }
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Port the following code from BBC_Basic to C with equivalent syntax and logic.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Please provide an equivalent version of this BBC_Basic code in C.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Convert the following code from BBC_Basic to C#, ensuring the logic remains intact.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Convert the following code from BBC_Basic to C#, ensuring the logic remains intact.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Convert the following code from BBC_Basic to C++, ensuring the logic remains intact.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Translate this program into C++ but keep the logic exactly as in BBC_Basic.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Preserve the algorithm and functionality while converting the code from BBC_Basic to Java.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Translate the given BBC_Basic code snippet into Java without altering its behavior.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Write a version of this BBC_Basic function in Python with identical behavior.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Preserve the algorithm and functionality while converting the code from BBC_Basic to Python.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Please provide an equivalent version of this BBC_Basic code in VB.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Change the following BBC_Basic code into VB without altering its purpose.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Port the provided BBC_Basic code into Go while preserving the original functionality.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Change the programming language of this snippet from BBC_Basic to Go without modifying what it does.
max_dept_num% = 7 dept_sum% = 12 PRINT "police sanitation fire" FOR police% = 2 TO max_dept_num% STEP 2 FOR sanitation% = 1 TO max_dept_num% IF sanitation% <> police% THEN fire% = (dept_sum% - police%) - sanitation% IF fire% > 0 AND fire% <= max_dept_num% AND fire% <> sanitation% AND fire% <> police% THEN PRINT " "; police%; " "; sanitation%; " "; fire% ENDIF NEXT NEXT END
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Generate an equivalent C version of this Clojure code.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Convert the following code from Clojure to C, ensuring the logic remains intact.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Translate the given Clojure code snippet into C# without altering its behavior.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Maintain the same structure and functionality when rewriting this code in C#.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Keep all operations the same but rewrite the snippet in C++.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Rewrite the snippet below in C++ so it works the same as the original Clojure code.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Transform the following Clojure implementation into Java, maintaining the same output and logic.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Maintain the same structure and functionality when rewriting this code in Java.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Generate an equivalent Python version of this Clojure code.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Produce a language-to-language conversion: from Clojure to Python, same semantics.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Convert this Clojure snippet to VB and keep its semantics consistent.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Produce a language-to-language conversion: from Clojure to VB, same semantics.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Change the following Clojure code into Go without altering its purpose.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Transform the following Clojure implementation into Go, maintaining the same output and logic.
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Produce a language-to-language conversion: from Common_Lisp to C, same semantics.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Keep all operations the same but rewrite the snippet in C.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Change the following Common_Lisp code into C# without altering its purpose.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Translate this program into C# but keep the logic exactly as in Common_Lisp.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Produce a functionally identical C++ code for the snippet given in Common_Lisp.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Translate the given Common_Lisp code snippet into C++ without altering its behavior.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Write the same code in Java as shown below in Common_Lisp.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Keep all operations the same but rewrite the snippet in Java.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Translate the given Common_Lisp code snippet into Python without altering its behavior.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Write the same algorithm in Python as shown in this Common_Lisp implementation.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Translate this program into VB but keep the logic exactly as in Common_Lisp.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Produce a language-to-language conversion: from Common_Lisp to VB, same semantics.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Port the following code from Common_Lisp to Go with equivalent syntax and logic.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Convert this Common_Lisp snippet to Go and keep its semantics consistent.
departmentNumbers =validRows( LAMBDA(ab, LET( x, INDEX(ab, 0, 1), y, INDEX(ab, 0, 2), z, 12 - (x + y), IF(y <> z, IF(1 <= z, IF(7 >= z, CHOOSE({1, 2, 3}, x, y, z), NA() ), NA() ), NA() ) ) )( cartesianProduct({2 SEQUENCE(7, 1, 1, 1) ) ) )
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Translate this program into C but keep the logic exactly as in D.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Ensure the translated C code behaves exactly like the original D snippet.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Translate the given D code snippet into C# without altering its behavior.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Convert this D snippet to C# and keep its semantics consistent.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Please provide an equivalent version of this D code in C++.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Translate the given D code snippet into C++ without altering its behavior.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Convert the following code from D to Java, ensuring the logic remains intact.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Produce a language-to-language conversion: from D to Java, same semantics.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Convert this D snippet to Python and keep its semantics consistent.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Change the programming language of this snippet from D to Python without modifying what it does.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Convert this D block to VB, preserving its control flow and logic.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Produce a functionally identical VB code for the snippet given in D.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Translate the given D code snippet into Go without altering its behavior.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Convert the following code from D to Go, ensuring the logic remains intact.
import std.stdio, std.range; void main() { int sol = 1; writeln("\t\tFIRE\t\tPOLICE\t\tSANITATION"); foreach( f; iota(1,8) ) { foreach( p; iota(1,8) ) { foreach( s; iota(1,8) ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { writefln("SOLUTION #%2d:\t%2d\t\t%3d\t\t%6d", sol++, f, p, s); } } } } }
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Preserve the algorithm and functionality while converting the code from Delphi to C.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Can you help me rewrite this code in C instead of Delphi, keeping it the same logically?
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Write the same code in C# as shown below in Delphi.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Change the following Delphi code into C# without altering its purpose.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Produce a functionally identical C++ code for the snippet given in Delphi.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Port the provided Delphi code into C++ while preserving the original functionality.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Maintain the same structure and functionality when rewriting this code in Java.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Convert the following code from Delphi to Java, ensuring the logic remains intact.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Maintain the same structure and functionality when rewriting this code in Python.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Ensure the translated Python code behaves exactly like the original Delphi snippet.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Preserve the algorithm and functionality while converting the code from Delphi to VB.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Produce a functionally identical VB code for the snippet given in Delphi.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Generate an equivalent Go version of this Delphi code.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Generate an equivalent Go version of this Delphi code.
program Department_numbers; uses System.SysUtils; var i, j, k, count: Integer; begin writeln('Police Sanitation Fire'); writeln('------ ---------- ----'); count := 0; i := 2; while i < 7 do begin for j := 1 to 7 do begin if j = i then Continue; for k := 1 to 7 do begin if (k = i) or (k = j) then Continue; if i + j + k <> 12 then Continue; writeln(format(' %d %d %d', [i, j, k])); inc(count); end; end; inc(i, 2); end; writeln(#10, count, ' valid combinations'); readln; end.
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Write a version of this Elixir function in C with identical behavior.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Generate an equivalent C version of this Elixir code.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Write a version of this Elixir function in C# with identical behavior.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Can you help me rewrite this code in C# instead of Elixir, keeping it the same logically?
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Generate a C++ translation of this Elixir snippet without changing its computational steps.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Produce a language-to-language conversion: from Elixir to C++, same semantics.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Preserve the algorithm and functionality while converting the code from Elixir to Java.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Convert this Elixir snippet to Java and keep its semantics consistent.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Rewrite the snippet below in Python so it works the same as the original Elixir code.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Convert the following code from Elixir to Python, ensuring the logic remains intact.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Rewrite the snippet below in VB so it works the same as the original Elixir code.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Please provide an equivalent version of this Elixir code in VB.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Generate a Go translation of this Elixir snippet without changing its computational steps.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Produce a language-to-language conversion: from Elixir to Go, same semantics.
IO.puts("P - F - S") for p <- [2,4,6], f <- 1..7, s <- 1..7, p != f and p != s and f != s and p + f + s == 12 do " end |> Enum.each(&IO.puts/1)
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Rewrite this program in C while keeping its functionality equivalent to the F# version.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Ensure the translated C code behaves exactly like the original F# snippet.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }
Produce a functionally identical C# code for the snippet given in F#.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Generate a C# translation of this F# snippet without changing its computational steps.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
using System; public class Program { public static void Main() { for (int p = 2; p <= 7; p+=2) { for (int s = 1; s <= 7; s++) { int f = 12 - p - s; if (s >= f) break; if (f > 7) continue; if (s == p || f == p) continue; Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}"); Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}"); } } } }
Transform the following F# implementation into C++, maintaining the same output and logic.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Generate a C++ translation of this F# snippet without changing its computational steps.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) { std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p << "\t\t" << std::setw( 6 ) << s << "\n"; } } } } return 0; }
Transform the following F# implementation into Java, maintaining the same output and logic.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Produce a functionally identical Java code for the snippet given in F#.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
public class DepartmentNumbers { public static void main(String[] args) { System.out.println("Police Sanitation Fire"); System.out.println("------ ---------- ----"); int count = 0; for (int i = 2; i <= 6; i += 2) { for (int j = 1; j <= 7; ++j) { if (j == i) continue; for (int k = 1; k <= 7; ++k) { if (k == i || k == j) continue; if (i + j + k != 12) continue; System.out.printf(" %d %d %d\n", i, j, k); count++; } } } System.out.printf("\n%d valid combinations", count); } }
Maintain the same structure and functionality when rewriting this code in Python.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Generate a Python translation of this F# snippet without changing its computational steps.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
from itertools import permutations def solve(): c, p, f, s = "\\,Police,Fire,Sanitation".split(',') print(f"{c:>3} {p:^6} {f:^4} {s:^10}") c = 1 for p, f, s in permutations(range(1, 8), r=3): if p + s + f == 12 and p % 2 == 0: print(f"{c:>3}: {p:^6} {f:^4} {s:^10}") c += 1 if __name__ == '__main__': solve()
Write the same algorithm in VB as shown in this F# implementation.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Write a version of this F# function in VB with identical behavior.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
Module Module1 Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p OrElse f = p Then Continue For End If Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}") Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}") Next Next End Sub End Module
Preserve the algorithm and functionality while converting the code from F# to Go.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Convert this F# snippet to Go and keep its semantics consistent.
type dNum = {Police:int; Fire:int; Sanitation:int} let fN n=n.Police%2=0&&n.Police+n.Fire+n.Sanitation=12&&n.Police<>n.Fire&&n.Police<>n.Sanitation&&n.Fire<>n.Sanitation List.init (7*7*7) (fun n->{Police=n%7+1;Fire=(n/7)%7+1;Sanitation=(n/49)+1})|>List.filter fN|>List.iter(printfn "%A")
package main import "fmt" func main() { fmt.Println("Police Sanitation Fire") fmt.Println("------ ---------- ----") count := 0 for i := 2; i < 7; i += 2 { for j := 1; j < 8; j++ { if j == i { continue } for k := 1; k < 8; k++ { if k == i || k == j { continue } if i + j + k != 12 { continue } fmt.Printf(" %d %d %d\n", i, j, k) count++ } } } fmt.Printf("\n%d valid combinations\n", count) }
Keep all operations the same but rewrite the snippet in C.
USING: formatting io kernel math math.combinatorics math.ranges sequences sets ; IN: rosetta-code.department-numbers 7 [1,b] 3 <k-permutations> [ [ first even? ] [ sum 12 = ] bi and ] filter "{ Police, Sanitation, Fire }" print nl [ "%[%d, %]\n" printf ] each
#include<stdio.h> int main() { int police,sanitation,fire; printf("Police Sanitation Fire\n"); printf("----------------------------------"); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf("\n%d\t\t%d\t\t%d",police,sanitation,fire); } } } } return 0; }