code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32 Type , or for more information. >>> import __future__ >>> __future__.all_feature_names ['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals', 'barry_as_FLUFL'] >>>
409Pragmatic directives
3python
2ihlz
(defn to-cdf [pdf] (reduce (fn [acc n] (conj acc (+ (or (last acc) 0) n))) [] pdf)) (defn choose [cdf] (let [r (rand)] (count (filter (partial > r) cdf)))) (def *names* '[aleph beth gimel daleth he waw zayin heth]) (def *pdf* (map double [1/5 1/6 1/7 1/8 1/9 1/10 1/11 1759/27720])) (let [nu...
410Probabilistic choice
6clojure
r3ag2
data Circle = Circle { x, y, r :: Double } deriving (Show, Eq) data Tangent = Externally | Internally deriving Eq solveApollonius :: Circle -> Circle -> Circle -> Tangent -> Tangent -> Tangent -> Circle solveApollonius c1 c2 c3 t1 t2 t3 = Circle (m + n * rs) (p + q * rs) rs ...
405Problem of Apollonius
8haskell
w53ed
uint64_t factorial(uint64_t n) { uint64_t product = 1; if (n < 2) { return 1; } for (; n > 0; n--) { uint64_t prev = product; product *= n; if (product < prev) { fprintf(stderr, ); return product; } } return product; } bool isP...
412Primality by Wilson's theorem
5c
gzb45
@inline @tailrec
409Pragmatic directives
16scala
r3egn
use List::Util qw(sum uniq); use ntheory qw(nth_prime); my $max = 99; my %tree; sub allocate { my($n, $i, $sum,, $prod) = @_; $i //= 0; $sum //= 0; $prod //= 1; for my $k (0..$max) { next if $k < $i; my $p = nth_prime($k+1); if (($sum + $p) <= $max) { allocate($n, $k, ...
406Primes - allocate descendants to their ancestors
2perl
3wgzs
(ns properdivisors (:gen-class)) (defn proper-divisors [n] " Proper divisors of n" (if (= n 1) [] (filter #(= 0 (rem n %)) (range 1 n)))) (def data (for [n (range 1 (inc 20000))] [n (proper-divisors n)])) (defn maximal-key [k x & xs] " Normal max-key only finds one key that produces maxim...
411Proper divisors
6clojure
76ar0
from __future__ import print_function from itertools import takewhile maxsum = 99 def get_primes(max): if max < 2: return [] lprimes = [2] for x in range(3, max + 1, 2): for p in lprimes: if x% p == 0: break else: lprimes.append(x) return...
406Primes - allocate descendants to their ancestors
3python
6xr3w
public class Circle { public double[] center; public double radius; public Circle(double[] center, double radius) { this.center = center; this.radius = radius; } public String toString() { return String.format("Circle[x=%.2f,y=%.2f,r=%.2f]",center[0],center[1], radius); } } public class Apolloni...
405Problem of Apollonius
9java
k9ihm
package main import ( "fmt" "sort" ) func sieve(limit uint64) []bool { limit++
407Prime conspiracy
0go
90jmt
use strict; use warnings; sub main { my $program = $0; print "Program: $program\n"; } unless(caller) { main; }
401Program name
2perl
c8e9a
sub gcd { my ($n, $m) = @_; while($n){ my $t = $n; $n = $m % $n; $m = $t; } return $m; } sub tripel { my $pmax = shift; my $prim = 0; my $count = 0; my $nmax = sqrt($pmax)/2; for( my $n=1; $n<=$nmax; $n++ ) { for( my $m=$n+1; (my $p = 2*$m*($m+$n)) ...
399Pythagorean triples
2perl
5fou2
import Data.List (group, sort) import Text.Printf (printf) import Data.Numbers.Primes (primes) freq :: [(Int, Int)] -> Float freq xs = realToFrac (length xs) / 100 line :: [(Int, Int)] -> IO () line t@((n1, n2):xs) = printf "%d ->%d count:%5d frequency:%2.2f%%\n" n1 n2 (length t) (freq t) main :: IO () main = mapM_...
407Prime conspiracy
8haskell
bcok2
null
405Problem of Apollonius
11kotlin
gzq4d
<?php $program = $_SERVER[]; echo ; ?>
401Program name
12php
x4cw5
public class PrimeConspiracy { public static void main(String[] args) { final int limit = 1000_000; final int sieveLimit = 15_500_000; int[][] buckets = new int[10][10]; int prevDigit = 2; boolean[] notPrime = sieve(sieveLimit); for (int n = 3, primeCount = 1; prim...
407Prime conspiracy
9java
gzw4m
void polySpiral(int windowWidth,int windowHeight){ int incr = 0, angle, i, length; double x,y,x1,y1; while(1){ incr = (incr + 5)%360; x = windowWidth/2; y = windowHeight/2; length = 5; angle = incr; for(i=1;i<=150;i++){ x1 = x + length*cos(factor*angle); y1 = y + length*sin(factor*angle); l...
413Polyspiral
5c
2iglo
<?php function gcd($a, $b) { if ($a == 0) return $b; if ($b == 0) return $a; if($a == $b) return $a; if($a > $b) return gcd($a-$b, $b); return gcd($a, $b-$a); } $pytha = 0; $prim = 0; $max_p = 100; for ($a = 1; $a <= $max_p / 3; $a++) { $aa = $a**2; for ($b =...
399Pythagorean triples
12php
ohg85
null
407Prime conspiracy
11kotlin
2ibli
null
407Prime conspiracy
1lua
vnp2x
import sys def main(): program = sys.argv[0] print(% program) if __name__ == : main()
401Program name
3python
lowcv
getProgram <- function(args) { sub("--file=", "", args[grep("--file=", args)]) } args <- commandArgs(trailingOnly = FALSE) program <- getProgram(args) cat("Program: ", program, "\n") q("no")
401Program name
13r
yqp6h
if ($problem) { exit integerErrorCode; }
403Program termination
2perl
bcfk4
package main import ( "fmt" "math/big" ) var ( zero = big.NewInt(0) one = big.NewInt(1) prev = big.NewInt(factorial(20)) )
412Primality by Wilson's theorem
0go
ik3og
package main import ( "fmt" "math/rand" "time" ) type mapping struct { item string pr float64 } func main() {
410Probabilistic choice
0go
srtqa
use utf8; use Math::Cartesian::Product; package Circle; sub new { my ($class, $args) = @_; my $self = { x => $args->{x}, y => $args->{y}, r => $args->{r}, }; bless $self, $class; } sub show { my ($self, $args) = @_; sprintf "x =%7.3f y =%7.3f r =%7.3f\n", $args->{x},...
405Problem of Apollonius
2perl
nbviw
import qualified Data.Text as T import Data.List main = do putStrLn $ showTable True ' ' '-' ' ' $ ["p","isPrime"]:map (\p -> [show p, show $ isPrime p]) numbers putStrLn $ "The first 120 prime numbers are:" putStrLn $ see 20 $ take 120 primes putStrLn "The 1,000th to 1,015th prime numbers are:" pu...
412Primality by Wilson's theorem
8haskell
vn72k
$ convert polyspiral.gif -coalesce polyspiral2.gif $ eog polyspiral2.gif
413Polyspiral
0go
qgixz
import System.Random (newStdGen, randomRs) dataBinCounts :: [Float] -> [Float] -> [Int] dataBinCounts thresholds range = let sampleSize = length range xs = ((-) sampleSize . length . flip filter range . (<)) <$> thresholds in zipWith (-) (xs ++ [sampleSize]) (0: xs) main :: IO () main = do g <- newStdGen ...
410Probabilistic choice
8haskell
90gmo
if (problem) exit(1);
403Program termination
12php
6xh3g
import java.math.BigInteger; public class PrimaltyByWilsonsTheorem { public static void main(String[] args) { System.out.printf("Primes less than 100 testing by Wilson's Theorem%n"); for ( int i = 0 ; i <= 100 ; i++ ) { if ( isPrime(i) ) { System.out.printf("%d ", i); ...
412Primality by Wilson's theorem
9java
yqv6g
use ntheory qw/forprimes nth_prime/; my $upto = 1_000_000; my %freq; my($this_digit,$last_digit)=(2,0); forprimes { ($last_digit,$this_digit) = ($this_digit, $_ % 10); $freq{$last_digit . $this_digit}++; } 3,nth_prime($upto); print "$upto first primes. Transitions prime% 10 next-prime% 10.\n"; printf "%s %s co...
407Prime conspiracy
2perl
sr6q3
typedef struct object *BaseObj; typedef struct sclass *Class; typedef void (*CloneFctn)(BaseObj s, BaseObj clo); typedef const char * (*SpeakFctn)(BaseObj s); typedef void (*DestroyFctn)(BaseObj s); typedef struct sclass { size_t csize; const char *cname; Class parent; CloneFctn clone; S...
414Polymorphic copy
5c
nbzi6
import Reflex import Reflex.Dom import Reflex.Dom.Time import Data.Text (Text, pack) import Data.Map (Map, fromList) import Data.Time.Clock (getCurrentTime) import Control.Monad.Trans (liftIO) type Point = (Float,Float) type Segment = (Point,Point) main = mainWidget $ do dTick <- tickLossy 0.05 =<< liftIO get...
413Polyspiral
8haskell
msvyf
puts puts
401Program name
14ruby
vnq2n
double table[][2] = { {0.06, 0.10}, {0.11, 0.18}, {0.16, 0.26}, {0.21, 0.32}, {0.26, 0.38}, {0.31, 0.44}, {0.36, 0.50}, {0.41, 0.54}, {0.46, 0.58}, {0.51, 0.62}, {0.56, 0.66}, {0.61, 0.70}, {0.66, 0.74}, {0.71, 0.78}, {0.76, 0.82}, {0.81, 0.86}, {0.86, 0.90}, {0.91, 0.94}, {0.96, 0.98}, {1.01, 1.00}, {-1, 0}, };...
415Price fraction
5c
jyb70
fn main() { println!("Program: {}", std::env::args().next().unwrap()); }
401Program name
15rust
udsvj
from fractions import gcd def pt1(maxperimeter=100): ''' ''' trips = [] for a in range(1, maxperimeter): aa = a*a for b in range(a, maxperimeter-a+1): bb = b*b for c in range(b, maxperimeter-b-a+1): cc = c*c if a+b+c > maxperimet...
399Pythagorean triples
3python
4ti5k
null
412Primality by Wilson's theorem
1lua
ta9fn
void reoshift(gsl_vector *v, int h) { if ( h > 0 ) { gsl_vector *temp = gsl_vector_alloc(v->size); gsl_vector_view p = gsl_vector_subvector(v, 0, v->size - h); gsl_vector_view p1 = gsl_vector_subvector(temp, h, v->size - h); gsl_vector_memcpy(&p1.vector, &p.vector); p = gsl_vector_subvector(temp, ...
416Polynomial long division
5c
avw11
import java.awt.*; import java.awt.event.ActionEvent; import javax.swing.*; public class PolySpiral extends JPanel { double inc = 0; public PolySpiral() { setPreferredSize(new Dimension(640, 640)); setBackground(Color.white); new Timer(40, (ActionEvent e) -> { inc = (inc +...
413Polyspiral
9java
f1ydv
bool polynomialfit(int obs, int degree, double *dx, double *dy, double *store);
417Polynomial regression
5c
ikno2
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
408Priority queue
0go
lohcw
from collections import namedtuple import math Circle = namedtuple('Circle', 'x, y, r') def solveApollonius(c1, c2, c3, s1, s2, s3): ''' >>> solveApollonius((0, 0, 1), (4, 0, 1), (2, 4, 2), 1,1,1) Circle(x=2.0, y=2.1, r=3.9) >>> solveApollonius((0, 0, 1), (4, 0, 1), (2, 4, 2), -1,-1,-1) Circle(x=2...
405Problem of Apollonius
3python
dpun1
object ScriptName extends App { println(s"Program of instantiated object: ${this.getClass.getName}")
401Program name
16scala
gzo4i
typedef uint32_t pint; typedef uint64_t xint; typedef unsigned int uint; uint8_t *pbits; pint next_prime(pint); int is_prime(xint); void sieve(pint); uint8_t bit_pos[30] = { 0, 1<<0, 0, 0, 0, 0, 0, 1<<1, 0, 0, 0, 1<<2, 0, 1<<3, 0, 0, 0, 1<<4, 0, 1<<5, 0, 0, 0, 1<<6, 0, 0, 0, 0, 0, 1<...
418Prime decomposition
5c
vnv2o
<!-- Polyspiral.html --> <html> <head><title>Polyspiral Generator</title></head> <script>
413Polyspiral
10javascript
yq26r
public class Prob{ static long TRIALS= 1000000; private static class Expv{ public String name; public int probcount; public double expect; public double mapping; public Expv(String name, int probcount, double expect, double mapping){ this.name= name; this.probcount= probcount; this.expect= expect...
410Probabilistic choice
9java
talf9
import groovy.transform.Canonical @Canonical class Task implements Comparable<Task> { int priority String name int compareTo(Task o) { priority <=> o?.priority } } new PriorityQueue<Task>().with { add new Task(priority: 3, name: 'Clear drains') add new Task(priority: 4, name: 'Feed cat') add n...
408Priority queue
7groovy
6x43o
import sys if problem: sys.exit(1)
403Program termination
3python
pltbm
def isPrime(n): if n < 2: return False if n% 2 == 0: return n == 2 if n% 3 == 0: return n == 3 d = 5 while d * d <= n: if n% d == 0: return False d += 2 if n% d == 0: return False d += 4 return True def generatePr...
407Prime conspiracy
3python
07ysq
null
413Polyspiral
11kotlin
8jf0q
(def values [10 18 26 32 38 44 50 54 58 62 66 70 74 78 82 86 90 94 98 100]) (defn price [v] (format "%.2f" (double (/ (values (int (/ (- (* v 100) 1) 5))) 100))))
415Price fraction
6clojure
12wpy
var probabilities = { aleph: 1/5.0, beth: 1/6.0, gimel: 1/7.0, daleth: 1/8.0, he: 1/9.0, waw: 1/10.0, zayin: 1/11.0, heth: 1759/27720 }; var sum = 0; var iterations = 1000000; var cumulative = {}; var randomly = {}; for (var name in probabilities) { sum += probabilitie...
410Probabilistic choice
10javascript
ms4yv
import Data.PQueue.Prio.Min main = print (toList (fromList [(3, "Clear drains"),(4, "Feed cat"),(5, "Make tea"),(1, "Solve RC tasks"), (2, "Tax return")]))
408Priority queue
8haskell
12ips
if(problem) q(status=10)
403Program termination
13r
jyi78
use strict; use warnings; use feature 'say'; use ntheory qw(factorial); my($ends_in_7, $ends_in_3); sub is_wilson_prime { my($n) = @_; $n > 1 or return 0; (factorial($n-1) % $n) == ($n-1) ? 1 : 0; } for (0..50) { my $m = 3 + 10 * $_; $ends_in_3 .= "$m " if is_wilson_prime($m); my $n = 7 + 10 ...
412Primality by Wilson's theorem
2perl
hmejl
suppressMessages(library(gmp)) limit <- 1e6 result <- vector('numeric', 99) prev_prime <- 2 count <- 0 getOutput <- function(transition) { if (result[transition] == 0) return() second <- transition %% 10 first <- (transition - second) / 10 cat(first,"->",second,"count:", sprintf("%6d",result[transition]),...
407Prime conspiracy
13r
w5te5
typedef int bool; typedef struct { int face; char suit; } card; card cards[5]; int compare_card(const void *a, const void *b) { card c1 = *(card *)a; card c2 = *(card *)b; return c1.face - c2.face; } bool equals_card(card c1, card c2) { if (c1.face == c2.face && c1.suit == c2.suit) return ...
419Poker hand analyser
5c
9sym1
(defn grevlex [term1 term2] (let [grade1 (reduce +' term1) grade2 (reduce +' term2) comp (- grade2 grade1)] (if (not= 0 comp) comp (loop [term1 term1 term2 term2] (if (empty? term1) 0 (let [grade1 (last term1) grade2 (last term2...
416Polynomial long division
6clojure
sr8qr
function love.load () love.window.setTitle("Polyspiral") incr = 0 end function love.update (dt) incr = (incr + 0.05) % 360 x1 = love.graphics.getWidth() / 2 y1 = love.graphics.getHeight() / 2 length = 5 angle = incr end function love.draw () for i = 1, 150 do x2 = x1 + math.cos...
413Polyspiral
1lua
oht8h
null
410Probabilistic choice
11kotlin
oh68z
class Circle def initialize(x, y, r) @x, @y, @r = [x, y, r].map(&:to_f) end attr_reader :x, :y, :r def self.apollonius(c1, c2, c3, s1=1, s2=1, s3=1) x1, y1, r1 = c1.x, c1.y, c1.r x2, y2, r2 = c2.x, c2.y, c2.r x3, y3, r3 = c3.x, c3.y, c3.r v11 = 2*x2 - 2*x1 v12 = 2*y2 - 2*y1 v13 = x...
405Problem of Apollonius
14ruby
ta4f2
(defn factors "Return a list of factors of N." ([n] (factors n 2 ())) ([n k acc] (if (= 1 n) acc (if (= 0 (rem n k)) (recur (quot n k) k (cons k acc)) (recur n (inc k) acc)))))
418Prime decomposition
6clojure
r3rg2
object ApolloniusSolver extends App { case class Circle(x: Double, y: Double, r: Double) object Tangent extends Enumeration { type Tangent = Value val intern = Value(-1) val extern = Value(1) } import Tangent._ import scala.Math._ val solveApollonius: (Circle, Circle, Circle, Triple[Tangent, Tangent, T...
405Problem of Apollonius
16scala
yqj63
class PythagoranTriplesCounter def initialize(limit) @limit = limit @total = 0 @primitives = 0 generate_triples(3, 4, 5) end attr_reader :total, :primitives private def generate_triples(a, b, c) perim = a + b + c return if perim > @limit @primitives += 1 @total += @limit / pe...
399Pythagorean triples
14ruby
r3dgs
using System; class Point { protected int x, y; public Point() : this(0) {} public Point(int x) : this(x,0) {} public Point(int x, int y) { this.x = x; this.y = y; } public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } public virtual void print() { Sy...
420Polymorphism
5c
mq3ys
use strict; use warnings; use Tk; use List::Util qw( min ); my $size = 500; my ($width, $height, $x, $y, $dist); my $angleinc = 0; my $active = 0; my $wait = 1000 / 30; my $radian = 90 / atan2 1, 0; my $mw = MainWindow->new; $mw->title( 'Polyspiral' ); my $c = $mw->Canvas( -width => $size, -height => $size, -relie...
413Polyspiral
2perl
4th5d
struct node { char *s; struct node* prev; }; void powerset(char **v, int n, struct node *up) { struct node me; if (!n) { putchar('['); while (up) { printf(, up->s); up = up->prev; } puts(); } else { me.s = *v; me.prev = up; powerset(v + 1, n - 1, up); powerset(v + 1, n - 1, &me); } } int ...
421Power set
5c
4f25t
items = {} items["aleph"] = 1/5.0 items["beth"] = 1/6.0 items["gimel"] = 1/7.0 items["daleth"] = 1/8.0 items["he"] = 1/9.0 items["waw"] = 1/10.0 items["zayin"] = 1/11.0 items["heth"] = 1759/27720 num_trials = 1000000 samples = {} for item, _ in pairs( items ) do samples[item] = 0 end math.randomsee...
410Probabilistic choice
1lua
ikyot
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
408Priority queue
9java
76xrj
use std::thread; fn f1 (a: u64, b: u64, c: u64, d: u64) -> u64 { let mut primitive_count = 0; for triangle in [[a - 2*b + 2*c, 2*a - b + 2*c, 2*a - 2*b + 3*c], [a + 2*b + 2*c, 2*a + b + 2*c, 2*a + 2*b + 3*c], [2*b + 2*c - a, b + 2*c - 2*a, 2*b + 3*c - 2*a]] .iter() { ...
399Pythagorean triples
15rust
76frc
if problem exit(1) end if problem abort end
403Program termination
14ruby
av31s
from math import factorial def is_wprime(n): return n == 2 or ( n > 1 and n% 2 != 0 and (factorial(n - 1) + 1)% n == 0 ) if __name__ == '__main__': c = int(input('Enter upper limit: ')) print(f'Primes under {c}:') print([n for n in range(c) if is_wprime(n)])
412Primality by Wilson's theorem
3python
k9whf
require def prime_conspiracy(m) conspiracy = Hash.new(0) Prime.take(m).map{|n| n%10}.each_cons(2){|a,b| conspiracy[[a,b]] += 1} puts conspiracy.sort.each do |(a,b),v| puts % [a, b, v, 100.0*v/m] end end prime_conspiracy(1_000_000)
407Prime conspiracy
14ruby
oh98v
null
407Prime conspiracy
15rust
ikcod
double x[NP] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; double y[NP] = {2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0}; void minmax(double *x, double *y, double *minx, double *maxx, double *miny, double *maxy, int n) { int i; *minx = *maxx = x[0]; *miny = *maxy = y[0]; for(i=1; i < n; i++) { ...
422Plot coordinate pairs
5c
5dcuk
(defn rank [card] (let [[fst _] card] (if (Character/isDigit fst) (Integer/valueOf (str fst)) ({\T 10, \J 11, \Q 12, \K 13, \A 14} fst)))) (defn suit [card] (let [[_ snd] card] (str snd))) (defn n-of-a-kind [hand n] (not (empty? (filter #(= true %) (map #(>= % n) (vals (frequencies (map rank...
419Poker hand analyser
6clojure
un2vi
package main import ( "fmt" "reflect" )
414Polymorphic copy
0go
r3kgm
import Foundation struct Circle { let center:[Double]! let radius:Double! init(center:[Double], radius:Double) { self.center = center self.radius = radius } func toString() -> String { return "Circle[x=\(center[0]),y=\(center[1]),r=\(radius)]" } } func solveApollonius...
405Problem of Apollonius
17swift
f15dk
object PythagoreanTriples extends App { println(" Limit Primatives All") for {e <- 2 to 7 limit = math.pow(10, e).longValue() } { var primCount, tripCount = 0 def parChild(a: BigInt, b: BigInt, c: BigInt): Unit = { val perim = a + b + c val (a2, b2, c2, c3) = (...
399Pythagorean triples
16scala
k93hk
fn main() { println!("The program is running"); return; println!("This line won't be printed"); }
403Program termination
15rust
eu6aj
import scala.annotation.tailrec import scala.collection.mutable object PrimeConspiracy extends App { val limit = 1000000 val sieveTop = 15485863 + 1 val buckets = Array.ofDim[Int](10, 10) var prevPrime = 2 def sieve(limit: Int) = { val composite = new mutable.BitSet(sieveTop) composite(0) = true ...
407Prime conspiracy
16scala
f1vd4
class T implements Cloneable { String property String name() { 'T' } T copy() { try { super.clone() } catch(CloneNotSupportedException e) { null } } @Override boolean equals(that) { this.name() == that?.name() && this.property == that?.property } } class S extends T { @Overr...
414Polymorphic copy
7groovy
vng28
import math import pygame from pygame.locals import * pygame.init() screen = pygame.display.set_mode((1024, 600)) pygame.display.set_caption() incr = 0 running = True while running: pygame.time.Clock().tick(60) for event in pygame.event.get(): if event.type==QUIT: running = False break incr = (incr + ...
413Polyspiral
3python
gzk4h
if (problem) {
403Program termination
16scala
qg9xw
var p *int
423Pointers and references
0go
2o6l7
import Data.STRef example :: ST s () example = do p <- newSTRef 1 k <- readSTRef p writeSTRef p (k+1)
423Pointers and references
8haskell
a2j1g
(use '(incanter core stats charts)) (def x (range 0 10)) (def y '(2.7 2.8 31.4 38.1 58.0 76.2 100.5 130.0 149.3 180.0)) (view (xy-plot x y))
422Plot coordinate pairs
6clojure
j657m
(use '[clojure.math.combinatorics:only [subsets] ]) (def S #{1 2 3 4}) user> (subsets S) (() (1) (2) (3) (4) (1 2) (1 3) (1 4) (2 3) (2 4) (3 4) (1 2 3) (1 2 4) (1 3 4) (2 3 4) (1 2 3 4))
421Power set
6clojure
hygjr
package main import ( "fmt" "strconv" ) func listProperDivisors(limit int) { if limit < 1 { return } width := len(strconv.Itoa(limit)) for i := 1; i <= limit; i++ { fmt.Printf("%*d -> ", width, i) if i == 1 { fmt.Println("(None)") continue ...
411Proper divisors
0go
07tsk
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
408Priority queue
11kotlin
udpvc
def w_prime?(i) return false if i < 2 ((1..i-1).inject(&:*) + 1) % i == 0 end p (1..100).select{|n| w_prime?(n) }
412Primality by Wilson's theorem
14ruby
plqbh
(defprotocol Printable (print-it [this] "Prints out the Printable.")) (deftype Point [x y] Printable (print-it [this] (println (str "Point: " x " " y)))) (defn create-point "Redundant constructor function." [x y] (Point. x y)) (deftype Circle [x y r] Printable (print-it [this] (println (str "Circle: ...
420Polymorphism
6clojure
vic2f
class T implements Cloneable { public String name() { return "T"; } public T copy() { try { return (T)super.clone(); } catch (CloneNotSupportedException e) { return null; } } } class S extends T { public String name() { return "S"; } } public class Polym...
414Polymorphic copy
9java
avq1y
import java.awt._ import java.awt.event.ActionEvent import javax.swing._ object PolySpiral extends App { SwingUtilities.invokeLater(() => new JFrame("PolySpiral") { class PolySpiral extends JPanel { private var inc = 0.0 override def paintComponent(gg: Graphics): Unit = { val ...
413Polyspiral
16scala
bcwk6
import Data.Ord import Data.List divisors :: (Integral a) => a -> [a] divisors n = filter ((0 ==) . (n `mod`)) [1 .. (n `div` 2)] main :: IO () main = do putStrLn "divisors of 1 to 10:" mapM_ (print . divisors) [1 .. 10] putStrLn "a number with the most divisors within 1 to 20000 (number, count):" print $ max...
411Proper divisors
8haskell
c8g94
use List::Util qw(first sum); use constant TRIALS => 1e6; sub prob_choice_picker { my %options = @_; my ($n, @a) = 0; while (my ($k,$v) = each %options) { $n += $v; push @a, [$n, $k]; } return sub { my $r = rand; ( first {$r <= $_->[0]} @a )->[1]; }; } my %ps = (aleph => 1/5, ...
410Probabilistic choice
2perl
gz14e
fn factorial_mod(mut n: u32, p: u32) -> u32 { let mut f = 1; while n!= 0 && f!= 0 { f = (f * n)% p; n -= 1; } f } fn is_prime(p: u32) -> bool { p > 1 && factorial_mod(p - 1, p) == p - 1 } fn main() { println!(" n | prime?\n------------"); for p in vec![2, 3, 9, 15, 29, 37,...
412Primality by Wilson's theorem
15rust
12spu
public class Foo { public int x = 0; } void somefunction() { Foo a;
423Pointers and references
9java
j6u7c