code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
func main() {
inf:
goto inf
} | 819Flow-control structures | 0go | 2bsl7 |
package main
import (
"fmt"
"strconv"
) | 817Floyd-Warshall algorithm | 0go | o978q |
null | 815Forward difference | 11kotlin | q3gx1 |
null | 814Four bit adder | 1lua | icbot |
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Exit
main = do
runExitTMaybe $ do
forM_ [1..5] $ \x -> do
forM_ [1..5] $ \y -> do
lift $ print (x, y)
when (x == 3 && y == 2) $
exitWith ()
putStrLn "Done." | 819Flow-control structures | 8haskell | ad91g |
module NumberToWord
NUMBERS = {
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
5 => 'five',
6 => 'six',
7 => 'seven',
8 => 'eight',
9 => 'nine',
10 => 'ten',
11 => 'eleven',
12 => 'twelve',
13 => 'thirteen',
14 => 'fourteen',
15 => 'fifteen',
16 =... | 816Four is magic | 14ruby | 5aduj |
class FloydWarshall {
static void main(String[] args) {
int[][] weights = [[1, 3, -2], [2, 1, 4], [2, 3, 3], [3, 4, 2], [4, 2, -1]]
int numVertices = 4
floydWarshall(weights, numVertices)
}
static void floydWarshall(int[][] weights, int numVertices) {
double[][] dist = new ... | 817Floyd-Warshall algorithm | 7groovy | xzuwl |
mult <- function(a,b) a*b | 808Function definition | 13r | rx2gj |
printf "%09.3f\n", 7.125; | 813Formatted numeric output | 2perl | tuwfg |
(def burn-prob 0.1)
(def new-tree-prob 0.5)
(defn grow-new-tree? [] (> new-tree-prob (rand)))
(defn burn-tree? [] (> burn-prob (rand)))
(defn tree-maker [] (if (grow-new-tree?):tree:grass))
(defn make-forest
([] (make-forest 5))
([size]
(take size (repeatedly #(take size (repeatedly tree-maker))))))
(defn tree... | 821Forest fire | 6clojure | bozkz |
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
var n int = 3 | 820Flipping bits game | 0go | bo3kh |
(def x 2.0)
(def xi 0.5)
(def y 4.0)
(def yi 0.25)
(def z (+ x y))
(def zi (/ 1.0 (+ x y)))
(def numbers [x y z])
(def invers [xi yi zi])
(defn multiplier [a b]
(fn [m] (* a b m)))
> (for [[n i] (zipmap numbers invers)]
((multiplier n i) 0.5))
(0.5 0.5 0.5) | 823First-class functions/Use numbers analogously | 6clojure | nl5ik |
fn main() {
magic(4);
magic(2_340);
magic(765_000);
magic(27_000_001);
magic(999_123_090);
magic(239_579_832_723_441);
magic(std::u64::MAX);
}
fn magic(num: u64) {
if num == 4 {
println!("four is magic!");
println!();
return;
}
let name = number_name(num)... | 816Four is magic | 15rust | 4ef5u |
import Control.Monad (join)
import Data.List (union)
import Data.Map hiding (foldr, union)
import Data.Maybe (fromJust, isJust)
import Data.Semigroup
import Prelude hiding (lookup, filter) | 817Floyd-Warshall algorithm | 8haskell | 2b8ll |
echo str_pad(7.125, 9, '0', STR_PAD_LEFT); | 813Formatted numeric output | 12php | k8lhv |
import Data.List (intersperse)
import System.Random (randomRIO)
import Data.Array (Array, (!), (//), array, bounds)
import Control.Monad (zipWithM_, replicateM, foldM, when)
type Board = Array (Char, Char) Int
flp :: Int -> Int
flp 0 = 1
flp 1 = 0
numRows, numCols :: Board -> String
numRows t =
let ((a, _), (b,... | 820Flipping bits game | 8haskell | d27n4 |
import Foundation
func fourIsMagic(_ number: NSNumber) -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .spellOut
formatter.locale = Locale(identifier: "en_EN")
var result: [String] = []
var numberString = formatter.string(from: number)!
result.append(numberString.capital... | 816Four is magic | 17swift | u1nvg |
function dif(a, b, ...)
if(b) then return b-a, dif(b, ...) end
end
function dift(t) return {dif(unpack(t))} end
print(unpack(dift{1,3,6,10,15})) | 815Forward difference | 1lua | s6rq8 |
switch (xx) {
case 1:
case 2:
...
break;
case 4:
...
break;
case 5:
...
break;
default:
break;
}
for (int i = 0; i < 10; ++i) {
...
if (some_condition) { break; }
...
}
_Time_: do {
for (int i = 0; i < 10; ++i) {
...
if (some_condition) { break... | 819Flow-control structures | 9java | jst7c |
$ jq -n '1, (2 | label $foo | debug | 3 | break $foo | debug), 4'
1
["DEBUG:",2]
4 | 819Flow-control structures | 10javascript | 1nmp7 |
void t(int n)
{
int i, j, c, len;
i = n * (n - 1) / 2;
for (len = c = 1; c < i; c *= 10, len++);
c -= i;
char tmp[32], s[4096], *p;
sprintf(tmp, , len, 0);
inline void inc_numstr(void) {
int k = len;
redo: if (!k--) return;
if (tmp[k] == '9') {
tmp[k] = '0';
goto redo;
}
if (++tmp[k] == ... | 824Floyd's triangle | 5c | o9280 |
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf();
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]) / 2.0;
}
int compare (const void *a, const void *b) {
double aa ... | 825Fivenum | 5c | 1nfpj |
typedef struct { int seq, cnt; } env_t;
env_t env[JOBS] = {{0, 0}};
int *seq, *cnt;
void hail()
{
printf(, *seq);
if (*seq == 1) return;
++*cnt;
*seq = (*seq & 1) ? 3 * *seq + 1 : *seq / 2;
}
void switch_to(int id)
{
seq = &env[id].seq;
cnt = &env[id].cnt;
}
int main()
{
int i;
jobs(i) { env[i].seq = i + 1;... | 826First class environments | 5c | tu5f4 |
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class FlippingBitsGame extends JPanel {
final int maxLevel = 7;
final int minLevel = 3;
private Random rand = new Random();
private int[][] grid, target;
private Rectangle box;
private int n = maxLevel... | 820Flipping bits game | 9java | s6vq0 |
import static java.lang.String.format;
import java.util.Arrays;
public class FloydWarshall {
public static void main(String[] args) {
int[][] weights = {{1, 3, -2}, {2, 1, 4}, {2, 3, 3}, {3, 4, 2}, {4, 2, -1}};
int numVertices = 4;
floydWarshall(weights, numVertices);
}
static vo... | 817Floyd-Warshall algorithm | 9java | 6ge3z |
from math import pi, exp
r = exp(pi)-pi
print r
print %(r,r,r,r,r,r)
print %(-r,-r,-r)
print %(r,r,r)
print %(r,r,r)
print %(-r,-r,-r)
print %(r,r,r)
print %(r,r,r) | 813Formatted numeric output | 3python | z5xtt |
(def hailstone-src
"(defn hailstone-step [env]
(let [{:keys[n cnt]} env]
(cond
(= n 1) {:n 1:cnt cnt}
(even? n) {:n (/ n 2):cnt (inc cnt)}
:else {:n (inc (* n 3)):cnt (inc cnt)})))")
(defn create-hailstone-table [f-src]
(let [done? (fn [e] (= (:n e) 1))
pr... | 826First class environments | 6clojure | m7jyq |
typedef struct list_t list_t, *list;
struct list_t{
int is_list, ival;
list *lst;
};
list new_list()
{
list x = malloc(sizeof(list_t));
x->ival = 0;
x->is_list = 1;
x->lst = 0;
return x;
}
void append(list parent, list child)
{
parent->lst = realloc(parent->lst, sizeof(list) * (parent->ival + 1));
parent->l... | 827Flatten a list | 5c | 2bblo |
function numOfRows(board) { return board.length; }
function numOfCols(board) { return board[0].length; }
function boardToString(board) { | 820Flipping bits game | 10javascript | nlriy |
package main
import "fmt"
func main() {
x := 2.
xi := .5
y := 4.
yi := .25
z := x + y
zi := 1 / (x + y) | 823First-class functions/Use numbers analogously | 0go | vpw2m |
null | 819Flow-control structures | 11kotlin | 5aoua |
i = 0
while true do
i = i + 1
if i > 10 then break end
end | 819Flow-control structures | 1lua | 4ei5c |
var graph = [];
for (i = 0; i < 10; ++i) {
graph.push([]);
for (j = 0; j < 10; ++j)
graph[i].push(i == j ? 0 : 9999999);
}
for (i = 1; i < 10; ++i) {
graph[0][i] = graph[i][0] = parseInt(Math.random() * 9 + 1);
}
for (k = 0; k < 10; ++k) {
for (i = 0; i < 10; ++i) {
for (j = 0; j < 10; ++j) {
if... | 817Floyd-Warshall algorithm | 10javascript | lk0cf |
> sprintf("%f", pi)
[1] "3.141593"
> sprintf("%.3f", pi)
[1] "3.142"
> sprintf("%1.0f", pi)
[1] "3"
> sprintf("%5.1f", pi)
[1] " 3.1"
> sprintf("%05.1f", pi)
[1] "003.1"
> sprintf("%+f", pi)
[1] "+3.141593"
> sprintf("% f", pi)
[1] " 3.141593"
> sprintf("%-10f", pi)
[1] "3.141593 "
> sprintf("%e", pi)
[1] "3.141593e+... | 813Formatted numeric output | 13r | nl1i2 |
package main
import (
"fmt"
"math"
"time"
)
const ld10 = math.Ln2 / math.Ln10
func commatize(n uint64) string {
s := fmt.Sprintf("%d", n)
le := len(s)
for i := le - 3; i >= 1; i -= 3 {
s = s[0:i] + "," + s[i:]
}
return s
}
func p(L, n uint64) uint64 {
i := L
digits :=... | 822First power of 2 that has leading decimal digits of 12 | 0go | 5asul |
def multiplier = { n1, n2 -> { m -> n1 * n2 * m } }
def = 0.00000001 | 823First-class functions/Use numbers analogously | 7groovy | m7by5 |
module Main
where
import Text.Printf
x = 2.0
xi = 0.5
y = 4.0
yi = 0.25
z = x + y
zi = 1.0 / ( x + y )
multiplier :: Double -> Double -> Double -> Double
multiplier a b = \m -> a * b * m
main :: IO ()
main = do
let
numbers = [x, y, z]
inverses = [xi, yi, zi]
pairs = zip numbers inverses
pri... | 823First-class functions/Use numbers analogously | 8haskell | ef6ai |
(defn TriangleList [n]
(let [l (map inc (range))]
(loop [l l x 1 nl []]
(if (= n (count nl))
nl
(recur (drop x l) (inc x) (conj nl (take x l)))))))
(defn TrianglePrint [n]
(let [t (TriangleList n)
m (count (str (last (last t))))
f (map #(map str %) t)
l (map #(map ... | 824Floyd's triangle | 6clojure | tugfv |
def multiply(a, b)
a * b
end | 808Function definition | 14ruby | pirbh |
fn multiply(a: i32, b: i32) -> i32 {
a * b
} | 808Function definition | 15rust | 1n7pu |
void toBaseN(char buffer[], long long num, int base) {
char *ptr = buffer;
char *tmp;
while (num >= 1) {
int rem = num % base;
num /= base;
*ptr++ = [rem];
}
*ptr-- = 0;
for (tmp = buffer; tmp < ptr; tmp++, ptr--) {
char c = *tmp;
*tmp = *ptr;... | 828First perfect square in base n with n unique digits | 5c | pioby |
package main
import "fmt"
const jobs = 12
type environment struct{ seq, cnt int }
var (
env [jobs]environment
seq, cnt *int
)
func hail() {
fmt.Printf("% 4d", *seq)
if *seq == 1 {
return
}
(*cnt)++
if *seq&1 != 0 {
*seq = 3*(*seq) + 1
} else {
*seq /= 2
... | 826First class environments | 0go | h08jq |
null | 820Flipping bits game | 11kotlin | adm13 |
import Control.Monad (guard)
import Text.Printf (printf)
p :: Int -> Int -> Int
p l n = calc !! pred n
where
digitCount = floor $ logBase 10 (fromIntegral l :: Float)
log10pwr = logBase 10 2
calc = do
raised <- [-1 ..]
let firstDigits = floor $ 10 ** (snd (properFracti... | 822First power of 2 that has leading decimal digits of 12 | 8haskell | xz9w4 |
hailstone n
| n == 1 = 1
| even n = n `div` 2
| odd n = 3*n + 1 | 826First class environments | 8haskell | iclor |
target, board, moves, W, H = {}, {}, 0, 3, 3
function getIndex( i, j ) return i + j * W - W end
function flip( d, r )
function invert( a ) if a == 1 then return 0 end return 1 end
local idx
if d == 1 then
for i = 1, W do
idx = getIndex( i, r )
board[idx] = invert( board[idx... | 820Flipping bits game | 1lua | ef9ac |
public class FirstPowerOfTwo {
public static void main(String[] args) {
runTest(12, 1);
runTest(12, 2);
runTest(123, 45);
runTest(123, 12345);
runTest(123, 678910);
}
private static void runTest(int l, int n) {
System.out.printf("p(%d,%d) =%,d%n", l, n, p(l,... | 822First power of 2 that has leading decimal digits of 12 | 9java | botk3 |
const x = 2.0;
const xi = 0.5;
const y = 4.0;
const yi = 0.25;
const z = x + y;
const zi = 1.0 / (x + y);
const pairs = [[x, xi], [y, yi], [z, zi]];
const testVal = 0.5;
const multiplier = (a, b) => m => a * b * m;
const test = () => {
return pairs.map(([a, b]) => {
const f = multiplier(a, b);
const result ... | 823First-class functions/Use numbers analogously | 10javascript | ad310 |
null | 817Floyd-Warshall algorithm | 11kotlin | d2knz |
def multiply(a: Int, b: Int) = a * b | 808Function definition | 16scala | wtkes |
r = 7.125
printf , r
printf , r
printf , -r
printf , r
puts % r
puts % r
puts % -r
puts % r | 813Formatted numeric output | 14ruby | 6gs3t |
sub dec2bin { sprintf "%04b", shift }
sub bin2dec { oct "0b".shift }
sub bin2bits { reverse split(//, substr(shift,0,shift)); }
sub bits2bin { join "", map { 0+$_ } reverse @_ }
sub bxor {
my($a, $b) = @_;
(!$a & $b) | ($a & !$b);
}
sub half_adder {
my($a, $b) = @_;
( bxor($a,$b), $a & $b );
}
sub full_adder... | 814Four bit adder | 2perl | gw34e |
(defn flatten [coll]
(lazy-seq
(when-let [s (seq coll)]
(if (coll? (first s))
(concat (flatten (first s)) (flatten (rest s)))
(cons (first s) (flatten (rest s))))))) | 827Flatten a list | 6clojure | gww4f |
null | 823First-class functions/Use numbers analogously | 11kotlin | 4es57 |
function printResult(dist, nxt)
print("pair dist path")
for i=0, #nxt do
for j=0, #nxt do
if i ~= j then
u = i + 1
v = j + 1
path = string.format("%d ->%d %2d %s", u, v, dist[i][j], u)
repeat
u = ... | 817Floyd-Warshall algorithm | 1lua | fvbdp |
fn main() {
let x = 7.125;
println!("{:9}", x);
println!("{:09}", x);
println!("{:9}", -x);
println!("{:09}", -x);
} | 813Formatted numeric output | 15rust | yr068 |
package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... | 825Fivenum | 0go | yrj64 |
null | 826First class environments | 11kotlin | pinb6 |
import kotlin.math.ln
import kotlin.math.pow
fun main() {
runTest(12, 1)
runTest(12, 2)
runTest(123, 45)
runTest(123, 12345)
runTest(123, 678910)
}
private fun runTest(l: Int, n: Int) { | 822First power of 2 that has leading decimal digits of 12 | 11kotlin | rxogo |
null | 823First-class functions/Use numbers analogously | 1lua | gw04j |
object FormattedNumeric {
val r = 7.125 | 813Formatted numeric output | 16scala | chi93 |
class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m]:... | 825Fivenum | 7groovy | fv5dn |
typedef double (*Class2Func)(double);
double functionA( double v)
{
return v*v*v;
}
double functionB(double v)
{
return exp(log(v)/3);
}
double Function1( Class2Func f2, double val )
{
return f2(val);
}
Class2Func WhichFunc( int idx)
{
return (idx < 4) ? &functionA : &functionB;
}
Class2Func funcLi... | 829First-class functions | 5c | wtdec |
local envs = { }
for i = 1, 12 do | 826First class environments | 1lua | 1ndpo |
sub dif {
my @s = @_;
map { $s[$_+1] - $s[$_] } 0 .. $
}
@a = qw<90 47 58 29 22 32 55 5 55 73>;
while (@a) { printf('%6d', $_) for @a = dif @a; print "\n" } | 815Forward difference | 2perl | vpn20 |
import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | 825Fivenum | 8haskell | h0oju |
use strict;
use warnings;
use Safe;
sub hail_next {
my $n = shift;
return 1 if $n == 1;
return $n * 3 + 1 if $n % 2;
$n / 2;
};
my @enviornments;
for my $initial ( 1..12 ) {
my $env = Safe->new;
${ $env->varglob('value') } = $initial;
${ $env->varglob('count') } = 0;
$env->share('&hail_ne... | 826First class environments | 2perl | yr76u |
FORK:
goto FORK; | 819Flow-control structures | 2perl | o9g8x |
import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... | 825Fivenum | 9java | 5awuf |
package main
import (
"fmt"
"math/big"
"strconv"
"time"
)
const maxBase = 27
const minSq36 = "1023456789abcdefghijklmnopqrstuvwxyz"
const minSq36x = "10123456789abcdefghijklmnopqrstuvwxyz"
var bigZero = new(big.Int)
var bigOne = new(big.Int).SetUint64(1)
func containsAll(sq string, base int) bool {
... | 828First perfect square in base n with n unique digits | 0go | 6g43p |
package main
import (
"fmt"
"math/rand"
"strings"
)
const (
rows = 20
cols = 30
p = .01
f = .001
)
const rx = rows + 2
const cx = cols + 2
func main() {
odd := make([]byte, rx*cx)
even := make([]byte, rx*cx)
for r := 1; r <= rows; r++ {
for c := 1; c <= cols; c+... | 821Forest fire | 0go | nlgi1 |
use strict;
use warnings qw(FATAL all);
my $n = shift(@ARGV) || 4;
if( $n < 2 or $n > 26 ) {
die "You can't play a size $n game\n";
}
my $n2 = $n*$n;
my (@rows, @cols);
for my $i ( 0 .. $n-1 ) {
my $row = my $col = "\x00" x $n2;
vec($row, $i * $n + $_, 8) ^= 1 for 0 .. $n-1;
vec($col, $i + $_ * $n, 8) ^= 1 for 0... | 820Flipping bits game | 2perl | 9jemn |
use strict;
use warnings;
use feature 'say';
use feature 'state';
use POSIX qw(fmod);
use Perl6::GatherTake;
use constant ln2ln10 => log(2) / log(10);
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub ordinal_digit {
my($d) = $_[0] =~ /(.)$/;
$d eq '1' ? 'st' : $d eq '2' ? 'nd' : $d ... | 822First power of 2 that has leading decimal digits of 12 | 2perl | d2gnw |
<?php
goto a;
echo 'Foo';
a:
echo 'Bar';
?> | 819Flow-control structures | 12php | gwn42 |
<?php
function forwardDiff($anArray, $times = 1) {
if ($times <= 0) { return $anArray; }
for ($accumilation = array(), $i = 1, $j = count($anArray); $i < $j; ++$i) {
$accumilation[] = $anArray[$i] - $anArray[$i - 1];
}
if ($times === 1) { return $accumilation; }
return forwardDiff($accumilation, $times ... | 815Forward difference | 12php | 0y7sp |
DECLARE @n INT
SELECT @n=123
SELECT SUBSTRING(CONVERT(CHAR(5), 10000+@n),2,4) AS FourDigits
SET @n=5
print + SUBSTRING(CONVERT(CHAR(3), 100+@n),2,2)
--Output: 05 | 813Formatted numeric output | 19sql | vpf2y |
function median(arr) {
let mid = Math.floor(arr.length / 2);
return (arr.length % 2 == 0) ? (arr[mid-1] + arr[mid]) / 2 : arr[mid];
}
Array.prototype.fiveNums = function() {
this.sort(function(a, b) { return a - b} );
let mid = Math.floor(this.length / 2),
loQ = (this.length % 2 == 0) ? this.slice(0, mid... | 825Fivenum | 10javascript | js87n |
static const char *months[] = {, , , , ,
, , , , , , };
static int long_months[] = {0, 2, 4, 6, 7, 9, 11};
int main() {
int n = 0, y, i, m;
struct tm t = {0};
printf();
for (y = 1900; y <= 2100; y++) {
for (i = 0; i < 7; i++) {
m = long_months[i];
t.tm_year = y-1900;... | 830Five weekends | 5c | chr9c |
import Control.Monad (guard)
import Data.List (find, unfoldr)
import Data.Char (intToDigit)
import qualified Data.Set as Set
import Text.Printf (printf)
digits :: Integral a => a -> a -> [a]
digits
b = unfoldr
(((>>) . guard . (0 /=)) <*> (pure . ((,) <$> (`mod` b) <*... | 828First perfect square in base n with n unique digits | 8haskell | jsq7g |
(use 'clojure.contrib.math)
(let [fns [#(Math/sin %) #(Math/cos %) (fn [x] (* x x x))]
inv [#(Math/asin %) #(Math/acos %) #(expt % 1/3)]]
(map #(% 0.5) (map #(comp %1 %2) fns inv))) | 829First-class functions | 6clojure | 8m605 |
import Control.Monad (replicateM, unless)
import Data.List (tails, transpose)
import System.Random (randomRIO)
data Cell
= Empty
| Tree
| Fire
deriving (Eq)
instance Show Cell where
show Empty = " "
show Tree = "T"
show Fire = "$"
randomCell :: IO Cell
randomCell = fmap ([Empty, Tree] !!) (randomRIO (0... | 821Forest fire | 8haskell | u1sv2 |
environments = [{'cnt':0, 'seq':i+1} for i in range(12)]
code = '''
print('% 4d'% seq, end='')
if seq!= 1:
cnt += 1
seq = 3 * seq + 1 if seq & 1 else seq
'''
while any(env['seq'] > 1 for env in environments):
for env in environments:
exec(code, globals(), env)
print()
print('Counts')
for env... | 826First class environments | 3python | m7jyh |
code <- quote(
if (n == 1) n else {
count <- count + 1;
n <- if (n%% 2 == 1) 3 * n + 1 else n/2
})
eprint <- function(envs, var="n")
cat(paste(sprintf("%4d", sapply(envs, `[[`, var)), collapse=" "), "\n")
envs <- mapply(function(...) list2env(list(...)), n=1:12, count=0)
... | 826First class environments | 13r | z54th |
null | 825Fivenum | 11kotlin | chb98 |
import java.math.BigInteger;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Program {
static final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz|";
stati... | 828First perfect square in base n with n unique digits | 9java | u1pvv |
from random import randrange
from copy import deepcopy
from string import ascii_lowercase
try:
input = raw_input
except:
pass
N = 3
board = [[0]* N for i in range(N)]
def setbits(board, count=1):
for i in range(count):
board[randrange(N)][randrange(N)] ^= 1
def shuffle(board, count=1):... | 820Flipping bits game | 3python | chw9q |
from math import log, modf, floor
def p(l, n, pwr=2):
l = int(abs(l))
digitcount = floor(log(l, 10))
log10pwr = log(pwr, 10)
raised, found = -1, 0
while found < n:
raised += 1
firstdigits = floor(10**(modf(log10pwr * raised)[0] + digitcount))
if firstdigits == l:
... | 822First power of 2 that has leading decimal digits of 12 | 3python | fvrde |
for i in range(n):
if (n%2) == 0:
continue
if (n%i) == 0:
result = i
break
else:
result = None
print | 819Flow-control structures | 3python | icrof |
def xor(a, b): return (a and not b) or (b and not a)
def ha(a, b): return xor(a, b), a and b
def fa(a, b, ci):
s0, c0 = ha(ci, a)
s1, c1 = ha(s0, b)
return s1, c0 or c1
def fa4(a, b):
width = 4
ci = [None] * width
co = [None] * width
s = [None] * width
for i in range(width)... | 814Four bit adder | 3python | rx6gq |
function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end | 825Fivenum | 1lua | lkpck |
typedef struct{
double x,y;
}point;
double lineSlope(point a,point b){
if(a.x-b.x == 0.0)
return NAN;
else
return (a.y-b.y)/(a.x-b.x);
}
point extractPoint(char* str){
int i,j,start,end,length;
char* holder;
point c;
for(i=0;str[i]!=00;i++){
if(str[i]=='(')
start = i;
if(str[i]==','||str[i]==')')
... | 831Find the intersection of two lines | 5c | lkrcy |
typedef struct{
double x,y,z;
}vector;
vector addVectors(vector a,vector b){
return (vector){a.x+b.x,a.y+b.y,a.z+b.z};
}
vector subVectors(vector a,vector b){
return (vector){a.x-b.x,a.y-b.y,a.z-b.z};
}
double dotProduct(vector a,vector b){
return a.x*b.x + a.y*b.y + a.z*b.z;
}
vector scaleVector(double l,vecto... | 832Find the intersection of a line with a plane | 5c | z5ctx |
(() => {
'use strict'; | 828First perfect square in base n with n unique digits | 10javascript | 7qxrd |
sub multiplier {
my ( $n1, $n2 ) = @_;
sub {
$n1 * $n2 * $_[0];
};
}
my $x = 2.0;
my $xi = 0.5;
my $y = 4.0;
my $yi = 0.25;
my $z = $x + $y;
my $zi = 1.0 / ( $x + $y );
my %zip;
@zip{ $x, $y, $z } = ( $xi, $yi, $zi );
while ( my ( $number, $inverse ) = each %zip ) {
print multiplier( $numb... | 823First-class functions/Use numbers analogously | 2perl | icuo3 |
sub FloydWarshall{
my $edges = shift;
my (@dist, @seq);
my $num_vert = 0;
map {
$dist[$_->[0] - 1][$_->[1] - 1] = $_->[2];
$num_vert = $_->[0] if $num_vert < $_->[0];
$num_vert = $_->[1] if $num_vert < $_->[1];
} @$edges;
my @vertices = 0..($num_vert - 1);
f... | 817Floyd-Warshall algorithm | 2perl | js37f |
func multiply(a: Double, b: Double) -> Double {
return a * b
} | 808Function definition | 17swift | bogkd |
(import java.util.GregorianCalendar
java.text.DateFormatSymbols)
(->> (for [year (range 1900 2101)
month [0 2 4 6 7 9 11]
:let [cal (GregorianCalendar. year month 1)
day (.get cal GregorianCalendar/DAY_OF_WEEK)]
:when (= day GregorianCalendar/FRIDAY)]
(println month "-" year))
count
(pr... | 830Five weekends | 6clojure | 5abuz |
import java.math.BigInteger
import java.time.Duration
import java.util.ArrayList
import java.util.HashSet
import kotlin.math.sqrt
const val ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz|"
var base: Byte = 0
var bmo: Byte = 0
var blim: Byte = 0
var ic: Byte = 0
var st0: Long = 0
var bllim: ... | 828First perfect square in base n with n unique digits | 11kotlin | 9j7mh |
import 'dart:math' as Math;
cube(x) => x*x*x;
cuberoot(x) => Math.pow(x, 1/3);
compose(f,g) => ((x)=>f(g(x)));
main(){
var functions = [Math.sin, Math.exp, cube];
var inverses = [Math.asin, Math.log, cuberoot];
for (int i = 0; i < 3; i++){
print(compose(functions[i], inverses[i])(0.5));
}
} | 829First-class functions | 18dart | k8shj |
envs = (1..12).map do |n|
Object.new.instance_eval {@n = n; @cnt = 0; self}
end
until envs.all? {|e| e.instance_eval{@n} == 1}
envs.each do |e|
e.instance_eval do
printf , @n
if @n > 1
@cnt += 1
@n = if @n.odd?
@n * 3 + 1
... | 826First class environments | 14ruby | chk9k |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.