code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
def eulers_sum_of_powers():
max_n = 250
pow_5 = [n**5 for n in range(max_n)]
pow5_to_n = {n**5: n for n in range(max_n)}
for x0 in range(1, max_n):
for x1 in range(1, x0):
for x2 in range(1, x1):
for x3 in range(1, x2):
pow_5_sum = sum(pow_5[i] for... | 892Euler's sum of powers conjecture | 3python | c7a9q |
use feature 'say';
use ntheory qw(forprimes is_prime);
sub emirp_list {
my $count = shift;
my($i, $inc, @n) = (13, 100+10*$count);
while (@n < $count) {
forprimes {
push @n, $_ if is_prime(reverse $_) && $_ ne reverse($_);
} $i, $i+$inc-1;
($i, $inc) = ($i+$inc, int($inc * 1.03) + 1000);
}
... | 903Emirp primes | 2perl | 5pju2 |
null | 902Even or odd | 11kotlin | szdq7 |
<?php
function is_prime($n) {
if ($n <= 3) {
return $n > 1;
} elseif (($n % 2 == 0) or ($n % 3 == 0)) {
return false;
}
$i = 5;
while ($i * $i <= $n) {
if ($n % $i == 0) {
return false;
}
$i += 2;
if ($n % $i == 0) {
return fal... | 903Emirp primes | 12php | oyt85 |
String s = "";
if(s != null && s.isEmpty()){ | 904Empty string | 9java | qtoxa |
var s = "";
var s = new String(); | 904Empty string | 10javascript | imtol |
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Mult{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int first = sc.nextInt();
int second = sc.nextInt();
if(first < 0){
first = -first;
second = -second;
}
Ma... | 901Ethiopian multiplication | 9java | re1g0 |
var eth = {
halve : function ( n ){ return Math.floor(n/2); },
double: function ( n ){ return 2*n; },
isEven: function ( n ){ return n%2 === 0); },
mult: function ( a , b ){
var sum = 0, a = [a], b = [b];
while ( a[0] !== 1 ){
a.unshift( eth.halve( a[0] ) );
b.unshift( eth.double... | 901Ethiopian multiplication | 10javascript | b0qki |
from __future__ import print_function
from prime_decomposition import primes, is_prime
from heapq import *
from itertools import islice
def emirp():
largest = set()
emirps = []
heapify(emirps)
for pr in primes():
while emirps and pr > emirps[0]:
yield heappop(emirps)
if pr i... | 903Emirp primes | 3python | 41h5k |
fun main(args: Array<String>) {
val s = ""
println(s.isEmpty()) | 904Empty string | 11kotlin | 1oxpd |
sub entropy {
my %count; $count{$_}++ for @_;
my $entropy = 0;
for (values %count) {
my $p = $_/@_;
$entropy -= $p * log $p;
}
$entropy / log 2
}
print entropy split //, "1223334444"; | 900Entropy | 2perl | wdne6 |
power5 = (1..250).each_with_object({}){|i,h| h[i**5]=i}
result = power5.keys.repeated_combination(4).select{|a| power5[a.inject(:+)]}
puts result.map{|a| a.map{|i| }.join(' + ') + } | 892Euler's sum of powers conjecture | 14ruby | 2hwlw |
import math
math.factorial(n) | 882Factorial | 3python | 3uszc |
library(gmp)
emirp <- function(start = 1, end = Inf, howmany = Inf, ignore = 0) {
count <- 0
p <- start
while (count<howmany+ignore && p <= end) {
p <- nextprime(p)
p_reverse <- as.bigz(paste0(rev(unlist(strsplit(as.character(p), ""))), collapse = ""))
if (p != p_reverse && isprime(p_reverse) > 0) {
if (... | 903Emirp primes | 13r | 2hglg |
package main
func main() { } | 905Empty program | 0go | p8ebg |
null | 905Empty program | 7groovy | 7wkrz |
<?php
function shannonEntropy($string) {
$h = 0.0;
$len = strlen($string);
foreach (count_chars($string, 1) as $count) {
$h -= (double) ($count / $len) * log((double) ($count / $len), 2);
}
return $h;
}
$strings = array(
'1223334444',
'1225554444',
'aaBBcccDDDD',
'122333444... | 900Entropy | 12php | lj7cj |
main = return () | 905Empty program | 8haskell | fl3d1 |
const MAX_N: u64 = 250;
fn eulers_sum_of_powers() -> (usize, usize, usize, usize, usize) {
let pow5: Vec<u64> = (0..MAX_N).map(|i| i.pow(5)).collect();
let pow5_to_n = |pow| pow5.binary_search(&pow);
for x0 in 1..MAX_N as usize {
for x1 in 1..x0 {
for x2 in 1..x1 {
for ... | 892Euler's sum of powers conjecture | 15rust | vkx2t |
null | 901Ethiopian multiplication | 11kotlin | vkj21 |
import scala.collection.Searching.{Found, search}
object EulerSopConjecture extends App {
val (maxNumber, fifth) = (250, (1 to 250).map { i => math.pow(i, 5).toLong })
def binSearch(fact: Int*) = fifth.search(fact.map(f => fifth(f)).sum)
def sop = (0 until maxNumber)
.flatMap(a => (a until maxNumber)
... | 892Euler's sum of powers conjecture | 16scala | 41050 |
null | 902Even or odd | 1lua | 03fsd |
require 'prime'
emirp = Enumerator.new do |y|
Prime.each do |prime|
rev = prime.to_s.reverse.to_i
y << prime if rev.prime? and rev!= prime
end
end
puts , emirp.first(20).join()
puts
emirp.with_index(1) do |prime,i|
print if (7700..8000).cover?(prime)
if i==10000
puts , , prime
break
end
... | 903Emirp primes | 14ruby | rebgs |
fact <- function(n) {
if (n <= 1) 1
else n * Recall(n - 1)
} | 882Factorial | 13r | dcent |
#![feature(iterator_step_by)]
extern crate primal;
fn is_prime(n: u64) -> bool {
if n == 2 || n == 3 || n == 5 || n == 7 || n == 11 || n == 13 { return true; }
if n% 2 == 0 || n% 3 == 0 || n% 5 == 0 || n% 7 == 0 || n% 11 == 0 || n% 13 == 0 { return false; }
let root = (n as f64).sqrt() as u64 + 1;
(17... | 903Emirp primes | 15rust | 7wprc |
def isEmirp( v:Long ) : Boolean = {
val b = BigInt(v.toLong)
val r = BigInt(v.toString.reverse.toLong)
b != r && b.isProbablePrime(16) && r.isProbablePrime(16)
} | 903Emirp primes | 16scala | ksehk |
null | 904Empty string | 1lua | aiq1v |
from __future__ import division
import math
def hist(source):
hist = {}; l = 0;
for e in source:
l += 1
if e not in hist:
hist[e] = 0
hist[e] += 1
return (l,hist)
def entropy(hist,l):
elist = []
for v in hist.values():
c = v / l
elist.append(-c *... | 900Entropy | 3python | xfdwr |
public class EmptyApplet extends java.applet.Applet {
@Override public void init() {
}
} | 905Empty program | 9java | 03ise |
null | 905Empty program | 10javascript | dcznu |
entropy = function(s)
{freq = prop.table(table(strsplit(s, '')[1]))
-sum(freq * log(freq, base = 2))}
print(entropy("1223334444")) | 900Entropy | 13r | 1o8pn |
extension BinaryInteger {
@inlinable
public func power(_ n: Self) -> Self {
return stride(from: 0, to: n, by: 1).lazy.map({_ in self }).reduce(1, *)
}
}
func sumOfPowers(maxN: Int = 250) -> (Int, Int, Int, Int, Int) {
let pow5 = (0..<maxN).map({ $0.power(5) })
let pow5ToN = {n in pow5.firstIndex(of: n)}
... | 892Euler's sum of powers conjecture | 17swift | ljec2 |
import Foundation
extension BinaryInteger {
var isPrime: Bool {
if self == 0 || self == 1 {
return false
} else if self == 2 {
return true
}
let max = Self(ceil((Double(self).squareRoot())))
for i in stride(from: 2, through: max, by: 1) where self% i == 0 {
return false
}... | 903Emirp primes | 17swift | gak49 |
function halve(a)
return a/2
end
function double(a)
return a*2
end
function isEven(a)
return a%2 == 0
end
function ethiopian(x, y)
local result = 0
while (x >= 1) do
if not isEven(x) then
result = result + y
end
x = math.floor(halve(x))
y = double(y)
... | 901Ethiopian multiplication | 1lua | ubhvl |
fun main(a: Array<String>) {} | 905Empty program | 11kotlin | enqa4 |
def entropy(s)
counts = Hash.new(0.0)
s.each_char { |c| counts[c] += 1 }
leng = s.length
counts.values.reduce(0) do |entropy, count|
freq = count / leng
entropy - freq * Math.log2(freq)
end
end
p entropy() | 900Entropy | 14ruby | sztqw |
fn entropy(s: &[u8]) -> f32 {
let mut histogram = [0u64; 256];
for &b in s {
histogram[b as usize] += 1;
}
histogram
.iter()
.cloned()
.filter(|&h| h!= 0)
.map(|h| h as f32 / s.len() as f32)
.map(|ratio| -ratio * ratio.log2())
.sum()
}
fn main()... | 900Entropy | 15rust | 03zsl |
import scala.math._
def entropy( v:String ) = { v
.groupBy (a => a)
.values
.map( i => i.length.toDouble / v.length )
.map( p => -p * log10(p) / log10(2))
.sum
} | 900Entropy | 16scala | imyox |
null | 905Empty program | 1lua | wdsea |
import Foundation
func entropy(of x: String) -> Double {
return x
.reduce(into: [String: Int](), {cur, char in
cur[String(char), default: 0] += 1
})
.values
.map({i in Double(i) / Double(x.count) } as (Int) -> Double)
.map({p in -p * log2(p) } as (Double) -> Double)
.reduce(0.0, +)
}
p... | 900Entropy | 17swift | qtfxg |
def factorial_recursive(n)
n.zero?? 1: n * factorial_recursive(n - 1)
end
def factorial_tail_recursive(n, prod = 1)
n.zero?? prod: factorial_tail_recursive(n - 1, prod * n)
end
def factorial_iterative(n)
(2...n).each { |i| n *= i }
n.zero?? 1: n
end
def factorial_inject(n)
(1..n).inject(1){ |prod, i| pr... | 882Factorial | 14ruby | y486n |
for(0..10){
print "$_ is ", qw(even odd)[$_ % 2],"\n";
} | 902Even or odd | 2perl | ubjvr |
if ($s eq "") {
print "The string is empty";
}
if ($s ne "") {
print "The string is not empty";
} | 904Empty string | 2perl | mg2yz |
<?php
$str = '';
if (empty($str)) { ... }
if (! empty($str)) { ... }
if ($str == '') { ... }
if ($str != '') { ... }
if (strlen($str) == 0) { ... }
if (strlen($str) != 0) { ... } | 904Empty string | 12php | ensa9 |
fn factorial_recursive (n: u64) -> u64 {
match n {
0 => 1,
_ => n * factorial_recursive(n-1)
}
}
fn factorial_iterative(n: u64) -> u64 {
(1..=n).product()
}
fn main () {
for i in 1..10 {
println!("{}", factorial_recursive(i))
}
for i in 1..10 {
println!("{}", fa... | 882Factorial | 15rust | mgoya |
echo (2 & 1)? 'odd' : 'even';
echo (3 & 1)? 'odd' : 'even';
echo (3 % 2)? 'odd' : 'even';
echo (4 % 2)? 'odd' : 'even'; | 902Even or odd | 12php | 86t0m |
def factorial(n: Int)={
var res = 1
for(i <- 1 to n)
res *= i
res
} | 882Factorial | 16scala | ljdcq |
s = ''
s = str()
if not s or s == '':
print()
if len(s) == 0:
print()
else:
print()
def emptystring(s):
if isinstance(s, (''.__class__ , u''.__class__) ):
if len(s) == 0:
return True
else
return False
elif s is None:
return True | 904Empty string | 3python | 9rvmf |
s <- ''
if (s == '') cat('Empty\n')
if (nchar(s) == 0) cat('Empty\n')
if (s!= '') cat('Not empty\n')
if (nchar(s) > 0) cat('Not empty\n') | 904Empty string | 13r | 3u9zt |
>>> def is_odd(i): return bool(i & 1)
>>> def is_even(i): return not is_odd(i)
>>> [(j, is_odd(j)) for j in range(10)]
[(0, False), (1, True), (2, False), (3, True), (4, False), (5, True), (6, False), (7, True), (8, False), (9, True)]
>>> [(j, is_even(j)) for j in range(10)]
[(0, True), (1, False), (2, True), (3, Fal... | 902Even or odd | 3python | 5phux |
typedef int bool;
int compareInts(const void *a, const void *b) {
int aa = *(int *)a;
int bb = *(int *)b;
return aa - bb;
}
bool contains(int a[], int b, size_t len) {
int i;
for (i = 0; i < len; ++i) {
if (a[i] == b) return TRUE;
}
return FALSE;
}
int gcd(int a, int b) {
whil... | 906EKG sequence convergence | 5c | ljvcy |
is.even <- function(x)!is.odd(x)
is.odd <- function(x) intToBits(x)[1] == 1
is.odd <- function(x) x%% 2 == 1 | 902Even or odd | 13r | ljgce |
package main
import (
"fmt"
"sort"
)
func contains(a []int, b int) bool {
for _, j := range a {
if j == b {
return true
}
}
return false
}
func gcd(a, b int) int {
for a != b {
if a > b {
a -= b
} else {
b -= a
}
... | 906EKG sequence convergence | 0go | xfswf |
import Data.List (findIndex, isPrefixOf, tails)
import Data.Maybe (fromJust)
seqEKGRec :: Int -> Int -> [Int] -> [Int]
seqEKGRec _ 0 l = l
seqEKGRec k n [] = seqEKGRec k (n - 2) [k, 1]
seqEKGRec k n l@(h: t) =
seqEKGRec
k
(pred n)
( head
( filter
(((&&) . flip notElem l) <*> ((1 <) ... | 906EKG sequence convergence | 8haskell | y4966 |
null | 905Empty program | 2perl | c7v9a |
main. | 905Empty program | 12php | xf0w5 |
s =
s = String.new
s = ; s.clear | 904Empty string | 14ruby | lj5cl |
print
p -5.upto(5).select(&:even?)
print
p -5.upto(5).select(&:odd?) | 902Even or odd | 14ruby | gab4q |
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EKGSequenceConvergence {
public static void main(String[] args) {
System.out.println("Calculate and show here the first 10 members of EKG[2], EKG[5], EKG[7], EKG[9]... | 906EKG sequence convergence | 9java | dctn9 |
let s = "";
println!("is empty: {}", s.is_empty());
let t = "x";
println!("is empty: {}", t.is_empty());
let a = String::new();
println!("is empty: {}", a.is_empty());
let b = "x".to_string();
println!("is empty: {}", b.is_empty());
println!("is not empty: {}",!b.is_empty()); | 904Empty string | 15rust | 2h4lt |
null | 904Empty string | 16scala | 5p7ut |
use strict;
sub halve { int((shift) / 2); }
sub double { (shift) * 2; }
sub iseven { ((shift) & 1) == 0; }
sub ethiopicmult
{
my ($plier, $plicand, $tutor) = @_;
print "ethiopic multiplication of $plier and $plicand\n" if $tutor;
my $r = 0;
while ($plier >= 1)
{
$r += $plicand unless iseven($plie... | 901Ethiopian multiplication | 2perl | 03ts4 |
let is_odd = |x: i32| x & 1 == 1;
let is_even = |x: i32| x & 1 == 0; | 902Even or odd | 15rust | repg5 |
def isEven( v:Int ) : Boolean = v % 2 == 0
def isOdd( v:Int ) : Boolean = v % 2 != 0 | 902Even or odd | 16scala | hqeja |
null | 906EKG sequence convergence | 11kotlin | 03osf |
<?php
function halve($x)
{
return floor($x/2);
}
function double($x)
{
return $x*2;
}
function iseven($x)
{
return !($x & 0x1);
}
function ethiopicmult($plier, $plicand, $tutor)
{
if ($tutor) echo ;
$r = 0;
while($plier >= 1) {
if ( !iseven($plier) ) $r += $plicand;
if ($tutor)
echo , (isev... | 901Ethiopian multiplication | 12php | 5pkus |
void wait_for_zombie(int s)
{
while(waitpid(-1, NULL, WNOHANG) > 0) ;
}
void echo_lines(int csock)
{
char buf[BUF_LEN];
int r;
while( (r = read(csock, buf, BUF_LEN)) > 0 ) {
(void)write(csock, buf, r);
}
exit(EXIT_SUCCESS);
}
void take_connections_forever(int ssock)
{
for(... | 907Echo server | 5c | 7wjrg |
package main
import (
"fmt"
"strings"
)
func btoi(b bool) int {
if b {
return 1
}
return 0
}
func evolve(l, rule int) {
fmt.Printf(" Rule #%d:\n", rule)
cells := "O"
for x := 0; x < l; x++ {
cells = addNoCells(cells)
width := 40 + (len(cells) >> 1)
fmt.... | 908Elementary cellular automaton/Infinite length | 0go | jxj7d |
use List::Util qw(none sum);
sub gcd { my ($u,$v) = @_; $v ? gcd($v, $u%$v) : abs($u) }
sub shares_divisors_with { gcd( $_[0], $_[1]) > 1 }
sub EKG {
my($n,$limit) = @_;
my @ekg = (1, $n);
while (@ekg < $limit) {
for my $i (2..1e18) {
next unless none { $_ == $i } @ekg and shares_divis... | 906EKG sequence convergence | 2perl | 5pgu2 |
import Control.Comonad
import Data.InfList (InfList (..), (+++))
import qualified Data.InfList as Inf
data Cells a = Cells (InfList a) a (InfList a) deriving Functor
view n (Cells l x r) = reverse (Inf.take n l) ++ [x] ++ (Inf.take n r)
fromList [] = fromList [0]
fromList (x:xs) = let zeros = Inf.repeat 0
... | 908Elementary cellular automaton/Infinite length | 8haskell | oyo8p |
var s = ""
if s.isEmpty { | 904Empty string | 17swift | c7u9t |
1
QUIT | 905Empty program | 3python | ljucv |
(use '[clojure.contrib.server-socket :only (create-server)])
(use '[clojure.contrib.duck-streams :only (read-lines write-lines)])
(defn echo [input output]
(write-lines (java.io.PrintWriter. output true) (read-lines input)))
(create-server 12321 echo) | 907Echo server | 6clojure | p81bd |
null | 908Elementary cellular automaton/Infinite length | 11kotlin | b0bkb |
from itertools import count, islice, takewhile
from math import gcd
def EKG_gen(start=2):
c = count(start + 1)
last, so_far = start, list(range(2, start))
yield 1, []
yield last, []
while True:
for index, sf in enumerate(so_far):
if gcd(last, sf) > 1:
last =... | 906EKG sequence convergence | 3python | 41r5k |
null | 905Empty program | 13r | y4c6h |
sub evolve {
my ($rule, $pattern) = @_;
my $offset = 0;
while (1) {
my ($l, $r, $st);
$pattern =~ s/^((.)\g2*)/$2$2/ and $l = $2, $offset -= length($2);
$pattern =~ s/(.)\g1*$/$1$1/ and $r = $1;
$st = $pattern;
$pattern =~ tr/01/.
printf "%5d|%s%s\n", $offset, ' ' x (40 + $offset), $pattern;
$pat... | 908Elementary cellular automaton/Infinite length | 2perl | 65636 |
-- Setup a table with some integers
CREATE TABLE ints(INT INTEGER);
INSERT INTO ints VALUES (-1);
INSERT INTO ints VALUES (0);
INSERT INTO ints VALUES (1);
INSERT INTO ints VALUES (2);
-- Are they even or odd?
SELECT
INT,
CASE MOD(INT, 2) WHEN 0 THEN 'Even' ELSE 'Odd' END
FROM
ints; | 902Even or odd | 19sql | p8qb1 |
package main
import "fmt"
func main() {
tree := eertree([]byte("eertree"))
fmt.Println(subPalindromes(tree))
}
type edges map[byte]int
type node struct {
length int
edges
suffix int
}
const evenRoot = 0
const oddRoot = 1
func eertree(s []byte) []node {
tree := []node{
evenRoot: {le... | 909Eertree | 0go | uk2vt |
typedef unsigned long long ull;
void evolve(ull state, int rule)
{
int i;
ull st;
printf(, rule);
do {
st = state;
for (i = N; i--; ) putchar(st & B(i) ? '
putchar('\n');
for (state = i = 0; i < N; i++)
if (rule & B(7 & (st>>(i-1) | st<<(N+1-i))))
state |= B(i);
} while (st != state);
}
int ma... | 910Elementary cellular automaton | 5c | d9onv |
def _notcell(c):
return '0' if c == '1' else '1'
def eca_infinite(cells, rule):
lencells = len(cells)
rulebits = '{0:08b}'.format(rule)
neighbours2next = {'{0:03b}'.format(n):rulebits[::-1][n] for n in range(8)}
c = cells
while True:
yield c
c = _notcell(c[0])*2 + c + _notcell(c... | 908Elementary cellular automaton/Infinite length | 3python | y4y6q |
null | 905Empty program | 14ruby | vk42n |
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Eertree {
public static void main(String[] args) {
List<Node> tree = eertree("eertree");
List<String> result = subPalindromes(tree);
System.out.println(result);
}
private... | 909Eertree | 9java | kqjhm |
func isEven(n:Int) -> Bool { | 902Even or odd | 17swift | 41k5g |
def notcell(c)
c.tr('01','10')
end
def eca_infinite(cells, rule)
neighbours2next = Hash[8.times.map{|i|[%i, [rule[i]]]}]
c = cells
Enumerator.new do |y|
loop do
y << c
c = notcell(c[0])*2 + c + notcell(c[-1])*2
c = (1..c.size-2).map{|i| neighbours2next[c[i-1..i+1]]}.join
end
... | 908Elementary cellular automaton/Infinite length | 14ruby | 9r9mz |
fn main(){} | 905Empty program | 15rust | ubgvj |
object emptyProgram extends App {} | 905Empty program | 16scala | gaj4i |
null | 909Eertree | 11kotlin | g154d |
func factorial(_ n: Int) -> Int {
return n < 2? 1: (2...n).reduce(1, *)
} | 882Factorial | 17swift | 6503j |
package main
import (
"fmt"
"rcu"
)
func main() {
limit := int(1e9)
gapStarts := make(map[int]int)
primes := rcu.Primes(limit * 5)
for i := 1; i < len(primes); i++ {
gap := primes[i] - primes[i-1]
if _, ok := gapStarts[gap]; !ok {
gapStarts[gap] = primes[i-1]
... | 911Earliest difference between prime gaps | 0go | 9g3mt |
import java.util.HashMap;
import java.util.Map;
public class PrimeGaps {
private Map<Integer, Integer> gapStarts = new HashMap<>();
private int lastPrime;
private PrimeGenerator primeGenerator = new PrimeGenerator(1000, 500000);
public static void main(String[] args) {
final int limit = 100000... | 911Earliest difference between prime gaps | 9java | g1v4m |
void eop_
for_i for_j c[i][j] = a[i][j] _op_ b[i][j];}
OPM(add, +);OPM(sub, -);OPM(mul, *);OPM(div, /);
void eop_s_
for_i for_j {x = a[i][j]; b[i][j] = res;}}
OPS(mul, x*s);OPS(div, x/s);OPS(add, x+s);OPS(sub, x-s);OPS(pow, pow(x, s)); | 912Element-wise operations | 5c | xdpwu |
typedef int64_t integer;
struct Pair {
integer md;
int tc;
};
integer mod(integer x, integer y) {
return ((x % y) + y) % y;
}
integer gcd(integer a, integer b) {
if (0 == a) return b;
if (0 == b) return a;
if (a == b) return a;
if (a > b) return gcd(a - b, b);
return gcd(a, b - a);
}
... | 913Egyptian fractions | 5c | y5d6f |
tutor = True
def halve(x):
return x
def double(x):
return x * 2
def even(x):
return not x% 2
def ethiopian(multiplier, multiplicand):
if tutor:
print(%
(multiplier, multiplicand))
result = 0
while multiplier >= 1:
if even(multiplier):
if tutor:
... | 901Ethiopian multiplication | 3python | 86z0o |
$str = "eertree";
for $n (1 .. length($str)) {
for $m (1 .. length($str)) {
$strrev = "";
$strpal = substr($str, $n-1, $m);
if ($strpal ne "") {
for $p (reverse 1 .. length($strpal)) {
$strrev .= substr($strpal, $p-1, 1);
}
($strpal eq $strrev) and push @pal,... | 909Eertree | 2perl | nmoiw |
use strict;
use warnings;
use ntheory qw( primes );
my @gaps;
my $primeref = primes( 1e9 );
for my $i ( 2 .. $
{
my $diff = $primeref->[$i] - $primeref->[$i - 1];
$gaps[ $diff >> 1 ] //= $primeref->[$i - 1];
}
my %first;
for my $i ( 1 .. $
{
defined $gaps[$i] && defined $gaps[$i-1] or next;
my $diff = a... | 911Earliest difference between prime gaps | 2perl | steq3 |
halve <- function(a) floor(a/2)
double <- function(a) a*2
iseven <- function(a) (a%%2)==0
ethiopicmult <- function(plier, plicand, tutor=FALSE) {
if (tutor) { cat("ethiopic multiplication of", plier, "and", plicand, "\n") }
result <- 0
while(plier >= 1) {
if (!iseven(plier)) { result <- result + plicand }
... | 901Ethiopian multiplication | 13r | xfnw2 |
from primesieve import primes
LIMIT = 10**9
pri = primes(LIMIT * 5)
gapstarts = {}
for i in range(1, len(pri)):
if pri[i] - pri[i - 1] not in gapstarts:
gapstarts[pri[i] - pri[i - 1]] = pri[i - 1]
PM, GAP1, = 10, 2
while True:
while GAP1 not in gapstarts:
GAP1 += 2
start1 = gapstarts[GAP1]... | 911Earliest difference between prime gaps | 3python | 0zwsq |
(defn initial-mtx [i1 i2 value]
(vec (repeat i1 (vec (repeat i2 value)))))
(defn operation [f mtx1 mtx2]
(if (vector? mtx1)
(vec (map #(vec (map f %1 %2)) mtx1 mtx2)))
(recur f (initial-mtx (count mtx2) (count (first mtx2)) mtx1) mtx2)
)) | 912Element-wise operations | 6clojure | o6x8j |
uint64_t egyptian_division(uint64_t dividend, uint64_t divisor, uint64_t *remainder) {
static uint64_t powers[64];
static uint64_t doublings[64];
int i;
for(i = 0; i < 64; i++) {
powers[i] = 1 << i;
doublings[i] = divisor << i;
if(doublings[i] > dividend)
break;
}
uint64_t answer = 0;
uint64_t acc... | 914Egyptian division | 5c | vh62o |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.