code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
expr1 <- quote(a+b*c)
expr2 <- parse(text="a+b*c")[[1]]
expr3 <- call("+", quote(`a`), call("*", quote(`b`), quote(`c`))) | 321Runtime evaluation | 13r | a5g1z |
function evalWithX(expr, a, b) {
var x = a;
var atA = eval(expr);
x = b;
var atB = eval(expr);
return atB - atA;
} | 322Runtime evaluation/In an environment | 10javascript | obp86 |
cities = [
{name: , population: 21},
{name: , population: 15.2},
{name: , population: 11.3},
{name: , population: 7.55},
{name: , population: 5.85},
{name: , population: 4.98},
{name: , population: 4.7},
{name: , population: 4.58},
{name: , population: 4.4},
{name: , pop... | 317Search a list of records | 14ruby | 1ujpw |
import Foundation
class PrimeSieve {
var composite: [Bool]
init(size: Int) {
composite = Array(repeating: false, count: size/2)
var p = 3
while p * p <= size {
if!composite[p/2 - 1] {
let inc = p * 2
var q = p * p
while q <= s... | 319Safe primes and unsafe primes | 17swift | daqnh |
null | 322Runtime evaluation/In an environment | 11kotlin | pvub6 |
struct City {
name: &'static str,
population: f64,
}
fn main() {
let cities = [
City {
name: "Lagos",
population: 21.0,
},
City {
name: "Cairo",
population: 15.2,
},
City {
name: "Kinshasa-Brazzaville",
... | 317Search a list of records | 15rust | a5h14 |
object SearchListOfRecords extends App {
val cities = Vector(
City("Lagos", 21.0e6),
City("Cairo", 15.2e6),
City("Kinshasa-Brazzaville", 11.3e6),
City("Greater Johannesburg", 7.55e6),
City("Mogadishu", 5.85e6),
City("Khartoum-Omdurman", 4.98e6),
City("Dar Es Salaam", 4.7e6),
City("Alex... | 317Search a list of records | 16scala | xrpwg |
a, b = 5, -7
ans = eval | 321Runtime evaluation | 14ruby | 0hbsu |
code = loadstring"return x^2" | 322Runtime evaluation/In an environment | 1lua | 1u5po |
package main
import (
"fmt"
"math/big"
)
func main() {
var n, e, d, bb, ptn, etn, dtn big.Int
pt := "Rosetta Code"
fmt.Println("Plain text: ", pt) | 324RSA code | 0go | 6sq3p |
CREATE TABLE african_capitals(name varchar2(100), population_in_millions NUMBER(3,2)); | 317Search a list of records | 19sql | 0hes1 |
package main
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"sort"
"strconv"
)
type Result struct {
lang string
users int
}
func main() {
const minimum = 25
ex := `"Category:(.+?)( User)?"(\}|,"categoryinfo":\{"size":(\d+),)`
re := regexp.MustCompile(ex)
page := "http... | 325Rosetta Code/Rank languages by number of users | 0go | ci89g |
module RSAMaker
where
import Data.Char ( chr )
encode :: String -> [Integer]
encode s = map (toInteger . fromEnum ) s
rsa_encode :: Integer -> Integer -> [Integer] -> [Integer]
rsa_encode n e numbers = map (\num -> mod ( num ^ e ) n ) numbers
rsa_decode :: Integer -> Integer -> [Integer] -> [Integer]
rsa_decode ... | 324RSA code | 8haskell | j9m7g |
struct Place {
var name: String
var population: Double
}
let places = [
Place(name: "Lagos", population: 21.0),
Place(name: "Cairo", population: 15.2),
Place(name: "Kinshasa-Brazzaville", population: 11.3),
Place(name: "Greater Johannesburg", population: 7.55),
Place(name: "Mogadishu", population: 5.85),... | 317Search a list of records | 17swift | pv7bl |
double rk4(double(*f)(double, double), double dx, double x, double y)
{
double k1 = dx * f(x, y),
k2 = dx * f(x + dx / 2, y + k1 / 2),
k3 = dx * f(x + dx / 2, y + k2 / 2),
k4 = dx * f(x + dx, y + k3);
return y + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
}
double rate(double x, double y)
{
return x * sqrt(y);
}
int ma... | 326Runge-Kutta method | 5c | ci09c |
use strict;
use warnings;
use JSON;
use URI::Escape;
use LWP::UserAgent;
my $client = LWP::UserAgent->new;
$client->agent("Rosettacode Perl task solver");
my $url = 'http://rosettacode.org/mw';
my $minimum = 100;
sub uri_query_string {
my(%fields) = @_;
'action=query&format=json&formatversion=2&' .
join '... | 325Rosetta Code/Rank languages by number of users | 2perl | 0h7s4 |
sub eval_with_x
{my $code = shift;
my $x = shift;
my $first = eval $code;
$x = shift;
return eval($code) - $first;}
print eval_with_x('3 * $x', 5, 10), "\n"; | 322Runtime evaluation/In an environment | 2perl | y086u |
import requests
URL =
PARAMS = {
: ,
: ,
: 2,
: ,
: ,
: 500,
: ,
}
def fetch_data():
counts = {}
continue_ = {: }
while continue_:
resp = requests.get(URL, params={**PARAMS, **continue_})
resp.raise_for_status()
data = resp.json()
... | 325Rosetta Code/Rank languages by number of users | 3python | 8kj0o |
<?php
function eval_with_x($code, $a, $b) {
$x = $a;
$first = eval($code);
$x = $b;
$second = eval($code);
return $second - $first;
}
echo eval_with_x('return 3 * $x;', 5, 10), ;
?> | 322Runtime evaluation/In an environment | 12php | a5412 |
enum { S_NONE, S_LIST, S_STRING, S_SYMBOL };
typedef struct {
int type;
size_t len;
void *buf;
} s_expr, *expr;
void whine(const char *s)
{
fprintf(stderr, , s);
}
expr parse_string(const char *s, char **e)
{
expr ex = calloc(sizeof(s_expr), 1);
char buf[256] = {0};
int i = 0;
while (*s) {
if (i >= 256) {... | 327S-expressions | 5c | ln0cy |
public static void main(String[] args) {
BigInteger n = new BigInteger("9516311845790656153499716760847001433441357");
BigInteger e = new BigInteger("65537");
BigInteger d = new BigInteger("5617843187844953170308463622230283376298685");
Charset c = Charsets.UTF_8;
String plainText = "Rosetta Co... | 324RSA code | 9java | utfvv |
int compareInts(const void *i1, const void *i2) {
int a = *((int *)i1);
int b = *((int *)i2);
return a - b;
}
int main() {
int i, j, nsum, vsum, vcount, values[6], numbers[4];
srand(time(NULL));
for (;;) {
vsum = 0;
for (i = 0; i < 6; ++i) {
for (j = 0; j < 4; ++j) {... | 328RPG attributes generator | 5c | zxptx |
>>> def eval_with_x(code, a, b):
return eval(code, {'x':b}) - eval(code, {'x':a})
>>> eval_with_x('2 ** x', 3, 5)
24 | 322Runtime evaluation/In an environment | 3python | m8oyh |
null | 324RSA code | 11kotlin | 9o8mh |
evalWithAB <- function(expr, var, a, b) {
env <- new.env()
assign(var, a, envir=env)
atA <- eval(parse(text=expr), env)
assign(var, b, envir=env)
atB <- eval(parse(text=expr), env)
return(atB - atA)
}
pri... | 322Runtime evaluation/In an environment | 13r | zxqth |
const char * lang_url =
;
const char * cat_url = ;
char *get_page(const char *url)
{
char cmd[1024];
char *ptr, *buf;
int bytes_read = 1, len = 0;
sprintf(cmd, %s\, url);
FILE *fp = popen(cmd, );
if (!fp) return 0;
for (ptr = buf = 0; bytes_read > 0; ) {
buf = realloc(buf, 1 + (len += BLOCK));
if (!p... | 329Rosetta Code/Rank languages by popularity | 5c | 6s132 |
package main
import "fmt"
import "io/ioutil"
import "log"
import "os"
import "regexp"
import "strings"
func main() {
err := fix()
if err != nil {
log.Fatalln(err)
}
}
func fix() (err error) {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
out, err := Lang(string(buf))
if err != nil {
... | 330Rosetta Code/Fix code tags | 0go | xrlwf |
use bigint;
$n = 9516311845790656153499716760847001433441357;
$e = 65537;
$d = 5617843187844953170308463622230283376298685;
package Message {
my @alphabet;
push @alphabet, $_ for 'A' .. 'Z', ' ';
my $rad = +@alphabet;
$code{$alphabet[$_]} = $_ for 0..$rad-1;
sub encode {
my($t) = @_;
... | 324RSA code | 2perl | wg4e6 |
def eratosthenes2(n):
multiples = set()
for i in range(2, n+1):
if i not in multiples:
yield i
multiples.update(range(i*i, n+1, i))
print(list(eratosthenes2(100))) | 309Sieve of Eratosthenes | 3python | zqmtt |
import 'dart:math' as Math;
num RungeKutta4(Function f, num t, num y, num dt){
num k1 = dt * f(t,y);
num k2 = dt * f(t+0.5*dt, y + 0.5*k1);
num k3 = dt * f(t+0.5*dt, y + 0.5*k2);
num k4 = dt * f(t + dt, y + k3);
return y + (1/6) * (k1 + 2*k2 + 2*k3 + k4);
}
void main(){
num t = 0;
num dt = 0.1;
num t... | 326Runge-Kutta method | 18dart | zxate |
def bind_x_to_value(x)
binding
end
def eval_with_x(code, a, b)
eval(code, bind_x_to_value(b)) - eval(code, bind_x_to_value(a))
end
puts eval_with_x('2 ** x', 3, 5) | 322Runtime evaluation/In an environment | 14ruby | cin9k |
object Eval extends App {
def evalWithX(expr: String, a: Double, b: Double)=
{val x = b; eval(expr)} - {val x = a; eval(expr)}
println(evalWithX("Math.exp(x)", 0.0, 1.0))
} | 322Runtime evaluation/In an environment | 16scala | utzv8 |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class FixCodeTags
{
public static void main(String[] args)
{
String sourcefile=args[0];
String convertedfile=args[1];
convert(sourcefile,convertedfile);
}
static String[] languages = {"abap", "a... | 330Rosetta Code/Fix code tags | 9java | da7n9 |
var langs = ['foo', 'bar', 'baz']; | 330Rosetta Code/Fix code tags | 10javascript | 6sp38 |
sieve <- function(n) {
if (n < 2) integer(0)
else {
primes <- rep(T, n)
primes[[1]] <- F
for(i in seq(sqrt(n))) {
if(primes[[i]]) {
primes[seq(i * i, n, i)] <- F
}
}
which(primes)
}
}
sieve(1000) | 309Sieve of Eratosthenes | 13r | nazi2 |
null | 330Rosetta Code/Fix code tags | 1lua | 8k50e |
import binascii
n = 9516311845790656153499716760847001433441357
e = 65537
d = 5617843187844953170308463622230283376298685
message='Rosetta Code!'
print('message ', message)
hex_data = binascii.hexlify(message.encode())
print('hex data ', hex_data)
plain_text = int(hex_data, 16)
... | 324RSA code | 3python | xrgwr |
(require
'[clojure.xml:as xml]
'[clojure.set:as set]
'[clojure.string:as string])
(import '[java.net URLEncoder]) | 331Rosetta Code/Find unimplemented tasks | 6clojure | pv3bd |
package main
var haystack = []string{"Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty",
"Charlie", "Bush", "Bozo", "Zag", "mouse", "hat", "cup", "deodorant",
"television", "soap", "methamphetamine", "severed cat heads", "foo",
"bar", "baz", "quux", "quuux", "quuuux", "bazola", "ztesch", "foo",
"bar", "... | 323Search a list | 0go | q77xz |
require 'openssl'
require 'prime'
def rsa_encode blocks, e, n
blocks.map{|b| b.to_bn.mod_exp(e, n).to_i}
end
def rsa_decode ciphers, d, n
rsa_encode ciphers, d, n
end
def text_to_blocks text, blocksize=64
text.each_byte.reduce(){|acc,b| acc << b.to_s(16).rjust(2, )}
.each_char.each_slice(blocksize).... | 324RSA code | 14ruby | sj7qw |
def haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
def needles = ["Washington","Bush","Wally"]
needles.each { needle ->
def index = haystack.indexOf(needle)
def lastindex = haystack.lastIndexOf(needle)
if (index < 0) {
assert lastindex < 0
println needle +... | 323Search a list | 7groovy | 1uup6 |
package main
import (
"fmt"
"math"
)
type ypFunc func(t, y float64) float64
type ypStepFunc func(t, y, dt float64) float64 | 326Runge-Kutta method | 0go | wgueg |
package main
import (
"encoding/xml"
"fmt"
"io"
"net/http"
"net/url"
)
const language = "Go"
var baseQuery = "http: | 331Rosetta Code/Find unimplemented tasks | 0go | darne |
my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog
html4strict cil objc asm progress teraterm hq9plus genero tsql
email pic16 tcl apt_sources io apache vhdl avisynth winbatch
vbnet ini scilab ocaml-brief sas actionscript3 qbasic perl bnf
cobol powershell php kixtart visualfoxpro mirc make javascript
cpp sdlbasic... | 330Rosetta Code/Fix code tags | 2perl | 5z8u2 |
extern crate num;
use num::bigint::BigUint;
use num::integer::Integer;
use num::traits::{One, Zero};
fn mod_exp(b: &BigUint, e: &BigUint, n: &BigUint) -> Result<BigUint, &'static str> {
if n.is_zero() {
return Err("modulus is zero");
}
if b >= n { | 324RSA code | 15rust | 0hjsl |
object RSA_saket{
val d = BigInt("5617843187844953170308463622230283376298685")
val n = BigInt("9516311845790656153499716760847001433441357")
val e = 65537
val text = "Rosetta Code"
val encode = (msg:BigInt) => pow_mod(msg,e,n)
val decode = (msg:BigInt) => pow_mod(msg,d,n)
val getmsg = (txt:... | 324RSA code | 16scala | ipbox |
(ns count-examples
(:import [java.net URLEncoder])
(:use [clojure.contrib.http.agent:only (http-agent string)]
[clojure.contrib.json:only (read-json)]
[clojure.contrib.string:only (join)]))
(defn url-encode [v] (URLEncoder/encode (str v) "utf-8"))
(defn rosettacode-get [path params]
(let [param-... | 332Rosetta Code/Count examples | 6clojure | y0b6b |
import Data.List
haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
needles = ["Washington","Bush"] | 323Search a list | 8haskell | m88yf |
class Runge_Kutta{
static void main(String[] args){
def y=1.0,t=0.0,counter=0;
def dy1,dy2,dy3,dy4;
def real;
while(t<=10)
{if(counter%10==0)
{real=(t*t+4)*(t*t+4)/16;
println("y("+t+")="+ y+ " Error:"+ (real-y));
}
dy1=dy(dery(y,t));
dy2=dy(dery(y+dy1/2,t+0.05));
dy3=dy(dery(y+dy2/2,t+0.05));
dy4=dy(dery(y+dy3,t+0.1)... | 326Runge-Kutta method | 7groovy | b29ky |
import Network.Browser
import Network.HTTP
import Network.URI
import Data.List
import Data.Maybe
import Text.XML.Light
import Control.Arrow
import Data.Char
getRespons url = do
rsp <- Network.Browser.browse $ do
setAllowRedirects True
setOutHandler $ const (return ())
request $ getRequest url
return... | 331Rosetta Code/Find unimplemented tasks | 8haskell | 5z0ug |
package main
import (
"errors"
"fmt"
"reflect"
"strconv"
"strings"
"unicode"
)
var input = `((data "quoted data" 123 4.5)
(data (!@# (4.5) "(more" "data)")))`
func main() {
fmt.Println("input:")
fmt.Println(input)
s, err := parseSexp(input)
if err != nil {
fmt.Printl... | 327S-expressions | 0go | xruwf |
package main
import (
"fmt"
"math/rand"
"sort"
"time"
)
func main() {
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
for {
var values [6]int
vsum := 0
for i := range values {
var numbers [4]int
for j := range numbers {
... | 328RPG attributes generator | 0go | kl6hz |
package main
import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
"regexp"
"sort"
"strconv"
"strings"
)
var baseQuery = "http: | 329Rosetta Code/Rank languages by popularity | 0go | pvybg |
int main()
{
double a, c, s, PI2 = atan2(1, 1) * 8;
int n, i;
for (n = 1; n < 10; n++) for (i = 0; i < n; i++) {
c = s = 0;
if (!i ) c = 1;
else if(n == 4 * i) s = 1;
else if(n == 2 * i) c = -1;
else if(3 * n == 4 * i) s = -1;
else
a = i * PI2 / n, c = cos(a), s = sin(a);
if (c) printf(, c);
... | 333Roots of unity | 5c | 0hlst |
typedef double complex cplx;
void quad_root
(double a, double b, double c, cplx * ra, cplx *rb)
{
double d, e;
if (!a) {
*ra = b ? -c / b : 0;
*rb = 0;
return;
}
if (!c) {
*ra = 0;
*rb = -b / a;
return;
}
b /= 2;
if (fabs(b) > fabs(c)) {
e = 1 - (a / b) * (c / b);
d = sqrt(fabs(e)) * fabs(b);
... | 334Roots of a quadratic function | 5c | da5nv |
import qualified Data.Functor.Identity as F
import qualified Text.Parsec.Prim as Prim
import Text.Parsec
((<|>), (<?>), many, many1, char, try, parse, sepBy, choice,
between)
import Text.Parsec.Token
(integer, float, whiteSpace, stringLiteral, makeTokenParser)
import Text.Parsec.Char (noneOf)
impo... | 327S-expressions | 8haskell | y0w66 |
import sys
import re
langs = ['ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog',
'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus',
'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache',
'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief',
'sas', 'a... | 330Rosetta Code/Fix code tags | 3python | 43o5k |
import Control.Monad (replicateM)
import System.Random (randomRIO)
import Data.Bool (bool)
import Data.List (sort)
character :: IO [Int]
character =
discardUntil
(((&&) . (75 <) . sum) <*> ((2 <=) . length . filter (15 <=)))
(replicateM 6 $ sum . tail . sort <$> replicateM 4 (randomRIO (1, 6 :: Int)))
disca... | 328RPG attributes generator | 8haskell | n1jie |
def html = new URL('http: | 329Rosetta Code/Rank languages by popularity | 7groovy | 7mfrz |
dv
:: Floating a
=> a -> a -> a
dv = (. sqrt) . (*)
fy t = 1 / 16 * (4 + t ^ 2) ^ 2
rk4
:: (Enum a, Fractional a)
=> (a -> a -> a) -> a -> a -> a -> [(a, a)]
rk4 fd y0 a h = zip ts $ scanl (flip fc) y0 ts
where
ts = [a,h ..]
fc t y =
sum . (y:) . zipWith (*) [1 / 6, 1 / 3, 1 / 3, 1 / 6] $
... | 326Runge-Kutta method | 8haskell | 6sw3k |
fixtags <- function(page)
{
langs <- c("c", "c-sharp", "r")
langs <- paste(langs, collapse="|")
page <- gsub(paste("<(", langs, ")>", sep=""), "<lang \\1>", page)
page <- gsub(paste("</(", langs, ")>", sep=""), "</
page <- gsub(paste("<code(", langs, ")>", sep=""), "<lang \\1>", page)
page <- gsub(... | 330Rosetta Code/Fix code tags | 13r | 2dqlg |
def eratosthenes(n)
nums = [nil, nil, *2..n]
(2..Math.sqrt(n)).each do |i|
(i**2..n).step(i){|m| nums[m] = nil} if nums[i]
end
nums.compact
end
p eratosthenes(100) | 309Sieve of Eratosthenes | 14ruby | 60c3t |
import Data.Aeson
import Network.HTTP.Base (urlEncode)
import Network.HTTP.Conduit (simpleHttp)
import Data.List (sortBy, groupBy)
import Data.Function (on)
import Data.Map (Map, toList)
data Language =
Language {
name :: String,
quantity :: Int
} deriving (Show)
instance FromJSON La... | 329Rosetta Code/Rank languages by popularity | 8haskell | fehd1 |
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
)
type header struct {
start, end int
lang string
}
type data struct {
count int
names *[]string
}
func newData(count int, name string) *data {
return &data{count, &[]string{name}}
}
var bmap = m... | 335Rosetta Code/Find bare lang tags | 0go | 9okmt |
(function (strXPath) {
var xr = document.evaluate(
strXPath,
document,
null, 0, 0
),
oNode = xr.iterateNext(),
lstTasks = [];
while (oNode) {
lstTasks.push(oNode.title);
oNode = xr.iterateNext();
}
return [
lstTasks.length + " items found in " + document.title,
'... | 331Rosetta Code/Find unimplemented tasks | 10javascript | utsvb |
text = DATA.read
slash_lang = '/lang'
langs = %w(foo bar baz)
for lang in langs
text.gsub!(Regexp.new()) {}
text.gsub!(Regexp.new(), )
end
text.gsub!(/<code (.*?)>/, '<lang \1>')
text.gsub!(/<\/code>/, )
print text
__END__
Lorem ipsum <code foo>saepe audire</code> elaboraret ne quo, id equidem
atomorum inciderint... | 330Rosetta Code/Fix code tags | 14ruby | ryngs |
import java.util.List;
import java.util.Random;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
public class Rpg {
private static final Random random = new Random();
public static int genAttribute() {
return random.ints(1, 6 + 1) | 328RPG attributes generator | 9java | q7uxa |
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func req(u string, foundCm func(string)) string {
resp, err := http.Get(u)
if err != nil {
fmt.Println(err) | 332Rosetta Code/Count examples | 0go | j9n7d |
typedef struct stream_t stream_t, *stream;
struct stream_t {
int (*get)(stream);
int (*put)(stream, int);
};
typedef struct {
int (*get)(stream);
int (*put)(stream, int);
char *string;
int pos;
} string_stream;
typedef struct {
int (*get)(stream);
int (*put)(stream, int);
FILE *fp;
} file_stream;
int ... | 336Run-length encoding | 5c | xr3wu |
import java.util.function.Predicate
import java.util.regex.Matcher
import java.util.regex.Pattern
class FindBareTags {
private static final Pattern TITLE_PATTERN = Pattern.compile("\"title\": \"([^\"]+)\"")
private static final Pattern HEADER_PATTERN = Pattern.compile("==\\{\\{header\\|([^}]+)}}==")
privat... | 335Rosetta Code/Find bare lang tags | 7groovy | zxgt5 |
(defn quadratic
"Compute the roots of a quadratic in the form ax^2 + bx + c = 1.
Returns any of nil, a float, or a vector."
[a b c]
(let [sq-d (Math/sqrt (- (* b b) (* 4 a c)))
f #(/ (% b sq-d) (* 2 a))]
(cond
(neg? sq-d) nil
(zero? sq-d) (f +)
(pos? sq-d) [(f +) (f -)]
... | 334Roots of a quadratic function | 6clojure | 6sj3q |
import static java.lang.Math.*;
import java.util.function.BiFunction;
public class RungeKutta {
static void runge(BiFunction<Double, Double, Double> yp_func, double[] t,
double[] y, double dt) {
for (int n = 0; n < t.length - 1; n++) {
double dy1 = dt * yp_func.apply(t[n], y[n]);
... | 326Runge-Kutta method | 9java | n1kih |
local requests = require('requests')
local lang = arg[1]
local function merge_tables(existing, from_req)
local result = existing
for _, v in ipairs(from_req) do
result[v.title] = true
end
return result
end
local function get_task_list(category)
local url = 'http://www.rosettacode.org/mw/api.php'
l... | 331Rosetta Code/Find unimplemented tasks | 1lua | 3qkzo |
package jfkbits;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.util.Iterator;
public class LispTokenizer implements Iterator<Token>
{ | 327S-expressions | 9java | dakn9 |
extern crate regex;
use std::io;
use std::io::prelude::*;
use regex::Regex;
const LANGUAGES: &str =
"_div abap actionscript actionscript3 ada apache applescript apt_sources asm asp autoit \
avisynth bash basic4gl bf blitzbasic bnf boo c c_mac caddcl cadlisp cfdg cfm cil cobol cpp \
cpp-qt csharp css d ... | 330Rosetta Code/Fix code tags | 15rust | 7mdrc |
object FixCodeTags extends App {
val rx = | 330Rosetta Code/Fix code tags | 16scala | klzhk |
function roll() {
const stats = {
total: 0,
rolls: []
}
let count = 0;
for(let i=0;i<=5;i++) {
let d6s = [];
for(let j=0;j<=3;j++) {
d6s.push(Math.ceil(Math.random() * 6))
}
d6s.sort().splice(0, 1);
rollTotal = d6s.reduce((a, b) => a+b, 0);
stats.rolls.push(rollTota... | 328RPG attributes generator | 10javascript | ip7ol |
fn primes(n: usize) -> impl Iterator<Item = usize> {
const START: usize = 2;
if n < START {
Vec::new()
} else {
let mut is_prime = vec![true; n + 1 - START];
let limit = (n as f64).sqrt() as usize;
for i in START..limit + 1 {
let mut it = is_prime[i - START..].ite... | 309Sieve of Eratosthenes | 15rust | y8l68 |
import Network.Browser
import Network.HTTP
import Network.URI
import Data.List
import Data.Maybe
import Text.XML.Light
import Control.Arrow
justifyR w = foldl ((.return).(++).tail) (replicate w ' ')
showFormatted t n = t ++ ": " ++ justifyR 4 (show n)
getRespons url = do
rsp <- Network.Browser.browse $ do
s... | 332Rosetta Code/Count examples | 8haskell | obu8p |
import java.util.List;
import java.util.Arrays;
List<String> haystack = Arrays.asList("Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo");
for (String needle : new String[]{"Washington","Bush"}) {
int index = haystack.indexOf(needle);
if (index < 0)
System.out.println(needle + " is n... | 323Search a list | 9java | feedv |
import System.Environment
import Network.HTTP
import Text.Printf
import Text.Regex.TDFA
import Data.List
import Data.Array
import qualified Data.Map as Map
splitByMatches :: String -> [MatchText String] -> [String]
splitByMatches str matches = foldr splitHead [str] matches
where splitHead match acc = before:a... | 335Rosetta Code/Find bare lang tags | 8haskell | b2nk2 |
function rk4(y, x, dx, f) {
var k1 = dx * f(x, y),
k2 = dx * f(x + dx / 2.0, +y + k1 / 2.0),
k3 = dx * f(x + dx / 2.0, +y + k2 / 2.0),
k4 = dx * f(x + dx, +y + k3);
return y + (k1 + 2.0 * k2 + 2.0 * k3 + k4) / 6.0;
}
function f(x, y) {
return x * Math.sqrt(y);
}
functi... | 326Runge-Kutta method | 10javascript | 3qez0 |
String.prototype.parseSexpr = function() {
var t = this.match(/\s*("[^"]*"|\(|\)|"|[^\s()"]+)/g)
for (var o, c=0, i=t.length-1; i>=0; i--) {
var n, ti = t[i].trim()
if (ti == '"') return
else if (ti == '(') t[i]='[', c+=1
else if (ti == ')') t[i]=']', c-=1
else if ((n=+ti) == ti) t[i]=n
else t[i] = '\'' +... | 327S-expressions | 10javascript | 6se38 |
var haystack = ['Zig', 'Zag', 'Wally', 'Ronald', 'Bush', 'Krusty', 'Charlie', 'Bush', 'Bozo']
var needles = ['Bush', 'Washington']
for (var i in needles) {
var found = false;
for (var j in haystack) {
if (haystack[j] == needles[i]) {
found = true;
break;
}
}
if (... | 323Search a list | 10javascript | y006r |
import kotlin.random.Random
fun main() {
while (true) {
val values = List(6) {
val rolls = generateSequence { 1 + Random.nextInt(6) }.take(4)
rolls.sorted().take(3).sum()
}
val vsum = values.sum()
val vcount = values.count { it >= 15 }
if (vsum < 75 |... | 328RPG attributes generator | 11kotlin | 1u9pd |
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
import java.util.*;
public class GetRCLanguages
{ | 329Rosetta Code/Rank languages by popularity | 9java | 0h5se |
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Coll... | 335Rosetta Code/Find bare lang tags | 9java | g6q4m |
null | 326Runge-Kutta method | 11kotlin | sjgq7 |
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent('');
sub enc { join '', map {sprintf '%%%02x', ord} split //, shift }
sub get { $ua->request( HTTP::Request->new( GET => shift))->content }
sub tasks {
my($category) = shift;
my $fmt = 'http://www.rosettacode.org/mw/api.php?' .
'actio... | 331Rosetta Code/Find unimplemented tasks | 2perl | b2zk4 |
null | 327S-expressions | 11kotlin | 0hgsf |
import java.util.ArrayList;
import ScreenScrape;
public class CountProgramExamples {
private static final String baseURL = "http: | 332Rosetta Code/Count examples | 9java | wgmej |
(defn compress [s]
(->> (partition-by identity s) (mapcat (juxt count first)) (apply str)))
(defn extract [s]
(->> (re-seq #"(\d+)([A-Z])" s)
(mapcat (fn [[_ n ch]] (repeat (Integer/parseInt n) ch)))
(apply str))) | 336Run-length encoding | 6clojure | obc8j |
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.util.regex.Pattern
import java.util.stream.Collectors
const val BASE = "http: | 335Rosetta Code/Find bare lang tags | 11kotlin | 2d1li |
lpeg = require 'lpeg' | 327S-expressions | 1lua | 8kr0e |
import scala.annotation.tailrec
import scala.collection.parallel.mutable
import scala.compat.Platform
object GenuineEratosthenesSieve extends App {
def sieveOfEratosthenes(limit: Int) = {
val (primes: mutable.ParSet[Int], sqrtLimit) = (mutable.ParSet.empty ++ (2 to limit), math.sqrt(limit).toInt)
@tailrec
... | 309Sieve of Eratosthenes | 16scala | cnu93 |
null | 323Search a list | 11kotlin | 8kk0q |
import java.net.URL
import java.io.*
object Popularity {
fun ofLanguages(): List<String> {
val languages = mutableListOf<String>()
var gcm = ""
do {
val path = url + (if (gcm == "") "" else "&gcmcontinue=" + gcm) + "&prop=categoryinfo" + "&format=txt"
try {
... | 329Rosetta Code/Rank languages by popularity | 11kotlin | e4ca4 |
double f(double x)
{
return x*x*x-3.0*x*x +2.0*x;
}
double secant( double xA, double xB, double(*f)(double) )
{
double e = 1.0e-12;
double fA, fB;
double d;
int i;
int limit = 50;
fA=(*f)(xA);
for (i=0; i<limit; i++) {
fB=(*f)(xB);
d = (xB - xA) / (fB - fA) * fB;
... | 337Roots of a function | 5c | y0r6f |
package main
import (
"fmt"
"math"
)
func qr(a, b, c float64) ([]float64, []complex128) {
d := b*b-4*a*c
switch {
case d == 0: | 334Roots of a quadratic function | 0go | 7m8r2 |
from operator import attrgetter
from typing import Iterator
import mwclient
URL = 'www.rosettacode.org'
API_PATH = '/mw/'
def unimplemented_tasks(language: str,
*,
url: str,
api_path: str) -> Iterator[str]:
site = mwclient.Site(url, pa... | 331Rosetta Code/Find unimplemented tasks | 3python | pv3bm |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.