code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
null | 868Extend your language | 11kotlin | 1iqpd |
class Integer
def factors() (1..self).select { |n| (self % n).zero? } end
end
p 45.factors | 861Factors of an integer | 14ruby | 06msu |
package Hailstone;
sub seq {
my $x = shift;
$x == 1 ? (1) : ($x & 1)? ($x, seq($x * 3 + 1))
: ($x, seq($x / 2))
}
my %cache = (1 => 1);
sub len {
my $x = shift;
$cache{$x} //= 1 + (
$x & 1 ? len($x * 3 + 1)
: len($x / 2))
}
unless (caller) {
for (1 .. 100_000) {
my $l = len($_);
($m,... | 875Executable library | 2perl | szwq3 |
let negInf = -1.0 / 0.0
let inf = 1.0 / 0.0 | 865Extreme floating point values | 17swift | om68k |
$ include ;
const proc: snusp (in string: sourceCode, in integer: memSize, inout file: input, inout file: output) is func
local
var array string: instructions is 0 times ;
var array char: memory is 0 times ' ';
var integer: dataPointer is 1;
var integer: instrPtrRow is 0;
var integer: instrPtrCol... | 872Execute SNUSP | 14ruby | 97cmz |
null | 868Extend your language | 1lua | ans1v |
fun isPrime(n: Int) : Boolean {
if (n < 2) return false
if (n % 2 == 0) return n == 2
if (n % 3 == 0) return n == 3
var d : Int = 5
while (d * d <= n) {
if (n % d == 0) return false
d += 2
if (n % d == 0) return false
d += 4
}
return true
}
fun generatePrimes... | 869Extensible prime generator | 11kotlin | edsa4 |
fn main() {
assert_eq!(vec![1, 2, 4, 5, 10, 10, 20, 25, 50, 100], factor(100)); | 861Factors of an integer | 15rust | 8y907 |
typedef struct { char * s; size_t alloc_len; } string;
typedef struct {
char *pat, *repl;
int terminate;
} rule_t;
typedef struct {
int n;
rule_t *rules;
char *buf;
} ruleset_t;
void ruleset_del(ruleset_t *r)
{
if (r->rules) free(r->rules);
if (r->buf) free(r->buf);
free(r);
}
string... | 877Execute a Markov algorithm | 5c | y4f6f |
local primegen = {
count_limit = 2,
value_limit = 3,
primelist = { 2, 3 },
nextgenvalue = 5,
nextgendelta = 2,
tbd = function(n)
if n < 2 then return false end
if n % 2 == 0 then return n==2 end
if n % 3 == 0 then return n==3 end
local limit = math.sqrt(n)
for f = 5, limit, 6 do
if... | 869Extensible prime generator | 1lua | wf0ea |
public static long itFibN(int n)
{
if (n < 2)
return n;
long ans = 0;
long n1 = 0;
long n2 = 1;
for(n--; n > 0; n--)
{
ans = n1 + n2;
n1 = n2;
n2 = ans;
}
return ans;
} | 862Fibonacci sequence | 9java | xtzwy |
enum { MY_EXCEPTION = 1 };
jmp_buf env;
void foo()
{
longjmp(env, MY_EXCEPTION);
}
void call_foo()
{
switch (setjmp(env)) {
case 0:
foo();
break;
case MY_EXCEPTION:
break;
default:
}
} | 878Exceptions | 5c | vky2o |
def hailstone(n):
seq = [n]
while n>1:
n = 3*n + 1 if n & 1 else n
seq.append(n)
return seq
if __name__ == '__main__':
h = hailstone(27)
assert len(h)==112 and h[:4]==[27, 82, 41, 124] and h[-4:]==[8, 4, 2, 1]
print(%
max((len(hailstone(i)), i) for i in range(1,100000)... | 875Executable library | 3python | 03xsq |
function fib(n) {
return n<2?n:fib(n-1)+fib(n-2);
} | 862Fibonacci sequence | 10javascript | om986 |
def factors(num: Int) = {
(1 to num).filter { divisor =>
num % divisor == 0
}
} | 861Factors of an integer | 16scala | nc2ic |
module hq9plus
function main = |args| {
var accumulator = 0
let source = readln("please enter your source code: ")
foreach ch in source: chars() {
case {
when ch == 'h' or ch == 'H' {
println("Hello, world!")
}
when ch == 'q' or ch == 'Q' {
println(source)
}
when... | 873Execute HQ9+ | 0go | upuvt |
module Hailstone
module_function
def hailstone n
seq = [n]
until n == 1
n = (n.even?)? (n / 2): (3 * n + 1)
seq << n
end
seq
end
end
if __FILE__ == $0
include Hailstone
hs27 = hailstone 27
p [hs27.length, hs27[0..3], hs27[-4..-1]]
n, len = (1 ... 100_000) .collect {|n|... | 875Executable library | 14ruby | oys8v |
// live demo: http://try.haxe.org/#2E7D4
static function hq9plus(code:String):String {
var out:String = "";
var acc:Int = 0;
for (position in 0 ... code.length) switch (code.charAt(position)) {
case "H", "h": out += "Hello, World!\n";
case "Q", "q": out += '$code\n';
case "9":
var quantity:Int = 99;
whil... | 873Execute HQ9+ | 8haskell | wfwed |
(try
(if (> (rand) 0.5)
(throw (RuntimeException. "oops!"))
(println "see this half the time")
(catch RuntimeException e
(println e)
(finally
(println "always see this")) | 878Exceptions | 6clojure | re2g2 |
object HailstoneSequence extends App { | 875Executable library | 16scala | flid4 |
package main
import (
"errors"
"fmt"
)
func expI(b, p int) (int, error) {
if p < 0 {
return 0, errors.New("negative power not allowed")
}
r := 1
for i := 1; i <= p; i++ {
r *= b
}
return r, nil
}
func expF(b float32, p int) float32 {
var neg bool
if p < 0 {
... | 874Exponentiation operator | 0go | 7wgr2 |
int main()
{
system();
return 0;
} | 879Execute a system command | 5c | ubyv4 |
(^) :: (Num a, Integral b) => a -> b -> a
_ ^ 0 = 1
x ^ n | n > 0 = f x (n-1) x where
f _ 0 y = y
f a d y = g a d where
g b i | even i = g (b*b) (i `quot` 2)
| otherwise = f b (i-1) (b*y)
_ ^ _ = error "Prelude.^: negative exponent" | 874Exponentiation operator | 8haskell | 86s0z |
package main
import (
"fmt"
"regexp"
"strings"
)
type testCase struct {
ruleSet, sample, output string
}
func main() {
fmt.Println("validating", len(testSet), "test cases")
var failures bool
for i, tc := range testSet {
if r, ok := interpret(tc.ruleSet, tc.sample); !ok {
... | 877Execute a Markov algorithm | 0go | 1ojp5 |
null | 876Exceptions/Catch an exception thrown in a nested call | 0go | ljycw |
(.. Runtime getRuntime (exec "cmd /C dir")) | 879Execute a system command | 6clojure | 7w2r0 |
1.upto(100) do |n|
print if a = (n % 3).zero?
print if b = (n % 5).zero?
print n unless (a || b)
puts
end | 835FizzBuzz | 14ruby | adx1s |
func factors(n: Int) -> [Int] {
return filter(1...n) { n% $0 == 0 }
} | 861Factors of an integer | 17swift | s3yqt |
function hq9plus(code) {
var out = '';
var acc = 0;
for (var i=0; i<code.length; i++) {
switch (code.charAt(i)) {
case 'H': out += "hello, world\n"; break;
case 'Q': out += code + "\n"; break;
case '9':
for (var j=99; j>1; j--) {
out += j + " bottles of beer on the wall, "... | 873Execute HQ9+ | 9java | k0khm |
def markovInterpreterFor = { rules ->
def ruleMap = [:]
rules.eachLine { line ->
(line =~ /\s*(.+)\s->\s([.]?)(.+)\s*/).each { text, key, terminating, value ->
if (key.startsWith('#')) { return }
ruleMap[key] = [text: value, terminating: terminating]
}
}
[interpre... | 877Execute a Markov algorithm | 7groovy | jx57o |
import Control.Monad.Error
import Control.Monad.Trans (lift)
data MyError = U0 | U1 | Other deriving (Eq, Read, Show)
instance Error MyError where
noMsg = Other
strMsg _ = Other
foo = do lift (putStrLn "foo")
mapM_ (\toThrow -> bar toThrow
`c... | 876Exceptions/Catch an exception thrown in a nested call | 8haskell | 1ohps |
public class Exp{
public static void main(String[] args){
System.out.println(pow(2,30));
System.out.println(pow(2.0,30)); | 874Exponentiation operator | 9java | en1a5 |
use warnings;
use strict;
use v5.10;
=for starters
Syntax:
if2 condition1, condition2, then2 {
}
else1 {
}
else2 {
}
orelse {
};
Any (but not all) of the `then' and `else' clauses can be omitted, and else1
and else2 can be specified in either order... | 868Extend your language | 2perl | mrvyz |
use Math::Prime::Util qw(nth_prime prime_count primes);
say "First 20: ", join(" ", @{primes(nth_prime(20))});
say "Between 100 and 150: ", join(" ", @{primes(100,150)});
say prime_count(7700,8000), " primes between 7700 and 8000";
say "${_}th prime: ", nth_prime($_) for map { 10**$_ } 1..8; | 869Extensible prime generator | 2perl | cju9a |
function hq9plus(code) {
var out = '';
var acc = 0;
for (var i=0; i<code.length; i++) {
switch (code.charAt(i)) {
case 'H': out += "hello, world\n"; break;
case 'Q': out += code + "\n"; break;
case '9':
for (var j=99; j>1; j--) {
out += j + " bottles of beer on the wall, "... | 873Execute HQ9+ | 10javascript | edeao |
import Data.List (isPrefixOf)
import Data.Maybe (catMaybes)
import Control.Monad
import Text.ParserCombinators.Parsec
import System.IO
import System.Environment (getArgs)
main = do
args <- getArgs
unless (length args == 1) $
fail "Please provide exactly one source file as an argument."
let sourcePath =... | 877Execute a Markov algorithm | 8haskell | t2of7 |
function pow(base, exp) {
if (exp != Math.floor(exp))
throw "exponent must be an integer";
if (exp < 0)
return 1 / pow(base, -exp);
var ans = 1;
while (exp > 0) {
ans *= base;
exp--;
}
return ans;
} | 874Exponentiation operator | 10javascript | 03qsz |
enum class Fibonacci {
ITERATIVE {
override fun get(n: Int): Long = if (n < 2) {
n.toLong()
} else {
var n1 = 0L
var n2 = 1L
repeat(n) {
val sum = n1 + n2
n1 = n2
n2 = sum
}
n1
... | 862Fibonacci sequence | 11kotlin | poib6 |
null | 873Execute HQ9+ | 11kotlin | geg4d |
class U0 extends Exception { }
class U1 extends Exception { }
public class ExceptionsTest {
public static void foo() throws U1 {
for (int i = 0; i <= 1; i++) {
try {
bar(i);
} catch (U0 e) {
System.out.println("Function foo caught exception U0");
... | 876Exceptions/Catch an exception thrown in a nested call | 9java | 7w5rj |
function U() {}
U.prototype.toString = function(){return this.className;}
function U0() {
this.className = arguments.callee.name;
}
U0.prototype = new U();
function U1() {
this.className = arguments.callee.name;
}
U1.prototype = new U();
function foo() {
for (var i = 1; i <= 2; i++) {
try {
... | 876Exceptions/Catch an exception thrown in a nested call | 10javascript | p8jb7 |
null | 874Exponentiation operator | 11kotlin | ksjh3 |
fn main() {
for i in 1..=100 {
match (i% 3, i% 5) {
(0, 0) => println!("fizzbuzz"),
(0, _) => println!("fizz"),
(_, 0) => println!("buzz"),
(_, _) => println!("{}", i),
}
}
} | 835FizzBuzz | 15rust | efqaj |
null | 876Exceptions/Catch an exception thrown in a nested call | 11kotlin | ubcvc |
function runCode( code )
local acc, lc = 0
for i = 1, #code do
lc = code:sub( i, i ):upper()
if lc == "Q" then print( lc )
elseif lc == "H" then print( "Hello, World!" )
elseif lc == "+" then acc = acc + 1
elseif lc == "9" then
for j = 99, 1, -1 do
... | 873Execute HQ9+ | 1lua | rwrga |
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Markov {
public static void main(String[] args) throws IOExc... | 877Execute a Markov algorithm | 9java | 86w06 |
local baz_counter=1
function baz()
if baz_counter==1 then
baz_counter=baz_counter+1
error("U0",3) | 876Exceptions/Catch an exception thrown in a nested call | 1lua | 5plu6 |
a, b = 1, 0
if (c1:= a == 1) and (c2:= b == 3):
print('a = 1 and b = 3')
elif c1:
print('a = 1 and b <> 3')
elif c2:
print('a <> 1 and b = 3')
else:
print('a <> 1 and b <> 3') | 868Extend your language | 3python | 97umf |
islice(count(7), 0, None, 2) | 869Extensible prime generator | 3python | lh5cv |
const char target[] = ;
const char tbl[] = ;
int irand(int n)
{
int r, rand_max = RAND_MAX - (RAND_MAX % n);
while((r = rand()) >= rand_max);
return r / (rand_max / n);
}
int unfitness(const char *a, const char *b)
{
int i, sum = 0;
for (i = 0; a[i]; i++)
sum += (a[i] != b[i]);
return sum;
}
void muta... | 880Evolutionary algorithm | 5c | ga945 |
const markov = ruleSet => {
const splitAt = (s, i) => [s.slice(0, i), s.slice(i)];
const stripLeading = (s, strip) => s.split('')
.filter((e, i) => i >= strip.length).join('');
const replace = (s, find, rep) => {
let result = s;
if (s.indexOf(find) >= 0) {
const a = splitAt(s, s.in... | 877Execute a Markov algorithm | 10javascript | fl8dg |
package main
import "fmt"
func foo() int {
fmt.Println("let's foo...")
defer func() {
if e := recover(); e != nil {
fmt.Println("Recovered from", e)
}
}()
var a []int
a[12] = 0
fmt.Println("there's no point in going on.")
panic("never reached")
panic(fmt.Scan) | 878Exceptions | 0go | sz1qa |
do
throwIO SomeException | 878Exceptions | 8haskell | 9rtmo |
number = {}
function number.pow( a, b )
local ret = 1
if b >= 0 then
for i = 1, b do
ret = ret * a.val
end
else
for i = b, -1 do
ret = ret / a.val
end
end
return ret
end
function number.New( v )
local num = { val = v }
local mt = ... | 874Exponentiation operator | 1lua | b0hka |
if2 <- function(condition1, condition2, both_true, first_true, second_true, both_false)
{
expr <- if(condition1)
{
if(condition2) both_true else first_true
} else if(condition2) second_true else both_false
eval(expr)
} | 868Extend your language | 13r | 35czt |
object FizzBuzz extends App {
1 to 100 foreach { n =>
println((n % 3, n % 5) match {
case (0, 0) => "FizzBuzz"
case (0, _) => "Fizz"
case (_, 0) => "Buzz"
case _ => n
})
}
} | 835FizzBuzz | 16scala | q38xw |
null | 877Execute a Markov algorithm | 11kotlin | wdbek |
null | 878Exceptions | 9java | t28f9 |
null | 877Execute a Markov algorithm | 1lua | xfpwz |
function doStuff() {
throw new Error('Not implemented!');
} | 878Exceptions | 10javascript | mgfyv |
class HopelesslyEgocentric
def method_missing(what, *args) self end
end
def if2(cond1, cond2)
if cond1 and cond2
yield
HopelesslyEgocentric.new
elsif cond1
Class.new(HopelesslyEgocentric) do
def else1; yield; HopelesslyEgocentric.new end
end.new
elsif cond2
Class.new(HopelesslyEgocent... | 868Extend your language | 14ruby | lh4cl |
#![allow(unused_variables)]
macro_rules! if2 {
($cond1: expr, $cond2: expr
=> $both:expr
=> $first: expr
=> $second:expr
=> $none:expr)
=> {
match ($cond1, $cond2) {
(true, true) => $both,
(true, _ ) => $first,
(_ , true) => $s... | 868Extend your language | 15rust | 2kglt |
(def c 100)
(def p 0.05)
(def target "METHINKS IT IS LIKE A WEASEL")
(def tsize (count target))
(def alphabet " ABCDEFGHIJLKLMNOPQRSTUVWXYZ") | 880Evolutionary algorithm | 6clojure | ksuhs |
sub foo {
foreach (0..1) {
eval { bar($_) };
if ($@ =~ /U0/) { print "Function foo caught exception U0\n"; }
else { die; }
}
}
sub bar {
baz(@_);
}
sub baz {
my $i = shift;
die ($i ? "U1" : "U0");
}
foo(); | 876Exceptions/Catch an exception thrown in a nested call | 2perl | 86x0w |
null | 878Exceptions | 11kotlin | oyw8z |
scala> def if2[A](x: => Boolean)(y: => Boolean)(xyt: => A) = new {
| def else1(xt: => A) = new {
| def else2(yt: => A) = new {
| def orElse(nt: => A) = {
| if(x) {
| if(y) xyt else xt
| } else if(y) {
| yt
| } else {
| ... | 868Extend your language | 16scala | 51jut |
use warnings;
use strict;
use feature qw(say switch);
my @programme = <> or die "No input. Specify a program file or pipe it to the standard input.\n";
for (@programme) {
for my $char (split //) {
given ($char) {
when ('H') { hello() }
when ('Q') { quinne(@programme) }... | 873Execute HQ9+ | 2perl | ncniw |
require
puts Prime.take(20).join()
puts Prime.each(150).drop_while{|pr| pr < 100}.join()
puts Prime.each(8000).drop_while{|pr| pr < 7700}.count
puts Prime.take(10_000).last | 869Extensible prime generator | 14ruby | vbg2n |
@ARGV == 1 or die "Please provide exactly one source file as an argument.\n";
open my $source, '<', $ARGV[0] or die "I couldn't open \"$ARGV[0]\" for reading. ($!.)\n";
my @rules;
while (<$source>)
{/\A
my @a = /(.*?)\s+->\s+(\.?)(.*)/ or die "Syntax error: $_";
push @rules, \@a;}
close $source;
my $input =... | 877Execute a Markov algorithm | 2perl | lj6c5 |
class U0(Exception): pass
class U1(Exception): pass
def foo():
for i in range(2):
try:
bar(i)
except U0:
print()
def bar(i):
baz(i)
def baz(i):
raise U1 if i else U0
foo() | 876Exceptions/Catch an exception thrown in a nested call | 3python | oyq81 |
package main
import (
"log"
"os"
"os/exec"
)
func main() {
cmd := exec.Command("ls", "-l")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
} | 879Execute a system command | 0go | 031sk |
mod pagesieve;
use pagesieve::{count_primes_paged, primes_paged};
fn main() {
println!("First 20 primes:\n {:?}",
primes_paged().take(20).collect::<Vec<_>>());
println!("Primes between 100 and 150:\n {:?}",
primes_paged().skip_while(|&x| x < 100)
.take_whil... | 869Extensible prime generator | 15rust | uprvj |
(ns brainfuck)
(def ^:dynamic *input*)
(def ^:dynamic *output*)
(defrecord Data [ptr cells])
(defn inc-ptr [next-cmd]
(fn [data]
(next-cmd (update-in data [:ptr] inc))))
(defn dec-ptr [next-cmd]
(fn [data]
(next-cmd (update-in data [:ptr] dec))))
(defn inc-cell [next-cmd]
(fn [data]
(next-cmd (u... | 881Execute Brain**** | 5c | 2htlo |
$accumulator = 0;
echo 'HQ9+: ';
$program = trim(fgets(STDIN));
foreach (str_split($program) as $chr) {
switch ($chr) {
case 'H':
case 'h':
printHelloWorld();
break;
case 'Q':
case 'q':
printSource($program);
break;
case '9':
... | 873Execute HQ9+ | 12php | 7x7rp |
number_of_calls_to_baz <- 0
foo <- function()
{
for(i in 1:2) tryCatch(bar())
}
bar <- function() baz()
baz <- function()
{
e <- simpleError(ifelse(number_of_calls_to_baz > 0, "U1", "U0"))
assign("number_of_calls_to_baz", number_of_calls_to_baz + 1, envir=globalenv())
stop(e)
} | 876Exceptions/Catch an exception thrown in a nested call | 13r | qtaxs |
error("Something bad happened!") | 878Exceptions | 1lua | imxot |
println "ls -la".execute().text | 879Execute a system command | 7groovy | enjal |
<?php
function markov($text, $ruleset) {
$lines = explode(PHP_EOL, $ruleset);
$rules = array();
foreach ($lines AS $line) {
$spc = ;
if (empty($line) OR preg_match('/^
continue;
} elseif (preg_match('/^(.+)' . $spc . '->' . $spc . '(\.?)(.*)$/', $line, $matches)) {
... | 877Execute a Markov algorithm | 12php | qt1x3 |
def foo
2.times do |i|
begin
bar(i)
rescue U0
$stderr.puts
end
end
end
def bar(i)
baz(i)
end
def baz(i)
raise i == 0? U0: U1
end
class U0 < StandardError; end
class U1 < StandardError; end
foo | 876Exceptions/Catch an exception thrown in a nested call | 14ruby | n90it |
import System.Cmd
main = system "ls" | 879Execute a system command | 8haskell | c7t94 |
#[derive(Debug)]
enum U {
U0(i32),
U1(String),
}
fn baz(i: u8) -> Result<(), U> {
match i {
0 => Err(U::U0(42)),
1 => Err(U::U1("This will be returned from main".into())),
_ => Ok(()),
}
}
fn bar(i: u8) -> Result<(), U> {
baz(i)
}
fn foo() -> Result<(), U> {
for i in 0... | 876Exceptions/Catch an exception thrown in a nested call | 15rust | dc8ny |
object ExceptionsTest extends App {
class U0 extends Exception
class U1 extends Exception
def foo {
for (i <- 0 to 1)
try {
bar(i)
} catch { case e: U0 => println("Function foo caught exception U0") }
}
def bar(i: Int) {
def baz(i: Int) = { if (i == 0) throw new U0 else throw new... | 876Exceptions/Catch an exception thrown in a nested call | 16scala | zvntr |
import Foundation
func soeDictOdds() -> UnfoldSequence<Int, Int> {
var bp = 5; var q = 25
var bps: UnfoldSequence<Int, Int>.Iterator? = nil
var dict = [9: 6] | 869Extensible prime generator | 17swift | 2k4lj |
(ns brainfuck)
(def ^:dynamic *input*)
(def ^:dynamic *output*)
(defrecord Data [ptr cells])
(defn inc-ptr [next-cmd]
(fn [data]
(next-cmd (update-in data [:ptr] inc))))
(defn dec-ptr [next-cmd]
(fn [data]
(next-cmd (update-in data [:ptr] dec))))
(defn inc-cell [next-cmd]
(fn [data]
(next-cmd (u... | 881Execute Brain**** | 6clojure | gam4f |
$ loadfile ( if required, the source code for this can be found at
http:
[ stack ] is accumulator ( --> s )
[ stack ] is sourcecode ( --> s )
[ say cr ] is H.HQ9+ ( --> )
[ sourcecode share
echo$ cr ] is Q.HQ9+ ( ... | 873Execute HQ9+ | 3python | dldn1 |
import re
def extractreplacements(grammar):
return [ (matchobj.group('pat'), matchobj.group('repl'), bool(matchobj.group('term')))
for matchobj in re.finditer(syntaxre, grammar)
if matchobj.group('rule')]
def replace(text, replacements):
while True:
for pat, repl, term ... | 877Execute a Markov algorithm | 3python | 2hylz |
enum MyException: ErrorType {
case U0
case U1
}
func foo() throws {
for i in 0 ... 1 {
do {
try bar(i)
} catch MyException.U0 {
print("Function foo caught exception U0")
}
}
}
func bar(i: Int) throws {
try baz(i) | 876Exceptions/Catch an exception thrown in a nested call | 17swift | imso0 |
import java.util.Scanner;
import java.io.*;
public class Program {
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("cmd /C dir"); | 879Execute a system command | 9java | zv8tq |
var shell = new ActiveXObject("WScript.Shell");
shell.run("cmd /c dir & pause"); | 879Execute a system command | 10javascript | 9rfml |
use strict ;
sub expon {
my ( $base , $expo ) = @_ ;
if ( $expo == 0 ) {
return 1 ;
}
elsif ( $expo == 1 ) {
return $base ;
}
elsif ( $expo > 1 ) {
my $prod = 1 ;
foreach my $n ( 0..($expo - 1) ) {
$prod *= $base ;
}
return $prod ;
}
elsif ( $expo < 0 ) {
... | 874Exponentiation operator | 2perl | 3utzs |
factorial()
{
if [ $1 -le 1 ]
then
echo 1
else
result=$(factorial $[$1-1])
echo $((result*$1))
fi
} | 882Factorial | 4bash | oyp8a |
use std::env;
fn execute(code: &str) {
let mut accumulator = 0;
for c in code.chars() {
match c {
'Q' => println!(, code),
'H' => println!(),
'9' => {
for n in (1..100).rev() {
println!(, n);
println!(, n);
... | 873Execute HQ9+ | 14ruby | tvtf2 |
null | 879Execute a system command | 11kotlin | imwo4 |
use std::env; | 873Execute HQ9+ | 15rust | zuzto |
def hq9plus(code: String) : String = {
var out = ""
var acc = 0
def bottle(num: Int) : Unit = {
if (num > 1) {
out += num + " bottles of beer on the wall, " + num + " bottles of beer.\n"
out += "Take one down and pass it around, " + (num - 1) + " bottle"
if (num... | 873Execute HQ9+ | 16scala | ygy63 |
def setup(ruleset)
ruleset.each_line.inject([]) do |rules, line|
if line =~ /^\s*
rules
elsif line =~ /^(.+)\s+->\s+(\.?)(.*)$/
rules << [$1, $3, $2!= ]
else
raise
end
end
end
def morcov(ruleset, input_data)
rules = setup(ruleset)
while (matched = rules.find { |match, replace... | 877Execute a Markov algorithm | 14ruby | ub9vz |
null | 862Fibonacci sequence | 1lua | 1inpo |
use std::str::FromStr;
#[derive(Clone, Debug)]
pub struct Rule {
pub pat: String,
pub rep: String,
pub terminal: bool,
}
impl Rule {
pub fn new(pat: String, rep: String, terminal: bool) -> Self {
Self { pat, rep, terminal }
}
pub fn applicable_range(&self, input: impl AsRef<str>) -> O... | 877Execute a Markov algorithm | 15rust | 5pcuq |
import scala.io.Source
object MarkovAlgorithm {
val RulePattern = """(.*?)\s+->\s+(\.?)(.*)""".r
val CommentPattern = """#.*|\s*""".r
def rule(line: String) = line match {
case CommentPattern() => None
case RulePattern(pattern, terminal, replacement) => Some(pattern, replacement, terminal == ".")
ca... | 877Execute a Markov algorithm | 16scala | revgn |
die "Danger, danger, Will Robinson!";
eval {
die "this could go wrong mightily";
};
print $@ if $@;
die $@; | 878Exceptions | 2perl | gal4e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.