code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
MULTIPLY = lambda x, y: x*y
class num(float):
def __pow__(self, b):
return reduce(MULTIPLY, [self]*b, 1)
print num(2).__pow__(3)
print num(2) ** 3
print num(2.3).__pow__(8)
print num(2.3) ** 8 | 874Exponentiation operator | 3python | 65z3w |
null | 879Execute a system command | 1lua | n9xi8 |
pow <- function(x, y)
{
x <- as.numeric(x)
y <- as.integer(y)
prod(rep(x, y))
}
"%pow%" <- function(x,y) pow(x,y)
pow(3, 4)
2.5%pow% 2 | 874Exponentiation operator | 13r | flndc |
SELECT CASE
WHEN MOD(level,15)=0 THEN 'FizzBuzz'
WHEN MOD(level,3)=0 THEN 'Fizz'
WHEN MOD(level,5)=0 THEN 'Buzz'
ELSE TO_CHAR(level)
END FizzBuzz
FROM dual
CONNECT BY LEVEL <= 100; | 835FizzBuzz | 19sql | 8mn02 |
import Foundation
func setup(ruleset: String) -> [(String, String, Bool)] {
return ruleset.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())
.filter { $0.rangeOfString("^s*#", options: .RegularExpressionSearch) == nil }
.reduce([(String, String, Bool)]()) { rules, line in
... | 877Execute a Markov algorithm | 17swift | vkm2r |
class MyException extends Exception
{
} | 878Exceptions | 12php | n9qig |
class Numeric
def pow(m)
raise TypeError, unless m.is_a? Integer
puts
Array.new(m, self).reduce(1,:*)
end
end
p 5.pow(3)
p 5.5.pow(3)
p 5.pow(3.1) | 874Exponentiation operator | 14ruby | mg6yj |
extern crate num;
use num::traits::One;
use std::ops::Mul;
fn pow<T>(mut base: T, mut exp: usize) -> T
where T: Clone + One + Mul<T, Output=T>
{
if exp == 0 { return T::one() }
while exp & 1 == 0 {
base = base.clone() * base;
exp >>= 1;
}
if exp == 1 { return base }
let mut acc... | 874Exponentiation operator | 15rust | 9rymm |
for i in 1...100 {
switch (i% 3, i% 5) {
case (0, 0):
print("FizzBuzz")
case (0, _):
print("Fizz")
case (_, 0):
print("Buzz")
default:
print(i)
}
} | 835FizzBuzz | 17swift | 1nwpt |
import exceptions
class SillyError(exceptions.Exception):
def __init__(self,args=None):
self.args=args | 878Exceptions | 3python | re2gq |
object Exponentiation {
import scala.annotation.tailrec
@tailrec def powI[N](n: N, exponent: Int)(implicit num: Integral[N]): N = {
import num._
exponent match {
case 0 => one
case _ if exponent % 2 == 0 => powI((n * n), (exponent / 2))
case _ => powI(n, (exponent - 1)) * n
}
}
@... | 874Exponentiation operator | 16scala | 2hclb |
e <- simpleError("This is a simpleError") | 878Exceptions | 13r | ubmvx |
package main
import (
"fmt"
"math/rand"
"time"
)
var target = []byte("METHINKS IT IS LIKE A WEASEL")
var set = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ ")
var parent []byte
func init() {
rand.Seed(time.Now().UnixNano())
parent = make([]byte, len(target))
for i := range parent {
parent[i] = ... | 880Evolutionary algorithm | 0go | imeog |
import System.Random
import Control.Monad
import Data.List
import Data.Ord
import Data.Array
showNum :: (Num a, Show a) => Int -> a -> String
showNum w = until ((>w-1).length) (' ':) . show
replace :: Int -> a -> [a] -> [a]
replace n c ls = take (n-1) ls ++ [c] ++ drop n ls
target = "METHINKS IT IS LIKE A WEASEL"
p... | 880Evolutionary algorithm | 8haskell | vk32k |
class SillyError < Exception
end | 878Exceptions | 14ruby | jxu7x |
null | 878Exceptions | 15rust | hq5j2 |
int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; ++i)
result *= i;
return result;
} | 882Factorial | 5c | n9ai6 |
null | 878Exceptions | 16scala | p8rbj |
my @results = qx(ls);
my @results = `ls`;
system "ls";
print `ls`;
exec "ls"; | 879Execute a system command | 2perl | relgd |
func raise<T: Numeric>(_ base: T, to exponent: Int) -> T {
precondition(exponent >= 0, "Exponent has to be nonnegative")
return Array(repeating: base, count: exponent).reduce(1, *)
}
infix operator **: MultiplicationPrecedence
func **<T: Numeric>(lhs: T, rhs: Int) -> T {
return raise(lhs, to: rhs)
}
let ... | 874Exponentiation operator | 17swift | y436e |
package main
import "fmt"
func main() { | 881Execute Brain**** | 0go | qthxz |
@exec($command,$output);
echo nl2br($output); | 879Execute a system command | 12php | dcqn8 |
class BrainfuckProgram {
def program = '', memory = [:]
def instructionPointer = 0, dataPointer = 0
def execute() {
while (instructionPointer < program.size())
switch(program[instructionPointer++]) {
case '>': dataPointer++; break;
case '<': dataPointer--; break... | 881Execute Brain**** | 7groovy | 1o4p6 |
import java.util.Random;
public class EvoAlgo {
static final String target = "METHINKS IT IS LIKE A WEASEL";
static final char[] possibilities = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ".toCharArray();
static int C = 100; | 880Evolutionary algorithm | 9java | y4i6g |
null | 880Evolutionary algorithm | 10javascript | 2hzlr |
import java.io.IOException;
public class Interpreter {
public final static int MEMORY_SIZE = 65536;
private final char[] memory = new char[MEMORY_SIZE];
private int dp;
private int ip;
private int border;
private void reset() {
for (int i = 0; i < MEMORY_SIZE; i++) {
mem... | 881Execute Brain**** | 8haskell | mgiyf |
import os
exit_code = os.system('ls')
output = os.popen('ls').read() | 879Execute a system command | 3python | 7w2rm |
import java.util.*
val target = "METHINKS IT IS LIKE A WEASEL"
val validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
val random = Random()
fun randomChar() = validChars[random.nextInt(validChars.length)]
fun hammingDistance(s1: String, s2: String) =
s1.zip(s2).map { if (it.first == it.second) 0 else 1 }.sum()
fun ... | 880Evolutionary algorithm | 11kotlin | flqdo |
enum MyException: ErrorType {
case TerribleException
} | 878Exceptions | 17swift | 7wvrq |
system("ls")
output=system("ls",intern=TRUE) | 879Execute a system command | 13r | 5pmuy |
import java.io.IOException;
public class Interpreter {
public final static int MEMORY_SIZE = 65536;
private final char[] memory = new char[MEMORY_SIZE];
private int dp;
private int ip;
private int border;
private void reset() {
for (int i = 0; i < MEMORY_SIZE; i++) {
mem... | 881Execute Brain**** | 9java | flxdv |
local target = "METHINKS IT IS LIKE A WEASEL"
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
local c, p = 100, 0.06
local function fitness(s)
local score = #target
for i = 1,#target do
if s:sub(i,i) == target:sub(i,i) then score = score - 1 end
end
return score
end
local function mutate(s, rate)
local result, ... | 880Evolutionary algorithm | 1lua | t2sfn |
function execute(code)
{
var mem = new Array(30000);
var sp = 10000;
var opcode = new String(code);
var oplen = opcode.length;
var ip = 0;
var loopstack = new Array();
var output = "";
for (var i = 0; i < 30000; ++i) mem[i] = 0;
while (ip < oplen) {
switch(opcode[ip]) {
... | 881Execute Brain**** | 10javascript | y4o6r |
string = `ls`
string = %x{ls}
system
print `ls`
exec
io = IO.popen('ls')
io.each {|line| puts line} | 879Execute a system command | 14ruby | hqujx |
use std::process::Command;
fn main() {
let output = Command::new("ls").output().unwrap_or_else(|e| {
panic!("failed to execute process: {}", e)
});
println!("{}", String::from_utf8_lossy(&output.stdout));
} | 879Execute a system command | 15rust | ks5h5 |
import scala.sys.process.Process
Process("ls", Seq("-oa"))! | 879Execute a system command | 16scala | 1orpf |
(defn factorial [x]
(apply * (range 2 (inc x)))) | 882Factorial | 6clojure | 3uszr |
null | 881Execute Brain**** | 11kotlin | 86p0q |
local funs = {
['>'] = 'ptr = ptr + 1; ',
['<'] = 'ptr = ptr - 1; ',
['+'] = 'mem[ptr] = mem[ptr] + 1; ',
['-'] = 'mem[ptr] = mem[ptr] - 1; ',
['['] = 'while mem[ptr] ~= 0 do ',
[']'] = 'end; ',
['.'] = 'io.write(string.char(mem[ptr])); ',
[','] = 'mem[ptr] = (io.read(1) or "\\0"):byte(); ',
}
local prog = [[
local ... | 881Execute Brain**** | 1lua | oy18h |
int fact(int n) {
if(n<0) {
throw new IllegalArgumentException('Argument less than 0');
}
return n==0? 1: n*fact(n-1);
}
main() {
print(fact(10));
print(fact(-1));
} | 882Factorial | 18dart | qtjxo |
use List::Util 'reduce';
use List::MoreUtils 'false';
sub randElm
{$_[int rand @_]}
sub minBy (&@)
{my $f = shift;
reduce {$f->($b) < $f->($a) ? $b : $a} @_;}
sub zip
{@_ or return ();
for (my ($n, @a) = 0 ;; ++$n)
{my @row;
foreach (@_)
{$n < @$_ or return @a;
push @row, $_->[$n];... | 880Evolutionary algorithm | 2perl | hqvjl |
define('TARGET','METHINKS IT IS LIKE A WEASEL');
define('TBL','ABCDEFGHIJKLMNOPQRSTUVWXYZ ');
define('MUTATE',15);
define('COPIES',30);
define('TARGET_COUNT',strlen(TARGET));
define('TBL_COUNT',strlen(TBL));
function unfitness($a,$b)
{
$sum=0;
for($i=0;$i<strlen($a);$i++)
if($a[$i]!=... | 880Evolutionary algorithm | 12php | zv0t1 |
my %code = split ' ', <<'END';
> $ptr++
< $ptr--
+ $memory[$ptr]++
- $memory[$ptr]--
, $memory[$ptr]=ord(getc)
. print(chr($memory[$ptr]))
[ while($memory[$ptr]){
] }
END
my ($ptr, @memory) = 0;
eval join ';', map @code{ /./g }, <>; | 881Execute Brain**** | 2perl | 41y5d |
<?php
function brainfuck_interpret(&$s, &$_s, &$d, &$_d, &$i, &$_i, &$o) {
do {
switch($s[$_s]) {
case '+': $d[$_d] = chr(ord($d[$_d]) + 1); break;
case '-': $d[$_d] = chr(ord($d[$_d]) - 1); break;
case '>': $_d++; if(!isset($d[$_d])) $d[$_d] = chr(0); break;
case '<': $_d--; break;
... | 881Execute Brain**** | 12php | imaov |
from string import letters
from random import choice, random
target = list()
charset = letters + ' '
parent = [choice(charset) for _ in range(len(target))]
minmutaterate = .09
C = range(100)
perfectfitness = float(len(target))
def fitness(trial):
'Sum of matching chars by position'
return sum(t==h for t,h... | 880Evolutionary algorithm | 3python | ksuhf |
set.seed(1234, kind="Mersenne-Twister")
target <- unlist(strsplit("METHINKS IT IS LIKE A WEASEL", ""))
charset <- c(LETTERS, " ")
parent <- sample(charset, length(target), replace=TRUE)
mutaterate <- 0.01
C <- 100
fitness <- function(parent, target) {
sum(parent == target) / length(target)
}
mutate <- fun... | 880Evolutionary algorithm | 13r | recgj |
[ stack ] is switch.arg ( --> [ )
[ switch.arg put ] is switch ( x --> )
[ switch.arg release ] is otherwise ( --> )
[ switch.arg share!= iff ]else[ done
otherwise ]'[ do ]... | 881Execute Brain**** | 3python | gam4h |
sub fib_iter {
my $n = shift;
use bigint try => "GMP,Pari";
my ($v2,$v1) = (-1,1);
($v2,$v1) = ($v1,$v2+$v1) for 0..$n;
$v1;
} | 862Fibonacci sequence | 2perl | ygr6u |
function fibIter($n) {
if ($n < 2) {
return $n;
}
$fibPrev = 0;
$fib = 1;
foreach (range(1, $n-1) as $i) {
list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
}
return $fib;
} | 862Fibonacci sequence | 12php | and12 |
@target =
Charset = [, *..]
COPIES = 100
def random_char; Charset.sample end
def fitness(candidate)
sum = 0
candidate.chars.zip(@target.chars) {|x,y| sum += (x[0].ord - y[0].ord).abs}
100.0 * Math.exp(Float(sum) / -10.0)
end
def mutation_rate(candidate)
1.0 - Math.exp( -(100.0 - fitness(candidate)) / 400.0)... | 880Evolutionary algorithm | 14ruby | p84bh |
null | 880Evolutionary algorithm | 15rust | 1ogpu |
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::stdin;
use std::num::Wrapping;
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() < 2 {
println!(, args[0]);
return;
}
let src: Vec<char> = {
let mut buf = Str... | 881Execute Brain**** | 14ruby | 7wcri |
import scala.annotation.tailrec
case class LearnerParams(target:String,rate:Double,C:Int)
val chars = ('A' to 'Z') ++ List(' ')
val randgen = new scala.util.Random
def randchar = {
val charnum = randgen.nextInt(chars.size)
chars(charnum)
}
class RichTraversable[T](t: Traversable[T]) {
def maxBy[B](fn: T =... | 880Evolutionary algorithm | 16scala | wdjes |
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::stdin;
use std::num::Wrapping;
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() < 2 {
println!("Usage: {} [path] (--debug)", args[0]);
return;
}
let src: Vec<char> =... | 881Execute Brain**** | 15rust | jxl72 |
import scala.annotation._
trait Func[T] {
val zero: T
def inc(t: T): T
def dec(t: T): T
def in: T
def out(t: T): Unit
}
object ByteFunc extends Func[Byte] {
override val zero: Byte = 0
override def inc(t: Byte) = ((t + 1) & 0xFF).toByte
override def dec(t: Byte) = ((t - 1) & 0xFF).toByte
o... | 881Execute Brain**** | 16scala | b0uk6 |
import Foundation
let valids = [">", "<", "+", "-", ".", ",", "[", "]"] as Set<Character>
var ip = 0
var dp = 0
var data = [UInt8](count: 30_000, repeatedValue: 0)
let input = Process.arguments
if input.count!= 2 {
fatalError("Need one input file")
}
let infile: String!
do {
infile = try String(contentsOfF... | 881Execute Brain**** | 17swift | re9gg |
func evolve(
to target: String,
parent: inout String,
mutationRate: Int,
copies: Int
) {
var parentFitness: Int {
return fitness(target: target, sentence: parent)
}
var generation = 0
while parent!= target {
generation += 1
let bestOfGeneration =
(0..<copies)
.map({_ in ... | 880Evolutionary algorithm | 17swift | b05kd |
from math import *
def analytic_fibonacci(n):
sqrt_5 = sqrt(5);
p = (1 + sqrt_5) / 2;
q = 1/p;
return int( (p**n + q**n) / sqrt_5 + 0.5 )
for i in range(1,31):
print analytic_fibonacci(i), | 862Fibonacci sequence | 3python | mr7yh |
fib=function(n,x=c(0,1)) {
if (abs(n)>1) for (i in seq(abs(n)-1)) x=c(x[2],sum(x))
if (n<0) return(x[2]*(-1)^(abs(n)-1)) else if (n) return(x[2]) else return(0)
}
sapply(seq(-31,31),fib) | 862Fibonacci sequence | 13r | zu5th |
package main
import (
"fmt"
"math/big"
)
func main() {
fmt.Println(factorial(800))
}
func factorial(n int64) *big.Int {
if n < 0 {
return nil
}
r := big.NewInt(1)
var f big.Int
for i := int64(2); i <= n; i++ {
r.Mul(r, f.SetInt64(i))
}
return r
} | 882Factorial | 0go | remgm |
def rFact
rFact = { (it > 1) ? it * rFact(it - 1): 1 as BigInteger } | 882Factorial | 7groovy | vkt28 |
factorial n = product [1..n] | 882Factorial | 8haskell | 03ks7 |
def fib(n)
if n < 2
n
else
prev, fib = 0, 1
(n-1).times do
prev, fib = fib, fib + prev
end
fib
end
end
p (0..10).map { |i| fib(i) } | 862Fibonacci sequence | 14ruby | cjh9k |
int main(void) {
double a, b, h, n2, r, u, v;
int k, k2, m, n;
printf();
n = 400;
h = 1;
for (k = 2; k <= n; k++) {
h += 1.0 / k;
}
a = log(n +.5 + 1.0 / (24*n));
printf(, h);
printf(, h - a, n);
printf();
n = 21;
double s[] = {0, n};
r = n;
k = 1;
do {
k += 1;
r *= (double) n / k;
s[k & 1] += r / ... | 883Euler's constant 0.5772... | 5c | jx970 |
fn main() {
let mut prev = 0; | 862Fibonacci sequence | 15rust | lhkcc |
use strict;
use warnings;
use List::Util qw( sum );
print sum( map 1 / $_, 1 .. 1e6) - log 1e6, "\n"; | 883Euler's constant 0.5772... | 2perl | p8vb0 |
def fib(i: Int): Int = i match {
case 0 => 0
case 1 => 1
case _ => fib(i - 1) + fib(i - 2)
} | 862Fibonacci sequence | 16scala | up1v8 |
n = 1e6
p (1..n).sum{ 1.0/_1 } - Math.log(n) | 883Euler's constant 0.5772... | 14ruby | en4ax |
null | 883Euler's constant 0.5772... | 15rust | wdge4 |
package programas;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Scanner;
public class IterativeFactorial {
public BigInteger factorial(BigInteger n) {
if ( n == null ) {
throw new IllegalArgumentException();
}
else if ( n.signum() == - 1 ) { | 882Factorial | 9java | ai41y |
function factorial(n) { | 882Factorial | 10javascript | szhqz |
int main() {
wchar_t pi = L'\u03c0';
wchar_t ae = L'\u2245';
double complex e = cexp(M_PI * I) + 1.0;
setlocale(LC_CTYPE, );
printf(, pi, creal(e), cimag(e), ae);
return 0;
} | 884Euler's identity | 5c | aiu11 |
package main
import (
"fmt"
"math"
"math/cmplx"
)
func main() {
fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0)
} | 884Euler's identity | 0go | mg0yi |
import static Complex.*
Number.metaClass.mixin ComplexCategory
def = Math.PI
def e = Math.E
println "e ** ( * i) + 1 = " + (e ** ( * i) + 1)
println "| e ** ( * i) + 1 | = " + (e ** ( * i) + 1). | 884Euler's identity | 7groovy | t2efh |
fun facti(n: Int) = when {
n < 0 -> throw IllegalArgumentException("negative numbers not allowed")
else -> {
var ans = 1L
for (i in 2..n) ans *= i
ans
}
}
fun factr(n: Int): Long = when {
n < 0 -> throw IllegalArgumentException("negative numbers not allowed")
n < 2 -> 1L
... | 882Factorial | 11kotlin | hqlj3 |
import Data.Complex
eulerIdentityZeroIsh :: Complex Double
eulerIdentityZeroIsh =
exp (0:+ pi) + 1
main :: IO ()
main = print eulerIdentityZeroIsh | 884Euler's identity | 8haskell | ksch0 |
public class EulerIdentity {
public static void main(String[] args) {
System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0)));
}
public static class Complex {
private double x, y;
public Complex(double re, double im) {
x = re;
... | 884Euler's identity | 9java | 41z58 |
null | 884Euler's identity | 11kotlin | ljicp |
SELECT round ( EXP ( SUM (ln ( ( 1 + SQRT( 5 ) ) / 2)
) OVER ( ORDER BY level ) ) / SQRT( 5 ) ) fibo
FROM dual
CONNECT BY level <= 10; | 862Fibonacci sequence | 19sql | gew4k |
local c = {
new = function(s,r,i) s.__index=s return setmetatable({r=r, i=i}, s) end,
add = function(s,o) return s:new(s.r+o.r, s.i+o.i) end,
exp = function(s) local e=math.exp(s.r) return s:new(e*math.cos(s.i), e*math.sin(s.i)) end,
mul = function(s,o) return s:new(s.r*o.r+s.i*o.i, s.r*o.i+s.i*o.r) end
}
local... | 884Euler's identity | 1lua | 2hnl3 |
use Math::Complex;
print exp(pi * i) + 1, "\n"; | 884Euler's identity | 2perl | qtrx6 |
>>> import math
>>> math.e ** (math.pi * 1j) + 1
1.2246467991473532e-16j | 884Euler's identity | 3python | sz7q9 |
exp(1i * pi) + 1 | 884Euler's identity | 13r | en5ad |
import Cocoa
func fibonacci(n: Int) -> Int {
let square_root_of_5 = sqrt(5.0)
let p = (1 + square_root_of_5) / 2
let q = 1 / p
return Int((pow(p,CDouble(n)) + pow(q,CDouble(n))) / square_root_of_5 + 0.5)
}
for i in 1...30 {
println(fibonacci(i))
} | 862Fibonacci sequence | 17swift | 97jmj |
include Math
E ** (PI * 1i) + 1 | 884Euler's identity | 14ruby | 86h01 |
use std::f64::consts::PI;
extern crate num_complex;
use num_complex::Complex;
fn main() {
println!("{:e}", Complex::new(0.0, PI).exp() + 1.0);
} | 884Euler's identity | 15rust | oyk83 |
import spire.math.{Complex, Real}
object Scratch extends App{ | 884Euler's identity | 16scala | dc1ng |
package main
import (
"fmt"
"math"
"rcu"
)
var limit = int(math.Log(1e6) * 1e6 * 1.2) | 885Erdös-Selfridge categorization of primes | 0go | gaz4n |
typedef double (*deriv_f)(double, double);
void ivp_euler(deriv_f f, double y, int step, int end_t)
{
int t = 0;
printf(, (int)step);
do {
if (t % 10 == 0) printf(FMT, y);
y += step * f(t, y);
} while ((t += step) <= end_t);
printf();
}
void analytic()
{
double t;
printf();
for (t = 0; t <= 100; t += 10... | 886Euler method | 5c | vki2o |
import java.util.*;
public class ErdosSelfridge {
private int[] primes;
private int[] category;
public static void main(String[] args) {
ErdosSelfridge es = new ErdosSelfridge(1000000);
System.out.println("First 200 primes:");
for (var e : es.getPrimesByCategory(200).entrySet()) {... | 885Erdös-Selfridge categorization of primes | 9java | 1o2p2 |
use strict;
use warnings;
use feature 'say';
use List::Util 'max';
use ntheory qw/factor/;
use Primesieve qw(generate_primes);
my @primes = (0, generate_primes (1, 10**8));
my %cat = (2 => 1, 3 => 1);
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub ES {
my ($n) = @_;
my @factors = f... | 885Erdös-Selfridge categorization of primes | 2perl | t2afg |
function fact(n)
return n > 0 and n * fact(n-1) or 1
end | 882Factorial | 1lua | ks2h2 |
(ns newton-cooling
(:gen-class))
(defn euler [f y0 a b h]
"Euler's Method.
Approximates y(time) in y'(time)=f(time,y) with y(a)=y0 and t=a..b and the step size h."
(loop [t a
y y0
result []]
(if (<= t b)
(recur (+ t h) (+ y (* (f (+ t h) y) h)) (conj result [(double t) (double y)]... | 886Euler method | 6clojure | rezg2 |
null | 885Erdös-Selfridge categorization of primes | 15rust | y4q68 |
typedef int bool;
typedef unsigned long long ull;
char as_digit(int d) {
return (d >= 0 && d <= 9) ? d + '0' : d - 10 + 'a';
}
void revstr(char *str) {
int i, len = strlen(str);
char t;
for (i = 0; i < len/2; ++i) {
t = str[i];
str[i] = str[len - i - 1];
str[len - i ... | 887Esthetic numbers | 5c | 9rqm1 |
package main
import (
"fmt"
"log"
"rcu"
"sort"
)
func ord(n int) string {
if n < 0 {
log.Fatal("Argument must be a non-negative integer.")
}
m := n % 100
if m >= 4 && m <= 20 {
return fmt.Sprintf("%sth", rcu.Commatize(n))
}
m %= 10
suffix := "th"
if m ==... | 888Equal prime and composite sums | 0go | aic1f |
use strict;
use warnings;
use feature <say state>;
use ntheory <is_prime next_prime>;
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub suffix { my($d) = $_[0] =~ /(.)$/; $d == 1 ? 'st' : $d == 2 ? 'nd' : $d == 3 ? 'rd' : 'th' }
sub prime_sum {
state $s = state $p = 2; state $i = 1;
i... | 888Equal prime and composite sums | 2perl | 2h0lf |
package main
import (
"fmt"
"math"
) | 886Euler method | 0go | szgqa |
package main
import (
"fmt"
"strconv"
)
func uabs(a, b uint64) uint64 {
if a > b {
return a - b
}
return b - a
}
func isEsthetic(n, b uint64) bool {
if n == 0 {
return false
}
i := n % b
n /= b
for n > 0 {
j := n % b
if uabs(i, j) != 1 {
... | 887Esthetic numbers | 0go | en2a6 |
def eulerStep = { xn, yn, h, dydx ->
(yn + h * dydx(xn, yn)) as BigDecimal
}
Map eulerMapping = { x0, y0, h, dydx, stopCond = { xx, yy, hh, xx0 -> abs(xx - xx0) > (hh * 100) }.rcurry(h, x0) ->
Map yMap = [:]
yMap[x0] = y0 as BigDecimal
def x = x0
while (!stopCond(x, yMap[x])) {
yMap[x + h]... | 886Euler method | 7groovy | ai21p |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.