code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
import scala.util.Random
object QuickSelect {
def quickSelect[A <% Ordered[A]](seq: Seq[A], n: Int, rand: Random = new Random): A = {
val pivot = rand.nextInt(seq.length);
val (left, right) = seq.partition(_ < seq(pivot))
if (left.length == n) {
seq(pivot)
} else if (left.length < n) {
qu... | 387Quickselect algorithm | 16scala | 3wnzy |
set.seed(12345L)
result <- rnorm(1000, mean = 1, sd = 0.5) | 379Random numbers | 13r | h91jj |
conn <- file("notes.txt", "r")
while(length(line <- readLines(conn, 1)) > 0) {
cat(line, "\n")
} | 383Read a file line by line | 13r | coc95 |
str =
reversed = str.reverse | 366Reverse a string | 14ruby | r6igs |
class Queue {
private List buffer
public Queue(List buffer = new LinkedList()) {
assert buffer != null
assert buffer.empty
this.buffer = buffer
}
def push (def item) { buffer << item }
final enqueue = this.&push
def pop() {
if (this.empty) throw new NoSuchElem... | 391Queue/Definition | 7groovy | msiy5 |
null | 390Quaternion type | 11kotlin | r3cgo |
data Fifo a = F [a] [a]
emptyFifo :: Fifo a
emptyFifo = F [] []
push :: Fifo a -> a -> Fifo a
push (F input output) item = F (item:input) output
pop :: Fifo a -> (Maybe a, Fifo a)
pop (F input (item:output)) = (Just item, F input output)
pop (F [] [] ) = (Nothing, F [] [])
pop (F input [] ) = ... | 391Queue/Definition | 8haskell | eurai |
fullname = favouritefruit =
needspeeling = seedsremoved = false
otherfamily = []
IO.foreach() do |line|
line.chomp!
key, value = line.split(nil, 2)
case key
when /^([
when ; fullname = value
when ; favouritefruit = value
when ; needspeeling = true
when ; seedsremoved = true
when ; otherfamily = valu... | 374Read a configuration file | 14ruby | jmx7x |
def rangeexpand(txt):
lst = []
for r in txt.split(','):
if '-' in r[1:]:
r0, r1 = r[1:].split('-', 1)
lst += range(int(r[0] + r0), int(r1) + 1)
else:
lst.append(int(r))
return lst
print(rangeexpand('-6,-3--1,3-5,7-11,14,15,17-20')) | 385Range expansion | 3python | hmrjw |
let mut buffer = b"abcdef".to_vec();
buffer.reverse();
assert_eq!(buffer, b"fedcba"); | 366Reverse a string | 15rust | 7ynrc |
Quaternion = {}
function Quaternion.new( a, b, c, d )
local q = { a = a or 1, b = b or 0, c = c or 0, d = d or 0 }
local metatab = {}
setmetatable( q, metatab )
metatab.__add = Quaternion.add
metatab.__sub = Quaternion.sub
metatab.__unm = Quaternion.unm
metatab.__mul = Quaternion.mul
... | 390Quaternion type | 1lua | 76lru |
func select<T where T: Comparable>(var elements: [T], n: Int) -> T {
var r = indices(elements)
while true {
let pivotIndex = partition(&elements, r)
if n == pivotIndex {
return elements[pivotIndex]
} else if n < pivotIndex {
r.endIndex = pivotIndex
} else {
r.startIndex = pivotInde... | 387Quickselect algorithm | 17swift | nbsil |
Array.new(1000) { 1 + Math.sqrt(-2 * Math.log(rand)) * Math.cos(2 * Math::PI * rand) } | 379Random numbers | 14ruby | e5sax |
rangeExpand <- function(text) {
lst <- gsub("(\\d)-", "\\1:", unlist(strsplit(text, ",")))
unlist(sapply(lst, function (x) eval(parse(text=x))), use.names=FALSE)
}
rangeExpand("-6,-3--1,3-5,7-11,14,15,17-20")
[1] -6 -3 -2 -1 3 4 5 7 8 9 10 11 14 15 17 18 19 20 | 385Range expansion | 13r | gzu47 |
IO.foreach do |line|
puts line
end | 383Read a file line by line | 14ruby | 4z45p |
extern crate rand;
use rand::distributions::{Normal, IndependentSample};
fn main() {
let mut rands = [0.0; 1000];
let normal = Normal::new(1.0, 0.5);
let mut rng = rand::thread_rng();
for num in rands.iter_mut() {
*num = normal.ind_sample(&mut rng);
}
} | 379Random numbers | 15rust | w40e4 |
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::iter::FromIterator;
use std::path::Path;
fn main() {
let path = String::from("file.conf");
let cfg = config_from_file(path);
println!("{:?}", cfg);
}
fn config_from_file(path: String) -> Config {
let path = Path::new(&path);
... | 374Read a configuration file | 15rust | h9qj2 |
use std::io::{BufReader,BufRead};
use std::fs::File;
fn main() {
let file = File::open("file.txt").unwrap();
for line in BufReader::new(file).lines() {
println!("{}", line.unwrap());
}
} | 383Read a file line by line | 15rust | g3g4o |
public class Queue<E>{
Node<E> head = null, tail = null;
static class Node<E>{
E value;
Node<E> next;
Node(E value, Node<E> next){
this.value= value;
this.next= next;
}
}
public Queue(){
}
public void enqueue(E value){ | 391Queue/Definition | 9java | hm2jm |
val conf = scala.io.Source.fromFile("config.file").
getLines.
toList.
filter(_.trim.size > 0).
filterNot("#;" contains _(0)).
map(_ split(" ", 2) toList).
map(_ :+ "true" take 2).
map {
s:List[String] => (s(0).toLowerCase, s(1).split(",").map(_.trim).toList)
}.toMap | 374Read a configuration file | 16scala | p28bj |
import scala.io._
Source.fromFile("foobar.txt").getLines.foreach(println) | 383Read a file line by line | 16scala | jmj7i |
var fifo = [];
fifo.push(42); | 391Queue/Definition | 10javascript | avg10 |
List.fill(1000)(1.0 + 0.5 * scala.util.Random.nextGaussian) | 379Random numbers | 16scala | s7iqo |
def range_expand(rng)
rng.split(',').flat_map do |part|
if part =~ /^(-?\d+)-(-?\d+)$/
($1.to_i .. $2.to_i).to_a
else
Integer(part)
end
end
end
p range_expand('-6,-3--1,3-5,7-11,14,15,17-20') | 385Range expansion | 14ruby | bcjkq |
"asdf".reverse | 366Reverse a string | 16scala | kcthk |
use std::str::FromStr; | 385Range expansion | 15rust | plhbu |
def rangex(str: String): Seq[Int] =
str split "," flatMap { (s) =>
val r = """(-?\d+)(?:-(-?\d+))?""".r
val r(a,b) = s
if (b == null) Seq(a.toInt) else a.toInt to b.toInt
} | 385Range expansion | 16scala | eupab |
null | 391Queue/Definition | 11kotlin | 4ty57 |
Queue = {}
function Queue.new()
return { first = 0, last = -1 }
end
function Queue.push( queue, value )
queue.last = queue.last + 1
queue[queue.last] = value
end
function Queue.pop( queue )
if queue.first > queue.last then
return nil
end
local val = queue[queue.first]
queue[queue... | 391Queue/Definition | 1lua | gzm4j |
package Quaternion;
use List::Util 'reduce';
use List::MoreUtils 'pairwise';
sub make {
my $cls = shift;
if (@_ == 1) { return bless [ @_, 0, 0, 0 ] }
elsif (@_ == 4) { return bless [ @_ ] }
else { die "Bad number of components: @_" }
}
sub _abs { sqrt reduce { $a + $b * ... | 390Quaternion type | 2perl | dpxnw |
sub rangext {
my $str = join ' ', @_;
1 while $str =~ s{([+-]?\d+) ([+-]?\d+)}
{$1.(abs($2 - $1) == 1 ? '~' : ',').$2}eg;
$str =~ s/(\d+)~(?:[+-]?\d+~)+([+-]?\d+)/$1-$2/g;
$str =~ tr/~/,/;
return $str;
}
my @test = qw(0 1 2 4 6 7 8 11 12 14
15 16 17 18 19 20 21 22 23 24... | 386Range extraction | 2perl | 765rh |
func reverseString(s: String) -> String {
return String(s.characters.reverse())
}
print(reverseString("asdf"))
print(reverseString("asdf")) | 366Reverse a string | 17swift | g3o49 |
package main
import "fmt"
func main() {
a := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ta:=%q\n\tfmt.Printf(a, a)\n}\n"
fmt.Printf(a, a)
} | 389Quine | 0go | nbxi1 |
from collections import namedtuple
import math
class Q(namedtuple('Quaternion', 'real, i, j, k')):
'Quaternion type: Q(real=0.0, i=0.0, j=0.0, k=0.0)'
__slots__ = ()
def __new__(_cls, real=0.0, i=0.0, j=0.0, k=0.0):
'Defaults all parts of quaternion to zero'
return super().__new__(_cls,... | 390Quaternion type | 3python | f1qde |
s="s=%s;printf s,s.inspect()";printf s,s.inspect() | 389Quine | 7groovy | srpq1 |
library(quaternions)
q <- Q(1, 2, 3, 4)
q1 <- Q(2, 3, 4, 5)
q2 <- Q(3, 4, 5, 6)
r <- 7.0
display <- function(x){
e <- deparse(substitute(x))
res <- if(class(x) == "Q") paste(x$r, "+", x$i, "i+", x$j, "j+", x$k, "k", sep = "") else x
cat(noquote(paste(c(e, " = ", res, "\n"), collapse="")))
invisible(res)
}
di... | 390Quaternion type | 13r | oha84 |
use Carp;
sub mypush (\@@) {my($list,@things)=@_; push @$list, @things}
sub mypop (\@) {my($list)=@_; @$list or croak "Empty"; shift @$list }
sub empty (@) {not @_} | 391Queue/Definition | 2perl | ikao3 |
let q s = putStrLn (s ++ show s) in q "let q s = putStrLn (s ++ show s) in q " | 389Quine | 8haskell | udyv2 |
def range_extract(lst):
'Yield 2-tuple ranges or 1-tuple single elements from list of increasing ints'
lenlst = len(lst)
i = 0
while i< lenlst:
low = lst[i]
while i <lenlst-1 and lst[i]+1 == lst[i+1]: i +=1
hi = lst[i]
if hi - low >= 2:
yield (low, hi)
... | 386Range extraction | 3python | jy47p |
extract.range = function(v) {
r <- c(1, which(diff(v) != 1) + 1, length(v) + 1)
paste0(collapse=",",
v[head(r, -1)],
ifelse(diff(r) == 1,
"",
paste0(ifelse(diff(r) == 2, ",", "-"),
v[r[-1] - 1])))
}
print(extract.range(c(
-6, -3, -2, -1,... | 386Range extraction | 13r | 4t25y |
class Fifo {
private $data = array();
public function push($element){
array_push($this->data, $element);
}
public function pop(){
if ($this->isEmpty()){
throw new Exception('Attempt to pop from an empty queue');
}
return array_shift($this->data);
}
public function enqueue($element)... | 391Queue/Definition | 12php | r39ge |
class Quaternion
def initialize(*parts)
raise ArgumentError, unless parts.size == 4
raise ArgumentError, unless parts.all? {|x| x.is_a?(Numeric)}
@parts = parts
end
def to_a; @parts; end
def to_s; end
alias inspect to_s... | 390Quaternion type | 14ruby | ze0tw |
use std::fmt::{Display, Error, Formatter};
use std::ops::{Add, Mul, Neg};
#[derive(Clone,Copy,Debug)]
struct Quaternion {
a: f64,
b: f64,
c: f64,
d: f64
}
impl Quaternion {
pub fn new(a: f64, b: f64, c: f64, d: f64) -> Quaternion {
Quaternion {
a: a,
b: b,
... | 390Quaternion type | 15rust | 3w8z8 |
case class Quaternion(re: Double = 0.0, i: Double = 0.0, j: Double = 0.0, k: Double = 0.0) {
lazy val im = (i, j, k)
private lazy val norm2 = re*re + i*i + j*j + k*k
lazy val norm = math.sqrt(norm2)
def negative = Quaternion(-re, -i, -j, -k)
def conjugate = Quaternion(re, -i, -j, -k)
def reciprocal = Quate... | 390Quaternion type | 16scala | msnyc |
def range_extract(l)
sorted, range = l.sort.concat([Float::MAX]), []
canidate_number = sorted.first
sorted.each_cons(2) do |current_number, next_number|
if current_number.succ < next_number
if canidate_number == current_number
range << canidate_number.to_s
el... | 386Range extraction | 14ruby | k9rhg |
use std::ops::Add;
struct RangeFinder<'a, T: 'a> {
index: usize,
length: usize,
arr: &'a [T],
}
impl<'a, T> Iterator for RangeFinder<'a, T> where T: PartialEq + Add<i8, Output=T> + Copy {
type Item = (T, Option<T>);
fn next(&mut self) -> Option<Self::Item> {
if self.index == self.length {... | 386Range extraction | 15rust | bc7kx |
import Foundation
struct Quaternion {
var a, b, c, d: Double
static let i = Quaternion(a: 0, b: 1, c: 0, d: 0)
static let j = Quaternion(a: 0, b: 0, c: 1, d: 0)
static let k = Quaternion(a: 0, b: 0, c: 0, d: 1)
}
extension Quaternion: Equatable {
static func ==(lhs: Quaternion, rhs: Quaternion) -> Bool {
... | 390Quaternion type | 17swift | tasfl |
(function(){print("("+arguments.callee.toString().replace(/\s/g,'')+")()");})() | 389Quine | 9java | msdym |
object Range {
def spanRange(ls:List[Int])={
var last=ls.head
ls span {x => val b=x<=last+1; last=x; b}
}
def toRangeList(ls:List[Int]):List[List[Int]]=ls match {
case Nil => List()
case _ => spanRange(ls) match {
case (range, Nil) => List(range)
case (range, rest) => r... | 386Range extraction | 16scala | avk1n |
(function(){print("("+arguments.callee.toString().replace(/\s/g,'')+")()");})() | 389Quine | 10javascript | vn625 |
class FIFO(object):
def __init__(self, *args):
self.contents = list(args)
def __call__(self):
return self.pop()
def __len__(self):
return len(self.contents)
def pop(self):
return self.contents.pop(0)
def push(self, item):
self.con... | 391Queue/Definition | 3python | nbeiz |
empty <- function() length(l) == 0
push <- function(x)
{
l <<- c(l, list(x))
print(l)
invisible()
}
pop <- function()
{
if(empty()) stop("can't pop from an empty list")
l[[1]] <<- NULL
print(l)
invisible()
}
l <- list()
empty()
push(3)
push("abc")
push(matrix(1:6, nrow=2))
empty()... | 391Queue/Definition | 13r | 07bsg |
null | 389Quine | 11kotlin | ta0f0 |
import Darwin
func ranges(from ints:[Int]) -> [(Int, Int)] {
var range: (Int, Int)?
var ranges = [(Int, Int)]()
for this in ints {
if let (start, end) = range {
if this == end + 1 {
range = (start, this)
}
else {
ranges.append(range!)
range = (this, this)
}
}
else { range = (this, thi... | 386Range extraction | 17swift | hmgj0 |
require 'forwardable'
class FIFO
extend Forwardable
def self.[](*objects)
new.push(*objects)
end
def initialize; @ary = []; end
def push(*objects)
@ary.push(*objects)
self
end
alias << push
alias enqueue push
def_delegator:@ary, :shift, ... | 391Queue/Definition | 14ruby | f1xdr |
use std::collections::VecDeque;
fn main() {
let mut stack = VecDeque::new();
stack.push_back("Element1");
stack.push_back("Element2");
stack.push_back("Element3");
assert_eq!(Some(&"Element1"), stack.front());
assert_eq!(Some("Element1"), stack.pop_front());
assert_eq!(Some("Element2"), sta... | 391Queue/Definition | 15rust | taqfd |
class Queue[T] {
private[this] class Node[T](val value:T) {
var next:Option[Node[T]]=None
def append(n:Node[T])=next=Some(n)
}
private[this] var head:Option[Node[T]]=None
private[this] var tail:Option[Node[T]]=None
def isEmpty=head.isEmpty
def enqueue(item:T)={
val n=new Node(item)
if(isEm... | 391Queue/Definition | 16scala | 6x831 |
s=[[io.write('s=[','[',s,']','];',s)]];io.write('s=[','[',s,']','];',s) | 389Quine | 1lua | ze8ty |
static uint64_t state;
static const uint64_t STATE_MAGIC = 0x2545F4914F6CDD1D;
void seed(uint64_t num) {
state = num;
}
uint32_t next_int() {
uint64_t x;
uint32_t answer;
x = state;
x = x ^ (x >> 12);
x = x ^ (x << 25);
x = x ^ (x >> 27);
state = x;
answer = ((x * STATE_MAGIC) >> ... | 392Pseudo-random numbers/Xorshift star | 5c | ohp80 |
package main
import (
"fmt"
"math"
)
const CONST = 0x2545F4914F6CDD1D
type XorshiftStar struct{ state uint64 }
func XorshiftStarNew(state uint64) *XorshiftStar { return &XorshiftStar{state} }
func (xor *XorshiftStar) seed(state uint64) { xor.state = state }
func (xor *XorshiftStar) nextInt() uint32 {
... | 392Pseudo-random numbers/Xorshift star | 0go | 4t652 |
import Data.Bits
import Data.Word
import System.Random
import Data.List
newtype XorShift = XorShift Word64
instance RandomGen XorShift where
next (XorShift state) = (out newState, XorShift newState)
where
newState = (\z -> z `xor` (z `shiftR` 27)) .
(\z -> z `xor` (z `shiftL` 25)) .
... | 392Pseudo-random numbers/Xorshift star | 8haskell | qgjx9 |
public class XorShiftStar {
private static final long MAGIC = Long.parseUnsignedLong("2545F4914F6CDD1D", 16);
private long state;
public void seed(long num) {
state = num;
}
public int nextInt() {
long x;
int answer;
x = state;
x = x ^ (x >>> 12);
x... | 392Pseudo-random numbers/Xorshift star | 9java | plub3 |
const uint64_t N = 6364136223846793005;
static uint64_t state = 0x853c49e6748fea9b;
static uint64_t inc = 0xda3e39cb94b95bdb;
uint32_t pcg32_int() {
uint64_t old = state;
state = old * N + inc;
uint32_t shifted = (uint32_t)(((old >> 18) ^ old) >> 27);
uint32_t rot = old >> 59;
return (shifted >> r... | 393Pseudo-random numbers/PCG32 | 5c | 12upj |
long long seed;
long long random(){
seed = seed * seed / 1000 % 1000000;
return seed;
}
int main(){
seed = 675248;
for(int i=1;i<=5;i++)
printf(,random());
return 0;
} | 394Pseudo-random numbers/Middle-square method | 5c | taef4 |
import kotlin.math.floor
class XorShiftStar {
private var state = 0L
fun seed(num: Long) {
state = num
}
fun nextInt(): Int {
var x = state
x = x xor (x ushr 12)
x = x xor (x shl 25)
x = x xor (x ushr 27)
state = x
return (x * MAGIC shr 32).toI... | 392Pseudo-random numbers/Xorshift star | 11kotlin | 769r4 |
function create()
local g = {
magic = 0x2545F4914F6CDD1D,
state = 0,
seed = function(self, num)
self.state = num
end,
next_int = function(self)
local x = self.state
x = x ~ (x >> 12)
x = x ~ (x << 25)
x = x ~ (x >> 2... | 392Pseudo-random numbers/Xorshift star | 1lua | jyc71 |
int main(int argc, char **argv){
int a,b,c,d;
int r[N+1];
memset(r,0,sizeof(r));
for(a=1; a<=N; a++){
for(b=a; b<=N; b++){
int aabb;
if(a&1 && b&1) continue;
aabb=a*a + b*b;
for(c=b; c<=N; c++){
int aabbcc=aabb + c*c;
d=(int)sqrt((float)aabbcc);
if(aabbcc == d*d && d<=N) r[d]... | 395Pythagorean quadruples | 5c | 2iilo |
use strict;
use warnings;
no warnings 'portable';
use feature 'say';
use Math::AnyNum qw(:overload);
package Xorshift_star {
sub new {
my ($class, %opt) = @_;
bless {state => $opt{seed}}, $class;
}
sub next_int {
my ($self) = @_;
my $state = $self->{state};
$state ... | 392Pseudo-random numbers/Xorshift star | 2perl | f1wd7 |
typedef struct{
double x,y;
}point;
void pythagorasTree(point a,point b,int times){
point c,d,e;
c.x = b.x - (a.y - b.y);
c.y = b.y - (b.x - a.x);
d.x = a.x - (a.y - b.y);
d.y = a.y - (b.x - a.x);
e.x = d.x + ( b.x - a.x - (a.y - b.y) ) / 2;
e.y = d.y - ( b.x - a.x + a.y - b.y ) / 2;
if(times>0){
... | 396Pythagoras tree | 5c | plcby |
static uint64_t x;
uint64_t next() {
uint64_t z = (x += 0x9e3779b97f4a7c15);
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
return z ^ (z >> 31);
}
double next_float() {
return next() / pow(2.0, 64);
}
int main() {
int i, j;
x = 1234567;
for(i = 0; i < 5; ++i... | 397Pseudo-random numbers/Splitmix64 | 5c | w5vec |
package main
import "fmt"
func random(seed int) int {
return seed * seed / 1e3 % 1e6
}
func main() {
seed := 675248
for i := 1; i <= 5; i++ {
seed = random(seed)
fmt.Println(seed)
}
} | 394Pseudo-random numbers/Middle-square method | 0go | hm9jq |
findPseudoRandom :: Int -> Int
findPseudoRandom seed =
let square = seed * seed
squarestr = show square
enlarged = replicate ( 12 - length squarestr ) '0' ++ squarestr
in read $ take 6 $ drop 3 enlarged
solution :: [Int]
solution = tail $ take 6 $ iterate findPseudoRandom 675248 | 394Pseudo-random numbers/Middle-square method | 8haskell | ikbor |
mask64 = (1 << 64) - 1
mask32 = (1 << 32) - 1
const = 0x2545F4914F6CDD1D
class Xorshift_star():
def __init__(self, seed=0):
self.state = seed & mask64
def seed(self, num):
self.state = num & mask64
def next_int(self):
x = self.state
x = (x ^ (x >> 12)) & mask6... | 392Pseudo-random numbers/Xorshift star | 3python | taxfw |
package main
import (
"fmt"
"math"
)
const CONST = 6364136223846793005
type Pcg32 struct{ state, inc uint64 }
func Pcg32New() *Pcg32 { return &Pcg32{0x853c49e6748fea9b, 0xda3e39cb94b95bdb} }
func (pcg *Pcg32) seed(seedState, seedSequence uint64) {
pcg.state = 0
pcg.inc = (seedSequence << 1) | 1
... | 393Pseudo-random numbers/PCG32 | 0go | yq064 |
package main
import (
"fmt"
"math"
)
type Splitmix64 struct{ state uint64 }
func Splitmix64New(state uint64) *Splitmix64 { return &Splitmix64{state} }
func (sm64 *Splitmix64) nextInt() uint64 {
sm64.state += 0x9e3779b97f4a7c15
z := sm64.state
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9
z = (z ^... | 397Pseudo-random numbers/Splitmix64 | 0go | c8s9g |
$s = q($s = q(%s); printf($s, $s);
); printf($s, $s); | 389Quine | 2perl | k95hc |
import Data.Bits
import Data.Word
import System.Random
import Data.List
data PCGen = PCGen !Word64 !Word64
mkPCGen state sequence =
let
n = 6364136223846793005 :: Word64
inc = (sequence `shiftL` 1) .|. 1 :: Word64
in PCGen ((inc + state)*n + inc) inc
instance RandomGen PCGen where
next (PCGen stat... | 393Pseudo-random numbers/PCG32 | 8haskell | hmcju |
import Data.Bits
import Data.Word
import Data.List
next :: Word64 -> (Word64, Word64)
next state = f4 $ state + 0x9e3779b97f4a7c15
where
f1 z = (z `xor` (z `shiftR` 30)) * 0xbf58476d1ce4e5b9
f2 z = (z `xor` (z `shiftR` 27)) * 0x94d049bb133111eb
f3 z = z `xor` (z `shiftR` 31)
f4 s = ((f3 . f2 . f1) s,... | 397Pseudo-random numbers/Splitmix64 | 8haskell | pl9bt |
use strict;
use warnings;
sub msq
{
use feature qw( state );
state $seed = 675248;
$seed = sprintf "%06d", $seed ** 2 / 1000 % 1e6;
}
print msq, "\n" for 1 .. 5; | 394Pseudo-random numbers/Middle-square method | 2perl | yqs6u |
public class PCG32 {
private static final long N = 6364136223846793005L;
private long state = 0x853c49e6748fea9bL;
private long inc = 0xda3e39cb94b95bdbL;
public void seed(long seedState, long seedSequence) {
state = 0;
inc = (seedSequence << 1) | 1;
nextInt();
state = ... | 393Pseudo-random numbers/PCG32 | 9java | 5fzuf |
use strict;
use warnings;
no warnings 'portable';
use feature 'say';
use Math::AnyNum qw(:overload);
package splitmix64 {
sub new {
my ($class, %opt) = @_;
bless {state => $opt{seed}}, $class;
}
sub next_int {
my ($self) = @_;
my $next = $self->{state} = ($self->{state} + ... | 397Pseudo-random numbers/Splitmix64 | 2perl | 07gs4 |
seed = 675248
def random():
global seed
s = str(seed ** 2)
while len(s) != 12:
s = + s
seed = int(s[3:9])
return seed
for i in range(0,5):
print(random()) | 394Pseudo-random numbers/Middle-square method | 3python | ms0yh |
class Xorshift_star
MASK64 = (1 << 64) - 1
MASK32 = (1 << 32) - 1
def initialize(seed = 0) = @state = seed & MASK64
def next_int
x = @state
x = x ^ (x >> 12)
x = (x ^ (x << 25)) & MASK64
x = x ^ (x >> 27)
@state = x
(((x * 0x2545F4914F6CDD1D) & MASK64) >> 32) & MASK32
end
def ... | 392Pseudo-random numbers/Xorshift star | 14ruby | 3wsz7 |
<?php $p = '<?php $p =%c%s%c; printf($p,39,$p,39);?>
'; printf($p,39,$p,39); ?> | 389Quine | 12php | 3wozq |
import kotlin.math.floor
class PCG32 {
private var state = 0x853c49e6748fea9buL
private var inc = 0xda3e39cb94b95bdbuL
fun nextInt(): UInt {
val old = state
state = old * N + inc
val shifted = old.shr(18).xor(old).shr(27).toUInt()
val rot = old.shr(59)
return (shift... | 393Pseudo-random numbers/PCG32 | 11kotlin | c8i98 |
package main
import "fmt"
const (
N = 2200
N2 = N * N * 2
)
func main() {
s := 3
var s1, s2 int
var r [N + 1]bool
var ab [N2 + 1]bool
for a := 1; a <= N; a++ {
a2 := a * a
for b := a; b <= N; b++ {
ab[a2 + b * b] = true
}
}
for c := 1; ... | 395Pythagorean quadruples | 0go | qggxz |
package main
import (
"image"
"image/color"
"image/draw"
"image/png"
"log"
"os"
)
const (
width, height = 800, 600
maxDepth = 11 | 396Pythagoras tree | 0go | 6xw3p |
def middle_square (seed)
return to_enum(__method__, seed) unless block_given?
s = seed.digits.size
loop { yield seed = (seed*seed).to_s.rjust(s*2, )[s/2, s].to_i }
end
puts middle_square(675248).take(5) | 394Pseudo-random numbers/Middle-square method | 14ruby | c8o9k |
function uint32(n)
return n & 0xffffffff
end
function uint64(n)
return n & 0xffffffffffffffff
end
N = 6364136223846793005
state = 0x853c49e6748fea9b
inc = 0xda3e39cb94b95bdb
function pcg32_seed(seed_state, seed_sequence)
state = 0
inc = (seed_sequence << 1) | 1
pcg32_int()
state = state + see... | 393Pseudo-random numbers/PCG32 | 1lua | lonck |
powersOfTwo :: [Int]
powersOfTwo = iterate (2 *) 1
unrepresentable :: [Int]
unrepresentable = merge powersOfTwo ((5 *) <$> powersOfTwo)
merge :: [Int] -> [Int] -> [Int]
merge xxs@(x:xs) yys@(y:ys)
| x < y = x: merge xs yys
| otherwise = y: merge xxs ys
main :: IO ()
main = do
putStrLn "The values of d <= 2200 ... | 395Pythagorean quadruples | 8haskell | mssyf |
mkBranches :: [(Float,Float)] -> [[(Float,Float)]]
mkBranches [a, b, c, d] = let d = 0.5 <*> (b <+> (-1 <*> a))
l1 = d <+> orth d
l2 = orth l1
in
[ [a <+> l2, b <+> (2 <*> l2), a <+> l1, a]
, [a ... | 396Pythagoras tree | 8haskell | jy67g |
import Foundation
struct XorshiftStar {
private let magic: UInt64 = 0x2545F4914F6CDD1D
private var state: UInt64
init(seed: UInt64) {
state = seed
}
mutating func nextInt() -> UInt64 {
state ^= state &>> 12
state ^= state &<< 25
state ^= state &>> 27
return (state &* magic) &>> 32
}
... | 392Pseudo-random numbers/Xorshift star | 17swift | zeqtu |
int64_t mod(int64_t x, int64_t y) {
int64_t m = x % y;
if (m < 0) {
if (y < 0) {
return m - y;
} else {
return m + y;
}
}
return m;
}
const static int64_t a1[3] = { 0, 1403580, -810728 };
const static int64_t m1 = (1LL << 32) - 209;
const static int64_... | 398Pseudo-random numbers/Combined recursive generator MRG32k3a | 5c | c8q9c |
use strict;
use warnings;
use feature 'say';
use Math::AnyNum qw(:overload);
package PCG32 {
use constant {
mask32 => 2**32 - 1,
mask64 => 2**64 - 1,
const => 6364136223846793005,
};
sub new {
my ($class, %opt) = @_;
my $seed = $opt{seed} // 1;
my $incr = ... | 393Pseudo-random numbers/PCG32 | 2perl | x4rw8 |
import java.util.ArrayList;
import java.util.List;
public class PythagoreanQuadruples {
public static void main(String[] args) {
long d = 2200;
System.out.printf("Values of d <%d where a, b, and c are non-zero and a^2 + b^2 + c^2 = d^2 has no solutions:%n%s%n", d, getPythagoreanQuadruples(d));
... | 395Pythagorean quadruples | 9java | f11dv |
MASK64 = (1 << 64) - 1
C1 = 0x9e3779b97f4a7c15
C2 = 0xbf58476d1ce4e5b9
C3 = 0x94d049bb133111eb
class Splitmix64():
def __init__(self, seed=0):
self.state = seed & MASK64
def seed(self, num):
self.state = num & MASK64
def next_int(self):
z = self.state = (self.state + ... | 397Pseudo-random numbers/Splitmix64 | 3python | 8jr0o |
(() => {
'use strict'; | 395Pythagorean quadruples | 10javascript | yqq6r |
mask64 = (1 << 64) - 1
mask32 = (1 << 32) - 1
CONST = 6364136223846793005
class PCG32():
def __init__(self, seed_state=None, seed_sequence=None):
if all(type(x) == int for x in (seed_state, seed_sequence)):
self.seed(seed_state, seed_sequence)
else:
self.state = self.inc =... | 393Pseudo-random numbers/PCG32 | 3python | qg7xi |
import java.awt.*;
import java.awt.geom.Path2D;
import javax.swing.*;
public class PythagorasTree extends JPanel {
final int depthLimit = 7;
float hue = 0.15f;
public PythagorasTree() {
setPreferredSize(new Dimension(640, 640));
setBackground(Color.white);
}
private void drawTree(... | 396Pythagoras tree | 9java | udnvv |
null | 395Pythagorean quadruples | 11kotlin | 8jj0q |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.