code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
Point = Struct.new(:x, :y)
def distance(p1, p2)
Math.hypot(p1.x - p2.x, p1.y - p2.y)
end
def closest_bruteforce(points)
mindist, minpts = Float::MAX, []
points.combination(2) do |pi,pj|
dist = distance(pi, pj)
if dist < mindist
mindist = dist
minpts = [pi, pj]
end
end
[mindist, minpt... | 1,036Closest-pair problem | 14ruby | 2gplw |
use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::net::{TcpListener, TcpStream};
use std::sync::{Arc, RwLock};
use std::thread;
type Username = String; | 1,051Chat server | 15rust | esbaj |
mul_inv <- function(a, b)
{
b0 <- b
x0 <- 0L
x1 <- 1L
if (b == 1) return(1L)
while(a > 1){
q <- as.integer(a/b)
t <- b
b <- a %% b
a <- t
t <- x0
x0 <- x1 - q*x0
x1 <- t
}
if (x1 < 0) x1 <- x1 + b0
return(x1)
}
chinese_remainder <- function(n, a)
{
len <- length(n)
... | 1,047Chinese remainder theorem | 13r | 2gvlg |
use strict;
sub circles {
my ($x1, $y1, $x2, $y2, $r) = @_;
return "Radius is zero" if $r == 0;
return "Coincident points gives infinite number of circles" if $x1 == $x2 and $y1 == $y2;
my ($dx, $dy) = ($x2 - $x1, $y2 - $y1);
my $q = sqrt($dx**2 + $dy**2);
return "Separation of points gr... | 1,046Circles of given radius through two points | 2perl | u74vr |
pinyin = {
'' => 'ji',
'' => 'y',
'' => 'bng',
'' => 'dng',
'' => 'w',
'' => 'j',
'' => 'gng',
'' => 'xn',
'' => 'rn',
'' => 'gi',
'' => 'z',
'' => 'chu',
'' => 'yn',
'' => 'mo',
'' => 'chn',
'' => 's',
'' => 'w',
'' => 'wi',
'' => 'shn',
'' => 'yu',
'' => 'x',
'' => 'hi'
}
... | 1,048Chinese zodiac | 14ruby | l4lcl |
t(chol(matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow=3, ncol=3)))
t(chol(matrix(c(18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106), nrow=4, ncol=4))) | 1,042Cholesky decomposition | 13r | z9cth |
null | 1,036Closest-pair problem | 15rust | vr12t |
fn chinese_zodiac(year: usize) -> String {
static ANIMALS: [&str; 12] = [
"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig",
];
static ASPECTS: [&str; 2] = ["Yang", "Yin"];
static ELEMENTS: [&str; 5] = ["Wood", "Fire", "Earth", "Metal",... | 1,048Chinese zodiac | 15rust | 2g2lt |
object Zodiac extends App {
val years = Seq(1935, 1938, 1968, 1972, 1976, 1984, 1985, 2017, 2018)
private def animals =
Seq("Rat",
"Ox",
"Tiger",
"Rabbit",
"Dragon",
"Snake",
"Horse",
"Goat",
"Monkey",
"Rooster",
"Dog",
"Pig")
private def ani... | 1,048Chinese zodiac | 16scala | 5j5ut |
import java.io.File;
public class FileExistsTest {
public static boolean isFileExists(String filename) {
boolean exists = new File(filename).exists();
return exists;
}
public static void test(String type, String filename) {
System.out.println("The following " + type + " called " + filename... | 1,053Check that file exists | 9java | ka4hm |
import argparse
import random
import shapely.geometry as geometry
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def main(args):
plt.style.use()
fig = plt.figure()
line, = plt.plot([], [], )
plt.xlim(0, 1)
plt.ylim(0, 1)
title... | 1,052Chaos game | 3python | ylf6q |
def comb(m, n)
(0...n).to_a.combination(m).to_a
end
comb(3, 5) | 1,031Combinations | 14ruby | 4h85p |
import scala.collection.mutable.ListBuffer
import scala.util.Random
object ClosestPair {
case class Point(x: Double, y: Double){
def distance(p: Point) = math.hypot(x-p.x, y-p.y)
override def toString = "(" + x + ", " + y + ")"
}
case class Pair(point1: Point, point2: Point) {
val distance: Double ... | 1,036Closest-pair problem | 16scala | 4hw50 |
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.FileExists('input.txt');
fso.FileExists('c:/input.txt');
fso.FolderExists('docs');
fso.FolderExists('c:/docs'); | 1,053Check that file exists | 10javascript | eshao |
pChaosGameS3 <- function(size, lim, clr, fn, ttl)
{
cat(" *** START:", date(), "size=",size, "lim=",lim, "clr=",clr, "\n");
sz1=floor(size/2); sz2=floor(sz1*sqrt(3)); xf=yf=v=0;
M <- matrix(c(0), ncol=size, nrow=size, byrow=TRUE);
x <- sample(1:size, 1, replace=FALSE);
y <- sample(1:sz2, 1, replace=FALSE);
... | 1,052Chaos game | 13r | tyofz |
use strict;
my @c = ();
push @c, 10, 11, 12;
push @c, 65;
print join(" ",@c) . "\n";
my %h = ();
$h{'one'} = 1;
$h{'two'} = 2;
foreach my $i ( keys %h ) {
print $i . " -> " . $h{$i} . "\n";
} | 1,037Collections | 2perl | ke8hc |
fn comb<T: std::fmt::Default>(arr: &[T], n: uint) {
let mut incl_arr: ~[bool] = std::vec::from_elem(arr.len(), false);
comb_intern(arr, n, incl_arr, 0);
}
fn comb_intern<T: std::fmt::Default>(arr: &[T], n: uint, incl_arr: &mut [bool], index: uint) {
if (arr.len() < n + index) { return; }
if (n == 0) {
let ... | 1,031Combinations | 15rust | gko4o |
def chinese_remainder(mods, remainders)
max = mods.inject(:* )
series = remainders.zip( mods ).map{|r,m| r.step( max, m ).to_a }
series.inject(:& ).first
end
p chinese_remainder([3,5,7], [2,3,2])
p chinese_remainder([10,4,9], [11,22,19]) | 1,047Chinese remainder theorem | 14ruby | rb7gs |
class MyClass:
name2 = 2
def __init__(self):
self.name1 = 0
def someMethod(self):
self.name1 = 1
MyClass.name2 = 3
myclass = MyClass()
class MyOtherClass:
count = 0
def __init__(self, name, gender=, age=None):
MyOtherClass.count +=... | 1,038Classes | 3python | fy2de |
null | 1,053Check that file exists | 11kotlin | ghl4d |
fmt.Println('a') | 1,054Character codes | 0go | 7b2r2 |
require 'matrix'
class Matrix
def symmetric?
return false if not square?
(0 ... row_size).each do |i|
(0 .. i).each do |j|
return false if self[i,j]!= self[j,i]
end
end
true
end
def cholesky_factor
raise ArgumentError, unless symmetric?
l = Array.new(row_size) {Array... | 1,042Cholesky decomposition | 14ruby | c549k |
implicit def toComb(m: Int) = new AnyRef {
def comb(n: Int) = recurse(m, List.range(0, n))
private def recurse(m: Int, l: List[Int]): List[List[Int]] = (m, l) match {
case (0, _) => List(Nil)
case (_, Nil) => Nil
case _ => (recurse(m - 1, l.tail) map (l.head :: _)) ::: recurse(m, l.tail)
}
} | 1,031Combinations | 16scala | j1d7i |
fn egcd(a: i64, b: i64) -> (i64, i64, i64) {
if a == 0 {
(b, 0, 1)
} else {
let (g, x, y) = egcd(b% a, a);
(g, y - (b / a) * x, x)
}
}
fn mod_inv(x: i64, n: i64) -> Option<i64> {
let (g, x, _) = egcd(x, n);
if g == 1 {
Some((x% n + n)% n)
} else {
None
... | 1,047Chinese remainder theorem | 15rust | 7pjrc |
import scala.util.{Success, Try}
object ChineseRemainderTheorem extends App {
def chineseRemainder(n: List[Int], a: List[Int]): Option[Int] = {
require(n.size == a.size)
val prod = n.product
def iter(n: List[Int], a: List[Int], sm: Int): Int = {
def mulInv(a: Int, b: Int): Int = {
def loo... | 1,047Chinese remainder theorem | 16scala | kebhk |
circS3 <- list(radius=5.5, centre=c(3, 4.2))
class(circS3) <- "circle"
plot.circle <- function(x, ...)
{
t <- seq(0, 2*pi, length.out=200)
plot(x$centre[1] + x$radius*cos(t),
x$centre[2] + x$radius*sin(t),
type="l", ...)
}
plot(circS3) | 1,038Classes | 13r | otm84 |
from collections import namedtuple
from math import sqrt
Pt = namedtuple('Pt', 'x, y')
Circle = Cir = namedtuple('Circle', 'x, y, r')
def circles_from_p1p2r(p1, p2, r):
'Following explanation at http:
if r == 0.0:
raise ValueError('radius of zero')
(x1, y1), (x2, y2) = p1, p2
if p1 == p2:
... | 1,046Circles of given radius through two points | 3python | 5jgux |
printf ("%d\n", ('a' as char) as int)
printf ("%c\n", 97) | 1,054Character codes | 7groovy | uryv9 |
fn cholesky(mat: Vec<f64>, n: usize) -> Vec<f64> {
let mut res = vec![0.0; mat.len()];
for i in 0..n {
for j in 0..(i+1){
let mut s = 0.0;
for k in 0..j {
s += res[i * n + k] * res[j * n + k];
}
res[i * n + j] = if i == j { (mat[i * n + i] ... | 1,042Cholesky decomposition | 15rust | l4gcc |
<?php
$a = array();
array_push($a, 55, 10, 20);
print_r($a);
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?> | 1,037Collections | 12php | 3c4zq |
import Data.Char
main = do
print (ord 'a')
print (chr 97)
print (ord '')
print (chr 960) | 1,054Character codes | 8haskell | 8da0z |
case class Matrix( val matrix:Array[Array[Double]] ) { | 1,042Cholesky decomposition | 16scala | u7jv8 |
CREATE TEMPORARY TABLE inputs(remainder INT, modulus INT);
INSERT INTO inputs VALUES (2, 3), (3, 5), (2, 7);
WITH recursive
-- Multiply out the product of moduli
multiplication(idx, product) AS (
SELECT 1, 1
UNION ALL
SELECT
multiplication.idx+1,
multiplication.product * inputs.modulus
... | 1,047Chinese remainder theorem | 19sql | 1qapg |
import Foundation
struct Point {
var x: Double
var y: Double
func distance(to p: Point) -> Double {
let x = pow(p.x - self.x, 2)
let y = pow(p.y - self.y, 2)
return (x + y).squareRoot()
}
}
extension Collection where Element == Point {
func closestPair() -> (Point, Point)? {
let (xP, xY) =... | 1,036Closest-pair problem | 17swift | l4bc2 |
extern crate image;
extern crate rand;
use rand::prelude::*;
use std::f32;
fn main() {
let max_iterations = 50_000;
let img_side = 800;
let tri_size = 400.0; | 1,052Chaos game | 15rust | cu39z |
import Darwin
func euclid(_ m:Int, _ n:Int) -> (Int,Int) {
if m% n == 0 {
return (0,1)
} else {
let rs = euclid(n% m, m)
let r = rs.1 - rs.0 * (n / m)
let s = rs.0
return (r,s)
}
}
func gcd(_ m:Int, _ n:Int) -> Int {
let rs = euclid(m, n)
return m * rs.... | 1,047Chinese remainder theorem | 17swift | gkr49 |
import javax.swing._
import java.awt._
import java.awt.event.ActionEvent
import scala.collection.mutable
import scala.util.Random
object ChaosGame extends App {
SwingUtilities.invokeLater(() =>
new JFrame("Chaos Game") {
class ChaosGame extends JPanel {
private val (dim, margin)= (new Dimension(6... | 1,052Chaos game | 16scala | vgm2s |
class MyClass
def initialize
@instance_var = 0
end
def add_1
@instance_var += 1
end
end
my_class = MyClass.new | 1,038Classes | 14ruby | z9utw |
function output( s, b )
if b then
print ( s, " does not exist." )
else
print ( s, " does exist." )
end
end
output( "input.txt", io.open( "input.txt", "r" ) == nil )
output( "/input.txt", io.open( "/input.txt", "r" ) == nil )
output( "docs", io.open( "docs", "r" ) == nil )
output( "/do... | 1,053Check that file exists | 1lua | rk2ga |
struct MyClass {
variable: i32, | 1,038Classes | 15rust | 3c5z8 |
Pt = Struct.new(:x, :y)
Circle = Struct.new(:x, :y, :r)
def circles_from(pt1, pt2, r)
raise ArgumentError, if pt1 == pt2 && r > 0
return [Circle.new(pt1.x, pt1.y, r)] if pt1 == pt2 && r == 0
dx, dy = pt2.x - pt1.x, pt2.y - pt1.y
q = Math.hypot(dx, dy)
raise ArgumentError, if q > 2.0*r
x3,... | 1,046Circles of given radius through two points | 14ruby | gk74q |
class MyClass(val myMethod: Int) { | 1,038Classes | 16scala | mvryc |
public class Foo {
public static void main(String[] args) {
System.out.println((int)'a'); | 1,054Character codes | 9java | esja5 |
use std::fmt;
#[derive(Clone,Copy)]
struct Point {
x: f64,
y: f64
}
fn distance (p1: Point, p2: Point) -> f64 {
((p1.x - p2.x).powi(2) + (p1.y - p2.y).powi(2)).sqrt()
}
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({:.4}, {:.4})", self.x, sel... | 1,046Circles of given radius through two points | 15rust | rbjg5 |
console.log('a'.charCodeAt(0)); | 1,054Character codes | 10javascript | 0n1sz |
func cholesky(matrix: [Double], n: Int) -> [Double] {
var res = [Double](repeating: 0, count: matrix.count)
for i in 0..<n {
for j in 0..<i+1 {
var s = 0.0
for k in 0..<j {
s += res[i * n + k] * res[j * n + k]
}
if i == j {
res[i * n + j] = (matrix[i * n + i] - s).squa... | 1,042Cholesky decomposition | 17swift | 9u5mj |
collection = [0, '1']
x = collection[0]
collection.append(2)
collection.insert(0, '-1')
y = collection[0]
collection.extend([2,'3'])
collection += [2,'3']
collection[2:6]
len(coll... | 1,037Collections | 3python | bwokr |
import org.scalatest.FunSuite
import math._
case class V2(x: Double, y: Double) {
val distance = hypot(x, y)
def /(other: V2) = V2((x+other.x) / 2.0, (y+other.y) / 2.0)
def -(other: V2) = V2(x-other.x,y-other.y)
override def equals(other: Any) = other match {
case p: V2 => abs(x-p.x) < 0.0001 && abs(y-p.y... | 1,046Circles of given radius through two points | 16scala | habja |
numeric(5)
1:10
c(1, 3, 6, 10, 7 + 8, sqrt(441)) | 1,037Collections | 13r | 7pqry |
func addCombo(prevCombo: [Int], var pivotList: [Int]) -> [([Int], [Int])] {
return (0..<pivotList.count)
.map {
_ -> ([Int], [Int]) in
(prevCombo + [pivotList.removeAtIndex(0)], pivotList)
}
}
func combosOfLength(n: Int, m: Int) -> [[Int]] {
return [Int](1...m)
.reduce([([Int](), [Int](0..... | 1,031Combinations | 17swift | 5j0u8 |
fun main(args: Array<String>) {
var c = 'a'
var i = c.toInt()
println("$c <-> $i")
i += 2
c = i.toChar()
println("$i <-> $c")
} | 1,054Character codes | 11kotlin | ka5h3 |
class MyClass{ | 1,038Classes | 17swift | tmvfl |
import Foundation
struct Point: Equatable {
var x: Double
var y: Double
}
struct Circle {
var center: Point
var radius: Double
static func circleBetween(
_ p1: Point,
_ p2: Point,
withRadius radius: Double
) -> (Circle, Circle?)? {
func applyPoint(_ p1: Point, _ p2: Point, op: (Double... | 1,046Circles of given radius through two points | 17swift | 4hr5g |
a = []
a[0] = 1
a[3] =
a << 3.14
a = Array.new
a = Array.new(3)
a = Array.new(3, 0)
a = Array.new(3){|i| i*2} | 1,037Collections | 14ruby | 1qnpw |
let a = [1u8,2,3,4,5]; | 1,037Collections | 15rust | asd14 |
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\Users\FransAdm> scala
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> | 1,037Collections | 16scala | xozwg |
use File::Spec::Functions qw(catfile rootdir);
print -e 'input.txt';
print -d 'docs';
print -e catfile rootdir, 'input.txt';
print -d catfile rootdir, 'docs'; | 1,053Check that file exists | 2perl | nzqiw |
print(string.byte("a")) | 1,054Character codes | 1lua | be4ka |
if (file_exists('input.txt')) echo 'input.txt is here right by my side';
if (file_exists('docs' )) echo 'docs is here with me';
if (file_exists('/input.txt')) echo 'input.txt is over there in the root dir';
if (file_exists('/docs' )) echo 'docs is over there in the root dir'; | 1,053Check that file exists | 12php | 7bvrp |
import os
os.path.isfile()
os.path.isfile()
os.path.isdir()
os.path.isdir() | 1,053Check that file exists | 3python | d3sn1 |
file.exists("input.txt")
file.exists("/input.txt")
file.exists("docs")
file.exists("/docs")
file.exists("input.txt", "/input.txt", "docs", "/docs") | 1,053Check that file exists | 13r | 8de0x |
File.file?()
File.file?()
File.directory?()
File.directory?() | 1,053Check that file exists | 14ruby | ty8f2 |
use std::fs;
fn main() {
for file in ["input.txt", "docs", "/input.txt", "/docs"].iter() {
match fs::metadata(file) {
Ok(attr) => {
if attr.is_dir() {
println!("{} is a directory", file);
}else {
println!("{} is a file", fi... | 1,053Check that file exists | 15rust | zmoto |
import java.nio.file.{ Files, FileSystems }
object FileExistsTest extends App {
val defaultFS = FileSystems.getDefault()
val separator = defaultFS.getSeparator()
def test(filename: String) {
val path = defaultFS.getPath(filename)
println(s"The following ${if (Files.isDirectory(path)) "directory" else ... | 1,053Check that file exists | 16scala | yld63 |
use strict;
use warnings;
use utf8;
binmode(STDOUT, ':utf8');
use Encode;
use Unicode::UCD 'charinfo';
use List::AllUtils qw(zip natatime);
for my $c (split //, 'A') {
my $o = ord $c;
my $utf8 = join '', map { sprintf "%x ", ord } split //, Encode::encode("utf8", $c);
my $iterator = natatime 2, zip
... | 1,054Character codes | 2perl | 39ozs |
echo ord('a'), ;
echo chr(97), ; | 1,054Character codes | 12php | pwgba |
print ord('a')
print chr(97) | 1,054Character codes | 3python | 6ci3w |
ascii <- as.integer(charToRaw("hello world")); ascii
text <- rawToChar(as.raw(ascii)); text | 1,054Character codes | 13r | f6sdc |
> .ord
=> 97
> 97.chr
=> | 1,054Character codes | 14ruby | m2dyj |
use std::char::from_u32;
fn main() { | 1,054Character codes | 15rust | 9vfmm |
scala> 'a' toInt
res2: Int = 97
scala> 97 toChar
res3: Char = a
scala> '\u0061'
res4: Char = a
scala> "\uD869\uDEA5"
res5: String = | 1,054Character codes | 16scala | 243lb |
let c1: UnicodeScalar = "a"
println(c1.value) | 1,054Character codes | 17swift | yln6e |
typedef int bool;
typedef enum { ENCRYPT, DECRYPT } cmode;
const char *l_alphabet = ;
const char *r_alphabet = ;
void chao(const char *in, char *out, cmode mode, bool show_steps) {
int i, j, index;
char store;
size_t len = strlen(in);
char left[27], right[27], temp[27];
strcpy(left, l_alphabet);
... | 1,055Chaocipher | 5c | es7av |
const int N = 15;
int main()
{
register int k, n;
unsigned long long int num, den;
int catalan;
printf();
for (n=2; n<=N; ++n) {
num = den = 1;
for (k=2; k<=n; ++k) {
num *= (n+k);
den *= k;
catalan =... | 1,056Catalan numbers/Pascal's triangle | 5c | x8jwu |
package main
import(
"fmt"
"strings"
"unicode/utf8"
)
type Mode int
const(
Encrypt Mode = iota
Decrypt
)
const(
lAlphabet = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"
rAlphabet = "PTLNBQDEOYSFAVZKGJRIHWXUMC"
)
func Chao(text string, mode Mode, showSteps bool) string {
len := len(text)
if utf8... | 1,055Chaocipher | 0go | 9vdmt |
static const char *dog = ;
static const char *Dog = ;
static const char *DOG = ;
int main()
{
printf(, dog, Dog, DOG);
return 0;
} | 1,057Case-sensitivity of identifiers | 5c | yl86f |
class Chaocipher {
private enum Mode {
ENCRYPT,
DECRYPT
}
private static final String L_ALPHABET = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"
private static final String R_ALPHABET = "PTLNBQDEOYSFAVZKGJRIHWXUMC"
private static int indexOf(char[] a, char c) {
for (int i = 0; i < a.length;... | 1,055Chaocipher | 7groovy | zm0t5 |
user=> (let [dog "Benjamin" Dog "Samba" DOG "Bernie"] (format "The three dogs are named%s,%s and%s." dog Dog DOG))
"The three dogs are named Benjamin, Samba and Bernie." | 1,057Case-sensitivity of identifiers | 6clojure | 24fl1 |
import Data.List (elemIndex)
chao :: Eq a => [a] -> [a] -> Bool -> [a] -> [a]
chao _ _ _ [] = []
chao l r plain (x: xs) = maybe [] go (elemIndex x src)
where
(src, dst)
| plain = (l, r)
| otherwise = (r, l)
go n =
dst !! n:
chao
(shifted 1 14 (rotated n l))
((shifted 2... | 1,055Chaocipher | 8haskell | be5k2 |
import java.util.Arrays;
public class Chaocipher {
private enum Mode {
ENCRYPT,
DECRYPT
}
private static final String L_ALPHABET = "HXUCZVAMDSLKPEFJRIGTWOBNYQ";
private static final String R_ALPHABET = "PTLNBQDEOYSFAVZKGJRIHWXUMC";
private static int indexOf(char[] a, char c) {
... | 1,055Chaocipher | 9java | gh94m |
const L_ALPHABET = "HXUCZVAMDSLKPEFJRIGTWOBNYQ";
const R_ALPHABET = "PTLNBQDEOYSFAVZKGJRIHWXUMC";
const ENCRYPT = 0;
const DECRYPT = 1;
function setCharAt(str, index, chr) {
if (index > str.length - 1) return str;
return str.substr(0, index) + chr + str.substr(index + 1);
}
function chao(text, mode, show_ste... | 1,055Chaocipher | 10javascript | kauhq |
null | 1,055Chaocipher | 11kotlin | 24zli |
package main
import "fmt"
func main() {
const n = 15
t := [n + 2]uint64{0, 1}
for i := 1; i <= n; i++ {
for j := i; j > 1; j-- {
t[j] += t[j-1]
}
t[i+1] = t[i]
for j := i + 1; j > 1; j-- {
t[j] += t[j-1]
}
fmt.Printf("%2d:%d\n", i, t[... | 1,056Catalan numbers/Pascal's triangle | 0go | l5fcw |
null | 1,055Chaocipher | 1lua | vg32x |
class Catalan
{
public static void main(String[] args)
{
BigInteger N = 15;
BigInteger k,n,num,den;
BigInteger catalan;
print(1);
for(n=2;n<=N;n++)
{
num = 1;
den = 1;
for(k=2;k<=n;k++)
{
num = num*(n+k);
... | 1,056Catalan numbers/Pascal's triangle | 7groovy | 6c83o |
void cartesianProduct(int** sets, int* setLengths, int* currentSet, int numSets, int times){
int i,j;
if(times==numSets){
printf();
for(i=0;i<times;i++){
printf(,currentSet[i]);
}
printf();
}
else{
for(j=0;j<setLengths[times];j++){
currentSet[times] = sets[times][j];
cartesianProduct(sets,setLen... | 1,058Cartesian product of two or more lists | 5c | vgf2o |
vertex face_point(face f)
{
int i;
vertex v;
if (!f->avg) {
f->avg = vertex_new();
foreach(i, v, f->v)
if (!i) f->avg->pos = v->pos;
else vadd(f->avg->pos, v->pos);
vdiv(f->avg->pos, len(f->v));
}
return f->avg;
}
vertex edge_point(edge e)
{
int i;
face f;
if (!e->e_pt) {
e->e_pt = vertex_... | 1,059Catmull–Clark subdivision surface | 5c | urfv4 |
import System.Environment (getArgs)
pascal :: [[Integer]]
pascal = [1]: map (\row -> 1: zipWith (+) row (tail row) ++ [1]) pascal
catalan :: [Integer]
catalan = map (diff . uncurry drop) $ zip [0..] (alt pascal)
where alt (x:_:zs) = x: alt zs
diff (x:y:_) = x - y
diff (x:_) = x
main :: IO ()... | 1,056Catalan numbers/Pascal's triangle | 8haskell | 1x4ps |
int main() {
const int N = 2;
int base = 10;
int c1 = 0;
int c2 = 0;
int k;
for (k = 1; k < pow(base, N); k++) {
c1++;
if (k % (base - 1) == (k * k) % (base - 1)) {
c2++;
printf(, k);
}
}
printf(, c2, c1, 100.0 - 100.0 * c2 / c1);
ret... | 1,060Casting out nines | 5c | ghz45 |
package main
import (
"fmt"
"sort"
)
type (
Point [3]float64
Face []int
Edge struct {
pn1 int | 1,059Catmull–Clark subdivision surface | 0go | 0njsk |
typedef int (*intFn)(int, int);
int reduce(intFn fn, int size, int *elms)
{
int i, val = *elms;
for (i = 1; i < size; ++i)
val = fn(val, elms[i]);
return val;
}
int add(int a, int b) { return a + b; }
int sub(int a, int b) { return a - b; }
int mul(int a, int b) { return a * b; }
int main(void)
{... | 1,061Catamorphism | 5c | 24olo |
import Data.Array
import Data.Foldable (length, concat, sum)
import Data.List (genericLength)
import Data.Maybe (mapMaybe)
import Prelude hiding (length, concat, sum)
import qualified Data.Map.Strict as Map
newtype VertexId = VertexId { getVertexId :: Int } deriving (Ix, Ord, Eq, Show)
newtype EdgeId = EdgeId { getE... | 1,059Catmull–Clark subdivision surface | 8haskell | cuo94 |
(ns clojure.examples.product
(:gen-class)
(:require [clojure.pprint:as pp]))
(defn cart [colls]
"Compute the cartesian product of list of lists"
(if (empty? colls)
'(())
(for [more (cart (rest colls))
x (first colls)]
(cons x more)))) | 1,058Cartesian product of two or more lists | 6clojure | rkyg2 |
public class Test {
public static void main(String[] args) {
int N = 15;
int[] t = new int[N + 2];
t[1] = 1;
for (int i = 1; i <= N; i++) {
for (int j = i; j > 1; j--)
t[j] = t[j] + t[j - 1];
t[i + 1] = t[i];
for (int j = i + 1;... | 1,056Catalan numbers/Pascal's triangle | 9java | 7bcrj |
typedef struct {
uint8_t magic[2];
} bmpfile_magic_t;
typedef struct {
uint32_t filesz;
uint16_t creator1;
uint16_t creator2;
uint32_t bmp_offset;
} bmpfile_header_t;
typedef struct {
uint32_t header_sz;
int32_t width;
int32_t height;
uint16_t nplanes;
uint16_t bitspp;
ui... | 1,062Canny edge detector | 5c | nzhi6 |
typedef struct cidr_tag {
uint32_t address;
unsigned int mask_length;
} cidr_t;
bool cidr_parse(const char* str, cidr_t* cidr) {
int a, b, c, d, m;
if (sscanf(str, , &a, &b, &c, &d, &m) != 5)
return false;
if (m < 1 || m > 32
|| a < 0 || a > UINT8_MAX
|| b < 0 || b > UINT8... | 1,063Canonicalize CIDR | 5c | jpz70 |
int is_prime(unsigned int n)
{
if (n <= 3) {
return n > 1;
}
else if (!(n % 2) || !(n % 3)) {
return 0;
}
else {
unsigned int i;
for (i = 5; i*i <= n; i += 6)
if (!(n % i) || !(n % (i + 2)))
return 0;
return 1;
}
}
void carmich... | 1,064Carmichael 3 strong pseudoprimes | 5c | aq911 |
> (reduce * '(1 2 3 4 5))
120
> (reduce + 100 '(1 2 3 4 5))
115 | 1,061Catamorphism | 6clojure | ght4f |
sub init {
@left = split '', 'HXUCZVAMDSLKPEFJRIGTWOBNYQ';
@right = split '', 'PTLNBQDEOYSFAVZKGJRIHWXUMC';
}
sub encode {
my($letter) = @_;
my $index = index join('', @right), $letter;
my $enc = $left[$index];
left_permute($index);
right_permute($index);
$enc
}
sub decode {
my(... | 1,055Chaocipher | 2perl | sibq3 |
var n = 15;
for (var t = [0, 1], i = 1; i <= n; i++) {
for (var j = i; j > 1; j--) t[j] += t[j - 1];
t[i + 1] = t[i];
for (var j = i + 1; j > 1; j--) t[j] += t[j - 1];
document.write(i == 1 ? '' : ', ', t[i + 1] - t[i]);
} | 1,056Catalan numbers/Pascal's triangle | 10javascript | pw5b7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.