code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
sub shuffle {
my @a = @_;
foreach my $n (1 .. $
my $k = int rand $n + 1;
$k == $n or @a[$k, $n] = @a[$n, $k];
}
return @a;
} | 686Knuth shuffle | 2perl | uxavr |
WITH KnapsackItems (item, [weight], VALUE) AS
(
SELECT 'map',9, 150
UNION ALL SELECT 'compass',13, 35
UNION ALL SELECT 'water',153, 200
UNION ALL SELECT 'sandwich',50, 160
UNION ALL SELECT 'glucose',15, 60
UNION ALL SELECT 'tin',68, 45
UNION ALL SELECT 'banana',27, 60
... | 692Knapsack problem/0-1 | 19sql | 4sk5x |
function yates_shuffle($arr){
$shuffled = Array();
while($arr){
$rnd = array_rand($arr);
$shuffled[] = $arr[$rnd];
array_splice($arr, $rnd, 1);
}
return $shuffled;
}
function knuth_shuffle(&$arr){
for($i=count($arr)-1;$i>0;$i--){
$rnd = mt_rand(0,$i);
list($arr[$i], $arr[$rnd]) = array($arr[$rnd], $arr... | 686Knuth shuffle | 12php | 8290m |
struct KnapsackItem {
var name: String
var weight: Int
var value: Int
}
func knapsack(items: [KnapsackItem], limit: Int) -> [KnapsackItem] {
var table = Array(repeating: Array(repeating: 0, count: limit + 1), count: items.count + 1)
for j in 1..<items.count+1 {
let item = items[j-1]
for w in 1..<li... | 692Knapsack problem/0-1 | 17swift | mbuyk |
from random import randrange
def knuth_shuffle(x):
for i in range(len(x)-1, 0, -1):
j = randrange(i + 1)
x[i], x[j] = x[j], x[i]
x = list(range(10))
knuth_shuffle(x)
print(, x) | 686Knuth shuffle | 3python | 5qeux |
int number_of_digits(int x){
int NumberOfDigits;
for(NumberOfDigits=0;x!=0;NumberOfDigits++){
x=x/10;
}
return NumberOfDigits;
}
int* convert_array(char array[], int NumberOfElements)
{
int *convertedArray=malloc(NumberOfElements*sizeof(int));
int originalElement, convertedElement;
... | 694JortSort | 5c | d43nv |
fisheryatesshuffle <- function(n)
{
pool <- seq_len(n)
a <- c()
while(length(pool) > 0)
{
k <- sample.int(length(pool), 1)
a <- c(a, pool[k])
pool <- pool[-k]
}
a
} | 686Knuth shuffle | 13r | labce |
int i;
double sum(int *i, int lo, int hi, double (*term)()) {
double temp = 0;
for (*i = lo; *i <= hi; (*i)++)
temp += term();
return temp;
}
double term_func() { return 1.0 / i; }
int main () {
printf(, sum(&i, 1, 100, term_func));
return 0;
} | 695Jensen's Device | 5c | e6qav |
(defn jort-sort [x] (= x (sort x))) | 694JortSort | 6clojure | 6hc3q |
int count_jewels(const char *s, const char *j) {
int count = 0;
for ( ; *s; ++s) if (strchr(j, *s)) ++count;
return count;
}
int main() {
printf(, count_jewels(, ));
printf(, count_jewels(, ));
return 0;
} | 696Jewels and stones | 5c | xmswu |
int jacobi(unsigned long a, unsigned long n) {
if (a >= n) a %= n;
int result = 1;
while (a) {
while ((a & 1) == 0) {
a >>= 1;
if ((n & 7) == 3 || (n & 7) == 5) result = -result;
}
SWAP(a, n);
if ((a & 3) == 3 && (n & 3) == 3) result = -result;
a %= n;
}
if (n == 1) return result;
return 0;
}
voi... | 697Jacobi symbol | 5c | ykm6f |
package main
import (
"log"
"sort"
)
func main() {
log.Println(jortSort([]int{1, 2, 1, 11, 213, 2, 4})) | 694JortSort | 0go | 7obr2 |
class Array
def knuth_shuffle!
j = length
i = 0
while j > 1
r = i + rand(j)
self[i], self[r] = self[r], self[i]
i += 1
j -= 1
end
self
end
end
r = Hash.new(0)
100_000.times do |i|
a = [1,2,3].knuth_shuffle!
r[a] += 1
end
r.keys.sort.each {|a| puts } | 686Knuth shuffle | 14ruby | g0x4q |
import Data.List (sort)
jortSort :: (Ord a) => [a] -> Bool
jortSort list = list == sort list | 694JortSort | 8haskell | 82d0z |
public class JortSort {
public static void main(String[] args) {
System.out.println(jortSort(new int[]{1, 2, 3}));
}
static boolean jortSort(int[] arr) {
return true;
}
} | 694JortSort | 9java | e6sa5 |
use rand::Rng;
extern crate rand;
fn knuth_shuffle<T>(v: &mut [T]) {
let mut rng = rand::thread_rng();
let l = v.len();
for n in 0..l {
let i = rng.gen_range(0, l - n);
v.swap(i, l - n - 1);
}
}
fn main() {
let mut v: Vec<_> = (0..10).collect();
println!("before: {:?}", v);
... | 686Knuth shuffle | 15rust | r8qg5 |
var jortSort = function( array ) { | 694JortSort | 10javascript | 0lnsz |
def shuffle[T](a: Array[T]) = {
for (i <- 1 until a.size reverse) {
val j = util.Random nextInt (i + 1)
val t = a(i)
a(i) = a(j)
a(j) = t
}
a
} | 686Knuth shuffle | 16scala | hn8ja |
package main
import "fmt"
var i int
func sum(i *int, lo, hi int, term func() float64) float64 {
temp := 0.0
for *i = lo; *i <= hi; (*i)++ {
temp += term()
}
return temp
}
func main() {
fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
} | 695Jensen's Device | 0go | 9p2mt |
package main
import (
"fmt"
"log"
"math/big"
)
func jacobi(a, n uint64) int {
if n%2 == 0 {
log.Fatal("'n' must be a positive odd integer")
}
a %= n
result := 1
for a != 0 {
for a%2 == 0 {
a /= 2
nn := n % 8
if nn == 3 || nn == 5 {
... | 697Jacobi symbol | 0go | 1zap5 |
def sum = { i, lo, hi, term ->
(lo..hi).sum { i.value = it; term() }
}
def obj = [:]
println (sum(obj, 1, 100, { 1 / obj.value })) | 695Jensen's Device | 7groovy | z7yt5 |
import Control.Monad.ST
import Data.STRef
sum_ :: STRef s Double -> Double -> Double -> ST s Double -> ST s Double
sum_ ref_i lo hi term = sum <$> mapM ((>> term) . writeSTRef ref_i) [lo .. hi]
foo :: Double
foo =
runST $
do i <- newSTRef undefined
sum_ i 1 100 $ recip <$> readSTRef i
main :: IO ()
main = ... | 695Jensen's Device | 8haskell | bfak2 |
package main
import (
"fmt"
"strings"
)
func js(stones, jewels string) (n int) {
for _, b := range []byte(stones) {
if strings.IndexByte(jewels, b) >= 0 {
n++
}
}
return
}
func main() {
fmt.Println(js("aAAbbbb", "aA"))
} | 696Jewels and stones | 0go | lavcw |
jewelCount
:: Eq a
=> [a] -> [a] -> Int
jewelCount jewels = foldr go 0
where
go c
| c `elem` jewels = succ
| otherwise = id
main :: IO ()
main = mapM_ print $ uncurry jewelCount <$> [("aA", "aAAbbbb"), ("z", "ZZ")] | 696Jewels and stones | 8haskell | 1zeps |
jacobi :: Integer -> Integer -> Integer
jacobi 0 1 = 1
jacobi 0 _ = 0
jacobi a n =
let a_mod_n = rem a n
in if even a_mod_n
then case rem n 8 of
1 -> jacobi (div a_mod_n 2) n
3 -> negate $ jacobi (div a_mod_n 2) n
5 -> negate $ jacobi (div a_mod_n 2) n
... | 697Jacobi symbol | 8haskell | trzf7 |
null | 694JortSort | 11kotlin | kdah3 |
import java.util.HashSet;
import java.util.Set;
public class App {
private static int countJewels(String stones, String jewels) {
Set<Character> bag = new HashSet<>();
for (char c : jewels.toCharArray()) {
bag.add(c);
}
int count = 0;
for (char c : stones.toChar... | 696Jewels and stones | 9java | 7ohrj |
public class JacobiSymbol {
public static void main(String[] args) {
int max = 30;
System.out.printf("n\\k ");
for ( int k = 1 ; k <= max ; k++ ) {
System.out.printf("%2d ", k);
}
System.out.printf("%n");
for ( int n = 1 ; n <= max ; n += 2 ) {
... | 697Jacobi symbol | 9java | 82o06 |
import java.util.function.*;
import java.util.stream.*;
public class Jensen {
static double sum(int lo, int hi, IntToDoubleFunction f) {
return IntStream.rangeClosed(lo, hi).mapToDouble(f).sum();
}
public static void main(String args[]) {
System.out.println(sum(1, 100, (i -> 1.0/i)));
... | 695Jensen's Device | 9java | g0j4m |
function copy (t)
local new = {}
for k, v in pairs(t) do new[k] = v end
return new
end
function jortSort (array)
local originalArray = copy(array)
table.sort(array)
for i = 1, #originalArray do
if originalArray[i] ~= array[i] then return false end
end
return true
end | 694JortSort | 1lua | bfeka |
(() => { | 696Jewels and stones | 10javascript | ptab7 |
var obj;
function sum(o, lo, hi, term) {
var tmp = 0;
for (o.val = lo; o.val <= hi; o.val++)
tmp += term();
return tmp;
}
obj = {val: 0};
alert(sum(obj, 1, 100, function() {return 1 / obj.val})); | 695Jensen's Device | 10javascript | kd1hq |
null | 696Jewels and stones | 11kotlin | ux4vc |
fun jacobi(A: Int, N: Int): Int {
assert(N > 0 && N and 1 == 1)
var a = A % N
var n = N
var result = 1
while (a != 0) {
var aMod4 = a and 3
while (aMod4 == 0) { | 697Jacobi symbol | 11kotlin | wyxek |
function count_jewels(s, j)
local count = 0
for i=1,#s do
local c = s:sub(i,i)
if string.match(j, c) then
count = count + 1
end
end
return count
end
print(count_jewels("aAAbbbb", "aA"))
print(count_jewels("ZZ", "z")) | 696Jewels and stones | 1lua | 5qgu6 |
fun sum(lo: Int, hi: Int, f: (Int) -> Double) = (lo..hi).sumByDouble(f)
fun main(args: Array<String>) = println(sum(1, 100, { 1.0 / it })) | 695Jensen's Device | 11kotlin | 2e5li |
function sum(var, a, b, str)
local ret = 0
for i = a, b do
ret = ret + setfenv(loadstring("return "..str), {[var] = i})()
end
return ret
end
print(sum("i", 1, 100, "1/i")) | 695Jensen's Device | 1lua | vw42x |
use strict;
use warnings;
sub J {
my($k,$n) = @_;
$k %= $n;
my $jacobi = 1;
while ($k) {
while (0 == $k % 2) {
$k = int $k / 2;
$jacobi *= -1 if $n%8 == 3 or $n%8 == 5;
}
($k, $n) = ($n, $k);
$jacobi *= -1 if $n%4 == 3 and $k%4 == 3;
$k %... | 697Jacobi symbol | 2perl | la2c5 |
sub jortsort {
my @s=sort @_;
for (0..$
return 0 unless $_[$_] eq $s[$_];
}
1;
} | 694JortSort | 2perl | 3j9zs |
def jacobi(a, n):
if n <= 0:
raise ValueError()
if n% 2 == 0:
raise ValueError()
a%= n
result = 1
while a != 0:
while a% 2 == 0:
a /= 2
n_mod_8 = n% 8
if n_mod_8 in (3, 5):
result = -result
a, n = n, a
if a% ... | 697Jacobi symbol | 3python | 2evlz |
import func Darwin.arc4random_uniform
extension Array {
func shuffle() -> Array {
var result = self; result.shuffleInPlace(); return result
}
mutating func shuffleInPlace() {
for i in 1 ..< count { swap(&self[i], &self[Int(arc4random_uniform(UInt32(i+1)))]) }
}
} | 686Knuth shuffle | 17swift | 4sw5g |
sub count_jewels {
my( $j, $s ) = @_;
my($c,%S);
$S{$_}++ for split //, $s;
$c += $S{$_} for split //, $j;
return "$c\n";
}
print count_jewels 'aA' , 'aAAbbbb';
print count_jewels 'z' , 'ZZ'; | 696Jewels and stones | 2perl | 82i0w |
>>> def jortsort(sequence):
return list(sequence) == sorted(sequence)
>>> for data in [(1,2,4,3), (14,6,8), ['a', 'c'], ['s', 'u', 'x'], 'CVGH', 'PQRST']:
print(f'jortsort({repr(data)}) is {jortsort(data)}')
jortsort((1, 2, 4, 3)) is False
jortsort((14, 6, 8)) is False
jortsort(['a', 'c']) is True
jortsort(['s', 'u',... | 694JortSort | 3python | 6hc3w |
def jacobi(a, n)
raise ArgumentError.new if n < 1 || n.even?
res = 1
until (a %= n) == 0
while a.even?
a >>= 1
res = -res if [3, 5].include? n % 8
end
a, n = n, a
res = -res if [a % 4, n % 4] == [3, 3]
end
n == 1? res: 0
end
puts
puts
puts
1.step(to: 17, by: 2) do |n|
print... | 697Jacobi symbol | 14ruby | ux5vz |
fn jacobi(mut n: i32, mut k: i32) -> i32 {
assert!(k > 0 && k% 2 == 1);
n%= k;
let mut t = 1;
while n!= 0 {
while n% 2 == 0 {
n /= 2;
let r = k% 8;
if r == 3 || r == 5 {
t = -t;
}
}
std::mem::swap(&mut n, &mut k);
... | 697Jacobi symbol | 15rust | 5q4uq |
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"sort"
)
func jaroSim(str1, str2 string) float64 {
if len(str1) == 0 && len(str2) == 0 {
return 1
}
if len(str1) == 0 || len(str2) == 0 {
return 0
}
match_distance := len(str1)
if len(str2) > match_distan... | 698Jaro-Winkler distance | 0go | scsqa |
def jacobi(a_p: Int, n_p: Int): Int =
{
var a = a_p
var n = n_p
if (n <= 0) return -1
if (n % 2 == 0) return -1
a %= n
var result = 1
while (a != 0) {
while (a % 2 == 0) {
a /= 2
if (n % 8 == 3 || n % 8 == 5) result = -result
}
val t = a
a = n
n... | 697Jacobi symbol | 16scala | r87gn |
void jacobsthal(mpz_t r, unsigned long n) {
mpz_t s;
mpz_init(s);
mpz_set_ui(r, 1);
mpz_mul_2exp(r, r, n);
mpz_set_ui(s, 1);
if (n % 2) mpz_neg(s, s);
mpz_sub(r, r, s);
mpz_div_ui(r, r, 3);
}
void jacobsthal_lucas(mpz_t r, unsigned long n) {
mpz_t a;
mpz_init(a);
mpz_set_ui(... | 699Jacobsthal numbers | 5c | uw2v4 |
def countJewels(s, j):
return sum(x in j for x in s)
print countJewels(, )
print countJewels(, ) | 696Jewels and stones | 3python | ovn81 |
J_n_S <- function(stones ="aAAbbbb", jewels = "aA") {
stones <- unlist(strsplit(stones, split = ""))
jewels <- unlist(strsplit(jewels, split = ""))
count <- sum(stones%in% jewels)
}
print(J_n_S("aAAbbbb", "aA"))
print(J_n_S("ZZ", "z"))
print(J_n_S("lgGKJGljglghGLGHlhglghoIPOgfdtrdDCHnvbnmBVC", "fFgGhH")) | 696Jewels and stones | 13r | q90xs |
import java.io.*;
import java.util.*;
public class JaroWinkler {
public static void main(String[] args) {
try {
List<String> words = loadDictionary("linuxwords.txt");
String[] strings = {
"accomodate", "definately", "goverment", "occured",
"publically... | 698Jaro-Winkler distance | 9java | trtf9 |
def jort_sort(array)
array == array.sort
end | 694JortSort | 14ruby | mb2yj |
use std::cmp::{Ord, Eq};
fn jort_sort<T: Ord + Eq + Clone>(array: Vec<T>) -> bool { | 694JortSort | 15rust | 9pvmm |
import Foundation
func jacobi(a: Int, n: Int) -> Int {
var a = a% n
var n = n
var res = 1
while a!= 0 {
while a & 1 == 0 {
a >>= 1
if n% 8 == 3 || n% 8 == 5 {
res = -res
}
}
(a, n) = (n, a)
if a% 4 == 3 && n% 4 == 3 {
res = -res
}
a%= n
}
return... | 697Jacobi symbol | 17swift | vwu2r |
my $i;
sub sum {
my ($i, $lo, $hi, $term) = @_;
my $temp = 0;
for ($$i = $lo; $$i <= $hi; $$i++) {
$temp += $term->();
}
return $temp;
}
print sum(\$i, 1, 100, sub { 1 / $i }), "\n"; | 695Jensen's Device | 2perl | scoq3 |
import java.util.Objects.deepEquals
def jortSort[K:Ordering]( a:Array[K] ) = deepEquals(a.sorted, a) | 694JortSort | 16scala | 2e4lb |
$i;
function sum (&$i, $lo, $hi, $term) {
$temp = 0;
for ($i = $lo; $i <= $hi; $i++) {
$temp += $term();
}
return $temp;
}
echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), ;
function sum ($lo,$hi)
{
$temp = 0;
for ($i = $lo; $i <= $hi; $i++)
{
$temp += (1 / $i);
}... | 695Jensen's Device | 12php | uxgv5 |
func jortSort<T:Comparable>(array: [T]) -> Bool {
return array == sorted(array)
} | 694JortSort | 17swift | ykl6e |
package main
import (
"fmt"
"math/big"
)
func jacobsthal(n uint) *big.Int {
t := big.NewInt(1)
t.Lsh(t, n)
s := big.NewInt(1)
if n%2 != 0 {
s.Neg(s)
}
t.Sub(t, s)
return t.Div(t, big.NewInt(3))
}
func jacobsthalLucas(n uint) *big.Int {
t := big.NewInt(1)
t.Lsh(t, n... | 699Jacobsthal numbers | 0go | 0cqsk |
use strict;
use warnings;
use List::Util qw(min max head);
sub jaro_winkler {
my($s, $t) = @_;
my(@s_matches, @t_matches, $matches);
return 0 if $s eq $t;
my $s_len = length $s; my @s = split //, $s;
my $t_len = length $t; my @t = split //, $t;
my $match_distance = int (max($s_len,$t_len)/2)... | 698Jaro-Winkler distance | 2perl | g0g4e |
jacobsthal :: [Integer]
jacobsthal = 0: 1: zipWith (\x y -> 2 * x + y) jacobsthal (tail jacobsthal)
jacobsthalLucas :: [Integer]
jacobsthalLucas = 2: 1: zipWith (\x y -> 2 * x + y) jacobsthalLucas (tail jacobsthalLucas)
jacobsthalOblong :: [Integer]
jacobsthalOblong = zipWith (*) jacobsthal (tail jacobsthal)
isPrime... | 699Jacobsthal numbers | 8haskell | cpm94 |
stones, jewels = ,
stones.count(jewels) | 696Jewels and stones | 14ruby | n5fit |
fn count_jewels(stones: &str, jewels: &str) -> u8 {
let mut count: u8 = 0;
for cur_char in stones.chars() {
if jewels.contains(cur_char) {
count += 1;
}
}
count
}
fn main() {
println!("{}", count_jewels("aAAbbbb", "aA"));
println!("{}", count_jewels("ZZ", "z"));
} | 696Jewels and stones | 15rust | d4tny |
class Ref(object):
def __init__(self, value=None):
self.value = value
def harmonic_sum(i, lo, hi, term):
temp = 0
i.value = lo
while i.value <= hi:
temp += term()
i.value += 1
return temp
i = Ref()
print harmonic_sum(i, 1, 100, lambda: 1.0/i.value) | 695Jensen's Device | 3python | 0lisq |
sum <- function(var, lo, hi, term)
eval(substitute({
.temp <- 0;
for (var in lo:hi) {
.temp <- .temp + term
}
.temp
}, as.list(match.call()[-1])),
enclos=parent.frame())
sum(i, 1, 100, 1/i)
x <- -1
sum(i, 1, 100, i^x) | 695Jensen's Device | 13r | wyse5 |
object JewelsStones extends App {
def countJewels(s: String, j: String): Int = s.count(i => j.contains(i))
println(countJewels("aAAbbbb", "aA"))
println(countJewels("ZZ", "z"))
} | 696Jewels and stones | 16scala | z76tr |
WORDS = [s.strip() for s in open().read().split()]
MISSPELLINGS = [
,
,
,
,
,
,
,
,
,
]
def jaro_winkler_distance(st1, st2):
if len(st1) < len(st2):
st1, st2 = st2, st1
len1, len2 = len(st1), len(st2)
if len2 == 0:
return 0.0
delta = max(0, len2 ... | 698Jaro-Winkler distance | 3python | r8rgq |
-- See how many jewels are among the stones
DECLARE @S VARCHAR(1024) = 'AaBbCcAa'
, @J VARCHAR(1024) = 'aA';
DECLARE @SLEN INT = len(@S);
DECLARE @JLEN INT = len(@J);
DECLARE @TCNT INT = 0;
DECLARE @SPOS INT = 1; -- curr position in @S
DECLARE @JPOS INT = 1; -- curr position in @J
DECLARE @FCHR CHAR(1); -- char to f... | 696Jewels and stones | 19sql | yk96x |
use strict;
use warnings;
use feature <say state>;
use bigint;
use List::Util 'max';
use ntheory 'is_prime';
sub table { my $t = 5 * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr }
sub jacobsthal { my($n) = @_; state @J = (0, 1); do { push @J, $J[-1] + 2 * $J[-2]} until... | 699Jacobsthal numbers | 2perl | r04gd |
func countJewels(_ stones: String, _ jewels: String) -> Int {
return stones.map({ jewels.contains($0)? 1: 0 }).reduce(0, +)
}
print(countJewels("aAAbbbb", "aA"))
print(countJewels("ZZ", "z")) | 696Jewels and stones | 17swift | iudo0 |
use std::fs::File;
use std::io::{self, BufRead};
fn load_dictionary(filename: &str) -> std::io::Result<Vec<String>> {
let file = File::open(filename)?;
let mut dict = Vec::new();
for line in io::BufReader::new(file).lines() {
dict.push(line?);
}
Ok(dict)
}
fn jaro_winkler_distance(string1:... | 698Jaro-Winkler distance | 15rust | hnhj2 |
import Foundation
func loadDictionary(_ path: String) throws -> [String] {
let contents = try String(contentsOfFile: path, encoding: String.Encoding.ascii)
return contents.components(separatedBy: "\n")
}
func jaroWinklerDistance(string1: String, string2: String) -> Double {
var st1 = Array(string1)
va... | 698Jaro-Winkler distance | 17swift | 7o7rq |
def sum(var, lo, hi, term, context)
sum = 0.0
lo.upto(hi) do |n|
sum += eval , context
end
sum
end
p sum , 1, 100, , binding | 695Jensen's Device | 14ruby | ovd8v |
var fs = require('fs') | 698Jaro-Winkler distance | 20typescript | 8280i |
use std::f32;
fn harmonic_sum<F>(lo: usize, hi: usize, term: F) -> f32
where
F: Fn(f32) -> f32,
{
(lo..hi + 1).fold(0.0, |acc, item| acc + term(item as f32))
}
fn main() {
println!("{}", harmonic_sum(1, 100, |i| 1.0 / i));
} | 695Jensen's Device | 15rust | iufod |
class MyInt { var i: Int = _ }
val i = new MyInt
def sum(i: MyInt, lo: Int, hi: Int, term: => Double) = {
var temp = 0.0
i.i = lo
while(i.i <= hi) {
temp = temp + term
i.i += 1
}
temp
}
sum(i, 1, 100, 1.0 / i.i) | 695Jensen's Device | 16scala | fg3d4 |
from math import floor, pow
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n% i == 0:
return False
return True
def odd(n):
return n and 1 != 0
def jacobsthal(n):
return floor((pow(2,n)+odd(n))/3)
def jacobsthal_lucas(n):
return int(pow(2,n)+pow(-1,n))
def jac... | 699Jacobsthal numbers | 3python | 78grm |
int foo() { return 1; }
main()
{
int a = 0;
otherwise a = 4 given (foo());
printf(, a);
exit(0);
} | 700Inverted syntax | 5c | gsu45 |
(if (= 1 1)
(print "Math works."))
(->> (print "Math still works.")
(if (= 1 1)))
(->> (print a " is " b)
(let [a 'homoiconicity
b 'awesome])) | 700Inverted syntax | 6clojure | kn7hs |
double jaro(const char *str1, const char *str2) {
int str1_len = strlen(str1);
int str2_len = strlen(str2);
if (str1_len == 0) return str2_len == 0 ? 1.0 : 0.0;
int match_distance = (int) max(str1_len, str2_len)/2 - 1;
int *str1_matches = calloc(str1_len, sizeof(int)... | 701Jaro similarity | 5c | 2amlo |
var i = 42 | 695Jensen's Device | 17swift | 82n0v |
null | 699Jacobsthal numbers | 15rust | knjh5 |
(ns test-project-intellij.core
(:gen-class))
(defn find-matches [s t]
" find match locations in the two strings "
" s_matches is set to true wherever there is a match in t and t_matches is set conversely "
(let [s_len (count s)
t_len (count t)
match_distance (int (- (/ (max s_len t_len) 2) 1))
... | 701Jaro similarity | 6clojure | gsv4f |
package main
import "fmt"
type ibool bool
const itrue ibool = true
func (ib ibool) iif(cond bool) bool {
if cond {
return bool(ib)
}
return bool(!ib)
}
func main() {
var needUmbrella bool
raining := true | 700Inverted syntax | 0go | iv0og |
when :: Monad m => m () -> Bool -> m ()
action `when` condition = if condition then action else return () | 700Inverted syntax | 8haskell | vec2k |
do ... while(condition); | 700Inverted syntax | 9java | yhz6g |
null | 700Inverted syntax | 11kotlin | f4ido |
int jos(int n, int k, int m) {
int a;
for (a = m + 1; a <= n; a++)
m = (m + k) % a;
return m;
}
typedef unsigned long long xint;
xint jos_large(xint n, xint k, xint m) {
if (k <= 1) return n - m - 1;
xint a = m;
while (a < n) {
xint q = (a - m + k - 2) / (k - 1);
if (a + q > n) q = n - a;
else if (!q... | 702Josephus problem | 5c | nusi6 |
if ($guess == 6) { print "Wow! Lucky Guess!"; };
print 'Wow! Lucky Guess!' if $guess == 6;
unless ($guess == 6) { print "Sorry, your guess was wrong!"; }
print 'Huh! You Guessed Wrong!' unless $guess == 6; | 700Inverted syntax | 2perl | hirjl |
typedef unsigned long long ull;
int is89(int x)
{
while (1) {
int s = 0;
do s += (x%10)*(x%10); while ((x /= 10));
if (s == 89) return 1;
if (s == 1) return 0;
x = s;
}
}
int main(void)
{
ull sums[32*81 + 1] = {1, 0};
for (int n = 1; ; n++) {
for (int i = n*81; i; i--) {
for (int j = 1; j < 10... | 703Iterated digits squaring | 5c | jou70 |
int check_isbn13(const char *isbn) {
int ch = *isbn, count = 0, sum = 0;
for ( ; ch != 0; ch = *++isbn, ++count) {
if (ch == ' ' || ch == '-') {
--count;
continue;
}
if (ch < '0' || ch > '9') {
return 0;
}
if (count & 1) {... | 704ISBN13 check digit | 5c | az711 |
(defn rotate [n s] (lazy-cat (drop n s) (take n s)))
(defn josephus [n k]
(letfn [(survivor [[ h & r:as l] k]
(cond (empty? r) h
:else (survivor (rest (rotate (dec k) l)) k)))]
(survivor (range n) k)))
(let [n 41 k 3]
(println (str "Given " n " prisoners in a circle num... | 702Josephus problem | 6clojure | 37nzr |
x = truevalue if condition else falsevalue | 700Inverted syntax | 3python | kn7hf |
do.if <- function(expr, cond) if(cond) expr | 700Inverted syntax | 13r | r05gj |
(ns async-example.core
(:require [clojure.math.numeric-tower :as math])
(:use [criterium.core])
(:gen-class))
(defn sum-sqr [digits]
" Square sum of list of digits "
(let [digits-sqr (fn [n]
(apply + (map #(* % %) digits)))]
(digits-sqr digits)))
(defn get-digits [n]
" Converts a d... | 703Iterated digits squaring | 6clojure | 1t7py |
int64_t isqrt(int64_t x) {
int64_t q = 1, r = 0;
while (q <= x) {
q <<= 2;
}
while (q > 1) {
int64_t t;
q >>= 2;
t = x - r - q;
r >>= 1;
if (t >= 0) {
x = t;
r += q;
}
}
return r;
}
int main() {
int64_t p;
i... | 705Isqrt (integer square root) of X | 5c | iveo2 |
if n < 0 then raise ArgumentError, end
raise ArgumentError, if n < 0
unless Process.respond_to?:fork then exit 1 end
exit 1 unless Process.respond_to?:fork
while ary.length > 0 do puts ary.shift end
puts ary.shift while ary.length > 0
until ary.empty? do puts ary.shift end
puts ary.shift until ary.empty? | 700Inverted syntax | 14ruby | pfhbh |
object Main extends App {
val raining = true
val needUmbrella = raining
println(s"Do I need an umbrella? ${if (needUmbrella) "Yes" else "No"}")
} | 700Inverted syntax | 16scala | w61es |
infix operator ~= {}
infix operator! {}
func ~=(lhs:Int, inout rhs:Int) {
rhs = lhs
}
func!(lhs:(() -> Void), rhs:Bool) {
if (rhs) {
lhs()
}
} | 700Inverted syntax | 17swift | bdjkd |
package main
import "fmt"
func jaro(str1, str2 string) float64 {
if len(str1) == 0 && len(str2) == 0 {
return 1
}
if len(str1) == 0 || len(str2) == 0 {
return 0
}
match_distance := len(str1)
if len(str2) > match_distance {
match_distance = len(str2)
}
match_dist... | 701Jaro similarity | 0go | qmaxz |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.