code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
import java.math.MathContext
import scala.annotation.tailrec
import scala.compat.Platform.currentTime
import scala.math.BigDecimal
object Calculate_Pi extends App {
val precision = new MathContext(32768 )
val (bigZero, bigOne, bigTwo, bigFour) =
(BigDecimal(0, precision), BigDecimal(1, precision), BigDecimal(... | 6Arithmetic-geometric mean/Calculate Pi | 16scala | kvhk |
class complex {
num real=0;
num imag=0;
complex(num r,num i){
this.real=r;
this.imag=i;
}
complex add(complex b){
return new complex(this.real + b.real, this.imag + b.imag);
}
complex mult(complex b){ | 9Arithmetic/Complex | 18dart | au1h |
using boost::spirit::rule;
using boost::spirit::parser_tag;
using boost::spirit::ch_p;
using boost::spirit::real_p;
using boost::spirit::tree_node;
using boost::spirit::node_val_data;
struct parser: public boost::spirit::grammar<parser>
{
enum rule_ids { addsub_id, multdiv_id, value_id, real_id };
str... | 11Arithmetic evaluation | 5c | evav |
(def precedence '{* 0, / 0
+ 1, - 1})
(defn order-ops
"((A x B) y C) or (A x (B y C)) depending on precedence of x and y"
[[A x B y C & more]]
(let [ret (if (<= (precedence x)
(precedence y))
(list (list A x B) y C)
(list A x (list B y C)))]
(if more
(recur (concat ret more))
... | 11Arithmetic evaluation | 6clojure | 0rsj |
package main
import (
"fmt"
"math"
)
const = 1e-14
func agm(a, g float64) float64 {
for math.Abs(a-g) > math.Abs(a)* {
a, g = (a+g)*.5, math.Sqrt(a*g)
}
return a
}
func main() {
fmt.Println(agm(1, 1/math.Sqrt2))
} | 10Arithmetic-geometric mean | 0go | 76r2 |
double agm (double a, double g) {
double an = a, gn = g
while ((an-gn).abs() >= 10.0**-14) { (an, gn) = [(an+gn)*0.5, (an*gn)**0.5] }
an
} | 10Arithmetic-geometric mean | 7groovy | udv9 |
agm :: (Floating a) => a -> a -> ((a, a) -> Bool) -> a
agm a g eq = snd $ until eq step (a, g)
where
step (a, g) = ((a + g) / 2, sqrt (a * g))
relDiff :: (Fractional a) => (a, a) -> a
relDiff (x, y) =
let n = abs (x - y)
d = (abs x + abs y) / 2
in n / d
main :: IO ()
main = do
let equal = (< 0.000... | 10Arithmetic-geometric mean | 8haskell | 8j0z |
public class ArithmeticGeometricMean {
public static double agm(double a, double g) {
double a1 = a;
double g1 = g;
while (Math.abs(a1 - g1) >= 1.0e-14) {
double arith = (a1 + g1) / 2.0;
double geom = Math.sqrt(a1 * g1);
a1 = arith;
g1 = geom;... | 10Arithmetic-geometric mean | 9java | eua5 |
function agm(a0, g0) {
var an = (a0 + g0) / 2,
gn = Math.sqrt(a0 * g0);
while (Math.abs(an - gn) > tolerance) {
an = (an + gn) / 2, gn = Math.sqrt(an * gn)
}
return an;
}
agm(1, 1 / Math.sqrt(2)); | 10Arithmetic-geometric mean | 10javascript | 07sz |
int main(){
double a,b,cycles,incr,i;
int steps,x=500,y=500;
printf();
scanf(,&a,&b);
printf();
scanf(,&cycles);
printf();
scanf(,&steps);
incr = 1.0/steps;
initwindow(1000,1000,);
for(i=0;i<=cycles*pi;i+=incr){
putpixel(x + (a + b*i)*cos(i),x + (a + b*i)*sin(i),15);
}
getch();
closegraph();
} | 12Archimedean spiral | 5c | xuwu |
package main
import (
"fmt"
"math"
"math/big"
)
func main() {
var recip big.Rat
max := int64(1 << 19)
for candidate := int64(2); candidate < max; candidate++ {
sum := big.NewRat(1, candidate)
max2 := int64(math.Sqrt(float64(candidate)))
for factor := int64(2); factor <=... | 8Arithmetic/Rational | 0go | j97d |
class Rational extends Number implements Comparable {
final BigInteger num, denom
static final Rational ONE = new Rational(1)
static final Rational ZERO = new Rational(0)
Rational(BigDecimal decimal) {
this(
decimal.scale() < 0 ? decimal.unscaledValue() * 10 ** -decimal.scale(): decima... | 8Arithmetic/Rational | 7groovy | 5zuv |
null | 10Arithmetic-geometric mean | 11kotlin | k9h3 |
import Data.Ratio ((%))
main = do
let n = 4
mapM_ print $
take
n
[ candidate
| candidate <- [2 .. 2 ^ 19]
, getSum candidate == 1 ]
where
getSum candidate =
1 % candidate +
sum
[ 1 % factor + 1 % (candidate `div` factor)
| factor <- [2 .. floor (sqrt ... | 8Arithmetic/Rational | 8haskell | ob8p |
(use '(incanter core stats charts io))
(defn Arquimidean-function
[a b theta]
(+ a (* theta b)))
(defn transform-pl-xy [r theta]
(let [x (* r (sin theta))
y (* r (cos theta))]
[x y]))
(defn arq-spiral [t] (transform-pl-xy (Arquimidean-function 0 7 t) t))
(view (parametric-plot arq-spiral 0 (* 10 M... | 12Archimedean spiral | 6clojure | o78j |
int myArray2[10] = { 1, 2, 0 };
float myFloats[] ={1.2, 2.5, 3.333, 4.92, 11.2, 22.0 }; | 13Arrays | 5c | ye6f |
package main
import (
"image"
"image/color"
"image/draw"
"image/png"
"log"
"math"
"os"
)
func main() {
const (
width, height = 600, 600
centre = width / 2.0
degreesIncr = 0.1 * math.Pi / 180
turns = 2
stop = 360 * turns * 10 * degreesIncr
fileName = "spiral.png"
)
... | 12Archimedean spiral | 0go | l0cw |
function agm(a, b, tolerance)
if not tolerance or tolerance < 1e-15 then
tolerance = 1e-15
end
repeat
a, b = (a + b) / 2, math.sqrt(a * b)
until math.abs(a-b) < tolerance
return a
end
print(string.format("%.15f", agm(1, 1 / math.sqrt(2)))) | 10Arithmetic-geometric mean | 1lua | bcka |
#!/usr/bin/env stack
import Codec.Picture( PixelRGBA8( .. ), writePng )
import Graphics.Rasterific
import Graphics.Rasterific.Texture
import Graphics.Rasterific.Transformations
archimedeanPoint a b t = V2 x y
where r = a + b * t
x = r * cos t
y = r * sin t
main :: IO ()
main = do
let white = Pix... | 12Archimedean spiral | 8haskell | 1cps |
public class BigRationalFindPerfectNumbers {
public static void main(String[] args) {
int MAX_NUM = 1 << 19;
System.out.println("Searching for perfect numbers in the range [1, " + (MAX_NUM - 1) + "]");
BigRational TWO = BigRational.valueOf(2);
for (int i = 1; i < MAX_NUM; i++) {
... | 8Arithmetic/Rational | 9java | wgej |
import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;
public class ArchimedeanSpiral extends JPanel {
public ArchimedeanSpiral() {
setPreferredSize(new Dimension(640, 640));
setBackground(Color.white);
}
void drawGrid(Graphics2D g) {
g.setColor(new Color(0xEEEEE... | 12Archimedean spiral | 9java | 7zrj |
package main
import (
"fmt"
"math/cmplx"
)
func main() {
a := 1 + 1i
b := 3.14159 + 1.25i
fmt.Println("a: ", a)
fmt.Println("b: ", b)
fmt.Println("a + b: ", a+b)
fmt.Println("a * b: ", a*b)
fmt.Println("-a: ", -a)
fmt.Println("1 / a: ", 1/a)
fmt.Println("a:... | 9Arithmetic/Complex | 0go | ufvt |
null | 8Arithmetic/Rational | 10javascript | 8k0l |
enum Op {
ADD('+', 2),
SUBTRACT('-', 2),
MULTIPLY('*', 1),
DIVIDE('/', 1);
static {
ADD.operation = { a, b -> a + b }
SUBTRACT.operation = { a, b -> a - b }
MULTIPLY.operation = { a, b -> a * b }
DIVIDE.operation = { a, b -> a / b }
}
final String symbol
... | 11Arithmetic evaluation | 0go | 9smt |
<!-- ArchiSpiral.html -->
<html>
<head><title>Archimedean spiral</title></head>
<body onload="pAS(35,'navy');">
<h3>Archimedean spiral</h3> <p id=bo></p>
<canvas id="canvId" width="640" height="640" style="border: 2px outset;"></canvas>
<script> | 12Archimedean spiral | 10javascript | p9b7 |
class Complex {
final Number real, imag
static final Complex i = [0,1] as Complex
Complex(Number r, Number i = 0) { (real, imag) = [r, i] }
Complex(Map that) { (real, imag) = [that.real ?: 0, that.imag ?: 0] }
Complex plus (Complex c) { [real + c.real, imag + c.imag] as Complex }
Complex plu... | 9Arithmetic/Complex | 7groovy | 98m4 |
enum Op {
ADD('+', 2),
SUBTRACT('-', 2),
MULTIPLY('*', 1),
DIVIDE('/', 1);
static {
ADD.operation = { a, b -> a + b }
SUBTRACT.operation = { a, b -> a - b }
MULTIPLY.operation = { a, b -> a * b }
DIVIDE.operation = { a, b -> a / b }
}
final String symbol
... | 11Arithmetic evaluation | 7groovy | zat5 |
null | 12Archimedean spiral | 11kotlin | uivc |
import Data.Complex
main = do
let a = 1.0:+ 2.0
let b = 4
putStrLn $ "Add: " ++ show (a + b)
putStrLn $ "Subtract: " ++ show (a - b)
putStrLn $ "Multiply: " ++ show (a * b)
putStrLn $ "Divide: " ++ show (a / b)
putStrLn $ "Negate: " ++ show (-a)
putStrLn $ "Inverse: " +... | 9Arithmetic/Complex | 8haskell | w4ed |
import Text.Parsec
import Text.Parsec.Expr
import Text.Parsec.Combinator
import Data.Functor
import Data.Function (on)
data Exp
= Num Int
| Add Exp
Exp
| Sub Exp
Exp
| Mul Exp
Exp
| Div Exp
Exp
expr
:: Stream s m Char
=> ParsecT s u m Exp
expr = buildExpressionParser tabl... | 11Arithmetic evaluation | 8haskell | b9k2 |
a=1
b=2
cycles=40
step=0.001
x=0
y=0
function love.load()
x = love.graphics.getWidth()/2
y = love.graphics.getHeight()/2
end
function love.draw()
love.graphics.print("a="..a,16,16)
love.graphics.print("b="..b,16,32)
for i=0,cycles*math.pi,step do
love.graphics.points(x+(a + b*i)*ma... | 12Archimedean spiral | 1lua | 5nu6 |
null | 8Arithmetic/Rational | 11kotlin | b2kb |
user=> (def my-list (list 1 2 3 4 5))
user=> my-list
(1 2 3 4 5)
user=> (first my-list)
1
user=> (nth my-list 3)
4
user=> (conj my-list 100)
(100 1 2 3 4 5)
user=> my-list
(1 2 3 4 5)
user=> (def my-new-list (conj my-list 100))
user=> my-new-list
(100 1 2 3 4 5)
user=> (cons 200 my-new-list)
(200 100 1 2 3 4... | 13Arrays | 6clojure | 20l1 |
import java.util.Stack;
public class ArithmeticEvaluation {
public interface Expression {
BigRational eval();
}
public enum Parentheses {LEFT}
public enum BinaryOperator {
ADD('+', 1),
SUB('-', 1),
MUL('*', 2),
DIV('/', 2);
public final char symbol;
... | 11Arithmetic evaluation | 9java | gt4m |
use Imager;
use constant PI => 3.14159265;
my ($w, $h) = (400, 400);
my $img = Imager->new(xsize => $w, ysize => $h);
for ($theta = 0; $theta < 52*PI; $theta += 0.025) {
$x = $w/2 + $theta * cos($theta/PI);
$y = $h/2 + $theta * sin($theta/PI);
$img->setpixel(x => $x, y => $y, color => '
}
$img->write(fil... | 12Archimedean spiral | 2perl | 8r0w |
public class Complex {
public final double real;
public final double imag;
public Complex() {
this(0, 0);
}
public Complex(double r, double i) {
real = r;
imag = i;
}
public Complex add(Complex b) {
return new Complex(this.real + b.real, this.imag + b.imag)... | 9Arithmetic/Complex | 9java | kchm |
function gcd(a,b) return a == 0 and b or gcd(b % a, a) end
do
local function coerce(a, b)
if type(a) == "number" then return rational(a, 1), b end
if type(b) == "number" then return a, rational(b, 1) end
return a, b
end
rational = setmetatable({
__add = function(a, b)
local a, b = coerce(a, b... | 8Arithmetic/Rational | 1lua | pvbw |
function evalArithmeticExp(s) {
s = s.replace(/\s/g,'').replace(/^\+/,'');
var rePara = /\([^\(\)]*\)/;
var exp = s.match(rePara);
while (exp = s.match(rePara)) {
s = s.replace(exp[0], evalExp(exp[0]));
}
return evalExp(s);
function evalExp(s) {
s = s.replace(/[\(\)]/g,'');
var reMD = /\d+\.... | 11Arithmetic evaluation | 10javascript | kmhq |
function Complex(r, i) {
this.r = r;
this.i = i;
}
Complex.add = function() {
var num = arguments[0];
for(var i = 1, ilim = arguments.length; i < ilim; i += 1){
num.r += arguments[i].r;
num.i += arguments[i].i;
}
return num;
}
Complex.multiply = function() {
var num = arguments[0];
for(var i = 1, ilim ... | 9Arithmetic/Complex | 10javascript | e5ao |
from turtle import *
from math import *
color()
down()
for i in range(200):
t = i / 20 * pi
x = (1 + 5 * t) * cos(t)
y = (1 + 5 * t) * sin(t)
goto(x, y)
up()
done() | 12Archimedean spiral | 3python | o781 |
with(list(s=seq(0, 10 * pi, length.out=500)),
plot((1 + s) * exp(1i * s), type="l")) | 12Archimedean spiral | 13r | q5xs |
null | 11Arithmetic evaluation | 11kotlin | 2oli |
class Complex(private val real: Double, private val imag: Double) {
operator fun plus(other: Complex) = Complex(real + other.real, imag + other.imag)
operator fun times(other: Complex) = Complex(
real * other.real - imag * other.imag,
real * other.imag + imag * other.real
)
fun inv(): ... | 9Arithmetic/Complex | 11kotlin | g34d |
my ($a0, $g0, $a1, $g1);
sub agm($$) {
$a0 = shift;
$g0 = shift;
do {
$a1 = ($a0 + $g0)/2;
$g1 = sqrt($a0 * $g0);
$a0 = ($a1 + $g1)/2;
$g0 = sqrt($a1 * $g1);
} while ($a0 != $a1);
return $a0;
}
print agm(1, 1/sqrt(2))."\n"; | 10Arithmetic-geometric mean | 2perl | 3wzs |
INCR = 0.1
attr_reader :x, :theta
def setup
sketch_title 'Archimedian Spiral'
@theta = 0
@x = 0
background(255)
translate(width / 2.0, height / 2.0)
begin_shape
(0..50*PI).step(INCR) do |theta|
@x = theta * cos(theta / PI)
curve_vertex(x, theta * sin(theta / PI))
end
end_shape
end
def settin... | 12Archimedean spiral | 14ruby | nhit |
require"lpeg"
P, R, C, S, V = lpeg.P, lpeg.R, lpeg.C, lpeg.S, lpeg.V | 11Arithmetic evaluation | 1lua | vi2x |
#[macro_use(px)]
extern crate bmp;
use bmp::{Image, Pixel};
use std::f64;
fn main() {
let width = 600u32;
let half_width = (width / 2) as i32;
let mut img = Image::new(width, width);
let draw_color = px!(255, 128, 128); | 12Archimedean spiral | 15rust | dkny |
define('PRECISION', 13);
function agm($a0, $g0, $tolerance = 1e-10)
{
$limit = number_format($tolerance, PRECISION, '.', '');
$an = $a0;
$gn = $g0;
do {
list($an, $gn) = arra... | 10Arithmetic-geometric mean | 12php | plba |
int main()
{
printf(, pow(0,0));
double complex c = cpow(0,0);
printf(, creal(c), cimag(c));
return 0;
} | 14Zero to the zero power | 5c | v02o |
object ArchimedeanSpiral extends App {
SwingUtilities.invokeLater(() =>
new JFrame("Archimedean Spiral") {
class ArchimedeanSpiral extends JPanel {
setPreferredSize(new Dimension(640, 640))
setBackground(Color.white)
private def drawGrid(g: Graphics2D): Unit = {
val (ang... | 12Archimedean spiral | 16scala | z1tr |
null | 9Arithmetic/Complex | 1lua | r6ga |
main(){ | 13Arrays | 18dart | dhnj |
user=> (use 'clojure.math.numeric-tower)
user=> (expt 0 0)
1
user=> (Math/pow 0 0)
1.0 | 14Zero to the zero power | 6clojure | rdg2 |
<Rows> <Columns>
<Blank pixel character> <Image Pixel character>
<Image of specified rows and columns made up of the two pixel types specified in the second line.> | 15Zhang-Suen thinning algorithm | 5c | u0v4 |
typedef unsigned long long u64;
u64 fib[] = {
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,
317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465,
14930352, 24157817, 39088169, 63245986, 102334155, 165580141,
... | 16Zeckendorf number representation | 5c | go45 |
from math import sqrt
def agm(a0, g0, tolerance=1e-10):
an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
while abs(an - gn) > tolerance:
an, gn = (an + gn) / 2.0, sqrt(an * gn)
return an
print agm(1, 1 / sqrt(2)) | 10Arithmetic-geometric mean | 3python | 6x3w |
arithmeticMean <- function(a, b) { (a + b)/2 }
geometricMean <- function(a, b) { sqrt(a * b) }
arithmeticGeometricMean <- function(a, b) {
rel_error <- abs(a - b) / pmax(a, b)
if (all(rel_error < .Machine$double.eps, na.rm=TRUE)) {
agm <- a
return(data.frame(agm, rel_error));
}
Recall(arithmeticMean(a... | 10Arithmetic-geometric mean | 13r | f1dc |
int inv(int a) {
return a ^ -1;
}
struct Zeckendorf {
int dVal, dLen;
};
void a(struct Zeckendorf *self, int n) {
void b(struct Zeckendorf *, int);
int i = n;
while (true) {
if (self->dLen < i) self->dLen = i;
int j = (self->dVal >> (i * 2)) & 3;
switch (j) {
case... | 17Zeckendorf arithmetic | 5c | 2wlo |
(def fibs (lazy-cat [1 1] (map + fibs (rest fibs))))
(defn z [n]
(if (zero? n)
"0"
(let [ps (->> fibs (take-while #(<= % n)) rest reverse)
fz (fn [[s n] p]
(if (>= n p)
[(conj s 1) (- n p)]
[(conj s 0) n]))]
(->> ps (reduce fz [[] n]) first ... | 16Zeckendorf number representation | 6clojure | kths |
use bigrat;
foreach my $candidate (2 .. 2**19) {
my $sum = 1 / $candidate;
foreach my $factor (2 .. sqrt($candidate)+1) {
if ($candidate % $factor == 0) {
$sum += 1 / $factor + 1 / ($candidate / $factor);
}
}
if ($sum->denominator() == 1) {
print "Sum of recipr. fact... | 8Arithmetic/Rational | 2perl | 6s36 |
package main
import (
"bytes"
"fmt"
"strings"
)
var in = `
00000000000000000000000000000000
01111111110000000111111110000000
01110001111000001111001111000000
01110000111000001110000111000000
01110001111000001110000000000000
01111111110000001110000000000000
01110111100000001110000111000000
0111001111001110... | 15Zhang-Suen thinning algorithm | 0go | 0usk |
require 'flt'
include Flt
BinNum.Context.precision = 512
def agm(a,g)
new_a = BinNum a
new_g = BinNum g
while new_a - new_g > new_a.class.Context.epsilon do
old_g = new_g
new_g = (new_a * new_g).sqrt
new_a = (old_g + new_a) * 0.5
end
new_g
end
puts agm(1, 1 / BinNum(2).sqrt) | 10Arithmetic-geometric mean | 14ruby | msyj |
sub ev
{my $exp = shift;
$exp =~ tr {0-9.+-/*()} {}cd;
return ev_ast(astize($exp));}
{my $balanced_paren_regex;
$balanced_paren_regex = qr
{\( ( [^()]+ | (??{$balanced_paren_regex}) )+ \)}x;
sub astize
{my $exp = shift;
$exp =~ /[^0-9.]/ or return $exp;
... | 11Arithmetic evaluation | 2perl | sgq3 |
def zhangSuen(text) {
def image = text.split('\n').collect { line -> line.collect { it == '#' ? 1: 0} }
def p2, p3, p4, p5, p6, p7, p8, p9
def step1 = { (p2 * p4 * p6 == 0) && (p4 * p6 * p8 == 0) }
def step2 = { (p2 * p4 * p8 == 0) && (p2 * p6 * p8 == 0) }
def reduce = { step ->
def toWhite ... | 15Zhang-Suen thinning algorithm | 7groovy | e9al |
null | 10Arithmetic-geometric mean | 15rust | 90mm |
int main()
{
mpz_t a;
mpz_init_set_ui(a, 5);
mpz_pow_ui(a, a, 1 << 18);
int len = mpz_sizeinbase(a, 10);
printf(, len);
char *s = mpz_get_str(0, 10, a);
printf(, len = strlen(s));
printf(, s, s + len - 20);
return 0;
} | 18Arbitrary-precision integers (included) | 5c | n5i6 |
import Data.Array
import qualified Data.List as List
data BW = Black | White
deriving (Eq, Show)
type Index = (Int, Int)
type BWArray = Array Index BW
toBW :: Char -> BW
toBW '0' = White
toBW '1' = Black
toBW ' ' = White
toBW '#' = Black
toBW _ = error "toBW: illegal char"
toBWArray :: [String] -> BWArray... | 15Zhang-Suen thinning algorithm | 8haskell | cw94 |
def agm(a: Double, g: Double, eps: Double): Double = {
if (math.abs(a - g) < eps) (a + g) / 2
else agm((a + g) / 2, math.sqrt(a * g), eps)
}
agm(1, math.sqrt(2)/2, 1e-15) | 10Arithmetic-geometric mean | 16scala | 2ilb |
package main
import (
"fmt"
"strings"
)
var (
dig = [3]string{"00", "01", "10"}
dig1 = [3]string{"", "1", "10"}
)
type Zeckendorf struct{ dVal, dLen int }
func NewZeck(x string) *Zeckendorf {
z := new(Zeckendorf)
if x == "" {
x = "0"
}
q := 1
i := len(x) - 1
z.dLen =... | 17Zeckendorf arithmetic | 0go | qcxz |
package main
import "fmt"
func getDivisors(n int) []int {
divs := []int{1, n}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs = append(divs, i)
if i != j {
divs = append(divs, j)
}
}
}
return divs
}
func sum(div... | 19Zumkeller numbers | 0go | f4d0 |
import Data.List (find, mapAccumL)
import Control.Arrow (first, second)
fibs :: Num a => a -> a -> [a]
fibs a b = res
where
res = a: b: zipWith (+) res (tail res)
data Fib = Fib { sign :: Int, digits :: [Int]}
mkFib s ds =
case dropWhile (==0) ds of
[] -> 0
ds -> Fib s (reverse ds)
instance Show... | 17Zeckendorf arithmetic | 8haskell | mpyf |
import Data.List (group, sort)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
isZumkeller :: Int -> Bool
isZumkeller n =
let ds = divisors n
m = sum ds
in ( even m
&& let half = div m 2
in elem half ds
|| ( all (half >=) ds
... | 19Zumkeller numbers | 8haskell | 4q5s |
(defn exp [n k] (reduce * (repeat k n)))
(def big (->> 2 (exp 3) (exp 4) (exp 5)))
(def sbig (str big))
(assert (= "62060698786608744707" (.substring sbig 0 20)))
(assert (= "92256259918212890625" (.substring sbig (- (count sbig) 20))))
(println (count sbig) "digits")
(println (str (.substring sbig 0 20) ".."
... | 18Arbitrary-precision integers (included) | 6clojure | 3jzr |
import java.awt.Point;
import java.util.*;
public class ZhangSuen {
final static String[] image = {
" ",
" ################# ############# ",
" ################## ################ ",
... | 15Zhang-Suen thinning algorithm | 9java | zktq |
from fractions import Fraction
for candidate in range(2, 2**19):
sum = Fraction(1, candidate)
for factor in range(2, int(candidate**0.5)+1):
if candidate% factor == 0:
sum += Fraction(1, factor) + Fraction(1, candidate
if sum.denominator == 1:
print(%
(candidate, int(sum), if sum == 1 ... | 8Arithmetic/Rational | 3python | y06q |
import operator
class AstNode(object):
def __init__( self, opr, left, right ):
self.opr = opr
self.l = left
self.r = right
def eval(self):
return self.opr(self.l.eval(), self.r.eval())
class LeafNode(object):
def __init__( self, valStrg ):
self.v = int(valStrg)
def eval(sel... | 11Arithmetic evaluation | 3python | 0rsq |
import java.util.List;
public class Zeckendorf implements Comparable<Zeckendorf> {
private static List<String> dig = List.of("00", "01", "10");
private static List<String> dig1 = List.of("", "1", "10");
private String x;
private int dVal = 0;
private int dLen = 0;
public Zeckendorf() {
... | 17Zeckendorf arithmetic | 9java | frdv |
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ZumkellerNumbers {
public static void main(String[] args) {
int n = 1;
System.out.printf("First 220 Zumkeller numbers:%n");
for ( int count = 1 ; count <= 220 ; n += 1 ) {
if ( isZumke... | 19Zumkeller numbers | 9java | cp9h |
function Point(x, y) {
this.x = x;
this.y = y;
}
var ZhangSuen = (function () {
function ZhangSuen() {
}
ZhangSuen.image =
[" ",
" ################# ############# ",
" ################## ##... | 15Zhang-Suen thinning algorithm | 10javascript | 9eml |
null | 17Zeckendorf arithmetic | 11kotlin | 8v0q |
use Math::Complex;
my $a = 1 + 1*i;
my $b = 3.14159 + 1.25*i;
print "$_\n" foreach
$a + $b,
$a * $b,
-$a,
1 / $a,
~$a; | 9Arithmetic/Complex | 2perl | npiw |
WITH
rec (rn, a, g, diff) AS (
SELECT 1, 1, 1/SQRT(2), 1 - 1/SQRT(2)
FROM dual
UNION ALL
SELECT rn + 1, (a + g)/2, SQRT(a * g), (a + g)/2 - SQRT(a * g)
FROM rec
WHERE diff > 1e-38
)
SELECT *
FROM rec
WHERE diff <= 1e-38
; | 10Arithmetic-geometric mean | 19sql | 5fu3 |
package main
import (
"fmt"
"math"
"math/big"
"math/cmplx"
)
func main() {
fmt.Println("float64: ", math.Pow(0, 0))
var b big.Int
fmt.Println("big integer:", b.Exp(&b, &b, nil))
fmt.Println("complex: ", cmplx.Pow(0, 0))
} | 14Zero to the zero power | 0go | suqa |
println 0**0 | 14Zero to the zero power | 7groovy | a91p |
typedef struct lnode_t {
struct lnode_t *prev;
struct lnode_t *next;
int v;
} Lnode;
Lnode *make_list_node(int v) {
Lnode *node = malloc(sizeof(Lnode));
if (node == NULL) {
return NULL;
}
node->v = v;
node->prev = NULL;
node->next = NULL;
return node;
}
void free_lnode(... | 20Yellowstone sequence | 5c | at11 |
import java.util.ArrayList
import kotlin.math.sqrt
object ZumkellerNumbers {
@JvmStatic
fun main(args: Array<String>) {
var n = 1
println("First 220 Zumkeller numbers:")
run {
var count = 1
while (count <= 220) {
if (isZumkeller(n)) {
... | 19Zumkeller numbers | 11kotlin | 37z5 |
import 'dart:math' show pow;
int fallingPowers(int base) =>
base == 1? 1: pow(base, fallingPowers(base - 1));
void main() {
final exponent = fallingPowers(4),
s = BigInt.from(5).pow(exponent).toString();
print('First twenty: ${s.substring(0, 20)}');
print('Last twenty: ${s.substring(s.length ... | 18Arbitrary-precision integers (included) | 18dart | q9xo |
null | 15Zhang-Suen thinning algorithm | 11kotlin | igo4 |
int main()
{
char is_open[100] = { 0 };
int pass, door;
for (pass = 0; pass < 100; ++pass)
for (door = pass; door < 100; door += pass+1)
is_open[door] = !is_open[door];
for (door = 0; door < 100; ++door)
printf(, door+1, (is_open[door]? : ));
return 0;
} | 21100 doors | 5c | ilo2 |
import Darwin
enum AGRError: Error {
case undefined
}
func agm(_ a: Double, _ g: Double, _ iota: Double = 1e-8) throws -> Double {
var a = a
var g = g
var a1: Double = 0
var g1: Double = 0
guard a * g >= 0 else {
throw AGRError.undefined
}
while abs(a - g) > iota {
a1 = (a + g) / 2
g1 = sqrt(a * g)
... | 10Arithmetic-geometric mean | 17swift | yq6e |
import Data.Complex
main = do
print $ 0 ^ 0
print $ 0.0 ^ 0
print $ 0 ^^ 0
print $ 0 ** 0
print $ (0:+ 0) ^ 0
print $ (0:+ 0) ** (0:+ 0) | 14Zero to the zero power | 8haskell | 9wmo |
$op_priority = { => 0, => 0, => 1, => 1}
class TreeNode
OP_FUNCTION = {
=> lambda {|x, y| x + y},
=> lambda {|x, y| x - y},
=> lambda {|x, y| x * y},
=> lambda {|x, y| x / y}}
attr_accessor :info, :left, :right
def initialize(info)
@info = info
end
def leaf?
@left.nil? and @r... | 11Arithmetic evaluation | 14ruby | oj8v |
use strict;
use warnings;
for ( split /\n/, <<END )
1 + 1
10 + 10
10100 + 1010
10100 - 1010
10100 * 1010
100010 * 100101
10100 / 1010
101000 / 1000
100001000001 / 100010
100001000001 / 100101
END
{
my ($left, $op, $right) = split;
my ($x, $y) = map Zeckendorf->new($_), $left, $right;
my $... | 17Zeckendorf arithmetic | 2perl | 405d |
function zhangSuenThin(img)
local dirs={
{ 0,-1},
{ 1,-1},
{ 1, 0},
{ 1, 1},
{ 0, 1},
{-1, 1},
{-1, 0},
{-1,-1},
{ 0,-1},
}
local black=1
local white=0
function A(x, y)
local c=0
local current=img[y+dirs[1][2]]... | 15Zhang-Suen thinning algorithm | 1lua | nri8 |
null | 11Arithmetic evaluation | 15rust | ihod |
for candidate in 2 .. 2**19
sum = Rational(1, candidate)
for factor in 2 .. Integer.sqrt(candidate)
if candidate % factor == 0
sum += Rational(1, factor) + Rational(1, candidate / factor)
end
end
if sum.denominator == 1
puts %
[candidate, sum.to_i, sum == 1? : ]
end
end | 8Arithmetic/Rational | 14ruby | 9omz |
System.out.println(Math.pow(0, 0)); | 14Zero to the zero power | 9java | tkf9 |
package org.rosetta.arithmetic_evaluator.scala
object ArithmeticParser extends scala.util.parsing.combinator.RegexParsers {
def readExpression(input: String) : Option[()=>Int] = {
parseAll(expr, input) match {
case Success(result, _) =>
Some(result)
case other =>
println(other)
... | 11Arithmetic evaluation | 16scala | fpd4 |
import copy
class Zeckendorf:
def __init__(self, x='0'):
q = 1
i = len(x) - 1
self.dLen = int(i / 2)
self.dVal = 0
while i >= 0:
self.dVal = self.dVal + (ord(x[i]) - ord('0')) * q
q = q * 2
i = i -1
def a(self, n):
i = n
... | 17Zeckendorf arithmetic | 3python | g84h |
use strict;
use warnings;
use feature 'say';
use ntheory <is_prime divisor_sum divisors vecsum forcomb lastfor>;
sub in_columns {
my($columns, $values) = @_;
my @v = split ' ', $values;
my $width = int(80/$columns);
printf "%${width}d"x$columns."\n", @v[$_*$columns .. -1+(1+$_)*$columns] for 0..-1+@v/$... | 19Zumkeller numbers | 2perl | pfb0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.