code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
null | 421Power set | 11kotlin | db8nz |
>>> def proper_divs2(n):
... return {x for x in range(1, (n + 1)
...
>>> [proper_divs2(n) for n in range(1, 11)]
[set(), {1}, {1}, {1, 2}, {1}, {1, 2, 3}, {1}, {1, 2, 4}, {1, 3}, {1, 2, 5}]
>>>
>>> n, length = max(((n, len(proper_divs2(n))) for n in range(1, 20001)), key=lambda pd: pd[1])
>>> n
15120
>>> length
... | 411Proper divisors | 3python | 76arm |
import java.math.BigInteger;
public class PopCount {
public static void main(String[] args) {
{ | 424Population count | 9java | sgpq0 |
require 'matrix'
def regress x, y, degree
x_data = x.map { |xi| (0..degree).map { |pow| (xi**pow).to_r } }
mx = Matrix[*x_data]
my = Matrix.column_vector(y)
((mx.t * mx).inv * mx.t * my).transpose.to_a[0].map(&:to_f)
end | 417Polynomial regression | 14ruby | 6xy3t |
use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>, | 408Priority queue | 15rust | dplny |
>>> x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]
>>> import pylab
>>> pylab.plot(x, y, 'bo')
>>> pylab.savefig('qsort-range-10-9.png') | 422Plot coordinate pairs | 3python | j657p |
{
package Point;
use Class::Spiffy -base;
use Clone qw(clone);
sub _print {
my %self = %{shift()};
while (my ($k,$v) = each %self) {
print "$k: $v\n";
}
}
sub members {
no strict;
grep {
1 == length and defined *$_{CO... | 420Polymorphism | 2perl | 2o9lf |
(() => {
'use strict'; | 424Population count | 10javascript | nkxiy |
object PolynomialRegression extends App {
private def xy = Seq(1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321).zipWithIndex.map(_.swap)
private def polyRegression(xy: Seq[(Int, Int)]): Unit = {
val r = xy.indices
def average[U](ts: Iterable[U])(implicit num: Numeric[U]) = num.toDouble(ts.sum) / ts.size
... | 417Polynomial regression | 16scala | c8l93 |
require(numbers);
V <- sapply(1:20000, Sigma, k = 0, proper = TRUE); ind <- which(V==max(V));
cat(" *** max number of divisors:", max(V), "\n"," *** for the following indices:",ind, "\n"); | 411Proper divisors | 13r | 5fkuy |
x <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
y <- c(2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0) | 422Plot coordinate pairs | 13r | 4fl5y |
null | 421Power set | 1lua | fpodp |
my @table = map [ /([\d\.]+)/g ], split "\n", <<'TBL';
>= 0.00 < 0.06 := 0.10
>= 0.06 < 0.11 := 0.18
>= 0.11 < 0.16 := 0.26
>= 0.16 < 0.21 := 0.32
>= 0.21 < 0.26 := 0.38
>= 0.26 < 0.31 := 0.44
>= 0.31 < 0.36 := 0.50
>= 0.36 < 0.41 := 0.54
>= 0.41 < 0.46 := 0.58
>= 0.46 < 0.51 := ... | 415Price fraction | 2perl | pleb0 |
import scala.collection.mutable.PriorityQueue
case class Task(prio:Int, text:String) extends Ordered[Task] {
def compare(that: Task)=that.prio compare this.prio
} | 408Priority queue | 16scala | zeutr |
function PrimeDecomposition( n )
local f = {}
if IsPrime( n ) then
f[1] = n
return f
end
local i = 2
repeat
while n % i == 0 do
f[#f+1] = i
n = n / i
end
repeat
i = i + 1
until IsPrime( i )
until n == 1... | 418Prime decomposition | 1lua | ikiot |
class Point
{
protected $_x;
protected $_y;
public function __construct()
{
switch( func_num_args() )
{
case 1:
$point = func_get_arg( 0 );
$this->setFromPoint( $point );
break;
case 2:
$x = func_get_arg( 0 );
$y = func_get_arg( 1 );
$this->s... | 420Polymorphism | 12php | sgwqs |
null | 424Population count | 11kotlin | a2713 |
let x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let y = [1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321]
func average(_ input: [Int]) -> Int {
return input.reduce(0, +) / input.count
}
func polyRegression(x: [Int], y: [Int]) {
let xm = average(x)
let ym = average(y)
let x2m = average(x.map { $0 * $0 })
... | 417Polynomial regression | 17swift | 3w6z2 |
require 'gnuplot'
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]
Gnuplot.open do |gp|
Gnuplot::Plot.new( gp ) do |plot|
plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
ds.with =
ds.notitle
end
end
end | 422Plot coordinate pairs | 14ruby | kmghg |
null | 424Population count | 1lua | evjac |
import scala.swing.Swing.pair2Dimension
import scala.swing.{ MainFrame, Panel, Rectangle }
import java.awt.{ Color, Graphics2D, geom }
object PlotCoordPairs extends scala.swing.SimpleSwingApplication { | 422Plot coordinate pairs | 16scala | a2h1n |
require
class Integer
def proper_divisors
return [] if self == 1
primes = prime_division.flat_map{|prime, freq| [prime] * freq}
(1...primes.size).each_with_object([1]) do |n, res|
primes.combination(n).map{|combi| res << combi.inject(:*)}
end.flatten.uniq
end
end
(1..10).map{|n| puts }
siz... | 411Proper divisors | 14ruby | hmwjx |
class Point(object):
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def __repr__(self):
return '<Point 0x%x x:%f y:%f>'% (id(self), self.x, self.y)
class Circle(object):
def __init__(self, center=None, radius=1.0):
self.center = center or Point()
self.radius... | 420Polymorphism | 3python | vic29 |
trait ProperDivisors {
fn proper_divisors(&self) -> Option<Vec<u64>>;
}
impl ProperDivisors for u64 {
fn proper_divisors(&self) -> Option<Vec<u64>> {
if self.le(&1) {
return None;
}
let mut divisors: Vec<u64> = Vec::new();
for i in 1..*self {
if *self% i... | 411Proper divisors | 15rust | k9xh5 |
class Task: Comparable, CustomStringConvertible {
var priority: Int
var name: String
init(priority: Int, name: String) {
self.priority = priority
self.name = name
}
var description: String {
return "\(priority), \(name)"
}
}
func ==(t1: Task, t2: Task) -> Bool {
return t1.priority == t2.priori... | 408Priority queue | 17swift | ik9o0 |
setClass("point",
representation(
x="numeric",
y="numeric"),
prototype(
x=0,
y=0))
p1 <- new("point", x=3)
p1@x
setMethod("print", signature("point"),
function(x, ...)
{
cat("This is a point, with location, (", x@x, ",", x@y, ").\n")
})
print(p1)
setClass("circ... | 420Polymorphism | 13r | 9s6mg |
>>> import bisect
>>> _cin = [.06, .11, .16, .21, .26, .31, .36, .41, .46, .51, .56, .61, .66, .71, .76, .81, .86, .91, .96, 1.01]
>>> _cout = [.10, .18, .26, .32, .38, .44, .50, .54, .58, .62, .66, .70, .74, .78, .82, .86, .90, .94, .98, 1.00]
>>> def pricerounder(pricein):
return _cout[ bisect.bisect_right(_cin, pr... | 415Price fraction | 3python | 12wpc |
def properDivisors(n: Int) = (1 to n/2).filter(i => n % i == 0)
def format(i: Int, divisors: Seq[Int]) = f"$i%5d ${divisors.length}%2d ${divisors mkString " "}"
println(f" n cnt PROPER DIVISORS")
val (count, list) = (1 to 20000).foldLeft( (0, List[Int]()) ) { (max, i) =>
val divisors = properDivisors(i... | 411Proper divisors | 16scala | 120pf |
class Point
attr_accessor :x,:y
def initialize(x=0, y=0)
self.x = x
self.y = y
end
def to_s
end
end
class Circle < Point
attr_accessor :r
def initialize(x=0, y=0, r=0)
self.x = x
self.y = y
self.r = r
end
def to_s
end
end | 420Polymorphism | 14ruby | 5d2uj |
price_fraction <- function(x)
{
stopifnot(all(x >= 0 & x <= 1))
breaks <- seq(0.06, 1.01, 0.05)
values <- c(.1, .18, .26, .32, .38, .44, .5, .54, .58, .62, .66, .7, .74, .78, .82, .86, .9, .94, .98, 1)
indices <- sapply(x, function(x) which(x < breaks)[1])
values[indices]
}
price_fraction(c(0, .01, 0.06, 0.... | 415Price fraction | 13r | hmpjj |
object PointCircle extends App {
class Point(x: Int = 0, y: Int = 0) {
def copy(x: Int = this.x, y: Int = this.y): Point = new Point(x, y)
override def toString = s"Point x: $x, y: $y"
}
object Point {
def apply(x: Int = 0, y: Int = 0): Point = new Point(x, y)
}
case class Circle(x: Int = 0,... | 420Polymorphism | 16scala | 734r9 |
use Algorithm::Combinatorics "subsets";
my @S = ("a","b","c");
my @PS;
my $iter = subsets(\@S);
while (my $p = $iter->next) {
push @PS, "[@$p]"
}
say join(" ",@PS); | 421Power set | 2perl | j647f |
func IsPrime(n int) bool {
if n < 0 { n = -n }
switch {
case n == 2:
return true
case n < 2 || n % 2 == 0:
return false
default:
for i = 3; i*i <= n; i += 2 {
if n % i == 0 { return false }
}
}
return true
} | 425Primality by trial division | 0go | nkwi1 |
func properDivs1(n: Int) -> [Int] {
return filter (1 ..< n) { n% $0 == 0 }
} | 411Proper divisors | 17swift | jye74 |
use strict;
use warnings;
use feature 'say';
sub evil {
my $i = 0;
sub { $i++ while population_count($i) % 2; $i++ }
}
sub odious {
my $i = 0;
sub { $i++ until population_count($i) % 2; $i++ }
}
sub population_count {
my $n = shift;
my $c;
for ($c = 0; $n; $n >>= 1) { $c += $n & 1 }
... | 424Population count | 2perl | 9sfmn |
<?php
function get_subset($binary, $arr) {
$subset = array();
foreach (range(0, count($arr)-1) as $i) {
if ($binary[$i]) {
$subset[] = $arr[count($arr) - $i - 1];
}
}
return $subset;
}
function print_array($arr) {
if (count($arr) > 0) {
echo join(, $arr);
} else {
echo ;
}
... | 421Power set | 12php | t1if1 |
def isPrime = {
it == 2 ||
it > 1 &&
(2..Math.max(2, (int) Math.sqrt(it))).every{ k -> it % k != 0 }
}
(0..20).grep(isPrime) | 425Primality by trial division | 7groovy | sgbq1 |
def rescale_price_fraction(value)
raise ArgumentError, if value < 0 || value >= 1.01
if value < 0.06 then 0.10
elsif value < 0.11 then 0.18
elsif value < 0.16 then 0.26
elsif value < 0.21 then 0.32
elsif value < 0.26 then 0.38
elsif value < 0.31 then 0.44
elsif value < 0.36 then ... | 415Price fraction | 14ruby | euqax |
isPrime n = n==2 || n>2 && all ((> 0).rem n) (2:[3,5..floor.sqrt.fromIntegral $ n+1]) | 425Primality by trial division | 8haskell | un6v2 |
fn fix_price(num: f64) -> f64 {
match num {
0.96...1.00 => 1.00,
0.91...0.96 => 0.98,
0.86...0.91 => 0.94,
0.81...0.86 => 0.90,
0.76...0.81 => 0.86,
0.71...0.76 => 0.82,
0.66...0.71 => 0.78,
0.61...0.66 => 0.74,
0.56...0.61 => 0.70,
0.5... | 415Price fraction | 15rust | w5se4 |
class RCPoint: Printable {
var x: Int
var y: Int
init(x: Int = 0, y: Int = 0) {
self.x = x
self.y = y
}
convenience init(p: RCPoint) {
self.init(x:p.x, y:p.y)
}
var description: String {
return "<RCPoint x: \(self.x) y: \(self.y)>"
}
}
class RCCircle: RCPoint {
var r: Int
init(p: RCPo... | 420Polymorphism | 17swift | unlvg |
function convertToBinary($integer) {
$binary = ;
do {
$quotient = (int) ($integer / 2);
$binary .= $integer % 2;
$integer = $quotient;
} while ($quotient > 0);
return $binary;
}
function getPopCount($integer) {
$binary = convertToBinary($integer);
$offset = 0;
... | 424Population count | 12php | wuhep |
def priceFraction(x:Double)=x match {
case n if n>=0 && n<0.06 => 0.10
case n if n<0.11 => 0.18
case n if n<0.36 => ((((n*100).toInt-11)/5)*6+26)/100.toDouble
case n if n<0.96 => ((((n*100).toInt-31)/5)*4+50)/100.toDouble
case _ => 1.00
}
def testPriceFraction()=
for(n <- 0.00 to (1.00, 0.01)) printl... | 415Price fraction | 16scala | sroqo |
sub prime_factors {
my ($n, $d, @out) = (shift, 1);
while ($n > 1 && $d++) {
$n /= $d, push @out, $d until $n % $d;
}
@out
}
print "@{[prime_factors(1001)]}\n"; | 418Prime decomposition | 2perl | gzg4e |
def list_powerset(lst):
result = [[]]
for x in lst:
result.extend([subset + [x] for subset in result])
return result
def list_powerset2(lst):
return reduce(lambda result, x: result + [subset + [x] for subset in result],
... | 421Power set | 3python | hygjw |
public static boolean prime(long a){
if(a == 2){
return true;
}else if(a <= 1 || a % 2 == 0){
return false;
}
long max = (long)Math.sqrt(a);
for(long n= 3; n <= max; n+= 2){
if(a % n == 0){ return false; }
}
return true;
} | 425Primality by trial division | 9java | mqnym |
let ranges = [
(0.00..<0.06, 0.10),
(0.06..<0.11, 0.18),
(0.11..<0.16, 0.26),
(0.16..<0.21, 0.32),
(0.21..<0.26, 0.38),
(0.26..<0.31, 0.44),
(0.31..<0.36, 0.50),
(0.36..<0.41, 0.54),
(0.41..<0.46, 0.58),
(0.46..<0.51, 0.62),
(0.51..<0.56, 0.66),
(0.56..<0.61, 0.70),
(0.61..<0.66, 0.74),
(0.6... | 415Price fraction | 17swift | avx1i |
function isPrime(n) {
if (n == 2 || n == 3 || n == 5 || n == 7) {
return true;
} else if ((n < 2) || (n % 2 == 0)) {
return false;
} else {
for (var i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
return true;
}
} | 425Primality by trial division | 10javascript | vi325 |
>>> def popcount(n): return bin(n).count()
...
>>> [popcount(3**i) for i in range(30)]
[1, 2, 2, 4, 3, 6, 6, 5, 6, 8, 9, 13, 10, 11, 14, 15, 11, 14, 14, 17, 17, 20, 19, 22, 16, 18, 24, 30, 25, 25]
>>> evil, odious, i = [], [], 0
>>> while len(evil) < 30 or len(odious) < 30:
... p = popcount(i)
... if p% 2: odi... | 424Population count | 3python | c0t9q |
for each element in the set:
for each subset constructed so far:
new subset = (subset + element) | 421Power set | 13r | gtv47 |
library(bit64)
popCount <- function(x) sum(as.numeric(strsplit(as.bitstring(as.integer64(x)), "")[[1]]))
finder <- function()
{
odious <- evil <- integer(0)
x <- odiousLength <- evilLength <- 0
while(evilLength + odiousLength != 60)
{
if(popCount(x) %% 2 == 0) evil[evilLength + 1] <- x else odious[odiousLen... | 424Population count | 13r | 6wi3e |
class Array
def power_set
inject([[]]) do |acc, you|
ret = []
acc.each do |i|
ret << i
ret << i + [you]
end
ret
end
end
def func_power_set
inject([[]]) { |ps,item|
ps + ... | 421Power set | 14ruby | b97kq |
null | 425Primality by trial division | 11kotlin | t1sf0 |
from __future__ import print_function
import sys
from itertools import islice, cycle, count
try:
from itertools import compress
except ImportError:
def compress(data, selectors):
return (d for d, s in zip(data, selectors) if s)
def is_prime(n):
return list(zip((True, False), decompose(n... | 418Prime decomposition | 3python | r3rgq |
use std::collections::BTreeSet;
fn powerset<T: Ord + Clone>(mut set: BTreeSet<T>) -> BTreeSet<BTreeSet<T>> {
if set.is_empty() {
let mut powerset = BTreeSet::new();
powerset.insert(set);
return powerset;
} | 421Power set | 15rust | pcjbu |
import scala.compat.Platform.currentTime
object Powerset extends App {
def powerset[A](s: Set[A]) = s.foldLeft(Set(Set.empty[A])) { case (ss, el) => ss ++ ss.map(_ + el)}
assert(powerset(Set(1, 2, 3, 4)) == Set(Set.empty, Set(1), Set(2), Set(3), Set(4), Set(1, 2), Set(1, 3), Set(1, 4),
Set(2, 3), Set(2, 4), S... | 421Power set | 16scala | evbab |
findfactors <- function(num) {
x <- NULL
firstprime<- 2; secondprime <- 3; everyprime <- num
while( everyprime!= 1 ) {
while( everyprime%%firstprime == 0 ) {
x <- c(x, firstprime)
everyprime <- floor(everyprime/ firstprime)
}
firstprime <- secondprime
secondprime <- secondprime + 2
}... | 418Prime decomposition | 13r | uduvx |
class Integer
def popcount
digits(2).count(1)
end
def evil?
self >= 0 && popcount.even?
end
end
puts , (0...30).map{|n| (3**n).popcount}.join(' ')
puts , 0.step.lazy.select(&:evil?).first(30).join(' ')
puts , 0.step.lazy.reject(&:evil?).first(30).join(' ') | 424Population count | 14ruby | 2o3lw |
fn main() {
let mut num = 1u64;
let mut vec = Vec::new();
for _ in 0..30 {
vec.push(num.count_ones());
num *= 3;
}
println!("pop count of 3^0, 3^1 ... 3^29:\n{:?}",vec);
let mut even = Vec::new();
let mut odd = Vec::new();
num = 1;
while even.len() < 30 || odd.len() ... | 424Population count | 15rust | vi62t |
import java.lang.Long.bitCount
object PopCount extends App {
val nNumber = 30
def powersThree(start: Long): LazyList[Long] = start #:: powersThree(start * 3L)
println("Population count of 3:")
println(powersThree(1L).map(bitCount).take(nNumber).mkString(", "))
def series(start: Long): LazyList[Long] = sta... | 424Population count | 16scala | 4f950 |
function IsPrime( n )
if n <= 1 or ( n ~= 2 and n % 2 == 0 ) then
return false
end
for i = 3, math.sqrt(n), 2 do
if n % i == 0 then
return false
end
end
return true
end | 425Primality by trial division | 1lua | za0ty |
irb(main):001:0> require 'prime'
=> true
irb(main):003:0> 2543821448263974486045199.prime_division
=> [[701, 1], [1123, 2], [2411, 1], [1092461, 2]] | 418Prime decomposition | 14ruby | jyj7x |
func populationCount(n: Int) -> Int {
guard n >= 0 else { fatalError() }
return String(n, radix: 2).filter({ $0 == "1" }).count
}
let pows = (0...)
.lazy
.map({ Int(pow(3, Double($0))) })
.map(populationCount)
.prefix(30)
let evils = (0...)
.lazy
.filter({ populationCount(n: $0) & 1 == 0 ... | 424Population count | 17swift | l8zc2 |
func powersetFrom<T>(_ elements: Set<T>) -> Set<Set<T>> {
guard elements.count > 0 else {
return [[]]
}
var powerset: Set<Set<T>> = [[]]
for element in elements {
for subset in powerset {
powerset.insert(subset.union([element]))
}
}
return powerset
} | 421Power set | 17swift | kmrhx |
[package]
name = "prime_decomposition"
version = "0.1.1"
edition = "2018"
[dependencies]
num-bigint = "0.3.0"
num-traits = "0.2.12" | 418Prime decomposition | 15rust | hmhj2 |
import annotation.tailrec
import collection.parallel.mutable.ParSeq
object PrimeFactors extends App {
def factorize(n: Long): List[Long] = {
@tailrec
def factors(tuple: (Long, Long, List[Long], Int)): List[Long] = {
tuple match {
case (1, _, acc, _) => acc
case (n, k, ac... | 418Prime decomposition | 16scala | plpbj |
package main
import (
"github.com/fogleman/gg"
"log"
"os/exec"
"runtime"
)
var palette = [2]string{
"FFFFFF", | 426Pinstripe/Printer | 0go | 5d6ul |
package main
import (
"log"
"os"
"os/exec"
)
func main() {
args := []string{
"-m", "-v", "0.75", "a.wav", "-v", "0.25", "b.wav",
"-d",
"trim", "4", "6",
"repeat", "5",
}
cmd := exec.Command("sox", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
... | 427Play recorded sounds | 0go | vit2m |
func primeDecomposition<T: BinaryInteger>(of n: T) -> [T] {
guard n > 2 else { return [] }
func step(_ x: T) -> T {
return 1 + (x << 2) - ((x >> 1) << 1)
}
let maxQ = T(Double(n).squareRoot())
var d: T = 1
var q: T = n% 2 == 0? 2: 3
while q <= maxQ && n% q!= 0 {
q = step(d)
d += 1
}
re... | 418Prime decomposition | 17swift | 767rq |
package main
import "fmt"
func gcd(a, b uint) uint {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func lcm(a, b uint) uint {
return a / gcd(a, b) * b
}
func ipow(x, p uint) uint {
prod := uint(1)
for p > 0 {
if p&1 != 0 {
prod *= x
}
p >>= 1
... | 428Pisano period | 0go | 4f352 |
import time
from pygame import mixer
mixer.init(frequency=16000)
s1 = mixer.Sound('test.wav')
s2 = mixer.Sound('test2.wav')
s1.play(-1)
time.sleep(0.5)
s2.play()
time.sleep(2)
s2.play(2)
time.sleep(10)
s1.set_volume(0.1)
time.sleep(5)
s1.set_volume(1)
time.sleep(5)
s1.stop()
s2.st... | 427Play recorded sounds | 3python | nkaiz |
import qualified Data.Text as T
main = do
putStrLn "PisanoPrime(p,2) for prime p lower than 15"
putStrLn . see 15 . map (`pisanoPrime` 2) . filter isPrime $ [1 .. 15]
putStrLn "PisanoPrime(p,1) for prime p lower than 180"
putStrLn . see 15 . map (`pisanoPrime` 1) . filter isPrime $ [1 .. 180]
let ns = [1 .. ... | 428Pisano period | 8haskell | q47x9 |
library(sound)
media_dir <- file.path(Sys.getenv("SYSTEMROOT"), "Media")
chimes <- loadSample(file.path(media_dir, "chimes.wav"))
chord <- loadSample(file.path(media_dir, "chord.wav"))
play(appendSample(chimes, chord))
play(chimes + chord)
play(cutSample(chimes, 0, 0.2))
for(i in 1:3) play(chimes) ... | 427Play recorded sounds | 13r | 0rksg |
require 'win32/sound'
include Win32
sound1 = ENV['WINDIR'] + '\Media\Windows XP Startup.wav'
sound2 = ENV['WINDIR'] + '\Media\Windows XP Shutdown.wav'
puts
[sound1, sound2].each do |s|
t1 = Time.now
Sound.play(s)
puts
end
puts
[sound1, sound2].each {|s| Sound.play(s, Sound::ASYNC)}
puts <<END
the above ... | 427Play recorded sounds | 14ruby | fpwdr |
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class PisanoPeriod {
public static void main(String[] args) {
System.out.printf("Print pisano(p^2) for every prime p lower than 15%n");
... | 428Pisano period | 9java | pcvb3 |
import AVFoundation | 427Play recorded sounds | 17swift | dbenh |
use strict;
use warnings;
use feature 'say';
use ntheory qw(primes factor_exp lcm);
sub pisano_period_pp {
my($a, $b, $n, $k) = (0, 1, $_[0]**$_[1]);
while (++$k) {
($a, $b) = ($b, ($a+$b) % $n);
return $k if $a == 0 and $b == 1;
}
}
sub pisano_period {
(lcm map { pisano_period_pp($$_[... | 428Pisano period | 2perl | fped7 |
from sympy import isprime, lcm, factorint, primerange
from functools import reduce
def pisano1(m):
if m < 2:
return 1
lastn, n = 0, 1
for i in range(m ** 2):
lastn, n = n, (lastn + n)% m
if lastn == 0 and n == 1:
return i + 1
return 1
def pisanoprime(p, k):
... | 428Pisano period | 3python | t1wfw |
int main()
{
int d=DETECT,m,maxX,maxY,x,y,increment=1;
initgraph(&d,&m,);
maxX = getmaxx();
maxY = getmaxy();
for(y=0;y<maxY;y+=maxY/sections)
{
for(x=0;x<maxX;x+=increment)
{
setfillstyle(SOLID_FILL,(x/increment)%2==0?BLACK:WHITE);
bar(x,y,x+increment,y+maxY/sections);
}
increment++;
}
getch(... | 429Pinstripe/Display | 5c | 1lvpj |
sub prime { my $n = shift || $_;
$n % $_ or return for 2 .. sqrt $n;
$n > 1
}
print join(', ' => grep prime, 1..100), "\n"; | 425Primality by trial division | 2perl | kmuhc |
int main()
{
CONSOLE_SCREEN_BUFFER_INFO info;
int cols, rows;
time_t t;
int i,j;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
cols = info.srWindow.Right - info.srWindow.Left + 1;
rows = info.srWindow.Bottom - info.srWindow.Top + 1;
HANDLE console;
console = GetStdHandle(ST... | 430Plasma effect | 5c | t1af4 |
<?php
function prime($a) {
if (($a % 2 == 0 && $a != 2) || $a < 2)
return false;
$limit = sqrt($a);
for ($i = 2; $i <= $limit; $i++)
if ($a % $i == 0)
return false;
return true;
}
foreach (range(1, 100) as $x)
if (prime($x)) echo ;
?> | 425Primality by trial division | 12php | 3e8zq |
$ convert plasma.gif -coalesce plasma2.gif
$ eog plasma2.gif | 430Plasma effect | 0go | hymjq |
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
type playfairOption int
const (
noQ playfairOption = iota
iEqualsJ
)
type playfair struct {
keyword string
pfo playfairOption
table [5][5]byte
}
func (p *playfair) init() { | 431Playfair cipher | 0go | q44xz |
package main
import "github.com/fogleman/gg"
var palette = [2]string{
"FFFFFF", | 429Pinstripe/Display | 0go | yxs64 |
import Control.Monad (guard)
import Data.Array (Array, assocs, elems, listArray, (!))
import Data.Char (toUpper)
import Data.List (nub, (\\))
import Data.List.Split (chunksOf)
import Data.Maybe (listToMaybe)
import Data.String.Utils (replace)
type Square a = Array (Int, Int) a
arr... | 431Playfair cipher | 8haskell | mqqyf |
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import static java.awt.image.BufferedImage.*;
import static java.lang.Math.*;
import javax.swing.*;
public class PlasmaEffect extends JPanel {
float[][] plasma;
float hueShift = 0;
BufferedImage img;
public PlasmaEffect() {
D... | 430Plasma effect | 9java | x54wy |
import java.awt.*;
import javax.swing.*;
public class PinstripeDisplay extends JPanel {
final int bands = 4;
public PinstripeDisplay() {
setPreferredSize(new Dimension(900, 600));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
int h = getHei... | 429Pinstripe/Display | 9java | 5dtuf |
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<style>
canvas {
position: absolute;
top: 50%;
left: 50%;
width: 700px;
height: 500px;
margin: -250px 0 0 -350px;
}
body {
background-color: ... | 430Plasma effect | 10javascript | ojh86 |
import java.awt.Point;
import java.util.Scanner;
public class PlayfairCipher {
private static char[][] charTable;
private static Point[] positions;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String key = prompt("Enter an encryption key (min length 6): ",... | 431Playfair cipher | 9java | fppdv |
null | 429Pinstripe/Display | 11kotlin | c0o98 |
null | 430Plasma effect | 11kotlin | pclb6 |
_ = love.graphics
p1, p2, points = {}, {}, {}
function hypotenuse( a, b )
return a * a + b * b
end
function love.load()
size = _.getWidth()
currentTime, doub, half = 0, size * 2, size / 2
local b1, b2
for j = 0, size * 2 do
for i = 0, size * 2 do
b1 = math.floor( 128 + 127 * ( ... | 430Plasma effect | 1lua | 1l2po |
null | 431Playfair cipher | 11kotlin | 8770q |
function love.load()
WIDTH = love.graphics.getWidth()
ROW_HEIGHT = math.floor(love.graphics.getHeight()/4)
love.graphics.setBackgroundColor({0,0,0})
love.graphics.setLineWidth(1)
love.graphics.setLineStyle("rough")
end
function love.draw()
for j = 0, 3 do
for i = 0, WIDTH, (j+1)*2 do
... | 429Pinstripe/Display | 1lua | l8ick |
def prime(a):
return not (a < 2 or any(a% x == 0 for x in xrange(2, int(a**0.5) + 1))) | 425Primality by trial division | 3python | b95kr |
use Imager;
my($xsize,$ysize) = (640,400);
$img = Imager->new(xsize => $xsize, ysize => $ysize);
my $eps = 10**-14;
my $height = int $ysize / 4;
for my $width (1..4) {
$stripes = int((1-$eps) + $xsize / $width / 2);
@row = ((0) x $width, (1) x $width) x $stripes;
for $x (0..$
for $y (0..$height) {... | 429Pinstripe/Display | 2perl | x5gw8 |
use Imager;
sub plasma {
my ($w, $h) = @_;
my $img = Imager->new(xsize => $w, ysize => $h);
for my $x (0 .. $w-1) {
for my $y (0 .. $h-1) {
my $hue = 4 + sin($x/19) + sin($y/9) + sin(($x+$y)/25) + sin(sqrt($x**2 + $y**2)/8);
$img->setpixel(x => $x, y => $y, color => {hsv =... | 430Plasma effect | 2perl | yxq6u |
is.prime <- function(n) n == 2 || n > 2 && n %% 2 == 1 && (n < 9 || all(n %% seq(3, floor(sqrt(n)), 2) > 0))
which(sapply(1:100, is.prime)) | 425Primality by trial division | 13r | 73lry |
import math
import colorsys
from PIL import Image
def plasma (w, h):
out = Image.new(, (w, h))
pix = out.load()
for x in range (w):
for y in range(h):
hue = 4.0 + math.sin(x / 19.0) + math.sin(y / 9.0) \
+ math.sin((x + y) / 25.0) + math.sin(math.sqrt(x**2.0 + y**2.0) / 8.0)
hsv = colorsys.hsv_to_rgb(hu... | 430Plasma effect | 3python | mqsyh |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.