code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
use strict;
use warnings;
my @pts = ('', qw( 01 23 03 12 012 13 013 132 0132) );
my @dots = qw( 4-0 8-0 4-4 8-4 );
my @images = map { sprintf("%-9s\n", "$_:") . draw($_) }
0, 1, 20, 300, 4000, 5555, 6789, 1133;
for ( 1 .. 13 )
{
s/(.+)\n/ print " $1"; '' /e for @images;
print "\n";
}
sub draw
{
my $n ... | 1,035Cistercian numerals | 2perl | otl8x |
import random
def is_Prime(n):
if n!=int(n):
return False
n=int(n)
if n==0 or n==1 or n==4 or n==6 or n==8 or n==9:
return False
if n==2 or n==3 or n==5 or n==7:
return True
s = 0
d = n-1
while d%2==0:
d>>=1
s+=1
assert(2**s * d == n-1)... | 1,034Circular primes | 3python | j1o7p |
package main
import (
"fmt"
"math/big"
)
var (
zero = new(big.Int)
prod = new(big.Int)
fact = new(big.Int)
)
func ccFactors(n, m uint64) (*big.Int, bool) {
prod.SetUint64(6*m + 1)
if !prod.ProbablyPrime(0) {
return zero, false
}
fact.SetUint64(12*m + 1)
if !fact.Probab... | 1,040Chernick's Carmichael numbers | 0go | 4hp52 |
import Unsafe.Coerce ( unsafeCoerce )
type Church a = (a -> a) -> a -> a
churchZero :: Church a
churchZero = const id
churchOne :: Church a
churchOne = id
succChurch :: Church a -> Church a
succChurch = (<*>) (.)
addChurch :: Church a -> Church a -> Church a
addChurch = (<*>). fmap (.)
multChurch :: Church a -... | 1,039Church numerals | 8haskell | e0nai |
funcs={}
for i=1,10 do
table.insert(funcs, function() return i*i end)
end
funcs[2]()
funcs[3]() | 1,033Closures/Value capture | 1lua | fygdp |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
public class ChernicksCarmichaelNumbers {
public static void main(String[] args) {
for ( long n = 3 ; n < 10 ; n++ ) {
long m = 0;
boolean foundComposite = true;
List<Long> factors = null;
... | 1,040Chernick's Carmichael numbers | 9java | px0b3 |
package lvijay;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
public class Church {
public static interface ChurchNum extends Function<ChurchNum, ChurchNum> {
}
public static ChurchNum zero() {
return f -> x -> x;
}
public static ChurchNum next(Chu... | 1,039Church numerals | 9java | haqjm |
def _init():
digi_bits = .strip()
lines = [[d.replace('.', ' ') for d in ln.strip().split()]
for ln in digi_bits.strip().split('\n')
if '
formats = '<2 >2 <2 >2'.split()
digits = [[f for dig in line]
for f, line in zip(formats, lines)]
return digits
_d... | 1,035Cistercian numerals | 3python | iz2of |
double *cholesky(double *A, int n) {
double *L = (double*)calloc(n * n, sizeof(double));
if (L == NULL)
exit(EXIT_FAILURE);
for (int i = 0; i < n; i++)
for (int j = 0; j < (i+1); j++) {
double s = 0;
for (int k = 0; k < j; k++)
s += L[i * n + k] * L[j... | 1,042Cholesky decomposition | 5c | tm9f4 |
int main()
{
int jobs = 41, tid;
omp_set_num_threads(5);
{
tid = omp_get_thread_num();
while (jobs > 0) {
if (!jobs) break;
printf(, tid, jobs--);
... | 1,043Checkpoint synchronization | 5c | 2gglo |
class Combinations(val m: Int, val n: Int) {
private val combination = IntArray(m)
init {
generate(0)
}
private fun generate(k: Int) {
if (k >= m) {
for (i in 0 until m) print("${combination[i]} ")
println()
}
else {
for (j in 0 until... | 1,031Combinations | 11kotlin | qilx1 |
(() => {
'use strict'; | 1,039Church numerals | 10javascript | asi10 |
package main
import (
"fmt"
"math"
"math/rand"
"time"
)
type xy struct {
x, y float64
}
const n = 1000
const scale = 100.
func d(p1, p2 xy) float64 {
return math.Hypot(p2.x-p1.x, p2.y-p1.y)
}
func main() {
rand.Seed(time.Now().Unix())
points := make([]xy, n)
for i := range point... | 1,036Closest-pair problem | 0go | bwikh |
require 'gmp'
require 'prime'
candidate_primes = Enumerator.new do |y|
DIGS = [1,3,7,9]
[2,3,5,7].each{|n| y << n.to_s}
(2..).each do |size|
DIGS.repeated_permutation(size) do |perm|
y << perm.join if (perm == min_rotation(perm)) && GMP::Z(perm.join).probab_prime? > 0
end
end
end
def min_rotation... | 1,034Circular primes | 14ruby | kenhg |
int main()
{
puts(isatty(fileno(stdout))
?
: );
return 0;
} | 1,044Check output device is a terminal | 5c | pxwby |
int main(void)
{
puts(isatty(fileno(stdin))
?
: );
return 0;
} | 1,045Check input device is a terminal | 5c | w8sec |
class Point {
final Number x, y
Point(Number x = 0, Number y = 0) { this.x = x; this.y = y }
Number distance(Point that) { ((this.x - that.x)**2 + (this.y - that.y)**2)**0.5 }
String toString() { "{x:${x}, y:${y}}" }
} | 1,036Closest-pair problem | 7groovy | rbqgh |
null | 1,034Circular primes | 15rust | bwdkx |
object CircularPrimes {
def main(args: Array[String]): Unit = {
println("First 19 circular primes:")
var p = 2
var count = 0
while (count < 19) {
if (isCircularPrime(p)) {
if (count > 0) {
print(", ")
}
print(p)
count += 1
}
p += 1
}
... | 1,034Circular primes | 16scala | asz1n |
typedef struct{
double x,y;
}point;
double distance(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
void findCircles(point p1,point p2,double radius)
{
double separation = distance(p1,p2),mirrorDistance;
if(separation == 0.0)
{
radius == 0.0 ? printf(,p1.x,p1.y):
... | 1,046Circles of given radius through two points | 5c | c529c |
(ns checkpoint.core
(:gen-class)
(:require [clojure.core.async:as async:refer [go <! >! <!! >!! alts! close!]]
[clojure.string:as string]))
(defn coordinate [ctl-ch resp-ch combine]
(go
(<! (async/timeout 2000))
(loop [members {}, received {}]
(let [rcvd-count (count received)
... | 1,043Checkpoint synchronization | 6clojure | gkk4f |
if x == 0:
foo()
elif x == 1:
bar()
elif x == 2:
baz()
else:
boz() | 1,023Conditional structures | 3python | 7pmrm |
int mul_inv(int a, int b)
{
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 - q * x0, x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
int chinese_remainder(int *n, int *a, int len)
{
int p, i, prod = 1, sum = 0;
for (i = 0; i ... | 1,047Chinese remainder theorem | 5c | l42cy |
use 5.020;
use warnings;
use ntheory qw/:all/;
use experimental qw/signatures/;
sub chernick_carmichael_factors ($n, $m) {
(6*$m + 1, 12*$m + 1, (map { (1 << $_) * 9*$m + 1 } 1 .. $n-2));
}
sub chernick_carmichael_number ($n, $callback) {
my $multiplier = ($n > 4) ? (1 << ($n-4)) : 1;
for (my $m = 1 ; ;... | 1,040Chernick's Carmichael numbers | 2perl | fycd7 |
def initN
n = Array.new(15){Array.new(11, ' ')}
for i in 1..15
n[i - 1][5] = 'x'
end
return n
end
def horiz(n, c1, c2, r)
for c in c1..c2
n[r][c] = 'x'
end
end
def verti(n, r1, r2, c)
for r in r1..r2
n[r][c] = 'x'
end
end
def diagd(n, c1, c2, r)
for c in c1... | 1,035Cistercian numerals | 14ruby | d6uns |
import Data.List (minimumBy, tails, unfoldr, foldl1')
import System.Random (newStdGen, randomRs)
import Control.Arrow ((&&&))
import Data.Ord (comparing)
vecLeng [[a, b], [p, q]] = sqrt $ (a - p) ^ 2 + (b - q) ^ 2
findClosestPair =
foldl1'' ((minimumBy (comparing vecLeng) .) . (. return) . (:)) .
concatMap (\... | 1,036Closest-pair problem | 8haskell | d6vn4 |
package main
import (
"os"
"fmt"
)
func main() {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal")
}
} | 1,044Check output device is a terminal | 0go | 6lc3p |
module Main where
import System.Posix.Terminal (queryTerminal)
import System.Posix.IO (stdOutput)
main :: IO ()
main = do
istty <- queryTerminal stdOutput
putStrLn
(if istty
then "stdout is tty"
else "stdout is not tty") | 1,044Check output device is a terminal | 8haskell | j1p7g |
(defn cholesky
[matrix]
(let [n (count matrix)
A (to-array-2d matrix)
L (make-array Double/TYPE n n)]
(doseq [i (range n) j (range (inc i))]
(let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))]
(aset L i j (if (= i j)
(Math/sqrt (- (aget A i i... | 1,042Cholesky decomposition | 6clojure | mvuyq |
package main
import (
"golang.org/x/crypto/ssh/terminal"
"fmt"
"os"
)
func main() {
if terminal.IsTerminal(int(os.Stdin.Fd())) {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal.")
}
} | 1,045Check input device is a terminal | 0go | c5v9g |
module Main (main) where
import System.Posix.IO (stdInput)
import System.Posix.Terminal (queryTerminal)
main :: IO ()
main = do
isTTY <- queryTerminal stdInput
putStrLn $ if isTTY
then "stdin is TTY"
else "stdin is not TTY" | 1,045Check input device is a terminal | 8haskell | pxebt |
function map(f, a, ...) if a then return f(a), map(f, ...) end end
function incr(k) return function(a) return k > a and a or a+1 end end
function combs(m, n)
if m * n == 0 then return {{}} end
local ret, old = {}, combs(m-1, n-1)
for i = 1, n do
for k, v in ipairs(old) do ret[#ret+1] = {i, map(incr(i), unpack... | 1,031Combinations | 1lua | sn2q8 |
function churchZero()
return function(x) return x end
end
function churchSucc(c)
return function(f)
return function(x)
return f(c(f)(x))
end
end
end
function churchAdd(c, d)
return function(f)
return function(x)
return c(f)(d(f)(x))
end
end
end
function churchMul(c, d... | 1,039Church numerals | 1lua | gka4j |
const char* animals[] = { ,,,,,,,,,,, };
const char* elements[] = { ,,,, };
const char* getElement(int year) {
int element = (int)floor((year - 4) % 10 / 2);
return elements[element];
}
const char* getAnimal(int year) {
return animals[(year - 4) % 12];
}
const char* getYY(int year) {
if (year % 2 == ... | 1,048Chinese zodiac | 5c | z9ztx |
null | 1,044Check output device is a terminal | 11kotlin | 9uvmh |
local function isTTY ( fd )
fd = tonumber( fd ) or 1
local ok, exit, signal = os.execute( string.format( "test -t%d", fd ) )
return (ok and exit == "exit") and signal == 0 or false
end
print( "stdin", isTTY( 0 ) )
print( "stdout", isTTY( 1 ) )
print( "stderr", isTTY( 2 ) ) | 1,044Check output device is a terminal | 1lua | c5u92 |
null | 1,045Check input device is a terminal | 11kotlin | vr421 |
use strict;
use warnings;
use 5.010;
if (-t) {
say "Input comes from tty.";
}
else {
say "Input doesn't come from tty.";
} | 1,045Check input device is a terminal | 2perl | 0dis4 |
from sympy import isprime
def primality_pretest(k):
if not (k% 3) or not (k% 5) or not (k% 7) or not (k% 11) or not(k% 13) or not (k% 17) or not (k% 19) or not (k% 23):
return (k <= 23)
return True
def is_chernick(n, m):
t = 9 * m
if not primality_pretest(6 * m + 1):
return False
... | 1,040Chernick's Carmichael numbers | 3python | tmlfw |
my @f = map(sub { $_ * $_ }, 0 .. 9);
print $f[$_](), "\n" for (0 .. 8); | 1,033Closures/Value capture | 2perl | j1i7f |
from sys import stdin
if stdin.isatty():
print()
else:
print() | 1,045Check input device is a terminal | 3python | 8fn0o |
char *months[] = {
, , , , , , , , , , , ,
};
struct Date {
int month, day;
bool active;
} dates[] = {
{5,15,true}, {5,16,true}, {5,19,true},
{6,17,true}, {6,18,true},
{7,14,true}, {7,16,true},
{8,14,true}, {8,15,true}, {8,17,true}
};
void printRemaining() {
int i, c;
for (i = 0,... | 1,049Cheryl's birthday | 5c | 6cz32 |
x <- 0
if(x == 0) print("foo")
x <- 1
if(x == 0) print("foo")
if(x == 0) print("foo") else print("bar") | 1,023Conditional structures | 13r | 5jzuy |
(ns test-p.core
(:require [clojure.math.numeric-tower :as math]))
(defn extended-gcd
"The extended Euclidean algorithm
Returns a list containing the GCD and the Bzout coefficients
corresponding to the inputs. "
[a b]
(cond (zero? a) [(math/abs b) 0 1]
(zero? b) [(math/abs a) 1 0]
:else (loo... | 1,047Chinese remainder theorem | 6clojure | 4hg5o |
package main
import "fmt"
func chowla(n int) int {
if n < 1 {
panic("argument must be a positive integer")
}
sum := 0
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
if i == j {
sum += i
} else {
sum += i + j
... | 1,041Chowla numbers | 0go | y2u64 |
<?php
$funcs = array();
for ($i = 0; $i < 10; $i++) {
$funcs[] = function () use ($i) { return $i * $i; };
}
echo $funcs[3](), ;
?> | 1,033Closures/Value capture | 12php | tmrf1 |
$ perl -e "warn -t STDOUT? 'Terminal': 'Other'"
Terminal
$ perl -e "warn -t STDOUT? 'Terminal': 'Other'" > x.tmp
Other | 1,044Check output device is a terminal | 2perl | w80e6 |
if(posix_isatty(STDOUT)) {
echo .PHP_EOL;
} else {
echo .PHP_EOL;
} | 1,044Check output device is a terminal | 12php | l45cj |
from sys import stdout
if stdout.isatty():
print 'The output device is a teletype. Or something like a teletype.'
else:
print 'The output device isn\'t like a teletype.' | 1,044Check output device is a terminal | 3python | xo8wr |
(ns tanevaulator
(:gen-class))
(def test-cases [
[[1, 1, 2], [1, 1, 3]],
[[2, 1, 3], [1, 1, 7]],
[[4, 1, 5], [-1, 1, 239]],
[[5, 1, 7], [2, 3, 79]],
[[1, 1, 2], [1, 1, 5], [1, 1, 8]],
... | 1,050Check Machin-like formulas | 6clojure | 4jv5o |
File.new().isatty
File.new().isatty | 1,045Check input device is a terminal | 14ruby | izfoh |
extern crate libc;
fn main() {
let istty = unsafe { libc::isatty(libc::STDIN_FILENO as i32) }!= 0;
if istty {
println!("stdout is tty");
} else {
println!("stdout is not tty");
}
} | 1,045Check input device is a terminal | 15rust | n3ti4 |
import org.fusesource.jansi.internal.CLibrary._
object IsATty extends App {
var enabled = true
def apply(enabled: Boolean): Boolean = { | 1,045Check input device is a terminal | 16scala | tm6fb |
package main
import (
"log"
"math/rand"
"sync"
"time"
)
func worker(part string) {
log.Println(part, "worker begins part")
time.Sleep(time.Duration(rand.Int63n(1e6)))
log.Println(part, "worker completes part")
wg.Done()
}
var (
partList = []string{"A", "B", "C", "D"}
nAssem... | 1,043Checkpoint synchronization | 0go | qiixz |
import Control.Parallel
data Task a = Idle | Make a
type TaskList a = [a]
type Results a = [a]
type TaskGroups a = [TaskList a]
type WorkerList a = [Worker a]
type Worker a = [Task a]
runTasks :: TaskList a -> Results a
runTasks [] = []
runTasks (x:[]) = x: []
runTasks (x:y:[]) = y `par` x: y: []
runTasks (x:y:ys)... | 1,043Checkpoint synchronization | 8haskell | mvvyf |
class Chowla {
static int chowla(int n) {
if (n < 1) throw new RuntimeException("argument must be a positive integer")
int sum = 0
int i = 2
while (i * i <= n) {
if (n % i == 0) {
int j = (int) (n / i)
sum += (i == j) ? i: i + j
... | 1,041Chowla numbers | 7groovy | fy9dn |
use 5.020;
use feature qw<signatures>;
no warnings qw<experimental::signatures>;
use constant zero => sub ($f) {
sub ($x) { $x }};
use constant succ => sub ($n) {
sub ($f) {
sub ($x) { $f->($n->($f)($x)) }}};
use constant add => sub ($n) {
... | 1,039Church numerals | 2perl | izmo3 |
import java.util.*;
public class ClosestPair
{
public static class Point
{
public final double x;
public final double y;
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public String toString()
{ return "(" + x + ", " + y + ")"; }
}
public static class ... | 1,036Closest-pair problem | 9java | snyq0 |
(def base-year 4)
(def celestial-stems ["" "" "" "" "" "" "" "" "" ""])
(def terrestrial-branches ["" "" "" "" "" "" "" "" "" "" "" ""])
(def zodiac-animals ["Rat" "Ox" "Tiger" "Rabbit" "Dragon" "Snake" "Horse" "Goat" "Monkey" "Rooster" "Dog" "Pig"])
(def elements ["Wood" "Fire" "Earth" "Metal" "Water"])
(def aspects [... | 1,048Chinese zodiac | 6clojure | 9u9ma |
f = File.open()
p f.isatty
p STDOUT.isatty | 1,044Check output device is a terminal | 14ruby | sniqw |
extern crate libc;
fn main() {
let istty = unsafe { libc::isatty(libc::STDOUT_FILENO as i32) }!= 0;
if istty {
println!("stdout is tty");
} else {
println!("stdout is not tty");
}
} | 1,044Check output device is a terminal | 15rust | 0dnsl |
import org.fusesource.jansi.internal.CLibrary._
object IsATty extends App {
var enabled = true
def apply(enabled: Boolean): Boolean = { | 1,044Check output device is a terminal | 16scala | iztox |
import Control.Concurrent (setNumCapabilities)
import Control.Monad.Par (runPar, get, spawnP)
import Control.Monad (join, (>=>))
import Data.List.Split (chunksOf)
import Data.List (intercalate, mapAccumL, genericTake, genericDrop)
import Data.Bifunctor (bimap)
i... | 1,041Chowla numbers | 8haskell | hawju |
function distance(p1, p2) {
var dx = Math.abs(p1.x - p2.x);
var dy = Math.abs(p1.y - p2.y);
return Math.sqrt(dx*dx + dy*dy);
}
function bruteforceClosestPair(arr) {
if (arr.length < 2) {
return Infinity;
} else {
var minDist = distance(arr[0], arr[1]);
var minPoints = arr.slice(0, 2);
for (v... | 1,036Closest-pair problem | 10javascript | n32iy |
package main
import "fmt"
func main() {
var a []interface{}
a = append(a, 3)
a = append(a, "apples", "oranges")
fmt.Println(a)
} | 1,037Collections | 0go | n3li1 |
public class Chowla {
public static void main(String[] args) {
int[] chowlaNumbers = findChowlaNumbers(37);
for (int i = 0; i < chowlaNumbers.length; i++) {
System.out.printf("chowla(%d) =%d%n", (i+1), chowlaNumbers[i]);
}
System.out.println();
int[][] primes = ... | 1,041Chowla numbers | 9java | 5jkuf |
<?php
$zero = function($f) { return function ($x) { return $x; }; };
$succ = function($n) {
return function($f) use (&$n) {
return function($x) use (&$n, &$f) {
return $f( ($n($f))($x) );
};
};
};
$add = function($n, $m) {
return function($f) use (&$n, &$m) {
return function($x) use (&$f, &$... | 1,039Church numerals | 12php | rbege |
funcs = []
for i in range(10):
funcs.append(lambda: i * i)
print funcs[3]() | 1,033Closures/Value capture | 3python | hanjw |
int tsocket;
struct sockaddr_in tsockinfo;
fd_set status, current;
void ClientText(int handle, char *buf, int buf_len);
struct client
{
char buffer[4096];
int pos;
char name[32];
} *connections[FD_SETSIZE];
void AddConnection(int handle)
{
connections[handle] = malloc(sizeof(struct client));
conne... | 1,051Chat server | 5c | 7b5rg |
import java.util.Scanner;
import java.util.Random;
public class CheckpointSync{
public static void main(String[] args){
System.out.print("Enter number of workers to use: ");
Scanner in = new Scanner(System.in);
Worker.nWorkers = in.nextInt();
System.out.print("Enter number of tasks to complete:");
runTasks(... | 1,043Checkpoint synchronization | 9java | fyydv |
def emptyList = []
assert emptyList.isEmpty(): "These are not the items you're looking for"
assert emptyList.size() == 0: "Empty list has size 0"
assert ! emptyList: "Empty list evaluates as boolean 'false'"
def initializedList = [ 1, "b", java.awt.Color.BLUE ]
assert initializedList.size() == 3
assert initializedList... | 1,037Collections | 7groovy | sn6q1 |
s <- sapply (1:10,
function (x) {
x
function (i=x) i*i
})
s[[5]]()
[1] 25 | 1,033Closures/Value capture | 13r | gk047 |
package main
import (
"fmt"
"math/big"
)
type mTerm struct {
a, n, d int64
}
var testCases = [][]mTerm{
{{1, 1, 2}, {1, 1, 3}},
{{2, 1, 3}, {1, 1, 7}},
{{4, 1, 5}, {-1, 1, 239}},
{{5, 1, 7}, {2, 3, 79}},
{{1, 1, 2}, {1, 1, 5}, {1, 1, 8}},
{{4, 1, 5}, {-1, 1, 70}, {1, 1, 99}},
... | 1,050Check Machin-like formulas | 0go | x8awf |
null | 1,043Checkpoint synchronization | 11kotlin | 8ff0q |
[1, 2, 3, 4, 5] | 1,037Collections | 8haskell | u71v2 |
null | 1,041Chowla numbers | 11kotlin | c5g98 |
'''Church numerals'''
from itertools import repeat
from functools import reduce
def churchZero():
'''The identity function.
No applications of any supplied f
to its argument.
'''
return lambda f: identity
def churchSucc(cn):
'''The successor of a given
Church numeral. One add... | 1,039Church numerals | 3python | n39iz |
package main
import "fmt" | 1,038Classes | 0go | 5j1ul |
null | 1,036Closest-pair problem | 11kotlin | asf13 |
int main(){
time_t t;
double side, vertices[3][3],seedX,seedY,windowSide;
int i,iter,choice;
printf();
scanf(,&side);
printf();
scanf(,&iter);
windowSide = 10 + 2*side;
initwindow(windowSide,windowSide,);
for(i=0;i<3;i++){
vertices[i][0] = windowSide/2 + side*cos(i*2*pi/3);
vertices[i][1] = windowSi... | 1,052Chaos game | 5c | f68d3 |
import Data.Ratio
import Data.List (foldl')
tanPlus:: Fractional a => a -> a -> a
tanPlus a b = (a + b) / (1 - a * b)
tanEval:: (Integral a, Fractional b) => (a, b) -> b
tanEval (0,_) = 0
tanEval (coef,f)
| coef < 0 = -tanEval (-coef, f)
| odd coef = tanPlus f $ tanEval (coef - 1, f)
| otherwise = tanPlus a a
wh... | 1,050Check Machin-like formulas | 8haskell | ylz66 |
package main
import (
"fmt"
"math"
) | 1,042Cholesky decomposition | 0go | haejq |
package main
import (
"fmt"
"time"
)
type birthday struct{ month, day int }
func (b birthday) String() string {
return fmt.Sprintf("%s%d", time.Month(b.month), b.day)
}
func (b birthday) monthUniqueIn(bds []birthday) bool {
count := 0
for _, bd := range bds {
if bd.month == b.month {
... | 1,049Cheryl's birthday | 0go | pwkbg |
function chowla(n)
local sum = 0
local i = 2
local j = 0
while i * i <= n do
if n % i == 0 then
j = math.floor(n / i)
sum = sum + i
if i ~= j then
sum = sum + j
end
end
i = i + 1
end
return sum
end
function ... | 1,041Chowla numbers | 1lua | l4rck |
class Stuff {
def guts
Stuff(injectedGuts) {
guts = injectedGuts
}
def flangulate() {
println "This stuff is flangulating its guts: ${guts}"
}
} | 1,038Classes | 7groovy | c5j9i |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CheckMachinFormula {
private static String FILE_NA... | 1,050Check Machin-like formulas | 9java | d3on9 |
def decompose = { a ->
assert a.size > 0 && a[0].size == a.size
def m = a.size
def l = [].withEagerDefault { [].withEagerDefault { 0 } }
(0..<m).each { i ->
(0..i).each { k ->
Number s = (0..<k).sum { j -> l[i][j] * l[k][j] } ?: 0
l[i][k] = (i == k)
... | 1,042Cholesky decomposition | 7groovy | 4hk5f |
import java.time.Month
class Main {
private static class Birthday {
private Month month
private int day
Birthday(Month month, int day) {
this.month = month
this.day = day
}
Month getMonth() {
return month
}
int getDay() ... | 1,049Cheryl's birthday | 7groovy | 7bgrz |
use warnings;
use strict;
use v5.10;
use Socket;
my $nr_items = 3;
sub short_sleep($) {
(my $seconds) = @_;
select undef, undef, undef, $seconds;
}
sub be_worker($$) {
my ($socket, $value) = @_;
for (1 .. $nr_items) {
sysread $socket, my $dummy, 1;
short_sleep rand 0.5;
s... | 1,043Checkpoint synchronization | 2perl | 4hh5d |
zero <- function(f) {function(x) x}
succ <- function(n) {function(f) {function(x) f(n(f)(x))}}
add <- function(n) {function(m) {function(f) {function(x) m(f)(n(f)(x))}}}
mult <- function(n) {function(m) {function(f) m(n(f))}}
expt <- function(n) {function(m) m(n)}
natToChurch <- function(n) {if(n == 0) zero else succ(n... | 1,039Church numerals | 13r | 0d3sg |
class Shape a where
perimeter :: a -> Double
area :: a -> Double
data Rectangle = Rectangle Double Double
data Circle = Circle Double
instance Shape Rectangle where
perimeter (Rectangle width height) = 2 * width + 2 * height
area (Rectangle width height) = width * height
instance Shape ... | 1,038Classes | 8haskell | xotw4 |
procs = Array.new(10){|i| ->{i*i} }
p procs[7].call | 1,033Closures/Value capture | 14ruby | bwfkq |
package main
import (
"fmt"
"math"
)
var (
Two = "Two circles."
R0 = "R==0.0 does not describe circles."
Co = "Coincident points describe an infinite number of circles."
CoR0 = "Coincident points with r==0.0 describe a degenerate circle."
Diam = "Points form a diameter and describe on... | 1,046Circles of given radius through two points | 0go | w8qeg |
null | 1,050Check Machin-like formulas | 11kotlin | 0nxsf |
module Cholesky (Arr, cholesky) where
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
type Idx = (Int,Int)
type Arr = UArray Idx Double
get :: Arr -> Arr -> Idx -> Double
get a l (i,j) | i == j = sqrt $ a!(j,j) - dot
| i > j = (a!(i,j) - dot) / l!(j,j... | 1,042Cholesky decomposition | 8haskell | iz3or |
import Data.List as L (filter, groupBy, head, length, sortOn)
import Data.Map.Strict as M (Map, fromList, keys, lookup)
import Data.Text as T (Text, splitOn, words)
import Data.Maybe (fromJust)
import Data.Ord (comparing)
import Data.Function (on)
import Data.Tuple (swap)
import Data.Bool (bool)
data DatePart
= Mont... | 1,049Cheryl's birthday | 8haskell | f6nd1 |
List arrayList = new ArrayList();
arrayList.add(new Integer(0)); | 1,037Collections | 9java | mv7ym |
fn main() {
let fs: Vec<_> = (0..10).map(|i| {move || i*i} ).collect();
println!("7th val: {}", fs[7]());
} | 1,033Closures/Value capture | 15rust | pxtbu |
val closures=for(i <- 0 to 9) yield (()=>i*i)
0 to 8 foreach (i=> println(closures(i)()))
println("---\n"+closures(7)()) | 1,033Closures/Value capture | 16scala | e06ab |
class Circles {
private static class Point {
private final double x, y
Point(Double x, Double y) {
this.x = x
this.y = y
}
double distanceFrom(Point other) {
double dx = x - other.x
double dy = y - other.y
return Math.sqrt... | 1,046Circles of given radius through two points | 7groovy | bw1ky |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.