Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Can you help me rewrite this code in Python instead of D, keeping it the same logically? | import std.stdio;
int[] divisors(int n) {
import std.range;
int[] divs = [1];
int[] divs2;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= ret... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Translate the given D code snippet into Python without altering its behavior. | import std.stdio;
int[] divisors(int n) {
import std.range;
int[] divs = [1];
int[] divs2;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= ret... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Keep all operations the same but rewrite the snippet in VB. | import std.stdio;
int[] divisors(int n) {
import std.range;
int[] divs = [1];
int[] divs2;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= ret... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Change the programming language of this snippet from D to VB without modifying what it does. | import std.stdio;
int[] divisors(int n) {
import std.range;
int[] divs = [1];
int[] divs2;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= ret... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Convert this D snippet to Go and keep its semantics consistent. | import std.stdio;
int[] divisors(int n) {
import std.range;
int[] divs = [1];
int[] divs2;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= ret... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Change the programming language of this snippet from D to Go without modifying what it does. | import std.stdio;
int[] divisors(int n) {
import std.range;
int[] divs = [1];
int[] divs2;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= ret... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Write a version of this Delphi function in C with identical behavior. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Write the same algorithm in C as shown in this Delphi implementation. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Maintain the same structure and functionality when rewriting this code in C#. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Write a version of this Delphi function in C# with identical behavior. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Transform the following Delphi implementation into C++, maintaining the same output and logic. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Write the same algorithm in C++ as shown in this Delphi implementation. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Write the same algorithm in Java as shown in this Delphi implementation. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Can you help me rewrite this code in Java instead of Delphi, keeping it the same logically? | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Produce a functionally identical Python code for the snippet given in Delphi. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Translate the given Delphi code snippet into Python without altering its behavior. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Produce a language-to-language conversion: from Delphi to VB, same semantics. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Preserve the algorithm and functionality while converting the code from Delphi to VB. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Convert this Delphi snippet to Go and keep its semantics consistent. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Convert this Delphi block to Go, preserving its control flow and logic. | program AbundantOddNumbers;
uses
SysUtils;
function SumProperDivisors(const N: Cardinal): Cardinal;
var
I, J: Cardinal;
begin
Result := 1;
I := 3;
while I < Sqrt(N)+1 do begin
if N mod I = 0 then begin
J := N div I;
Inc(Result, I);
if I <> J then Inc(Result, J);
end;
Inc(I, 2... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Can you help me rewrite this code in C instead of F#, keeping it the same logically? |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Convert the following code from F# to C, ensuring the logic remains intact. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Port the following code from F# to C# with equivalent syntax and logic. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Generate a C# translation of this F# snippet without changing its computational steps. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Can you help me rewrite this code in C++ instead of F#, keeping it the same logically? |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Preserve the algorithm and functionality while converting the code from F# to C++. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Write the same code in Java as shown below in F#. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Produce a functionally identical Java code for the snippet given in F#. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Please provide an equivalent version of this F# code in Python. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Change the following F# code into Python without altering its purpose. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Write a version of this F# function in VB with identical behavior. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Write the same algorithm in VB as shown in this F# implementation. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Port the following code from F# to Go with equivalent syntax and logic. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Convert this F# block to Go, preserving its control flow and logic. |
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of t... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Write the same code in C as shown below in Factor. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Translate the given Factor code snippet into C without altering its behavior. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Port the provided Factor code into C# while preserving the original functionality. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Convert this Factor snippet to C# and keep its semantics consistent. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Ensure the translated C++ code behaves exactly like the original Factor snippet. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Convert the following code from Factor to C++, ensuring the logic remains intact. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Rewrite the snippet below in Java so it works the same as the original Factor code. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Ensure the translated Java code behaves exactly like the original Factor snippet. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Change the following Factor code into Python without altering its purpose. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Transform the following Factor implementation into Python, maintaining the same output and logic. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Write a version of this Factor function in VB with identical behavior. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Convert the following code from Factor to VB, ensuring the logic remains intact. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Preserve the algorithm and functionality while converting the code from Factor to Go. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Generate a Go translation of this Factor snippet without changing its computational steps. | USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Rewrite this program in C# while keeping its functionality equivalent to the Fortran version. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Preserve the algorithm and functionality while converting the code from Fortran to C#. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Write the same code in C++ as shown below in Fortran. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Transform the following Fortran implementation into C++, maintaining the same output and logic. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Change the following Fortran code into C without altering its purpose. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Please provide an equivalent version of this Fortran code in C. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Rewrite this program in Java while keeping its functionality equivalent to the Fortran version. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Convert this Fortran block to Java, preserving its control flow and logic. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Convert this Fortran snippet to Python and keep its semantics consistent. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Change the programming language of this snippet from Fortran to Python without modifying what it does. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Translate the given Fortran code snippet into VB without altering its behavior. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Port the provided Fortran code into VB while preserving the original functionality. | program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
write(*,*)'N sum'
... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Convert this Groovy block to C, preserving its control flow and logic. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Ensure the translated C code behaves exactly like the original Groovy snippet. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Change the following Groovy code into C# without altering its purpose. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Port the following code from Groovy to C# with equivalent syntax and logic. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Translate this program into C++ but keep the logic exactly as in Groovy. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Translate the given Groovy code snippet into C++ without altering its behavior. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Rewrite the snippet below in Java so it works the same as the original Groovy code. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Can you help me rewrite this code in Java instead of Groovy, keeping it the same logically? | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Transform the following Groovy implementation into Python, maintaining the same output and logic. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Produce a functionally identical Python code for the snippet given in Groovy. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Translate the given Groovy code snippet into VB without altering its behavior. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Generate an equivalent VB version of this Groovy code. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Translate this program into Go but keep the logic exactly as in Groovy. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Convert this Groovy block to Go, preserving its control flow and logic. | class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
divs.add(1)
List<Integer> divs2 = new ArrayList<>()
int i = 2
while (i * i < n) {
if (n % i == 0) {
int j = (int) (n / i)
divs.add(i)
... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Write the same algorithm in C as shown in this Haskell implementation. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Convert this Haskell snippet to C and keep its semantics consistent. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Transform the following Haskell implementation into C#, maintaining the same output and logic. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Translate this program into C# but keep the logic exactly as in Haskell. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Convert the following code from Haskell to C++, ensuring the logic remains intact. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Produce a language-to-language conversion: from Haskell to C++, same semantics. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Change the programming language of this snippet from Haskell to Java without modifying what it does. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Change the following Haskell code into Python without altering its purpose. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Please provide an equivalent version of this Haskell code in Python. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Change the following Haskell code into VB without altering its purpose. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Maintain the same structure and functionality when rewriting this code in VB. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Keep all operations the same but rewrite the snippet in Go. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Keep all operations the same but rewrite the snippet in Go. | import Data.List (nub)
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Ensure the translated C code behaves exactly like the original Julia snippet. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Write the same code in C as shown below in Julia. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | #include <stdio.h>
#include <math.h>
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n +... |
Port the provided Julia code into C# while preserving the original functionality. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Produce a functionally identical C# code for the snippet given in Julia. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | using static System.Console;
using System.Collections.Generic;
using System.Linq;
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
Write... |
Rewrite the snippet below in C++ so it works the same as the original Julia code. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Produce a functionally identical C++ code for the snippet given in Julia. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... |
Rewrite this program in Java while keeping its functionality equivalent to the Julia version. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Convert this Julia snippet to Java and keep its semantics consistent. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,1000... |
Port the provided Julia code into Python while preserving the original functionality. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Change the programming language of this snippet from Julia to Python without modifying what it does. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... |
oddNumber = 1
aCount = 0
dSum = 0
from math import sqrt
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
print ("The first 25 abu... |
Ensure the translated VB code behaves exactly like the original Julia snippet. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Write the same code in VB as shown below in Julia. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | Module AbundantOddNumbers
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD... |
Write a version of this Julia function in Go with identical behavior. | using Primes
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
sort(f)
end
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
funct... | package main
import (
"fmt"
"strconv"
)
func divisors(n int) []int {
divs := []int{1}
divs2 := []int{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs2 = append(divs2, j)
}
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.