code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> canvas { position: absolute; top: 45%; left: 50%; width: 640px; height: 640px; margin: -320px 0 0 -320px; } </style> </head> <body> <canvas></c...
396Pythagoras tree
10javascript
763rd
class Splitmix64 MASK64 = (1 << 64) - 1 C1, C2, C3 = 0x9e3779b97f4a7c15, 0xbf58476d1ce4e5b9, 0x94d049bb133111eb def initialize(seed = 0) = @state = seed & MASK64 def rand_i z = @state = (@state + C1) & MASK64 z = ((z ^ (z >> 30)) * C2) & MASK64 z = ((z ^ (z >> 27)) * C3) & MASK64 (z ^ (z >> 3...
397Pseudo-random numbers/Splitmix64
14ruby
ikjoh
package main import ( "fmt" "log" "math" ) var a1 = []int64{0, 1403580, -810728} var a2 = []int64{527612, 0, -1370589} const m1 = int64((1 << 32) - 209) const m2 = int64((1 << 32) - 22853) const d = m1 + 1
398Pseudo-random numbers/Combined recursive generator MRG32k3a
0go
w52eg
null
395Pythagorean quadruples
1lua
ohh8h
import Data.List randoms :: Int -> [Int] randoms seed = unfoldr go ([seed,0,0],[seed,0,0]) where go (x1,x2) = let x1i = sum (zipWith (*) x1 a1) `mod` m1 x2i = sum (zipWith (*) x2 a2) `mod` m2 in Just $ ((x1i - x2i) `mod` m1, (x1i:init x1, x2i:init x2)) a1 = [0, 1403580, -810728] m1...
398Pseudo-random numbers/Combined recursive generator MRG32k3a
8haskell
6xa3k
class PCG32 MASK64 = (1 << 64) - 1 MASK32 = (1 << 32) - 1 CONST = 6364136223846793005 def seed(seed_state, seed_sequence) @state = 0 @inc = ((seed_sequence << 1) | 1) & MASK64 next_int @state = @state + seed_state next_int end def next_int old = @state @state = ((old * CONST) ...
393Pseudo-random numbers/PCG32
14ruby
07hsu
null
396Pythagoras tree
11kotlin
90smh
w = print('w = ' + chr(34) + w + chr(34) + chr(10) + w)
389Quine
3python
bc4kr
public class App { private static long mod(long x, long y) { long m = x % y; if (m < 0) { if (y < 0) { return m - y; } else { return m + y; } } return m; } public static class RNG {
398Pseudo-random numbers/Combined recursive generator MRG32k3a
9java
nbjih
(function(){x<-intToUtf8(34);s<-"(function(){x<-intToUtf8(34);s<-%s%s%s;cat(sprintf(s,x,s,x))})()";cat(sprintf(s,x,s,x))})()
389Quine
13r
762ry
import kotlin.math.floor fun mod(x: Long, y: Long): Long { val m = x % y return if (m < 0) { if (y < 0) { m - y } else { m + y } } else m } class RNG {
398Pseudo-random numbers/Combined recursive generator MRG32k3a
11kotlin
sr5q7
my $N = 2200; push @sq, $_**2 for 0 .. $N; my @not = (0) x $N; @not[0] = 1; for my $d (1 .. $N) { my $last = 0; for my $a (reverse ceiling($d/3) .. $d) { for my $b (1 .. ceiling($a/2)) { my $ab = $sq[$a] + $sq[$b]; last if $ab > $sq[$d]; my $x = sqrt($sq[$d] - $ab);...
395Pythagorean quadruples
2perl
4tt5d
typedef unsigned long long xint; typedef unsigned long ulong; inline ulong gcd(ulong m, ulong n) { ulong t; while (n) { t = n; n = m % n; m = t; } return m; } int main() { ulong a, b, c, pytha = 0, prim = 0, max_p = 100; xint aa, bb, cc; for (a = 1; a <= max_p / 3; a++) { aa = (xint)a...
399Pythagorean triples
5c
loqcy
use strict; use warnings; use feature 'say'; package MRG32k3a { use constant { m1 => 2**32 - 209, m2 => 2**32 - 22853 }; use Const::Fast; const my @a1 => < 0 1403580 -810728>; const my @a2 => <527612 0 -1370589>; sub new { my ($class,undef,$seed) = @_; ...
398Pseudo-random numbers/Combined recursive generator MRG32k3a
2perl
udovr
def quad(top=2200): r = [False] * top ab = [False] * (top * 2)**2 for a in range(1, top): for b in range(a, top): ab[a * a + b * b] = True s = 3 for c in range(1, top): s1, s, s2 = s, s + 2, s + 2 for d in range(c + 1, top): if ab[s1]: ...
395Pythagorean quadruples
3python
gzz4h
use Imager; sub tree { my ($img, $x1, $y1, $x2, $y2, $depth) = @_; return () if $depth <= 0; my $dx = ($x2 - $x1); my $dy = ($y1 - $y2); my $x3 = ($x2 - $dy); my $y3 = ($y2 - $dx); my $x4 = ($x1 - $dy); my $y4 = ($y1 - $dx); my $x5 = ($x4 + 0.5 * ($dx - $dy)); my $y5 = ($y4 -...
396Pythagoras tree
2perl
w5ue6
a1 = [0, 1403580, -810728] m1 = 2**32 - 209 a2 = [527612, 0, -1370589] m2 = 2**32 - 22853 d = m1 + 1 class MRG32k3a(): def __init__(self, seed_state=123): self.seed(seed_state) def seed(self, seed_state): assert 0 <seed_state < d, f self.x1 = [seed_state, 0, 0] self.x2 = [se...
398Pseudo-random numbers/Combined recursive generator MRG32k3a
3python
5fiux
squares <- d <- seq_len(2200)^2 aAndb <- outer(squares, squares, '+') aAndb <- aAndb[upper.tri(aAndb, diag = TRUE)] sapply(squares, function(c) d <<- setdiff(d, aAndb + c)) print(sqrt(d))
395Pythagorean quadruples
13r
vnn27
(defn gcd [a b] (if (zero? b) a (recur b (mod a b)))) (defn pyth [peri] (for [m (range 2 (Math/sqrt (/ peri 2))) n (range (inc (mod m 2)) m 2) :let [p (* 2 m (+ m n))] :while (<= p peri) :when (= 1 (gcd m n)) :let [m2 (* m m), n2 (* n n), [a b] (sort [(- m2 n...
399Pythagorean triples
6clojure
4ti5o
_=;puts _%_
389Quine
14ruby
12rpw
fn main() { let x = "fn main() {\n let x = "; let y = "print!(\"{}{:?};\n let y = {:?};\n {}\", x, x, y, y)\n}\n"; print!("{}{:?}; let y = {:?}; {}", x, x, y, y) }
389Quine
15rust
av714
typedef struct { int m, n; double ** v; } mat_t, *mat; mat matrix_new(int m, int n) { mat x = malloc(sizeof(mat_t)); x->v = malloc(sizeof(double*) * m); x->v[0] = calloc(sizeof(double), m * n); for (int i = 0; i < m; i++) x->v[i] = x->v[0] + n * i; x->m = m; x->n = n; return x; } void matrix_delete(mat m) ...
400QR decomposition
5c
zektx
val q = "\"" * 3 val c = """val q = "\"" * 3 val c = %s%s%s println(c format (q, c, q)) """ println(c format (q, c, q))
389Quine
16scala
x4kwg
def mod(x, y) m = x % y if m < 0 then if y < 0 then return m - y else return m + y end end return m end A1 = [0, 1403580, -810728] A1.freeze M1 = (1 << 32) - 209 A2 = [527612, 0, -1370589] A2.freeze M2 = (1 << 32) - 22853 D = M1 + 1 $x1 = [0, 0, 0] ...
398Pseudo-random numbers/Combined recursive generator MRG32k3a
14ruby
gzd4q
n = 2200 l_add, l = {}, {} 1.step(n) do |x| x2 = x*x x.step(n) {|y| l_add[x2 + y*y] = true} end s = 3 1.step(n) do |x| s1 = s s += 2 s2 = s (x+1).step(n) do |y| l[y] = true if l_add[s1] s1 += s2 s2 += 2 end end puts (1..n).reject{|x| l[x]}.join()
395Pythagorean quadruples
14ruby
766ri
from turtle import goto, pu, pd, color, done def level(ax, ay, bx, by, depth=0): if depth > 0: dx,dy = bx-ax, ay-by x3,y3 = bx-dy, by-dx x4,y4 = ax-dy, ay-dx x5,y5 = x4 + (dx - dy)/2, y4 - (dx + dy)/2 goto(ax, ay), pd() for x, y in ((bx, by), (x3, y3), (x4, y4), (ax,...
396Pythagoras tree
3python
x45wr
use std::collections::BinaryHeap; fn a094958_iter() -> Vec<u16> { (0..12) .map(|n| vec![1 << n, 5 * (1 << n)]) .flatten() .filter(|x| x < &2200) .collect::<BinaryHeap<u16>>() .into_sorted_vec() } fn a094958_filter() -> Vec<u16> { (1..2200)
395Pythagorean quadruples
15rust
jyy72
object PythagoreanQuadruple extends App { val MAX = 2200 val MAX2: Int = MAX * MAX * 2 val found = Array.ofDim[Boolean](MAX + 1) val a2b2 = Array.ofDim[Boolean](MAX2 + 1) var s = 3 for (a <- 1 to MAX) { val a2 = a * a for (b <- a to MAX) a2b2(a2 + b * b) = true } for (c <- 1 to MAX) { var ...
395Pythagorean quadruples
16scala
bcck6
pythtree <- function(ax,ay,bx,by,d) { if(d<0) {return()}; clr="darkgreen"; dx=bx-ax; dy=ay-by; x3=bx-dy; y3=by-dx; x4=ax-dy; y4=ay-dx; x5=x4+(dx-dy)/2; y5=y4-(dx+dy)/2; segments(ax,-ay,bx,-by, col=clr); segments(bx,-by,x3,-y3, col=clr); segments(x3,-y3,x4,-y4, col=clr); segments(x4,-y4,ax,-ay, col=clr...
396Pythagoras tree
13r
12lpn
func missingD(upTo n: Int) -> [Int] { var a2 = 0, s = 3, s1 = 0, s2 = 0 var res = [Int](repeating: 0, count: n + 1) var ab = [Int](repeating: 0, count: n * n * 2 + 1) for a in 1...n { a2 = a * a for b in a...n { ab[a2 + b * b] = 1 } } for c in 1..<n { s1 = s s += 2 s2 = s ...
395Pythagorean quadruples
17swift
r33gg
def setup sketch_title 'Pythagoras Tree' background(255) stroke(0, 255, 0) tree(width / 2.3, height, width / 1.8, height, 10) end def tree(x1, y1, x2, y2, depth) return if depth <= 0 dx = (x2 - x1) dy = (y1 - y2) x3 = (x2 - dy) y3 = (y2 - dx) x4 = (x1 - dy) y4 = (y1 - dx) x5 = (x4 + 0.5 * (dx...
396Pythagoras tree
14ruby
srgqw
int main(int argc, char **argv) { printf(, argv[0]); return 0; }
401Program name
5c
6xb32
({print($0+$0.debugDescription+")")})("({print($0+$0.debugDescription+\")\")})(")
389Quine
17swift
plgbl
use svg::node::element::{Group, Polygon}; fn main() { let mut doc = svg::Document::new().set("stroke", "white"); let mut base: Vec<[(f64, f64); 2]> = vec![[(-200.0, 0.0), (200.0, 0.0)]]; for lvl in 0..12u8 { let rg = |step| lvl.wrapping_mul(step).wrapping_add(80 - step * 2); let mut group =...
396Pythagoras tree
15rust
07rsl
package main import ( "fmt" "math" "github.com/skelterjohn/go.matrix" ) func sign(s float64) float64 { if s > 0 { return 1 } else if s < 0 { return -1 } return 0 } func unitVector(n int) *matrix.DenseMatrix { vec := matrix.Zeros(n, 1) vec.Set(0, 0, 1) return v...
400QR decomposition
0go
k9zhz
import java.awt._ import java.awt.geom.Path2D import javax.swing.{JFrame, JPanel, SwingUtilities, WindowConstants} object PythagorasTree extends App { SwingUtilities.invokeLater(() => { new JFrame { class PythagorasTree extends JPanel { setPreferredSize(new Dimension(640, 640)) setBackgr...
396Pythagoras tree
16scala
ikhox
import Data.List import Text.Printf (printf) eps = 1e-6 :: Double mmult :: Num a => [[a]] -> [[a]] -> [[a]] nth :: Num a => [[a]] -> Int -> Int -> a mmult_num :: Num a => [[a]] -> a -> [[a]] madd :: Num a => [[a]] -> [[a]] -> [[a]] idMatrix :: Num a => Int -> Int -> [[a]] adjustWithE :: [[Double]] -> Int -> [[Doub...
400QR decomposition
8haskell
nbrie
":" ":" (ns scriptname (:gen-class)) (defn -main [& args] (let [program (first *command-line-args*)] (println "Program:" program))) (when (.contains (first *command-line-args*) *source-path*) (apply -main (rest *command-line-args*)))
401Program name
6clojure
lowcb
int es_check(uint32_t *sieve, uint64_t n) { if ((n != 2 && !(n & 1)) || (n < 2)) return 0; else return !(sieve[n >> 6] & (1 << (n >> 1 & 31))); } uint32_t *es_sieve(const uint64_t nth, uint64_t *es_size) { *es_size = nth * log(nth) + nth * (log(log(nth)) - 0.9385f) + 1; uint32_t *sieve ...
402Primorial numbers
5c
loecy
import Jama.Matrix; import Jama.QRDecomposition; public class Decompose { public static void main(String[] args) { var matrix = new Matrix(new double[][] { {12, -51, 4}, { 6, 167, -68}, {-4, 24, -41}, }); var qr = new QRDecomposition(matrix); ...
400QR decomposition
9java
qg2xa
#!/usr/bin/env dart main() { var program = new Options().script; print("Program: ${program}"); }
401Program name
18dart
nbgiq
(ns example (:gen-class)) (defn primes-hashmap "Infinite sequence of primes using an incremental Sieve or Eratosthenes with a Hashmap" [] (letfn [(nxtoddprm [c q bsprms cmpsts] (if (>= c q) (let [p2 (* (first bsprms) 2), nbps (next bsprms), ...
402Primorial numbers
6clojure
4t05o
int main(int argc, char **argv) { ... return 0; } if(problem){ exit(exit_code); }
403Program termination
5c
76org
(if problem (. System exit integerErrorCode)) }
403Program termination
6clojure
pltbd
package main import "fmt" var total, prim, maxPeri int64 func newTri(s0, s1, s2 int64) { if p := s0 + s1 + s2; p <= maxPeri { prim++ total += maxPeri / p newTri(+1*s0-2*s1+2*s2, +2*s0-1*s1+2*s2, +2*s0-2*s1+3*s2) newTri(+1*s0+2*s1+2*s2, +2*s0+1*s1+2*s2, +2*s0+2*s1+3*s2) new...
399Pythagorean triples
0go
x42wf
class Triple { BigInteger a, b, c def getPerimeter() { this.with { a + b + c } } boolean isValid() { this.with { a*a + b*b == c*c } } } def initCounts (def n = 10) { (n..1).collect { 10g**it }.inject ([:]) { Map map, BigInteger perimeterLimit -> map << [(perimeterLimit): [primative: 0g, total: ...
399Pythagorean triples
7groovy
plybo
pytr :: Int -> [(Bool, Int, Int, Int)] pytr n = filter (\(_, a, b, c) -> a + b + c <= n) [ (prim a b c, a, b, c) | a <- xs, b <- drop a xs, c <- drop b xs, a ^ 2 + b ^ 2 == c ^ 2 ] where xs = [1 .. n] prim a b _ = gcd a b == 1 main :: IO () main = putStrLn $ ...
399Pythagorean triples
8haskell
yqa66
use strict; use warnings; use PDL; use PDL::LinearAlgebra qw(mqr); my $a = pdl( [12, -51, 4], [ 6, 167, -68], [-4, 24, -41], [-1, 1, 0], [ 2, 0, 3] ); my ($q, $r) = mqr($a); print $q, $r, $q x $r;
400QR decomposition
2perl
msayz
package main import ( "fmt" "os" ) func main() { fmt.Println("Program:", os.Args[0]) }
401Program name
0go
pl3bg
package main import ( "fmt" "math/big" "time" "github.com/jbarham/primegen.go" ) func main() { start := time.Now() pg := primegen.New() var i uint64 p := big.NewInt(1) tmp := new(big.Int) for i <= 9 { fmt.Printf("primorial(%v) =%v\n", i, p) i++ p = p.Mul(p, tmp.SetUint64(pg.Next())) } for _, j := r...
402Primorial numbers
0go
x49wf
#!/usr/bin/env groovy def program = getClass().protectionDomain.codeSource.location.path println "Program: " + program
401Program name
7groovy
76nrz
import System (getProgName) main :: IO () main = getProgName >>= putStrLn . ("Program: " ++)
401Program name
8haskell
f17d1
import Control.Arrow ((&&&)) import Data.List (scanl1, foldl1') getNthPrimorial:: Int -> Integer getNthPrimorial n = foldl1' (*) (take n primes) primes :: [Integer] primes = 2: filter isPrime [3,5..] isPrime :: Integer -> Bool isPrime = isPrime_ primes where isPrime_ :: [Integer] -> Integer -> Bool isPrime...
402Primorial numbers
8haskell
yqb66
import java.math.BigInteger; public class PrimorialNumbers { final static int sieveLimit = 1300_000; static boolean[] notPrime = sieve(sieveLimit); public static void main(String[] args) { for (int i = 0; i < 10; i++) System.out.printf("primorial(%d):%d%n", i, primorial(i)); f...
402Primorial numbers
9java
dpgn9
import java.math.BigInteger; import static java.math.BigInteger.ONE; public class PythTrip{ public static void main(String[] args){ long tripCount = 0, primCount = 0;
399Pythagorean triples
9java
dpjn9
import numpy as np def qr(A): m, n = A.shape Q = np.eye(m) for i in range(n - (m == n)): H = np.eye(m) H[i:, i:] = make_householder(A[i:, i]) Q = np.dot(Q, H) A = np.dot(H, A) return Q, A def make_householder(a): v = a / (a[0] + np.copysign(np.linalg.norm(a), a[0]))...
400QR decomposition
3python
90emf
bool is_prime(unsigned int n) { assert(n < 64); static bool isprime[] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0,...
404Prime triangle
5c
f14d3
public class ScriptName { public static void main(String[] args) { String program = System.getProperty("sun.java.command").split(" ")[0]; System.out.println("Program: " + program); } }
401Program name
9java
07vse
(() => { "use strict";
399Pythagorean triples
10javascript
6x138
a <- matrix(c(12, -51, 4, 6, 167, -68, -4, 24, -41), nrow=3, ncol=3, byrow=T) d <- qr(a) qr.Q(d) qr.R(d) x <- 0:10 y <- 3*x^2 + 2*x + 1 a <- cbind(1, x, x^2) qr.coef(qr(a), y) a <- cbind(x, x^2) lsfit(a, y)$coefficients xx <- x*x m <- lm(y ~ x + xx) coef(m)
400QR decomposition
13r
3wbzt
function foo() { return arguments.callee.name; }
401Program name
10javascript
dprnu
null
402Primorial numbers
11kotlin
072sf
typedef complex double vec; typedef struct { vec c; double r; } circ; double cross(vec a, vec b) { return re(a) * im(b) - im(a) * re(b); } double abs2(vec a) { return a * conj(a); } int apollonius_in(circ aa[], int ss[], int flip, int divert) { vec n[3], x[3], t[3], a, b, center; int s[3], iter = 0, res = 0; ...
405Problem of Apollonius
5c
079st
null
401Program name
11kotlin
euma4
package main import "fmt" var canFollow [][]bool var arrang []int var bFirst = true var pmap = make(map[int]bool) func init() { for _, i := range []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37} { pmap[i] = true } } func ptrs(res, n, done int) int { ad := arrang[done-1] if n-done <= 1 { ...
404Prime triangle
0go
jyo7d
null
399Pythagorean triples
11kotlin
075sf
func main() { if problem { return } }
403Program termination
0go
dp4ne
if (problem) System.exit(intExitCode)
403Program termination
7groovy
07lsh
import Control.Monad import System.Exit when problem do exitWith ExitSuccess exitWith (ExitFailure integerErrorCode) exitSuccess exitFailure
403Program termination
8haskell
5fqug
public class PrimeTriangle { public static void main(String[] args) { long start = System.currentTimeMillis(); for (int i = 2; i <= 20; ++i) { int[] a = new int[i]; for (int j = 0; j < i; ++j) a[j] = j + 1; if (findRow(a, 0, i)) pri...
404Prime triangle
9java
w56ej
FILE *FileOut; char format[] = ; int Primes[NBRPRIMES]; int iPrimes; short Ancestors[NBRANCESTORS]; struct Children { long long Child; struct Children *pNext; }; struct Children *Parents[MAXPARENT+1][2]; int CptDescendants[MAXPARENT+1]; long long MaxDescendant = (long long) pow(3.0, 33.0); sho...
406Primes - allocate descendants to their ancestors
5c
dpvnv
import java.io.{PrintWriter, StringWriter} import Jama.{Matrix, QRDecomposition} object QRDecomposition extends App { val matrix = new Matrix( Array[Array[Double]](Array(12, -51, 4), Array(6, 167, -68), Array(-4, 24, -41))) val d = new QRDecomposition(matrix) def toString(m: Matrix): ...
400QR decomposition
16scala
5f8ut
use strict; use warnings; use feature 'say'; use ntheory 'is_prime'; use List::MoreUtils qw(zip slideatatime); use Algorithm::Combinatorics qw(permutations); say '1 2'; my @count = (0, 0, 1); for my $n (3..17) { my @even_nums = grep { 0 == $_ % 2 } 2..$n-1; my @odd_nums = grep { 1 == $_ % 2 } 3..$n-1; f...
404Prime triangle
2perl
6xj36
#!/usr/bin/env lua function main(arg) local program = arg[0] print("Program: " .. program) end if type(package.loaded[(...)]) ~= "userdata" then main(arg) else module(..., package.seeall) end
401Program name
1lua
w59ea
use ntheory qw(pn_primorial); say "First ten primorials: ", join ", ", map { pn_primorial($_) } 0..9; say "primorial(10^$_) has ".(length pn_primorial(10**$_))." digits" for 1..6;
402Primorial numbers
2perl
5fsu2
if(problem){ System.exit(integerErrorCode);
403Program termination
9java
90pmu
package main import ( "fmt" "sort" ) func getPrimes(max int) []int { if max < 2 { return []int{} } lprimes := []int{2} outer: for x := 3; x <= max; x += 2 { for _, p := range lprimes { if x%p == 0 { continue outer } } lpri...
406Primes - allocate descendants to their ancestors
0go
76sr2
if (some_condition) quit();
403Program termination
10javascript
udxvb
typedef unsigned char byte; struct Transition { byte a, b; unsigned int c; } transitions[100]; void init() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { int idx = i * 10 + j; transitions[idx].a = i; transitions[idx].b = j; tra...
407Prime conspiracy
5c
eufav
import Data.Numbers.Primes (isPrime) import Data.List type Memo2 a = Memo (Memo a) data Memo a = Node a (Memo a) (Memo a) deriving Functor memo :: Integral a => Memo p -> a -> p memo (Node a l r) n | n == 0 = a | odd n = memo l (n `div` 2) | otherwise = memo r (n `div` 2 - 1) nats :: Integral a => Memo a...
406Primes - allocate descendants to their ancestors
8haskell
8j90z
typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes = (node_t *)realloc(h->nodes, h->size *...
408Priority queue
5c
x4twu
from pyprimes import nprimes from functools import reduce primelist = list(nprimes(1000001)) def primorial(n): return reduce(int.__mul__, primelist[:n], 1) if __name__ == '__main__': print('First ten primorals:', [primorial(n) for n in range(10)]) for e in range(7): n = 10**e print('...
402Primorial numbers
3python
4t05k
fn is_prime(n: u32) -> bool { assert!(n < 64); ((1u64 << n) & 0x28208a20a08a28ac)!= 0 } fn prime_triangle_row(a: &mut [u32]) -> bool { if a.len() == 2 { return is_prime(a[0] + a[1]); } for i in (1..a.len() - 1).step_by(2) { if is_prime(a[0] + a[i]) { a.swap(i, 1); ...
404Prime triangle
15rust
c8p9z
import Foundation func isPrime(_ n: Int) -> Bool { guard n > 0 && n < 64 else { return false } return ((UInt64(1) << n) & 0x28208a20a08a28ac)!= 0 } func primeTriangleRow(_ a: inout [Int], start: Int, length: Int) -> Bool { if length == 2 { return isPrime(a[start] + a[start + 1]) } ...
404Prime triangle
17swift
mskyk
start Hi printf(); printf(); printf(); end
409Pragmatic directives
5c
yq46f
int rand_idx(double *p, int n) { double s = rand() / (RAND_MAX + 1.0); int i; for (i = 0; i < n - 1 && (s -= p[i]) >= 0; i++); return i; } int main() { const char *names[LEN] = { , , , , , , , }; double s, p[LEN] = { 1./5, 1./6, 1./7, 1./8, 1./9, 1./10, 1./11, 1e300 }; int i, count[LEN] = {0}; for (i ...
410Probabilistic choice
5c
vnh2o
null
403Program termination
11kotlin
ze7ts
null
409Pragmatic directives
0go
12op5
null
409Pragmatic directives
11kotlin
w5dek
ffi = require("ffi") ffi.cdef[[ #pragma pack(1) typedef struct { char c; int i; } foo; #pragma pack(4) typedef struct { char c; int i; } bar; ]] print(ffi.sizeof(ffi.new("foo"))) print(ffi.sizeof(ffi.new("bar")))
409Pragmatic directives
1lua
x4fwz
import java.io.*; import java.util.*; public class PrimeDescendants { public static void main(String[] args) { try (Writer writer = new BufferedWriter(new OutputStreamWriter(System.out))) { printPrimeDesc(writer, 100); } catch (IOException ex) { ex.printStackTrace(); ...
406Primes - allocate descendants to their ancestors
9java
euta5
require 'prime' def primorial_number(n) pgen = Prime.each (1..n).inject(1){|p,_| p*pgen.next} end puts (1..5).each do |n| puts end
402Primorial numbers
14ruby
r3ogs
use warnings; use strict;
409Pragmatic directives
2perl
lojc5
int proper_divisors(const int n, bool print_flag) { int count = 0; for (int i = 1; i < n; ++i) { if (n % i == 0) { count++; if (print_flag) printf(, i); } } if (print_flag) printf(); return count; } int main(void) { for (int i =...
411Proper divisors
5c
udhv4
null
406Primes - allocate descendants to their ancestors
11kotlin
k9oh3
user=> (use 'clojure.data.priority-map) user=> (def p (priority-map "Clear drains" 3, "Feed cat" 4, "Make tea" 5, "Solve RC tasks" 1)) #'user/p user=> p {"Solve RC tasks" 1, "Clear drains" 3, "Feed cat" 4, "Make tea" 5} user=> (assoc p "Tax return" 2) {"Solve RC tasks" 1, "Tax return" 2, "Clear drains" 3, "Feed cat...
408Priority queue
6clojure
ohm8j
package main import ( "fmt" "math" ) type circle struct { x, y, r float64 } func main() { c1 := circle{0, 0, 1} c2 := circle{4, 0, 1} c3 := circle{2, 4, 2} fmt.Println(ap(c1, c2, c3, true)) fmt.Println(ap(c1, c2, c3, false)) } func ap(c1, c2, c3 circle, s bool) circle { x1sq := c...
405Problem of Apollonius
0go
udevt
extern crate primal; extern crate rayon; extern crate rug; use rayon::prelude::*; use rug::Integer; fn partial(p1: usize, p2: usize) -> String { let mut aux = Integer::from(1); let (_, hi) = primal::estimate_nth_prime(p2 as u64); let sieve = primal::Sieve::new(hi as usize); let prime1 = sieve.nth_prim...
402Primorial numbers
15rust
76irc
import spire.math.SafeLong import spire.implicits._ import scala.collection.parallel.immutable.ParVector object Primorial { def main(args: Array[String]): Unit = { println( s"""|First 10 Primorials: |${LazyList.range(0, 10).map(n => f"$n: ${primorial(n).toBigInt}%,d").mkString("\n")} |...
402Primorial numbers
16scala
k9fhk
if some_condition then os.exit( number ) end
403Program termination
1lua
3wjzo