code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
import Data.List (unfoldr, genericIndex)
import Control.Monad (replicateM, foldM, mzero)
isEsthetic b = all ((== 1) . abs) . differences . toBase b
where
differences lst = zipWith (-) lst (tail lst)
esthetics_m b =
do differences <- (\n -> replicateM n [-1, 1]) <$> [0..]
firstDigit <- [1..b-1]
dif... | 887Esthetic numbers | 8haskell | 3uazj |
dsolveBy _ _ [] _ = error "empty solution interval"
dsolveBy method f mesh x0 = zip mesh results
where results = scanl (method f) x0 intervals
intervals = zip mesh (tail mesh) | 886Euler method | 8haskell | 9rsmo |
static unsigned long gcd_ui(unsigned long x, unsigned long y) {
unsigned long t;
if (y < x) { t = x; x = y; y = t; }
while (y > 0) {
t = y; y = x % y; x = t;
}
return x;
}
unsigned long binomial(unsigned long n, unsigned long k) {
unsigned long d, g, r = 1;
if (k == 0) return 1;
if (k == 1) ret... | 889Evaluate binomial coefficients | 5c | 41i5t |
public class Euler {
private static void euler (Callable f, double y0, int a, int b, int h) {
int t = a;
double y = y0;
while (t < b) {
System.out.println ("" + t + " " + y);
t += h;
y += h * f.compute (t, y);
}
System.out.println ("DONE");
}
public static void main (String[... | 886Euler method | 9java | t21f9 |
import java.util.ArrayList;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
public class EstheticNumbers {
interface RecTriConsumer<A, B, C> {
void accept(RecTriConsumer<A, B, C> f, A a, B b, C c);
}
private static boolean isEsthetic(long n, long b) {
if (n == 0) {
... | 887Esthetic numbers | 9java | imjos |
null | 886Euler method | 10javascript | mgqyv |
function isEsthetic(inp, base = 10) {
let arr = inp.toString(base).split('');
if (arr.length == 1) return false;
for (let i = 0; i < arr.length; i++)
arr[i] = parseInt(arr[i], base);
for (i = 0; i < arr.length-1; i++)
if (Math.abs(arr[i]-arr[i+1]) !== 1) return false;
return true;
}
function collectE... | 887Esthetic numbers | 10javascript | zv1t2 |
(defn binomial-coefficient [n k]
(let [rprod (fn [a b] (reduce * (range a (inc b))))]
(/ (rprod (- n k -1) n) (rprod 1 k)))) | 889Evaluate binomial coefficients | 6clojure | hqzjr |
int makehist(char *S,int *hist,int len){
int wherechar[256];
int i,histlen;
histlen=0;
for(i=0;i<256;i++)wherechar[i]=-1;
for(i=0;i<len;i++){
if(wherechar[(int)S[i]]==-1){
wherechar[(int)S[i]]=histlen;
histlen++;
}
hist[wherechar[(int)S[i]]]++;
}
return histlen;
}
double entropy(int *hist,int histle... | 890Entropy/Narcissist | 5c | 5p8uk |
int main() {
puts(getenv());
puts(getenv());
puts(getenv());
return 0;
} | 891Environment variables | 5c | qtlxc |
typedef long long mylong;
void compute(int N, char find_only_one_solution)
{ const int M = 30;
int a, b, c, d, e;
mylong s, t, max, *p5 = (mylong*)malloc(sizeof(mylong)*(N+M));
for(s=0; s < N; ++s)
p5[s] = s * s, p5[s] *= p5[s] * s;
for(max = p5[N - 1]; s < (N + M); p5[s++] = max + 1);
for(a = 1; a < N; ++... | 892Euler's sum of powers conjecture | 5c | 3uhza |
null | 886Euler method | 11kotlin | oyj8z |
(System/getenv "HOME") | 891Environment variables | 6clojure | im4om |
import kotlin.math.abs
fun isEsthetic(n: Long, b: Long): Boolean {
if (n == 0L) {
return false
}
var i = n % b
var n2 = n / b
while (n2 > 0) {
val j = n2 % b
if (abs(i - j) != 1L) {
return false
}
n2 /= b
i = j
}
return true
}
fun... | 887Esthetic numbers | 11kotlin | qt5x1 |
function to(n, b)
local BASE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if n == 0 then
return "0"
end
local ss = ""
while n > 0 do
local idx = (n % b) + 1
n = math.floor(n / b)
ss = ss .. BASE:sub(idx, idx)
end
return string.reverse(ss)
end
function isEstheti... | 887Esthetic numbers | 1lua | sz4q8 |
T0 = 100
TR = 20
k = 0.07
delta_t = { 2, 5, 10 }
n = 100
NewtonCooling = function( t ) return -k * ( t - TR ) end
function Euler( f, y0, n, h )
local y = y0
for x = 0, n, h do
print( "", x, y )
y = y + h * f( y )
end
end
for i = 1, #delta_t do
print( "delta_t = ", delta_t[i] )
Euler( NewtonC... | 886Euler method | 1lua | imhot |
(ns test-p.core
(:require [clojure.math.numeric-tower:as math])
(:require [clojure.data.int-map:as i]))
(defn solve-power-sum [max-value max-sols]
" Finds solutions by using method approach of EchoLisp
Large difference is we store a dictionary of all combinations
of y^5 - x^5 with the x, y value so we c... | 892Euler's sum of powers conjecture | 6clojure | c7a9b |
package main
import (
"fmt"
"io/ioutil"
"log"
"math"
"os"
"runtime"
)
func main() {
_, src, _, _ := runtime.Caller(0)
fmt.Println("Source file entropy:", entropy(src))
fmt.Println("Binary file entropy:", entropy(os.Args[0]))
}
func entropy(file string) float64 {
d, err := iout... | 890Entropy/Narcissist | 0go | 8650g |
int list[] = {-7, 1, 5, 2, -4, 3, 0};
int eq_idx(int *a, int len, int **ret)
{
int i, sum, s, cnt;
cnt = s = sum = 0;
*ret = malloc(sizeof(int) * len);
for (i = 0; i < len; i++)
sum += a[i];
for (i = 0; i < len; i++) {
if (s * 2 + a[i] == sum) {
(*ret)[cnt] = i;
... | 893Equilibrium index | 5c | re8g7 |
import qualified Data.ByteString as BS
import Data.List
import System.Environment
(>>>) = flip (.)
main = getArgs >>= head >>> BS.readFile >>= BS.unpack >>> entropy >>> print
entropy = sort >>> group >>> map genericLength >>> normalize >>> map lg >>> sum
where lg c = -c * logBase 2 c
normalize c = let sc =... | 890Entropy/Narcissist | 8haskell | ljxch |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class EntropyNarcissist {
private static final String FILE_NAME = "src/EntropyNarcissist.java";
public static void main(String[] args) {
Sy... | 890Entropy/Narcissist | 9java | 3ubzg |
enum fruits { apple, banana, cherry };
enum fruits { apple = 0, banana = 1, cherry = 2 }; | 894Enumerations | 5c | 86l04 |
null | 895Enforced immutability | 5c | szmq5 |
null | 890Entropy/Narcissist | 11kotlin | n9rij |
function getFile (filename)
local inFile = io.open(filename, "r")
local fileContent = inFile:read("*all")
inFile:close()
return fileContent
end
function log2 (x) return math.log(x) / math.log(2) end
function entropy (X)
local N, count, sum, i = X:len(), {}, 0
for char = 1, N do
i = X:s... | 890Entropy/Narcissist | 1lua | dc7nq |
(def fruits #{:apple:banana:cherry})
(defn fruit? [x] (contains? fruits x))
(def fruit-value (zipmap fruits (iterate inc 1)))
(println (fruit?:apple))
(println (fruit-value:banana)) | 894Enumerations | 6clojure | fl4dm |
use 5.020;
use warnings;
use experimental qw(signatures);
use ntheory qw(fromdigits todigitstring);
sub generate_esthetic ($root, $upto, $callback, $base = 10) {
my $v = fromdigits($root, $base);
return if ($v > $upto);
$callback->($v);
my $t = $root->[-1];
__SUB__->([@$root, $t + 1], $upto, $... | 887Esthetic numbers | 2perl | vko20 |
use strict ;
use warnings ;
use feature 'say' ;
sub log2 {
my $number = shift ;
return log( $number ) / log( 2 ) ;
}
open my $fh , "<" , $ARGV[ 0 ] or die "Can't open $ARGV[ 0 ]$!\n" ;
my %frequencies ;
my $totallength = 0 ;
while ( my $line = <$fh> ) {
chomp $line ;
next if $line =~ /^$/ ;
map { $freq... | 890Entropy/Narcissist | 2perl | 7wdrh |
user> (def d [1 2 3 4 5])
#'user/d
user> (assoc d 3 7)
[1 2 3 7 5]
user> d
[1 2 3 4 5] | 895Enforced immutability | 6clojure | n9vik |
(defn equilibrium [lst]
(loop [acc '(), i 0, left 0, right (apply + lst), lst lst]
(if (empty? lst)
(reverse acc)
(let [[x & xs] lst
right (- right x)
acc (if (= left right) (cons i acc) acc)]
(recur acc (inc i) (+ left x) right xs))))) | 893Equilibrium index | 6clojure | b0fkz |
<?php
$h = 0;
$s = file_get_contents(__FILE__);
$l = strlen($s);
foreach ( count_chars($s, 1) as $c )
$h -=
( $c / $l ) *
log( $c / $l, 2 );
echo $h; | 890Entropy/Narcissist | 12php | fljdh |
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println(os.Getenv("SHELL"))
} | 891Environment variables | 0go | 2hxl7 |
System.getenv().each { property, value -> println "$property = $value"} | 891Environment variables | 7groovy | y4p6o |
sub euler_method {
my ($t0, $t1, $k, $step_size) = @_;
my @results = ( [0, $t0] );
for (my $s = $step_size; $s <= 100; $s += $step_size) {
$t0 -= ($t0 - $t1) * $k * $step_size;
push @results, [$s, $t0];
}
return @results;
}
sub analytical {
... | 886Euler method | 2perl | gat4e |
import math
from collections import Counter
def entropy(s):
p, lns = Counter(s), float(len(s))
return -sum( count/lns * math.log(count/lns, 2) for count in p.values())
with open(__file__) as f:
b=f.read()
print(entropy(b)) | 890Entropy/Narcissist | 3python | jxf7p |
typedef long long int dlong;
typedef struct {
dlong x, y;
} epnt;
typedef struct {
long a, b;
dlong N;
epnt G;
dlong r;
} curve;
typedef struct {
long a, b;
} pair;
const long mxN = 1073741789;
const long mxr = 1073807325;
const long inf = -2147483647;
curve e;
epnt zerO;
int inverr;
... | 896Elliptic Curve Digital Signature Algorithm | 5c | oyc80 |
import System.Environment
main = do getEnv "HOME" >>= print
getEnvironment >>= print | 891Environment variables | 8haskell | aiy1g |
package main
import "fmt"
import "math/big"
func main() {
fmt.Println(new(big.Int).Binomial(5, 3))
fmt.Println(new(big.Int).Binomial(60, 30))
} | 889Evaluate binomial coefficients | 0go | oyg8q |
from collections import deque
from itertools import dropwhile, islice, takewhile
from textwrap import wrap
from typing import Iterable, Iterator
Digits = str
def esthetic_nums(base: int) -> Iterator[int]:
queue: deque[tuple[int, int]] = deque()
queue.extendleft((d, d) for d in range(1, base))
whi... | 887Esthetic numbers | 3python | ubivd |
def factorial = { x ->
assert x > -1
x == 0 ? 1: (1..x).inject(1G) { BigInteger product, BigInteger factor -> product *= factor }
}
def combinations = { n, k ->
assert k >= 0
assert n >= k
factorial(n).intdiv(factorial(k)*factorial(n-k))
} | 889Evaluate binomial coefficients | 7groovy | xf2wl |
def entropy(s)
counts = s.each_char.tally
size = s.size.to_f
counts.values.reduce(0) do |entropy, count|
freq = count / size
entropy - freq * Math.log2(freq)
end
end
s = File.read(__FILE__)
p entropy(s) | 890Entropy/Narcissist | 14ruby | kszhg |
use std::fs::File;
use std::io::{Read, BufReader};
fn entropy<I: IntoIterator<Item = u8>>(iter: I) -> f32 {
let mut histogram = [0u64; 256];
let mut len = 0u64;
for b in iter {
histogram[b as usize] += 1;
len += 1;
}
histogram
.iter()
.cloned()
.filter(|&h|... | 890Entropy/Narcissist | 15rust | b03kx |
typedef struct { double x, y; } pt;
pt zero(void) { return (pt){ INFINITY, INFINITY }; }
int is_zero(pt p) { return p.x > 1e20 || p.x < -1e20; }
pt neg(pt p) { return (pt){ p.x, -p.y }; }
pt dbl(pt p) {
if (is_zero(p)) return p;
pt r;
double L = (3 * p.x * p.x) / (2 * p.y);
r.x = L * L - 2 * p.x;
r.y = L * (... | 897Elliptic curve arithmetic | 5c | 1onpj |
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"encoding/binary"
"fmt"
"log"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
check(err)
... | 896Elliptic Curve Digital Signature Algorithm | 0go | 41w52 |
package main
func main() {
s := "immutable"
s[0] = 'a'
} | 895Enforced immutability | 0go | vka2m |
pi = 3.14159
msg = "Hello World" | 895Enforced immutability | 8haskell | enzai |
System.getenv("HOME") | 891Environment variables | 9java | jxd7c |
var shell = new ActiveXObject("WScript.Shell");
var env = shell.Environment("PROCESS");
WScript.echo('SYSTEMROOT=' + env.item('SYSTEMROOT')); | 891Environment variables | 10javascript | 1o6p7 |
typedef unsigned long long ull;
void evolve(ull state, int rule)
{
int i, p, q, b;
for (p = 0; p < 10; p++) {
for (b = 0, q = 8; q--; ) {
ull st = state;
b |= (st&1) << q;
for (state = i = 0; i < N; i++)
if (rule & B(7 & (st>>(i-1) | st<<(N+1-i))))
state |= B(i);
}
printf(, b);
}
putcha... | 898Elementary cellular automaton/Random Number Generator | 5c | t2vf4 |
final int immutableInt = 4;
int mutableInt = 4;
mutableInt = 6; | 895Enforced immutability | 9java | hqojm |
const pi = 3.1415;
const msg = "Hello World"; | 895Enforced immutability | 10javascript | ait10 |
choose :: (Integral a) => a -> a -> a
choose n k = product [k+1..n] `div` product [1..n-k] | 889Evaluate binomial coefficients | 8haskell | 2hsll |
const (
apple = iota
banana
cherry
) | 894Enumerations | 0go | 5pxul |
enum Fruit { apple, banana, cherry }
enum ValuedFruit {
apple(1), banana(2), cherry(3);
def value
ValuedFruit(val) {value = val}
String toString() { super.toString() + "(${value})" }
}
println Fruit.values()
println ValuedFruit.values() | 894Enumerations | 7groovy | c7p9i |
use strict;
use warnings;
use Crypt::EC_DSA;
my $ecdsa = new Crypt::EC_DSA;
my ($pubkey, $prikey) = $ecdsa->keygen;
print "Message: ", my $msg = 'Rosetta Code', "\n";
print "Private Key:\n$prikey \n";
print "Public key :\n", $pubkey->x, "\n", $pubkey->y, "\n";
my $signature = $ecdsa->sign( Message => $msg, Key =>... | 896Elliptic Curve Digital Signature Algorithm | 2perl | flud7 |
int dir_empty(const char *path)
{
struct dirent *ent;
int ret = 1;
DIR *d = opendir(path);
if (!d) {
fprintf(stderr, , path);
perror();
return -1;
}
while ((ent = readdir(d))) {
if (!strcmp(ent->d_name, ) || !(strcmp(ent->d_name, )))
continue;
ret = 0;
break;
}
closedir(d);
return ret;
}
int... | 899Empty directory | 5c | 2hhlo |
null | 895Enforced immutability | 11kotlin | 41x57 |
local pi <const> = 3.14159265359 | 895Enforced immutability | 1lua | gaq4j |
int makehist(unsigned char *S,int *hist,int len){
int wherechar[256];
int i,histlen;
histlen=0;
for(i=0;i<256;i++)wherechar[i]=-1;
for(i=0;i<len;i++){
if(wherechar[(int)S[i]]==-1){
wherechar[(int)S[i]]=histlen;
histlen++;
}
hist[wherechar[(int)S[i]]]++;
}
return histlen;
}
double entropy(int *hist,i... | 900Entropy | 5c | p80by |
void halve(int *x) { *x >>= 1; }
void doublit(int *x) { *x <<= 1; }
bool iseven(const int x) { return (x & 1) == 0; }
int ethiopian(int plier,
int plicand, const bool tutor)
{
int result=0;
if (tutor)
printf(, plier, plicand);
while(plier >= 1) {
if ( iseven(plier) ) {
if (tutor) printf(... | 901Ethiopian multiplication | 5c | wdiec |
null | 891Environment variables | 11kotlin | 5p0ua |
if (x & 1) {
} else {
} | 902Even or odd | 5c | c749c |
def euler(f,y0,a,b,h):
t,y = a,y0
while t <= b:
print % (t,y)
t += h
y += h * f(t,y)
def newtoncooling(time, temp):
return -0.07 * (temp - 20)
euler(newtoncooling,100,0,100,10) | 886Euler method | 3python | rezgq |
euler <- function(f, y0, a, b, h)
{
t <- a
y <- y0
while (t < b)
{
cat(sprintf("%6.3f%6.3f\n", t, y))
t <- t + h
y <- y + h*f(t, y)
}
}
newtoncooling <- function(time, temp){
return(-0.07*(temp-20))
}
euler(newtoncooling, 100, 0, 100, 10) | 886Euler method | 13r | ubnvx |
data Fruit = Apple | Banana | Cherry deriving Enum | 894Enumerations | 8haskell | xfyw4 |
package main
import "fmt"
const n = 64
func pow2(x uint) uint64 {
return uint64(1) << x
}
func evolve(state uint64, rule int) {
for p := 0; p < 10; p++ {
b := uint64(0)
for q := 7; q >= 0; q-- {
st := state
b |= (st & 1) << uint(q)
state = 0
fo... | 898Elementary cellular automaton/Random Number Generator | 0go | hqsjq |
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
fmt.Println(ex([]int32{-7, 1, 5, 2, -4, 3, 0})) | 893Equilibrium index | 0go | n95i1 |
def isEsthetic(n, b)
if n == 0 then
return false
end
i = n % b
n2 = (n / b).floor
while n2 > 0
j = n2 % b
if (i - j).abs!= 1 then
return false
end
n2 = n2 / b
i = j
end
return true
end
def listEsths(n, n2, m, m2, perLine, all)
... | 887Esthetic numbers | 14ruby | 41d5p |
public class Binomial { | 889Evaluate binomial coefficients | 9java | 6513z |
package main
import (
"fmt"
"math"
)
const bCoeff = 7
type pt struct{ x, y float64 }
func zero() pt {
return pt{math.Inf(1), math.Inf(1)}
}
func is_zero(p pt) bool {
return p.x > 1e20 || p.x < -1e20
}
func neg(p pt) pt {
return pt{p.x, -p.y}
}
func dbl(p pt) pt {
if is_zero(p) {
r... | 897Elliptic curve arithmetic | 0go | y4r64 |
enum Fruits{
APPLE, BANANA, CHERRY
} | 894Enumerations | 9java | b0dk3 |
import CellularAutomata (fromList, rule, runCA)
import Control.Comonad
import Data.List (unfoldr)
rnd = fromBits <$> unfoldr (pure . splitAt 8) bits
where
size = 80
bits =
extract
<$> runCA
(rule 30)
(fromList (1: replicate size 0))
fromBits = foldl ((+) . (2 *)) 0 | 898Elementary cellular automaton/Random Number Generator | 8haskell | im9or |
null | 898Elementary cellular automaton/Random Number Generator | 11kotlin | p8ob6 |
from collections import namedtuple
from hashlib import sha256
from math import ceil, log
from random import randint
from typing import NamedTuple
secp256k1_data = dict(
p=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F,
a=0x0,
b=0x7,
r=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE... | 896Elliptic Curve Digital Signature Algorithm | 3python | t25fw |
(require '[clojure.java.io:as io])
(defn empty-dir? [path]
(let [file (io/file path)]
(assert (.exists file))
(assert (.isDirectory file))
(-> file .list empty?))) | 899Empty directory | 6clojure | gaa4f |
import System.Random (randomRIO)
import Data.List (findIndices, takeWhile)
import Control.Monad (replicateM)
import Control.Arrow ((&&&))
equilibr xs =
findIndices (\(a, b) -> sum a == sum b) . takeWhile (not . null . snd) $
flip ((&&&) <$> take <*> (drop . pred)) xs <$> [1 ..]
langeSliert = replicateM 2000 (rand... | 893Equilibrium index | 8haskell | ubxv2 |
print( os.getenv( "PATH" ) ) | 891Environment variables | 1lua | 4185c |
null | 887Esthetic numbers | 15rust | gaf4o |
function binom(n, k) {
var coeff = 1;
var i;
if (k < 0 || k > n) return 0;
for (i = 0; i < k; i++) {
coeff = coeff * (n - i) / (i + 1);
}
return coeff;
}
console.log(binom(5, 3)); | 889Evaluate binomial coefficients | 10javascript | ljqcf |
import Data.Monoid
import Control.Monad (guard)
import Test.QuickCheck (quickCheck) | 897Elliptic curve arithmetic | 8haskell | hq0ju |
null | 894Enumerations | 10javascript | wd6e2 |
use constant PI => 3.14159;
use constant MSG => "Hello World"; | 895Enforced immutability | 2perl | im2o3 |
define(, 3.14159265358);
define(, ); | 895Enforced immutability | 12php | resge |
(defn entropy [s]
(let [len (count s), log-2 (Math/log 2)]
(->> (frequencies s)
(map (fn [[_ v]]
(let [rf (/ v len)]
(-> (Math/log rf) (/ log-2) (* rf) Math/abs))))
(reduce +)))) | 900Entropy | 6clojure | xfdwk |
(defn halve [n]
(bit-shift-right n 1))
(defn twice [n]
(bit-shift-left n 1))
(defn even [n]
(zero? (bit-and n 1)))
(defn emult [x y]
(reduce +
(map second
(filter #(not (even (first %)))
(take-while #(pos? (first %))
(map vector
(iterate halve... | 901Ethiopian multiplication | 6clojure | 86z05 |
(if (even? some-var) (do-even-stuff))
(if (odd? some-var) (do-odd-stuff)) | 902Even or odd | 6clojure | 5phuz |
def euler(y, a, b, h)
a.step(b,h) do |t|
puts % [t,y]
y += h * yield(t,y)
end
end
[10, 5, 2].each do |step|
puts
euler(100,0,100,step) {|time, temp| -0.07 * (temp - 20) }
puts
end | 886Euler method | 14ruby | jx67x |
import static java.lang.Math.*;
import java.util.Locale;
public class Test {
public static void main(String[] args) {
Pt a = Pt.fromY(1);
Pt b = Pt.fromY(2);
System.out.printf("a =%s%n", a);
System.out.printf("b =%s%n", b);
Pt c = a.plus(b);
System.out.printf("c = a... | 897Elliptic curve arithmetic | 9java | 5pauf |
null | 894Enumerations | 11kotlin | re0go |
package Automaton {
sub new {
my $class = shift;
my $rule = [ reverse split //, sprintf "%08b", shift ];
return bless { rule => $rule, cells => [ @_ ] }, $class;
}
sub next {
my $this = shift;
my @previous = @{$this->{cells}};
$this->{cells} = [
@{$this->{rule}}[
map ... | 898Elementary cellular automaton/Random Number Generator | 2perl | y4g6u |
public class Equlibrium {
public static void main(String[] args) {
int[] sequence = {-7, 1, 5, 2, -4, 3, 0};
equlibrium_indices(sequence);
}
public static void equlibrium_indices(int[] sequence){ | 893Equilibrium index | 9java | mgbym |
extension Sequence {
func take(_ n: Int) -> [Element] {
var res = [Element]()
for el in self {
guard res.count!= n else {
return res
}
res.append(el)
}
return res
}
}
extension String {
func isEsthetic(base: Int = 10) -> Bool {
zip(dropFirst(0), dropFirst())
... | 887Esthetic numbers | 17swift | 5pnu8 |
package main
import (
"fmt"
"log"
)
func main() {
fmt.Println(eulerSum())
}
func eulerSum() (x0, x1, x2, x3, y int) {
var pow5 [250]int
for i := range pow5 {
pow5[i] = i * i * i * i * i
}
for x0 = 4; x0 < len(pow5); x0++ {
for x1 = 3; x1 < x0; x1++ {
for x2 = 2; x2 < x1; x2++ {
for x3 = 1; x3 < x2;... | 892Euler's sum of powers conjecture | 0go | b0tkh |
fn header() {
print!(" Time: ");
for t in (0..100).step_by(10) {
print!(" {:7}", t);
}
println!();
}
fn analytic() {
print!("Analytic: ");
for t in (0..=100).step_by(10) {
print!(" {:7.3}", 20.0 + 80.0 * (-0.07 * f64::from(t)).exp());
}
println!();
}
fn euler<F: Fn(f... | 886Euler method | 15rust | hqyj2 |
object App{
def main(args : Array[String]) = {
def cooling( step : Int ) = {
eulerStep( (step , y) => {-0.07 * (y - 20)} ,
100.0,0,100,step)
}
cooling(10)
cooling(5)
cooling(2)
}
def eulerStep( func : (Int,Double) => Double,y0 : Double,
begin : Int, end : Int , step : Int)... | 886Euler method | 16scala | p8cbj |
null | 889Evaluate binomial coefficients | 11kotlin | dcjnz |
typedef unsigned uint;
int is_prime(uint n)
{
if (!(n%2) || !(n%3)) return 0;
uint p = 1;
while(p*p < n)
if (n%(p += 4) == 0 || n%(p += 2) == 0)
return 0;
return 1;
}
uint reverse(uint n)
{
uint r;
for (r = 0; n; n /= 10)
... | 903Emirp primes | 5c | lj4cy |
null | 897Elliptic curve arithmetic | 11kotlin | c7h98 |
local fruit = {apple = 0, banana = 1, cherry = 2} | 894Enumerations | 1lua | 7w8ru |
from elementary_cellular_automaton import eca, eca_wrap
def rule30bytes(lencells=100):
cells = '1' + '0' * (lencells - 1)
gen = eca(cells, 30)
while True:
yield int(''.join(next(gen)[0] for i in range(8)), 2)
if __name__ == '__main__':
print([b for i,b in zip(range(10), rule30bytes())]) | 898Elementary cellular automaton/Random Number Generator | 3python | mgryh |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.