code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
package main
import (
"fmt"
"rcu"
"sort"
)
var ascPrimesSet = make(map[int]bool) | 0Ascending primes | 0go | 6t3p |
local function is_prime(n)
if n < 2 then return false end
if n % 2 == 0 then return n==2 end
if n % 3 == 0 then return n==3 end
for f = 5, n^0.5, 6 do
if n%f==0 or n%(f+2)==0 then return false end
end
return true
end
local function ascending_primes()
local digits, candidates, primes = {1,2,3,4,5,6,7,... | 0Ascending primes | 1lua | cy92 |
use strict;
use warnings;
use ntheory qw( is_prime );
print join('', map { sprintf "%10d", $_ } sort { $a <=> $b }
grep /./ && is_prime($_),
glob join '', map "{$_,}", 1 .. 9) =~ s/.{50}\K/\n/gr; | 0Ascending primes | 2perl | w1e6 |
from sympy import isprime
def ascending(x=0):
for y in range(x*10 + (x%10) + 1, x*10 + 10):
yield from ascending(y)
yield(y)
print(sorted(x for x in ascending() if isprime(x))) | 0Ascending primes | 3python | xawr |
x=("1 2" "3 4")
y=(5 6)
sum=( "${x[@]}" "${y[@]}" )
for i in "${sum[@]}"; do echo "$i"; done
1 2
3 4
5
6 | 1Array concatenation | 4bash | ak1r |
(TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));
void *array_concat(const void *a, size_t an,
const void *b, size_t bn, size_t s)
{
char *p = malloc(s * (an + bn));
memcpy(p, a, an*s);
memcpy(p + an*s, b, bn*s);
return p;
}
const int a[] = { 1, 2, 3, 4,... | 1Array concatenation | 5c | wpec |
(concat [1 2 3] [4 5 6]) | 1Array concatenation | 6clojure | 8x05 |
package main
import "fmt"
func main() { | 1Array concatenation | 0go | c69g |
def list = [1, 2, 3] + ["Crosby", "Stills", "Nash", "Young"] | 1Array concatenation | 7groovy | 3dzd |
(++) :: [a] -> [a] -> [a] | 1Array concatenation | 8haskell | pjbt |
public static Object[] concat(Object[] arr1, Object[] arr2) {
Object[] res = new Object[arr1.length + arr2.length];
System.arraycopy(arr1, 0, res, 0, arr1.length);
System.arraycopy(arr2, 0, res, arr1.length, arr2.length);
return res;
} | 1Array concatenation | 9java | rug0 |
var a = [1,2,3],
b = [4,5,6],
c = a.concat(b); | 1Array concatenation | 10javascript | b7ki |
fun main(args: Array<String>) {
val a: Array<Int> = arrayOf(1, 2, 3) | 1Array concatenation | 11kotlin | v921 |
a = {1, 2, 3}
b = {4, 5, 6}
for _, v in pairs(b) do
table.insert(a, v)
end
print(table.concat(a, ", ")) | 1Array concatenation | 1lua | ucvl |
my @arr1 = (1, 2, 3);
my @arr2 = (4, 5, 6);
my @arr3 = (@arr1, @arr2); | 1Array concatenation | 2perl | 0ws4 |
$arr1 = array(1, 2, 3);
$arr2 = array(4, 5, 6);
$arr3 = array_merge($arr1, $arr2); | 1Array concatenation | 12php | 5lus |
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2
assert arr4 == [1, 2, 3, 4, 5, 6]
arr4.extend(arr3)
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9] | 1Array concatenation | 3python | 8x0o |
a1 <- c(1, 2, 3)
a2 <- c(3, 4, 5)
a3 <- c(a1, a2) | 1Array concatenation | 13r | x1w2 |
enum { MAX_ROWS=14, MAX_NAMES=20, NAME_SZ=80 };
char *Lines[MAX_ROWS] = {
,
,
,
,
,
,
,
,
,
,
,
,
};
typedef struct {
unsigned bit3s;
unsigned mask;
unsigned data;
char A[NAME_SZ+2];
}NAME_T;
NAME_T names[MAX_NAMES];
unsigned idx_name;
enum{ID,BITS,QDCOUNT,ANCOUNT,NS... | 2ASCII art diagram converter | 5c | c39c |
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2
arr4.concat(arr3) | 1Array concatenation | 14ruby | isoh |
fn main() {
let a_vec = vec![1, 2, 3, 4, 5];
let b_vec = vec![6; 5];
let c_vec = concatenate_arrays(&a_vec, &b_vec);
println!("{:?} ~ {:?} => {:?}", a_vec, b_vec, c_vec);
}
fn concatenate_arrays<T: Clone>(x: &[T], y: &[T]) -> Vec<T> {
let mut concat = x.to_vec();
concat.extend_from_slice(y);
... | 1Array concatenation | 15rust | n0i4 |
package main
import (
"fmt"
"log"
"math/big"
"strings"
)
type result struct {
name string
size int
start int
end int
}
func (r result) String() string {
return fmt.Sprintf("%-7s %2d %3d %3d", r.name, r.size, r.start, r.end)
}
func validate(diagram string) []string {
v... | 2ASCII art diagram converter | 0go | wbeg |
val arr1 = Array( 1, 2, 3 )
val arr2 = Array( 4, 5, 6 )
val arr3 = Array( 7, 8, 9 )
arr1 ++ arr2 ++ arr3 | 1Array concatenation | 16scala | tifb |
import Text.ParserCombinators.ReadP
import Control.Monad (guard)
data Field a = Field { fieldName :: String
, fieldSize :: Int
, fieldValue :: Maybe a}
instance Show a => Show (Field a) where
show (Field n s a) = case a of
Nothing -> n ++ "\t" ++ show s
Just x -> n ... | 2ASCII art diagram converter | 8haskell | 6d3k |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class AsciiArtDiagramConverter {
private static final String TEST = "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\r\n" +
"| ID ... | 2ASCII art diagram converter | 9java | nsih |
null | 2ASCII art diagram converter | 10javascript | 3nz0 |
local function validate(diagram)
local lines = {}
for s in diagram:gmatch("[^\r\n]+") do
s = s:match("^%s*(.-)%s*$")
if s~="" then lines[#lines+1]=s end
end | 2ASCII art diagram converter | 1lua | 0esd |
use strict;
use warnings;
$_ = <<END;
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ... | 2ASCII art diagram converter | 2perl | u9vr |
let array1 = [1,2,3]
let array2 = [4,5,6]
let array3 = array1 + array2 | 1Array concatenation | 17swift | oq8k |
def validate(diagram):
rawlines = diagram.splitlines()
lines = []
for line in rawlines:
if line != '':
lines.append(line)
if len(lines) == 0:
print('diagram has no non-empty lines!')
return None
width = len(lines[0])
cols = (width - 1)
if ... | 2ASCII art diagram converter | 3python | 5cux |
header = <<HEADER
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+-... | 2ASCII art diagram converter | 14ruby | g24q |
use std::{borrow::Cow, io::Write};
pub type Bit = bool;
#[derive(Clone, Debug)]
pub struct Field {
name: String,
from: usize,
to: usize,
}
impl Field {
pub fn new(name: String, from: usize, to: usize) -> Self {
assert!(from < to);
Self { name, from, to }
}
pub fn name(&self) ... | 2ASCII art diagram converter | 15rust | rvg5 |
fruit=("apple" "orange" "lemon")
echo "${ | 3Array length | 4bash | 9tms |
int main()
{
const char *fruit[2] = { , };
int length = sizeof(fruit) / sizeof(fruit[0]);
printf(, length);
return 0;
} | 3Array length | 5c | l3cy |
(count ["apple" "orange"])
(alength (into-array ["apple" "orange"])) | 3Array length | 6clojure | 4c5o |
arrLength(arr) {
return arr.length;
}
main() {
var fruits = ['apple', 'orange'];
print(arrLength(fruits));
} | 3Array length | 18dart | 3izz |
package main
import "fmt"
func main() {
arr := [...]string{"apple", "orange", "pear"}
fmt.Printf("Length of%v is%v.\n", arr, len(arr))
} | 3Array length | 0go | xbwf |
def fruits = ['apple','orange']
println fruits.size() | 3Array length | 7groovy | prbo |
length ["apple", "orange"] | 3Array length | 8haskell | yd66 |
public class ArrayLength {
public static void main(String[] args) {
System.out.println(new String[]{"apple", "orange"}.length);
}
} | 3Array length | 9java | dsn9 |
console.log(['apple', 'orange'].length); | 3Array length | 10javascript | 6n38 |
fun main(args: Array<String>) {
println(arrayOf("apple", "orange").size)
} | 3Array length | 11kotlin | 0asf |
null | 3Array length | 1lua | 8e0e |
my @array = qw "apple orange banana", 4, 42;
scalar @array;
0 + @arrray;
'' . @array;
my $elems = @array;
scalar @{ [1,2,3] };
my $array_ref = \@array;
scalar @$array_ref;
sub takes_a_scalar ($) { my ($a) = @_; return $a }
takes_a_scalar @array; | 3Array length | 2perl | 59u2 |
print count(['apple', 'orange']); | 3Array length | 12php | ow85 |
int main(int argc, char *argv[])
{
int a, b;
if (argc < 3) exit(1);
b = atoi(argv[--argc]);
if (b == 0) exit(2);
a = atoi(argv[--argc]);
printf(, a+b);
printf(, a-b);
printf(, a*b);
printf(, a/b);
printf(, a%b);
return 0;
} | 4Arithmetic/Integer | 5c | z8tx |
(defn myfunc []
(println "Enter x and y")
(let [x (read), y (read)]
(doseq [op '(+ - * / Math/pow rem)]
(let [exp (list op x y)]
(printf "%s=%s\n" exp (eval exp)))))) | 4Arithmetic/Integer | 6clojure | 9fma |
>>> print(len(['apple', 'orange']))
2
>>> | 3Array length | 3python | 4c5k |
a <- c('apple','orange')
length(a) | 3Array length | 13r | 26lg |
puts ['apple', 'orange'].length | 3Array length | 14ruby | r2gs |
fn main() {
let array = ["foo", "bar", "baz", "biff"];
println!("the array has {} elements", array.len());
} | 3Array length | 15rust | 7vrc |
println(Array("apple", "orange").length) | 3Array length | 16scala | k4hk |
SELECT COUNT() FROM (VALUES ('apple'),('orange')); | 3Array length | 19sql | 17pg |
let fruits = ["apple", "orange"] | 3Array length | 17swift | gl49 |
package main
import "fmt"
func main() {
var a, b int
fmt.Print("enter two integers: ")
fmt.Scanln(&a, &b)
fmt.Printf("%d +%d =%d\n", a, b, a+b)
fmt.Printf("%d -%d =%d\n", a, b, a-b)
fmt.Printf("%d *%d =%d\n", a, b, a*b)
fmt.Printf("%d /%d =%d\n", a, b, a/b) | 4Arithmetic/Integer | 0go | k5hz |
def arithmetic = { a, b ->
println """
a + b = ${a} + ${b} = ${a + b}
a - b = ${a} - ${b} = ${a - b}
a * b = ${a} * ${b} = ${a * b}
a / b = ${a} / ${b} = ${a / b} !!! Converts to floating point!
(int)(a / b) = (int)(${a} / ${b}) = ${(int)(a / b)} ... | 4Arithmetic/Integer | 7groovy | gc46 |
main = do
a <- readLn :: IO Integer
b <- readLn :: IO Integer
putStrLn $ "a + b = " ++ show (a + b)
putStrLn $ "a - b = " ++ show (a - b)
putStrLn $ "a * b = " ++ show (a * b)
putStrLn $ "a to the power of b = " ++ show (a ** b)
putStrLn $ "a to the power of b = " ++ show (a ^ b)
putStrLn $ "a to the po... | 4Arithmetic/Integer | 8haskell | nxie |
import java.util.Scanner;
public class IntegerArithmetic {
public static void main(String[] args) { | 4Arithmetic/Integer | 9java | qbxa |
var a = parseInt(get_input("Enter an integer"), 10);
var b = parseInt(get_input("Enter an integer"), 10);
WScript.Echo("a = " + a);
WScript.Echo("b = " + b);
WScript.Echo("sum: a + b = " + (a + b));
WScript.Echo("difference: a - b = " + (a - b));
WScript.Echo("product: a * b = " + (a * b));
WScript.Echo("quo... | 4Arithmetic/Integer | 10javascript | iwol |
void divisor_count_and_sum(unsigned int n, unsigned int* pcount,
unsigned int* psum) {
unsigned int divisor_count = 1;
unsigned int divisor_sum = 1;
unsigned int power = 2;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
++divisor_count;
divisor_sum += power;
... | 5Arithmetic numbers | 5c | 6o32 |
null | 4Arithmetic/Integer | 11kotlin | 1rpd |
package main
import (
"fmt"
"math"
"rcu"
"sort"
)
func main() {
arithmetic := []int{1}
primes := []int{}
limit := int(1e6)
for n := 3; len(arithmetic) < limit; n++ {
divs := rcu.Divisors(n)
if len(divs) == 2 {
primes = append(primes, n)
arithmeti... | 5Arithmetic numbers | 0go | p4bg |
use strict;
use warnings;
use feature 'say';
use List::Util <max sum>;
use ntheory <is_prime divisors>;
use Lingua::EN::Numbers qw(num2en num2en_ordinal);
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub table { my $t = 10 * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/... | 5Arithmetic numbers | 2perl | cf9a |
def factors(n: int):
f = set([1, n])
i = 2
while True:
j = n
if j < i:
break
if i * j == n:
f.add(i)
f.add(j)
i += 1
return f
arithmetic_count = 0
composite_count = 0
n = 1
while arithmetic_count <= 1000000:
f = factors(n)
if ... | 5Arithmetic numbers | 3python | ltcv |
fn divisor_count_and_sum(mut n: u32) -> (u32, u32) {
let mut divisor_count = 1;
let mut divisor_sum = 1;
let mut power = 2;
while (n & 1) == 0 {
divisor_count += 1;
divisor_sum += power;
power <<= 1;
n >>= 1;
}
let mut p = 3;
while p * p <= n {
let mut... | 5Arithmetic numbers | 15rust | u6vj |
local x = io.read()
local y = io.read()
print ("Sum: " , (x + y))
print ("Difference: ", (x - y))
print ("Product: " , (x * y))
print ("Quotient: " , (x / y)) | 4Arithmetic/Integer | 1lua | a71v |
my $a = <>;
my $b = <>;
print
"sum: ", $a + $b, "\n",
"difference: ", $a - $b, "\n",
"product: ", $a * $b, "\n",
"integer quotient: ", int($a / $b), "\n",
"remainder: ", $a % $b, "\n",
"exponent: ", $a ** $b, "\n"
; | 4Arithmetic/Integer | 2perl | mdyz |
<?php
$a = fgets(STDIN);
$b = fgets(STDIN);
echo
, $a + $b, ,
, $a - $b, ,
, $a * $b, ,
, (int)($a / $b), ,
, floor($a / $b), ,
, $a % $b, ,
, $a ** $b, ;
?> | 4Arithmetic/Integer | 12php | eja9 |
x = int(raw_input())
y = int(raw_input())
print % (x + y)
print % (x - y)
print % (x * y)
print % (x / y)
print % (x% y)
print % divmod(x, y)
print % x**y
raw_input( ) | 4Arithmetic/Integer | 3python | 9fmf |
cat("insert number ")
a <- scan(nmax=1, quiet=TRUE)
cat("insert number ")
b <- scan(nmax=1, quiet=TRUE)
print(paste('a+b=', a+b))
print(paste('a-b=', a-b))
print(paste('a*b=', a*b))
print(paste('a%/%b=', a%/%b))
print(paste('a%%b=', a%%b))
print(paste('a^b=', a^b)) | 4Arithmetic/Integer | 13r | 3ozt |
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (300000);
mpf_t x0, y0, resA, resB, Z, var;
mpf_init_set_ui (x0, 1);
mpf_init_set_d (y0, 0.5);
... | 6Arithmetic-geometric mean/Calculate Pi | 5c | lfcy |
puts 'Enter x and y'
x = gets.to_i
y = gets.to_i
puts ,
,
,
,
,
, | 4Arithmetic/Integer | 14ruby | lzcl |
(ns async-example.core
(:use [criterium.core])
(:gen-class))
(import '(org.apfloat Apfloat ApfloatMath))
(def precision 8192)
(def one (Apfloat. 1M precision))
(def two (Apfloat. 2M precision))
(def four (Apfloat. 4M precision))
(def half (Apfloat. 0.5M precision))
(def quarter (Apfloat. 0.25M precision))
(def... | 6Arithmetic-geometric mean/Calculate Pi | 6clojure | 4y5o |
use std::env;
fn main() {
let args: Vec<_> = env::args().collect();
let a = args[1].parse::<i32>().unwrap();
let b = args[2].parse::<i32>().unwrap();
println!("sum: {}", a + b);
println!("difference: {}", a - b);
println!("product: {}", a * b);
println!("integer... | 4Arithmetic/Integer | 15rust | 23lt |
val a = Console.readInt
val b = Console.readInt
val sum = a + b | 4Arithmetic/Integer | 16scala | 5mut |
package main
import (
"fmt"
"math/big"
)
func main() {
one := big.NewFloat(1)
two := big.NewFloat(2)
four := big.NewFloat(4)
prec := uint(768) | 6Arithmetic-geometric mean/Calculate Pi | 0go | xjwf |
import java.math.MathContext
class CalculatePi {
private static final MathContext con1024 = new MathContext(1024)
private static final BigDecimal bigTwo = new BigDecimal(2)
private static final BigDecimal bigFour = new BigDecimal(4)
private static BigDecimal bigSqrt(BigDecimal bd, MathContext con) {
... | 6Arithmetic-geometric mean/Calculate Pi | 7groovy | p5bo |
import Prelude hiding (pi)
import Data.Number.MPFR hiding (sqrt, pi, div)
import Data.Number.MPFR.Instances.Near ()
digitBits :: (Integral a, Num a) => a -> a
digitBits n = (n + 1) `div` 2 * 8
pi :: Integer -> MPFR
pi digits =
let eps = fromString ("1e-" ++ show digits)
(fromInteger $ digitBits digit... | 6Arithmetic-geometric mean/Calculate Pi | 8haskell | yo66 |
null | 7Arena storage pool | 5c | 79rg |
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Objects;
public class Calculate_Pi {
private static final MathContext con1024 = new MathContext(1024);
private static final BigDecimal bigTwo = new BigDecimal(2);
private static final BigDecimal bigFour = new BigDecimal(4);
pr... | 6Arithmetic-geometric mean/Calculate Pi | 9java | dwn9 |
-- test.sql
-- Tested in SQL*plus
DROP TABLE test;
CREATE TABLE test (a INTEGER, b INTEGER);
INSERT INTO test VALUES ('&&A','&&B');
commit;
SELECT a-b difference FROM test;
SELECT a*b product FROM test;
SELECT trunc(a/b) integer_quotient FROM test;
SELECT MOD(a,b) remainder FROM test;
SELECT POWER(a,b) expon... | 4Arithmetic/Integer | 19sql | rlgp |
import java.math.BigDecimal
import java.math.MathContext
val con1024 = MathContext(1024)
val bigTwo = BigDecimal(2)
val bigFour = bigTwo * bigTwo
fun bigSqrt(bd: BigDecimal, con: MathContext): BigDecimal {
var x0 = BigDecimal.ZERO
var x1 = BigDecimal.valueOf(Math.sqrt(bd.toDouble()))
while (x0 != x1) {
... | 6Arithmetic-geometric mean/Calculate Pi | 11kotlin | 0bsf |
typedef long long int fr_int_t;
typedef struct { fr_int_t num, den; } frac;
fr_int_t gcd(fr_int_t m, fr_int_t n)
{
fr_int_t t;
while (n) { t = n; n = m % n; m = t; }
return m;
}
frac frac_new(fr_int_t num, fr_int_t den)
{
frac a;
if (!den) {
printf(FMTFMT, num, den);
abort();
}
int g = gcd(num, den);
if... | 8Arithmetic/Rational | 5c | fed3 |
void cprint(double complex c)
{
printf(, creal(c), cimag(c));
}
void complex_operations() {
double complex a = 1.0 + 1.0I;
double complex b = 3.14159 + 1.2I;
double complex c;
printf(); cprint(a);
printf(); cprint(b);
c = a + b;
printf(); cprint(c);
c = a * b;
printf(); cprint(c);
c = ... | 9Arithmetic/Complex | 5c | 0jst |
package main
import (
"fmt"
"runtime"
"sync"
) | 7Arena storage pool | 0go | dene |
let a = 6
let b = 4
print("sum =\(a+b)")
print("difference = \(a-b)")
print("product = \(a*b)")
print("Integer quotient = \(a/b)")
print("Remainder = (a%b)")
print("No operator for Exponential") | 4Arithmetic/Integer | 17swift | ct9t |
null | 7Arena storage pool | 11kotlin | zqts |
pool = {} | 7Arena storage pool | 1lua | 3szo |
double agm( double a, double g ) {
double iota = 1.0E-16;
double a1, g1;
if( a*g < 0.0 ) {
printf( );
exit(1);
}
while( fabs(a-g)>iota ) {
a1 = (a + g) / 2.0;
g1 = sqrt(a * g);
a = a1;
g = g1;
}
return a;
}
int main( void ) {
double x, y;
printf( ... | 10Arithmetic-geometric mean | 5c | dpnv |
use Math::BigFloat try => "GMP,Pari";
my $digits = shift || 100;
print agm_pi($digits), "\n";
sub agm_pi {
my $digits = shift;
my $acc = $digits + 8;
my $HALF = Math::BigFloat->new("0.5");
my ($an, $bn, $tn, $pn) = (Math::BigFloat->bone, $HALF->copy->bsqrt($acc),
$HALF->copy->b... | 6Arithmetic-geometric mean/Calculate Pi | 2perl | 56u2 |
user> 22/7
22/7
user> 34/2
17
user> (+ 37/5 42/9)
181/15 | 8Arithmetic/Rational | 6clojure | y06b |
(ns rosettacode.arithmetic.cmplx
(:require [clojure.algo.generic.arithmetic:as ga])
(:import [java.lang Number]))
(defrecord Complex [^Number r ^Number i]
Object
(toString [{:keys [r i]}]
(apply str
(cond
(zero? r) [(if (= i 1) "" i) "i"]
(zero? i) [r]
:else [r (if (neg? i)... | 9Arithmetic/Complex | 6clojure | d1nb |
(ns agmcompute
(:gen-class))
(import '(org.apfloat Apfloat ApfloatMath))
(def precision 70)
(def one (Apfloat. 1M precision))
(def two (Apfloat. 2M precision))
(def half (Apfloat. 0.5M precision))
(def isqrt2 (.divide one (ApfloatMath/pow two half)))
(def TOLERANCE (Apfloat. 0.000000M precision))
(defn agm [a g]... | 10Arithmetic-geometric mean | 6clojure | 6x3q |
from decimal import *
D = Decimal
getcontext().prec = 100
a = n = D(1)
g, z, half = 1 / D(2).sqrt(), D(0.25), D(0.5)
for i in range(18):
x = [(a + g) * half, (a * g).sqrt()]
var = x[0] - a
z -= var * var * n
n += n
a, g = x
print(a * a / z) | 6Arithmetic-geometric mean/Calculate Pi | 3python | 4y5k |
(malloc 1000 'raw) ; raw allocation, bypass the GC, requires free()-ing
(malloc 1000 'uncollectable) ; no GC, for use with other GCs that Racket can be configured with
(malloc 1000 'atomic) ; a block of memory without internal pointers
(malloc 1000 'nonatomic) ; a block of pointers
(malloc 1000... | 7Arena storage pool | 3python | pubm |
library(Rmpfr)
agm <- function(n, prec) {
s <- mpfr(0, prec)
a <- mpfr(1, prec)
g <- sqrt(mpfr("0.5", prec))
p <- as.bigz(4)
for (i in seq(n)) {
m <- (a + g) / 2L
g <- sqrt(a * g)
a <- m
s <- s + p * (a * a - g * g)
p <- p + p
}
4L * a * a / (1L - s)
}
1e6 * log(10) / log(2)
p <- ... | 6Arithmetic-geometric mean/Calculate Pi | 13r | 2tlg |
#![feature(rustc_private)]
extern crate arena;
use arena::TypedArena;
fn main() { | 7Arena storage pool | 15rust | egaj |
package require Tcl 8.6
oo::class create Pool {
superclass oo::class
variable capacity pool busy
unexport create
constructor args {
next {*}$args
set capacity 100
set pool [set busy {}]
}
method new {args} {
if {[llength $pool]} {
set pool [lassign $pool obj]
} else {
if {[llength... | 7Arena storage pool | 16scala | qjxw |
require 'flt'
Flt::BinNum.Context.precision = 8192
a = n = 1
g = 1 / Flt::BinNum(2).sqrt
z = 0.25
(0..17).each{
x = [(a + g) * 0.5, (a * g).sqrt]
var = x[0] - a
z -= var * var * n
n += n
a = x[0]
g = x[1]
}
puts a * a / z | 6Arithmetic-geometric mean/Calculate Pi | 14ruby | r9gs |
null | 6Arithmetic-geometric mean/Calculate Pi | 15rust | 7crc |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.