code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
size_t bellIndex(int row, int col) {
return row * (row - 1) / 2 + col;
}
int getBell(int *bellTri, int row, int col) {
size_t index = bellIndex(row, col);
return bellTri[index];
}
void setBell(int *bellTri, int row, int col, int value) {
size_t index = bellIndex(row, col);
bellTri[index] = value;
... | 1,106Bell numbers | 5c | 5reuk |
package main
import (
"fmt"
"sort"
)
func getBins(limits, data []int) []int {
n := len(limits)
bins := make([]int, n+1)
for _, d := range data {
index := sort.SearchInts(limits, d) | 1,104Bin given limits | 0go | axz1f |
fun printSequence(sequence: String, width: Int = 50) {
fun <K, V> printWithLabel(k: K, v: V) {
val label = k.toString().padStart(5)
println("$label: $v")
}
println("SEQUENCE:")
sequence.chunked(width).withIndex().forEach { (i, line) ->
printWithLabel(i*width + line.length, line)... | 1,101Bioinformatics/base count | 11kotlin | jbd7r |
class DNA_Seq
attr_accessor :seq
def initialize(bases: %i[A C G T] , size: 0)
@bases = bases
@seq = Array.new(size){ bases.sample }
end
def mutate(n = 10)
n.times{|n| method([:s, :d, :i].sample).call}
end
def to_s(n = 50)
just_size = @seq.size / n
(0...@seq.size).step(n).map{|from| ... | 1,099Bioinformatics/Sequence mutation | 14ruby | eqcax |
float *benford_distribution(void)
{
static float prob[9];
for (int i = 1; i < 10; i++)
prob[i - 1] = log10f(1 + 1.0 / i);
return prob;
}
float *get_actual_distribution(char *fn)
{
FILE *input = fopen(fn, );
if (!input)
{
perror();
exit(EXIT_FAILURE);
}
int tall... | 1,107Benford's law | 5c | q83xc |
import Control.Monad (foldM)
import Data.List (partition)
binSplit :: Ord a => [a] -> [a] -> [[a]]
binSplit lims ns = counts ++ [rest]
where
(counts, rest) = foldM split ns lims
split l i = let (a, b) = partition (< i) l in ([a], b)
binCounts :: Ord a => [a] -> [a] -> [Int]
binCounts b = fmap length . binS... | 1,104Bin given limits | 8haskell | zyrt0 |
function prettyprint(seq) | 1,101Bioinformatics/base count | 1lua | hpfj8 |
let bases: [Character] = ["A", "C", "G", "T"]
enum Action: CaseIterable {
case swap, delete, insert
}
@discardableResult
func mutate(dna: inout String) -> Action {
guard let i = dna.indices.shuffled().first(where: { $0!= dna.endIndex }) else {
fatalError()
}
let action = Action.allCases.randomElement()!
... | 1,099Bioinformatics/Sequence mutation | 17swift | ax91i |
do {\
size_t i;\
for (i = 0; i < (n); ++i)\
mpq_
} while (0)
void bernoulli(mpq_t rop, unsigned int n)
{
unsigned int m, j;
mpq_t *a = malloc(sizeof(mpq_t) * (n + 1));
mpq_for(a, init, n + 1);
for (m = 0; m <= n; ++m) {
mpq_set_ui(a[m], 1, m + 1);
for (j... | 1,108Bernoulli numbers | 5c | 3m5za |
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Bins {
public static <T extends Comparable<? super T>> int[] bins(
List<? extends T> limits, Iterable<? extends T> data) {
int[] result = new int[limits.size() + 1];
for (T n : data) {
... | 1,104Bin given limits | 9java | od28d |
require_relative 'raster_graphics'
class RGBColour
def ==(other)
values == other.values
end
end
class Pixmap
def flood_fill(pixel, new_colour)
current_colour = self[pixel.x, pixel.y]
queue = Queue.new
queue.enq(pixel)
until queue.empty?
p = queue.pop
next unless self[p.x, p.y] ==... | 1,094Bitmap/Flood fill | 14ruby | jbm7x |
null | 1,096Box the compass | 11kotlin | f3pdo |
(ns example
(:gen-class))
(defn abs [x]
(if (> x 0)
x
(- x)))
(defn calc-benford-stats [digits]
" Frequencies of digits in data "
(let [y (frequencies digits)
tot (reduce + (vals y))]
[y tot]))
(defn show-benford-stats [v]
" Prints in percent the actual, Benford expected, and differenc... | 1,107Benford's law | 6clojure | ifcom |
use rand::prelude::*;
use std::collections::HashMap;
use std::fmt::{Display, Formatter, Error};
pub struct Seq<'a> {
alphabet: Vec<&'a str>,
distr: rand::distributions::Uniform<usize>,
pos_distr: rand::distributions::Uniform<usize>,
seq: Vec<&'a str>,
}
impl Display for Seq<'_> {
fn fmt(&self, f: ... | 1,099Bioinformatics/Sequence mutation | 15rust | wsle4 |
use std::fs::File; | 1,094Bitmap/Flood fill | 15rust | hp9j2 |
import java.awt.Color
import scala.collection.mutable
object Flood {
def floodFillStack(bm:RgbBitmap, x: Int, y: Int, targetColor: Color): Unit = { | 1,094Bitmap/Flood fill | 16scala | pe2bj |
function binner(limits, data)
local bins = setmetatable({}, {__index=function() return 0 end})
local n, flr = #limits+1, math.floor
for _, x in ipairs(data) do
local lo, hi = 1, n
while lo < hi do
local mid = flr((lo + hi) / 2)
if not limits[mid] or x < limits[mid] then hi=mid else lo=mid+1 e... | 1,104Bin given limits | 1lua | q8mx0 |
use strict;
use warnings;
use feature 'say';
my %cnt;
my $total = 0;
while ($_ = <DATA>) {
chomp;
printf "%4d:%s\n", $total+1, s/(.{10})/$1 /gr;
$total += length;
$cnt{$_}++ for split //
}
say "\nTotal bases: $total";
say "$_: " . ($cnt{$_}//0) for <A C G T>;
__DATA__
CGTAAAAAATTACAACGTCCTTTGGCTATCT... | 1,101Bioinformatics/base count | 2perl | t6jfg |
ns test-project-intellij.core
(:gen-class))
(defn a-t [n]
" Used Akiyama-Tanigawa algorithm with a single loop rather than double nested loop "
" Clojure does fractional arithmetic automatically so that part is easy "
(loop [m 0
j m
A (vec (map #(/ 1 %) (range 1 (+ n 2))))]
(cond ... | 1,108Bernoulli numbers | 6clojure | cvj9b |
void best_shuffle(const char* txt, char* result) {
const size_t len = strlen(txt);
if (len == 0)
return;
assert(len == strlen(result));
size_t counts[UCHAR_MAX];
memset(counts, '\0', UCHAR_MAX * sizeof(int));
size_t fmax = 0;
for (size_t i = 0; i < len; i++) {
c... | 1,109Best shuffle | 5c | rheg7 |
(defn score [before after]
(->> (map = before after)
(filter true? ,)
count))
(defn merge-vecs [init vecs]
(reduce (fn [counts [index x]]
(assoc counts x (conj (get counts x []) index)))
init vecs))
(defn frequency
"Returns a collection of indecies of distinct items"
[coll]
(->> (map-indexed vector... | 1,109Best shuffle | 6clojure | ba0kz |
package main
import (
"bytes"
"fmt"
) | 1,105Binary strings | 0go | odl8q |
use strict;
use warnings; no warnings 'uninitialized';
use feature 'say';
use experimental 'signatures';
use constant Inf => 1e10;
my @tests = (
{
limits => [23, 37, 43, 53, 67, 83],
data => [
95,21,94,12,99,4,70,75,83,93,52,80,57, 5,53,86,65,17,92,83,71,61,54,58,47,
16, 8... | 1,104Bin given limits | 2perl | 25alf |
from collections import Counter
def basecount(dna):
return sorted(Counter(dna).items())
def seq_split(dna, n=50):
return [dna[i: i+n] for i in range(0, len(dna), n)]
def seq_pp(dna, n=50):
for i, part in enumerate(seq_split(dna, n)):
print(f)
print()
tot = 0
for base, count in basecou... | 1,101Bioinformatics/base count | 3python | zyhtt |
package main
import (
"fmt"
"math/big"
)
func bellTriangle(n int) [][]*big.Int {
tri := make([][]*big.Int, n)
for i := 0; i < n; i++ {
tri[i] = make([]*big.Int, i)
for j := 0; j < i; j++ {
tri[i][j] = new(big.Int)
}
}
tri[1][0].SetUint64(1)
for i := 2; i... | 1,106Bell numbers | 0go | 8n90g |
import java.nio.charset.StandardCharsets
class MutableByteString {
private byte[] bytes
private int length
MutableByteString(byte... bytes) {
setInternal(bytes)
}
int length() {
return length
}
boolean isEmpty() {
return length == 0
}
byte get(int index) ... | 1,105Binary strings | 7groovy | x06wl |
gene1 <- "CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATG
CTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTG
AGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGAT
GGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT
CGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGG
TCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA
TTTA... | 1,101Bioinformatics/base count | 13r | ntgi2 |
null | 1,096Box the compass | 1lua | t61fn |
class Bell {
private static class BellTriangle {
private List<Integer> arr
BellTriangle(int n) {
int length = (int) (n * (n + 1) / 2)
arr = new ArrayList<>(length)
for (int i = 0; i < length; ++i) {
arr.add(0)
}
set(1, 0, ... | 1,106Bell numbers | 7groovy | wszel |
import Text.Regex
string = "world" :: String | 1,105Binary strings | 8haskell | 251ll |
from bisect import bisect_right
def bin_it(limits: list, data: list) -> list:
bins = [0] * (len(limits) + 1)
for d in data:
bins[bisect_right(limits, d)] += 1
return bins
def bin_print(limits: list, bins: list) -> list:
print(f)
for lo, hi, count in zip(limits, limits[1:], bins[... | 1,104Bin given limits | 3python | v4e29 |
package raster | 1,100Bitmap/Bresenham's line algorithm | 0go | mlayi |
bellTri :: [[Integer]]
bellTri =
let f xs = (last xs, xs)
in map snd (iterate (f . uncurry (scanl (+))) (1, [1]))
bell :: [Integer]
bell = map head bellTri
main :: IO ()
main = do
putStrLn "First 10 rows of Bell's Triangle:"
mapM_ print (take 10 bellTri)
putStrLn "\nFirst 15 Bell numbers:"
mapM_ print (t... | 1,106Bell numbers | 8haskell | lubch |
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class MutableByteString {
private byte[] bytes;
private int length;
public MutableByteString(byte... bytes) {
setInternal(bytes);
}
public int length() {
return length;... | 1,105Binary strings | 9java | 6973z |
limits1 <- c(23, 37, 43, 53, 67, 83)
data1 <- c(95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47,
16,8,9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55)
limits2 <- c(14, 18, 249, 312, 389, 392, 513, 591, 634, 720)
data2 <- c(445,814,519,697,700,130,255,889,481,122,932,7... | 1,104Bin given limits | 13r | 92bmg |
module Bitmap.Line(line) where
import Bitmap
import Control.Monad
import Control.Monad.ST
import qualified Data.STRef
var = Data.STRef.newSTRef
get = Data.STRef.readSTRef
mutate = Data.STRef.modifySTRef
line :: Color c => Image s c -> Pixel -> Pixel -> c -> ST s ()
line i (Pixel (xa, ya)) (Pixel (xb, yb)) c = do
... | 1,100Bitmap/Bresenham's line algorithm | 8haskell | k1zh0 |
import java.util.ArrayList;
import java.util.List;
public class Bell {
private static class BellTriangle {
private List<Integer> arr;
BellTriangle(int n) {
int length = n * (n + 1) / 2;
arr = new ArrayList<>(length);
for (int i = 0; i < length; ++i) {
... | 1,106Bell numbers | 9java | 3mgzg |
null | 1,105Binary strings | 10javascript | lupcf |
dna = <<DNA_STR
CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATG
CTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTG
AGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGAT
GGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT
CGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGG
TCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTAT... | 1,101Bioinformatics/base count | 14ruby | 69b3t |
use std::collections::HashMap;
fn main() {
let dna = "CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATG\
CTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTG\
AGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGAT\
GGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT\
CGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGG\
T... | 1,101Bioinformatics/base count | 15rust | ycp68 |
my $x = 0.0;
my $true_or_false = $x ? 'true' : 'false'; | 1,090Boolean values | 2perl | 3m8zs |
package main
import (
"bytes"
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
)
func main() { | 1,102Bitmap | 0go | solqa |
import Foundation
let dna = """
CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATG
CTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTG
AGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGAT
GGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT
CGATTCTGCTTATAACACTATGTTCTTATGAAA... | 1,101Bioinformatics/base count | 17swift | 3mkz2 |
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
public class Bresenham {
public static void main(String[] args) {
SwingUtilities.invokeLater(Bresenham::r... | 1,100Bitmap/Bresenham's line algorithm | 9java | 47o58 |
go?=>
member(N,1..5),
println(N),
fail,% or false/0 to get other solutions
nl.
go => true. | 1,090Boolean values | 12php | pe4ba |
module Bitmap(module Bitmap) where
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
newtype Pixel = Pixel (Int, Int) deriving Eq
instance Ord Pixel where
compare (Pixel (x1, y1)) (Pixel (x2, y2)) =
case compare y1 y2 of
EQ -> compare x1 x2
v -> v
instance Ix Pix... | 1,102Bitmap | 8haskell | 921mo |
class BellTriangle(n: Int) {
private val arr: Array<Int>
init {
val length = n * (n + 1) / 2
arr = Array(length) { 0 }
set(1, 0, 1)
for (i in 2..n) {
set(i, 0, get(i - 1, i - 2))
for (j in 1 until i) {
val value = get(i, j - 1) + get(i - ... | 1,106Bell numbers | 11kotlin | nt2ij |
class ByteString(private val bytes: ByteArray) : Comparable<ByteString> {
val length get() = bytes.size
fun isEmpty() = bytes.isEmpty()
operator fun plus(other: ByteString): ByteString = ByteString(bytes + other.bytes)
operator fun plus(byte: Byte) = ByteString(bytes + byte)
operator fun get(ind... | 1,105Binary strings | 11kotlin | dzunz |
Test = Struct.new(:limits, :data)
tests = Test.new( [23, 37, 43, 53, 67, 83],
[95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47,
16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55]),
Test.new( [14, 18, 249, 312, 389, 392, 513, 59... | 1,104Bin given limits | 14ruby | 5rxuj |
function bline(x0, y0, x1, y1) {
var dx = Math.abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
var dy = Math.abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
var err = (dx>dy ? dx : -dy)/2;
while (true) {
setPixel(x0,y0);
if (x0 === x1 && y0 === y1) break;
var e2 = err;
if (e2 > -dx) { err -= dy; x0 += sx; }
if... | 1,100Bitmap/Bresenham's line algorithm | 10javascript | hptjh |
null | 1,106Bell numbers | 1lua | dzvnq |
package main
import (
"fmt"
"math"
)
func Fib1000() []float64 {
a, b, r := 0., 1., [1000]float64{}
for i := range r {
r[i], a, b = b, b, b+a
}
return r[:]
}
func main() {
show(Fib1000(), "First 1000 Fibonacci numbers")
}
func show(c []float64, title string) {
var f [9]int
... | 1,107Benford's law | 0go | 25bl7 |
fn make_bins(limits: &Vec<usize>, data: &Vec<usize>) -> Vec<Vec<usize>> {
let mut bins: Vec<Vec<usize>> = Vec::with_capacity(limits.len() + 1);
for _ in 0..=limits.len() {bins.push(Vec::new());}
limits.iter().enumerate().for_each(|(idx, limit)| {
data.iter().for_each(|elem| {
if id... | 1,104Bin given limits | 15rust | 47q5u |
def tallyFirstDigits = { size, generator ->
def population = (0..<size).collect { generator(it) }
def firstDigits = [0]*10
population.each { number ->
firstDigits[(number as String)[0] as int] ++
}
firstDigits
} | 1,107Benford's law | 7groovy | ycr6o |
import qualified Data.Map as M
import Data.Char (digitToInt)
fstdigit :: Integer -> Int
fstdigit = digitToInt . head . show
n = 1000 :: Int
fibs = 1: 1: zipWith (+) fibs (tail fibs)
fibdata = map fstdigit $ take n fibs
freqs = M.fromListWith (+) $ zip fibdata (repeat 1)
tab :: [(Int, Double, Double)]
tab =
[ ( ... | 1,107Benford's law | 8haskell | axd1g |
package main
import (
"fmt"
"math/rand"
"time"
)
var ts = []string{"abracadabra", "seesaw", "elk", "grrrrrr", "up", "a"}
func main() {
rand.Seed(time.Now().UnixNano())
for _, s := range ts { | 1,109Best shuffle | 0go | nt9i1 |
foo = 'foo' | 1,105Binary strings | 1lua | f35dp |
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
public class BasicBitmapStorage {
private final BufferedImage image;
public BasicBitmapStorage(int width, int height) {
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
... | 1,102Bitmap | 9java | t67f9 |
def shuffle(text) {
def shuffled = (text as List)
for (sourceIndex in 0..<text.size()) {
for (destinationIndex in 0..<text.size()) {
if (shuffled[sourceIndex] != shuffled[destinationIndex] && shuffled[sourceIndex] != text[destinationIndex] && shuffled[destinationIndex] != text[sourceInde... | 1,109Best shuffle | 7groovy | sozq1 |
null | 1,100Bitmap/Bresenham's line algorithm | 1lua | 25ql3 |
>>> True
True
>>> not True
False
>>>
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>>
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>>
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I a... | 1,090Boolean values | 3python | 69o3w |
package main
import "fmt"
func bitwise(a, b int16) {
fmt.Printf("a: %016b\n", uint16(a))
fmt.Printf("b: %016b\n", uint16(b)) | 1,103Bitwise operations | 0go | eq6a6 |
null | 1,102Bitmap | 10javascript | mlpyv |
shufflingQuality l1 l2 = length $ filter id $ zipWith (==) l1 l2
printTest prog = mapM_ test texts
where
test s = do
x <- prog s
putStrLn $ unwords $ [ show s
, show x
, show $ shufflingQuality s x]
texts = [ "abba", "abracadabra", "seesaw", "... | 1,109Best shuffle | 8haskell | ugbv2 |
(cond ([(< 4 3) 'apple]
['bloggle 'pear]
[else 'nectarine]) | 1,090Boolean values | 13r | f3qdc |
def bitwise = { a, b ->
println """
a & b = ${a} & ${b} = ${a & b}
a | b = ${a} | ${b} = ${a | b}
a ^ b = ${a} ^ ${b} = ${a ^ b}
~ a = ~ ${a} = ${~ a}
a << b = ${a} << ${b} = ${a << b}
a >> b = ${a} >> ${b} = ${a >> b} arithmetic (sign-preserving) shift
a >>> b = ${a} >>> ${b} = ${a ... | 1,103Bitwise operations | 7groovy | k1dh7 |
use strict 'vars';
use warnings;
use feature 'say';
use bigint;
my @b = 1;
my @Aitkens = [1];
push @Aitkens, do {
my @c = $b[-1];
push @c, $b[$_] + $c[$_] for 0..$
@b = @c;
[@c]
} until (@Aitkens == 50);
my @Bell_numbers = map { @$_[0] } @Aitkens;
say 'First fifteen and fiftieth Bell numbers:';
prin... | 1,106Bell numbers | 2perl | 7ksrh |
import java.math.BigInteger;
import java.util.Locale;
public class BenfordsLaw {
private static BigInteger[] generateFibonacci(int n) {
BigInteger[] fib = new BigInteger[n];
fib[0] = BigInteger.ONE;
fib[1] = BigInteger.ONE;
for (int i = 2; i < fib.length; i++) {
fib[i] ... | 1,107Benford's law | 9java | jbs7c |
int bsearch (int *a, int n, int x) {
int i = 0, j = n - 1;
while (i <= j) {
int k = i + ((j - i) / 2);
if (a[k] == x) {
return k;
}
else if (a[k] < x) {
i = k + 1;
}
else {
j = k - 1;
}
}
return -1;
}
int bsearc... | 1,110Binary search | 5c | 8n304 |
null | 1,102Bitmap | 11kotlin | odu8z |
const fibseries = n => [...Array(n)]
.reduce(
(fib, _, i) => i < 2 ? (
fib
) : fib.concat(fib[i - 1] + fib[i - 2]),
[1, 1]
);
const benford = array => [1, 2, 3, 4, 5, 6, 7, 8, 9]
.map(val => [val, array
.reduce(
(sum, item) => sum + (
... | 1,107Benford's law | 10javascript | 1wnp7 |
package main
import (
"fmt"
"math/big"
)
func b(n int) *big.Rat {
var f big.Rat
a := make([]big.Rat, n+1)
for m := range a {
a[m].SetFrac64(1, int64(m+1))
for j := m; j >= 1; j-- {
d := &a[j-1]
d.Mul(f.SetInt64(int64(j)), d.Sub(d, &a[j]))
}
}
return f.Set(&a[0])
}
func main() {
for n := 0; n <= 6... | 1,108Bernoulli numbers | 0go | ba8kh |
function to_binary () {
if [ $1 -ge 0 ]
then
val=$1
binary_digits=()
while [ $val -gt 0 ]; do
bit=$((val % 2))
quotient=$((val / 2))
binary_digits+=("${bit}")
val=$quotient
done
echo "${binary_digits[*]}" | rev
else
... | 1,111Binary digits | 4bash | x0nwb |
import Data.Bits
bitwise :: Int -> Int -> IO ()
bitwise a b =
mapM_
print
[ a .&. b
, a .|. b
, a `xor` b
, complement a
, shiftL a b
, shiftR a b
, shift a b
, shift a (-b)
, rotateL a b
, rotateR a b
, rotate a b
, rotate a (-b)
]
main ::... | 1,103Bitwise operations | 8haskell | 3mjzj |
import Data.Ratio
import System.Environment
main = getArgs >>= printM . defaultArg
where
defaultArg as =
if null as
then 60
else read (head as)
printM m =
mapM_ (putStrLn . printP) .
takeWhile ((<= m) . fst) . filter (\(_, b) -> b /= 0 % 1) . zip [0 ..] $
bernoullis
printP (i, r) =
... | 1,108Bernoulli numbers | 8haskell | dzln4 |
import java.util.Random;
public class BestShuffle {
private final static Random rand = new Random();
public static void main(String[] args) {
String[] words = {"abracadabra", "seesaw", "grrrrrr", "pop", "up", "a"};
for (String w : words)
System.out.println(bestShuffle(w));
}
... | 1,109Best shuffle | 9java | mlgym |
$s = undef;
say 'Nothing to see here' if ! defined $s;
say $s = '';
say 'Empty string' if $s eq '';
say $s = 'be';
say $t = $s;
say 'Same' if $t eq $s;
say $t = $t .'e' ... | 1,105Binary strings | 2perl | jb87f |
fn main() {
let true_value = true;
if true_value {
println!(, true_value);
}
let false_value = false;
if!false_value {
println!(, false_value);
}
} | 1,090Boolean values | 14ruby | mlnyj |
fn main() { | 1,090Boolean values | 15rust | 92dmm |
function Allocate_Bitmap( width, height )
local bitmap = {}
for i = 1, width do
bitmap[i] = {}
for j = 1, height do
bitmap[i][j] = {}
end
end
return bitmap
end
function Fill_Bitmap( bitmap, color )
for i = 1, #bitmap do
for j = 1, #bitmap[1] do
... | 1,102Bitmap | 1lua | if5ot |
import java.math.BigInteger
interface NumberGenerator {
val numbers: Array<BigInteger>
}
class Benford(ng: NumberGenerator) {
override fun toString() = str
private val firstDigits = IntArray(9)
private val count = ng.numbers.size.toDouble()
private val str: String
init {
for (n in ng... | 1,107Benford's law | 11kotlin | 5raua |
function raze(a) { | 1,109Best shuffle | 10javascript | v4k25 |
repeat with each item of [True, False, Yes, No, On, Off, ""]
put it & " is " & (it is true)
end repeat | 1,090Boolean values | 16scala | 25zlb |
use utf8;
my @names = (
"North",
"North by east",
"North-northeast",
"Northeast by north",
"Northeast",
"Northeast by east",
"East-northeast",
"East by north",
"East",
"East by south",
"East-southeast",
"Southeast by east",
"Southeast",
"Southeast by south",
"South-southeast",
"South by east",
"South"... | 1,096Box the compass | 2perl | hpyjl |
def bellTriangle(n):
tri = [None] * n
for i in xrange(n):
tri[i] = [0] * i
tri[1][0] = 1
for i in xrange(2, n):
tri[i][0] = tri[i - 1][i - 2]
for j in xrange(1, i):
tri[i][j] = tri[i][j - 1] + tri[i - 1][j - 1]
return tri
def main():
bt = bellTriangle(51)
... | 1,106Bell numbers | 3python | jb07p |
(defn bsearch
([coll t]
(bsearch coll 0 (dec (count coll)) t))
([coll l u t]
(if (> l u) -1
(let [m (quot (+ l u) 2) mth (nth coll m)]
(cond
(> mth t) (recur coll l (dec m) t)
(< mth t) (recur coll (inc m) u t)
... | 1,110Binary search | 6clojure | f3cdm |
actual = {}
expected = {}
for i = 1, 9 do
actual[i] = 0
expected[i] = math.log10(1 + 1 / i)
end
n = 0
file = io.open("fibs1000.txt", "r")
for line in file:lines() do
digit = string.byte(line, 1) - 48
actual[digit] = actual[digit] + 1
n = n + 1
end
file:close()
print("digit actual expected")
for... | 1,107Benford's law | 1lua | 47e5c |
import org.apache.commons.math3.fraction.BigFraction;
public class BernoulliNumbers {
public static void main(String[] args) {
for (int n = 0; n <= 60; n++) {
BigFraction b = bernouilli(n);
if (!b.equals(BigFraction.ZERO))
System.out.printf("B(%-2d) =%-1s%n", n , b)... | 1,108Bernoulli numbers | 9java | so3q0 |
import java.util.Random
object BestShuffle {
operator fun invoke(s1: String) : String {
val s2 = s1.toCharArray()
s2.shuffle()
for (i in s2.indices)
if (s2[i] == s1[i])
for (j in s2.indices)
if (s2[i] != s2[j] && s2[i] != s1[j] && s2[j] != s1[... | 1,109Best shuffle | 11kotlin | t62f0 |
def bellTriangle(n)
tri = Array.new(n)
for i in 0 .. n - 1 do
tri[i] = Array.new(i)
for j in 0 .. i - 1 do
tri[i][j] = 0
end
end
tri[1][0] = 1
for i in 2 .. n - 1 do
tri[i][0] = tri[i - 1][i - 2]
for j in 1 .. i - 1 do
tri[i][j] = tri[i... | 1,106Bell numbers | 14ruby | k1ohg |
math.randomseed(os.time())
local function shuffle(t)
for i = #t, 2, -1 do
local j = math.random(i)
t[i], t[j] = t[j], t[i]
end
end
local function bestshuffle(s, r)
local order, shufl, count = {}, {}, 0
for ch in s:gmatch(".") do order[#order+1], shufl[#shufl+1] = ch, ch end
if r then shuffle(shufl) ... | 1,109Best shuffle | 1lua | zyvty |
use strict;
use Image::Imlib2;
sub my_draw_line
{
my ( $img, $x0, $y0, $x1, $y1) = @_;
my $steep = (abs($y1 - $y0) > abs($x1 - $x0));
if ( $steep ) {
( $y0, $x0 ) = ( $x0, $y0);
( $y1, $x1 ) = ( $x1, $y1 );
}
if ( $x0 > $x1 ) {
( $x1, $x0 ) = ( $x0, $x1 );
( $y1, $y0 ) = ( $y0, $y1 );
... | 1,100Bitmap/Bresenham's line algorithm | 2perl | q82x6 |
public static void bitwise(int a, int b){
System.out.println("a AND b: " + (a & b));
System.out.println("a OR b: "+ (a | b));
System.out.println("a XOR b: "+ (a ^ b));
System.out.println("NOT a: " + ~a);
System.out.println("a << b: " + (a << b)); | 1,103Bitwise operations | 9java | ifuos |
use num::BigUint;
fn main() {
let bt = bell_triangle(51); | 1,106Bell numbers | 15rust | baikx |
import scala.collection.mutable.ListBuffer
object BellNumbers {
class BellTriangle {
val arr: ListBuffer[Int] = ListBuffer.empty[Int]
def this(n: Int) {
this()
val length = n * (n + 1) / 2
for (_ <- 0 until length) {
arr += 0
}
this (1, 0) = 1
for (i <- 2 to n) ... | 1,106Bell numbers | 16scala | axf1n |
import org.apache.commons.math3.fraction.BigFraction
object Bernoulli {
operator fun invoke(n: Int) : BigFraction {
val A = Array(n + 1, init)
for (m in 0..n)
for (j in m downTo 1)
A[j - 1] = A[j - 1].subtract(A[j]).multiply(integers[j])
return A.first()
}
... | 1,108Bernoulli numbers | 11kotlin | axn13 |
s1 =
s2 = 'You may use any of \' or This text
goes over several lines
up to the closing triple quote" | 1,105Binary strings | 3python | hpojw |
% if {""} then {puts true} else {puts false}
expected boolean value but got "" | 1,090Boolean values | 17swift | yci6e |
function bitwise(a, b){
alert("a AND b: " + (a & b));
alert("a OR b: "+ (a | b));
alert("a XOR b: "+ (a ^ b));
alert("NOT a: " + ~a);
alert("a << b: " + (a << b)); | 1,103Bitwise operations | 10javascript | zy7t2 |
#!/usr/bin/env luajit
local gmp = require 'gmp' ('libgmp')
local ffi = require'ffi'
local mpz, mpq = gmp.types.z, gmp.types.q
local function mpq_for(buf, op, n)
for i=0,n-1 do
op(buf[i])
end
end
local function bernoulli(rop, n)
local a=ffi.new("mpq_t[?]", n+1)
mpq_for(a, gmp.q_init, n+1)
for m=0,n do
gmp.q_se... | 1,108Bernoulli numbers | 1lua | eqdac |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.