code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
import Data.List (elemIndex, intercalate, sortOn)
import Data.Maybe (mapMaybe)
import Text.Printf (printf)
jaro :: Ord a => [a] -> [a] -> Float
jaro x y
| 0 == m = 0
| otherwise =
(1 / 3)
* ( (m / s1) + (m / s2) + ((m - t) / m))
where
f = fromIntegral . length
[m, t] =
[f, fromIntegral ... | 701Jaro similarity | 8haskell | mkzyf |
struct Wheel {
char *seq;
int len;
int pos;
};
struct Wheel *create(char *seq) {
struct Wheel *w = malloc(sizeof(struct Wheel));
if (w == NULL) {
return NULL;
}
w->seq = seq;
w->len = strlen(seq);
w->pos = 0;
return w;
}
char cycle(struct Wheel *w) {
char c = w->s... | 706Intersecting number wheels | 5c | vez2o |
package main
import (
"fmt"
)
func main() {
var d, n, o, u, u89 int64
for n = 1; n < 100000000; n++ {
o = n
for {
u = 0
for {
d = o%10
o = (o - d) / 10
u += d*d
if o == 0 {
break
}
}
if u == 89 || u == 1 {
if u == 89 { u89++ }
break
}
o = u
}
}
fmt.Print... | 703Iterated digits squaring | 0go | f40d0 |
Clojure 1.1.0
user=> (defn f [s1 s2 sep] (str s1 sep sep s2))
#'user/f
user=> (f "Rosetta" "Code" ":")
"Rosetta::Code"
user=> | 707Interactive programming (repl) | 6clojure | uwzvi |
public class JaroDistance {
public static double jaro(String s, String t) {
int s_len = s.length();
int t_len = t.length();
if (s_len == 0 && t_len == 0) return 1;
int match_distance = Integer.max(s_len, t_len) / 2 - 1;
boolean[] s_matches = new boolean[s_len];
boo... | 701Jaro similarity | 9java | f4odv |
import Data.List (unfoldr)
import Data.Tuple (swap)
step :: Int -> Int
step = sum . map (^ 2) . unfoldr f where
f 0 = Nothing
f n = Just . swap $ n `divMod` 10
iter :: Int -> Int
iter = head . filter (`elem` [1, 89]) . iterate step
main = do
print $ length $ filter ((== 89) . iter) [1 .. 99999999] | 703Iterated digits squaring | 8haskell | 4qc5s |
import java.util.stream.IntStream;
public class IteratedDigitsSquaring {
public static void main(String[] args) {
long r = IntStream.range(1, 100_000_000)
.parallel()
.filter(n -> calc(n) == 89)
.count();
System.out.println(r);
}
private sta... | 703Iterated digits squaring | 9java | cpz9h |
package main
import (
"fmt"
"sort"
"strconv"
)
type wheel struct {
next int
values []string
}
type wheelMap = map[string]wheel
func generate(wheels wheelMap, start string, maxCount int) {
count := 0
w := wheels[start]
for {
s := w.values[w.next]
v, err := strconv.At... | 706Intersecting number wheels | 0go | s9kqa |
package main
import (
"fmt"
"strings"
"unicode/utf8"
)
func checkIsbn13(isbn string) bool { | 704ISBN13 check digit | 0go | mkdyi |
object Jaro {
fun distance(s1: String, s2: String): Double {
val s1_len = s1.length
val s2_len = s2.length
if (s1_len == 0 && s2_len == 0) return 1.0
val match_distance = Math.max(s1_len, s2_len) / 2 - 1
val s1_matches = BooleanArray(s1_len)
val s2_matches = BooleanAr... | 701Jaro similarity | 11kotlin | 8lx0q |
package main
import (
"fmt"
"log"
"math/big"
)
var zero = big.NewInt(0)
var one = big.NewInt(1)
func isqrt(x *big.Int) *big.Int {
if x.Cmp(zero) < 0 {
log.Fatal("Argument cannot be negative.")
}
q := big.NewInt(1)
for q.Cmp(x) <= 0 {
q.Lsh(q, 2)
}
z := new(big.Int)... | 705Isqrt (integer square root) of X | 0go | gs94n |
char chr_legal[] = ;
int chr_idx[256] = {0};
char idx_chr[256] = {0};
typedef struct trie_t *trie, trie_t;
struct trie_t {
trie next[sizeof(chr_legal)];
int eow;
};
trie trie_new() { return calloc(sizeof(trie_t), 1); }
trie trie_trav(trie root, const char * str, int no_create)
{
int c;
while (ro... | 708Inverted index | 5c | mk8ys |
null | 709Introspection | 5c | 4qz5t |
import Data.Char (isDigit)
import Data.List (mapAccumL)
import qualified Data.Map.Strict as M
import Data.Maybe (fromMaybe)
clockWorkTick ::
M.Map Char String ->
(M.Map Char String, Char)
clockWorkTick = flip click 'A'
where
click wheels name
| isDigit name = (wheels, name)
| otherwise =
... | 706Intersecting number wheels | 8haskell | 9bnmo |
import Data.Char (digitToInt, isDigit)
import Text.Printf (printf)
pair :: Num a => [a] -> [(a, a)]
pair [] = []
pair xs = p (take 2 xs): pair (drop 2 xs)
where
p ps = case ps of
(x: y: zs) -> (x, y)
(x: zs) -> (x, 0)
validIsbn13 :: String -> Bool
validIsbn13 isbn
| length (digits isbn) /= 13 = Fa... | 704ISBN13 check digit | 8haskell | kn5h0 |
null | 703Iterated digits squaring | 11kotlin | 37iz5 |
import Data.Bits
isqrt :: Integer -> Integer
isqrt n = go n 0 (q `shiftR` 2)
where
q = head $ dropWhile (< n) $ iterate (`shiftL` 2) 1
go z r 0 = r
go z r q = let t = z - r - q
in if t >= 0
then go t (r `shiftR` 1 + q) (q `shiftR` 2)
else go z (r `shiftR` 1) (q... | 705Isqrt (integer square root) of X | 8haskell | s9bqk |
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
(if (>= version 1.5)
(println "Version ok")
(throw (Error. "Bad version"))))
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
(if (>= version 1.0)
(println "Version ok")
(thro... | 709Introspection | 6clojure | hi9jr |
squares = {}
for i = 0, 9 do
for j = 0, 9 do
squares[i * 10 + j] = i * i + j * j
end
end
for i = 1, 99 do
for j = 0, 99 do
squares[i * 100 + j] = squares[i] + squares[j]
end
end
function sum_squares(n)
if n < 9999.5 then
return squares[n]
else
local m = math.fl... | 703Iterated digits squaring | 1lua | 6jn39 |
package intersectingNumberWheels;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
public class WheelController {
private static final String IS_NUMBER = "[0-9]";
private static final int TWENTY = 20;
private static Map<String, Whe... | 706Intersecting number wheels | 9java | tgqf9 |
public static void main(){
System.out.println(isISBN13("978-1734314502"));
System.out.println(isISBN13("978-1734314509"));
System.out.println(isISBN13("978-1788399081"));
System.out.println(isISBN13("978-1788399083"));
}
public static boolean isISBN13(String in){
int pre = In... | 704ISBN13 check digit | 9java | 4q958 |
(ns inverted-index.core
(:require [clojure.set:as sets]
[clojure.java.io:as io]))
(def pattern #"\w+")
(defn normalize [match] (.toLowerCase match))
(defn term-seq [text] (map normalize (re-seq pattern text)))
(defn set-assoc
"Produces map with v added to the set associated with key k in map m... | 708Inverted index | 6clojure | vef2f |
(() => {
'use strict'; | 706Intersecting number wheels | 10javascript | mkiyv |
int main (int argc, char *argv[])
{
printf();
printf(, -(-2147483647-1));
printf(, 2000000000 + 2000000000);
printf(, -2147483647 - 2147483647);
printf(, 46341 * 46341);
printf(, (-2147483647-1) / -1);
printf();
printf(, -(-9223372036854775807-1));
printf(, 5000000000000000000+5000000000000000000);
... | 710Integer overflow | 5c | 5xfuk |
import java.math.BigInteger;
public class Isqrt {
private static BigInteger isqrt(BigInteger x) {
if (x.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException("Argument cannot be negative");
}
var q = BigInteger.ONE;
while (q.compareTo(x) <= 0) {
... | 705Isqrt (integer square root) of X | 9java | 1tgp2 |
import java.util.Collections
import java.util.stream.IntStream
object WheelController {
private val IS_NUMBER = "[0-9]".toRegex()
private const val TWENTY = 20
private var wheelMap = mutableMapOf<String, WheelModel>()
private fun advance(wheel: String) {
val w = wheelMap[wheel]
if (w!!... | 706Intersecting number wheels | 11kotlin | o218z |
package main
import "fmt"
func f(s1, s2, sep string) string {
return s1 + sep + sep + s2
}
func main() {
fmt.Println(f("Rosetta", "Code", ":"))
} | 707Interactive programming (repl) | 0go | e3ga6 |
C:\Apps\groovy>groovysh
Groovy Shell (1.6.2, JVM: 1.6.0_13)
Type 'help' or '\h' for help.
---------------------------------------------------------------------------------------------------
groovy:000> f = { a, b, sep -> a + sep + sep + b }
===> groovysh_evaluate$_run_closure1@5e8d7d
groovy:000> println f('Rosetta','Co... | 707Interactive programming (repl) | 7groovy | kn2h7 |
fun isValidISBN13(text: String): Boolean {
val isbn = text.replace(Regex("[- ]"), "")
return isbn.length == 13 && isbn.map { it - '0' }
.mapIndexed { index, value -> when (index% 2) { 0 -> value else -> 3 * value } }
.sum()% 10 == 0
} | 704ISBN13 check digit | 11kotlin | l1zcp |
use strict;
use warnings;
use List::Util qw(min max);
sub jaro {
my($s, $t) = @_;
my(@s_matches, @t_matches, $matches);
return 1 if $s eq $t;
my($s_len, @s) = (length $s, split //, $s);
my($t_len, @t) = (length $t, split //, $t);
my $match_distance = int (max($s_len, $t_len) / 2) - 1;
fo... | 701Jaro similarity | 2perl | 4q25d |
package main
import "fmt" | 702Josephus problem | 0go | r0vgm |
$ ghci
___ ___ _
/ _ \ /\ /\/ __(_)
/ /_\// /_/ / / | | GHC Interactive, version 6.4.2, for Haskell 98.
/ /_\\/ __ / /___| | http://www.haskell.org/ghc/
\____/\/ /_/\____/|_| Type:? for help.
Loading package base-1.0 ... linking ... done.
Prelude> let f as bs sep = as ++ sep ++ sep ++ b... | 707Interactive programming (repl) | 8haskell | 37szj |
function checkIsbn13(isbn)
local count = 0
local sum = 0
for c in isbn:gmatch"." do
if c == ' ' or c == '-' then | 704ISBN13 check digit | 1lua | 2a3l3 |
typedef struct{
double focalLength;
double resolution;
double memory;
}Camera;
typedef struct{
double balance;
double batteryLevel;
char** contacts;
}Phone;
typedef struct{
Camera cameraSample;
Phone phoneSample;
}CameraPhone; | 711Inheritance/Multiple | 5c | qm4xc |
import java.math.BigInteger
fun isqrt(x: BigInteger): BigInteger {
if (x < BigInteger.ZERO) {
throw IllegalArgumentException("Argument cannot be negative")
}
var q = BigInteger.ONE
while (q <= x) {
q = q.shiftLeft(2)
}
var z = x
var r = BigInteger.ZERO
while (q > BigInte... | 705Isqrt (integer square root) of X | 11kotlin | jo27r |
int[] Josephus (int size, int kill, int survivors) { | 702Josephus problem | 7groovy | vem28 |
use strict;
use warnings;
use feature 'say';
sub get_next {
my($w,%wheels) = @_;
my $wh = \@{$wheels{$w}};
my $value = $$wh[0][$$wh[1]];
$$wh[1] = ($$wh[1]+1) % @{$$wh[0]};
defined $wheels{$value} ? get_next($value,%wheels) : $value;
}
sub spin_wheels {
my(%wheels) = @_;
say "$_: " . join... | 706Intersecting number wheels | 2perl | gsm4e |
'''Jaro distance'''
from __future__ import division
def jaro(s, t):
'''Jaro distance between two strings.'''
s_len = len(s)
t_len = len(t)
if s_len == 0 and t_len == 0:
return 1
match_distance = (max(s_len, t_len)
s_matches = [False] * s_len
t_matches = [False] * t_len
ma... | 701Jaro similarity | 3python | gsv4h |
use warnings;
use strict;
my @sq = map { $_ ** 2 } 0 .. 9;
my %cache;
my $cnt = 0;
sub Euler92 {
my $n = 0 + join( '', sort split( '', shift ) );
$cache{$n} //= ($n == 1 || $n == 89) ? $n :
Euler92( sum( @sq[ split '', $n ] ) )
}
sub sum {
my $sum;
$sum += shift while @_;
$sum;
}
for (1 .. 100... | 703Iterated digits squaring | 2perl | pfrb0 |
(defprotocol Camera)
(defprotocol MobilePhone)
(deftype CameraPhone []
Camera
MobilePhone) | 711Inheritance/Multiple | 6clojure | ivhom |
(* -1 (dec -9223372036854775807))
(+ 5000000000000000000 5000000000000000000)
(- -9223372036854775807 9223372036854775807)
(* 3037000500 3037000500) | 710Integer overflow | 6clojure | joy7m |
function isqrt(x)
local q = 1
local r = 0
while q <= x do
q = q << 2
end
while q > 1 do
q = q >> 2
local t = x - r - q
r = r >> 1
if t >= 0 then
x = t
r = r + q
end
end
return r
end
print("Integer square root for number... | 705Isqrt (integer square root) of X | 1lua | hivj8 |
package main
import (
"debug/elf"
"debug/gosym"
"fmt"
"log"
"math"
"os"
"runtime"
)
var bloop = -3.4
func main() {
fmt.Println("task 1: verify version")
fmt.Println(" program compiled with", runtime.Version())
fmt.Println("task 2: check for presence of variable and function... | 709Introspection | 0go | o2k8q |
import Data.List ((\\))
import System.Environment (getArgs)
prisoners :: Int -> [Int]
prisoners n = [0 .. n - 1]
counter :: Int -> [Int]
counter k = cycle [k, k-1 .. 1]
killList :: [Int] -> [Int] -> ([Int], [Int], [Int])
killList xs cs = (killed, survivors, newCs)
where
(killed, newCs) = kill xs cs []
... | 702Josephus problem | 8haskell | 0ces7 |
public static void main(String[] args) {
System.out.println(concat("Rosetta", "Code", ":"));
}
public static String concat(String a, String b, String c) {
return a + c + c + b;
}
Rosetta::Code | 707Interactive programming (repl) | 9java | iv1os |
$ java -cp js.jar org.mozilla.javascript.tools.shell.Main
Rhino 1.7 release 2 2009 03 22
js> function f(a,b,s) {return a + s + s + b;}
js> f('Rosetta', 'Code', ':')
Rosetta::Code
js> quit()
$ | 707Interactive programming (repl) | 10javascript | zrqt2 |
import Data.Version
import Control.Monad
import System.Info
minGHCVersion = Version [6, 8] []
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
fail "Compiler too old." | 709Introspection | 8haskell | 2anll |
from itertools import islice
class INW():
def __init__(self, **wheels):
self._wheels = wheels
self.isect = {name: self._wstate(name, wheel)
for name, wheel in wheels.items()}
def _wstate(self, name, wheel):
assert all(val in self._wheels for val in... | 706Intersecting number wheels | 3python | r09gq |
c:\kotlin-compiler-1.0.6>kotlinc
Welcome to Kotlin version 1.0.6-release-127 (JRE 1.8.0_31-b13)
Type :help for help, :quit for quit
>>> fun f(s1: String, s2: String, sep: String) = s1 + sep + sep + s2
>>> f("Rosetta", "Code", ":")
Rosetta::Code
>>> :quit | 707Interactive programming (repl) | 11kotlin | qmjx1 |
use strict;
use warnings;
use feature 'say';
sub check_digit {
my($isbn) = @_; my($sum);
$sum += (1,3)[$_%2] * (split '', join '', split /\D/, $isbn)[$_] for 0..11;
(10 - $sum % 10) % 10;
}
for (<978-1734314502 978-1734314509 978-1788399081 978-1788399083 978-2-74839-908-0 978-2-74839-908-5>) {
my($is... | 704ISBN13 check digit | 2perl | qmbx6 |
class Animal
{
}
class Dog : Animal
{
}
class Lab : Dog
{
}
class Collie : Dog
{
}
class Cat : Animal
{
} | 712Inheritance/Single | 5c | 37aza |
import java.util.ArrayList;
public class Josephus {
public static int execute(int n, int k){
int killIdx = 0;
ArrayList<Integer> prisoners = new ArrayList<Integer>(n);
for(int i = 0;i < n;i++){
prisoners.add(i);
}
System.out.println("Prisoners executed in order:"... | 702Josephus problem | 9java | azh1y |
from math import ceil, log10, factorial
def next_step(x):
result = 0
while x > 0:
result += (x% 10) ** 2
x /= 10
return result
def check(number):
candidate = 0
for n in number:
candidate = candidate * 10 + n
while candidate != 89 and candidate != 1:
candidate =... | 703Iterated digits squaring | 3python | 1t7pc |
package main
import "fmt"
func main() { | 710Integer overflow | 0go | 8lj0g |
char *get_line(FILE* fp)
{
int len = 0, got = 0, c;
char *buf = 0;
while ((c = fgetc(fp)) != EOF) {
if (got + 1 >= len) {
len *= 2;
if (len < 4) len = 4;
buf = realloc(buf, len);
}
buf[got++] = c;
if (c == '\n') break;
}
if (c == EOF && !got) return 0;
buf[got++] = '\0';
return buf;
}
int mai... | 713Input loop | 5c | r0fg7 |
public class VersCheck {
public static void main(String[] args) {
String vers = System.getProperty("java.version");
vers = vers.substring(0,vers.indexOf('.')) + "." + | 709Introspection | 9java | 6jq3z |
var Josephus = {
init: function(n) {
this.head = {};
var current = this.head;
for (var i = 0; i < n-1; i++) {
current.label = i+1;
current.next = {prev: current};
current = current.next;
}
current.label = n;
current.next = this.head;
this.head.prev = current;
return t... | 702Josephus problem | 10javascript | s9aqz |
groups = [{A: [1, 2, 3]},
{A: [1, :B, 2], B: [3, 4]},
{A: [1, :D, :D], D: [6, 7, 8]},
{A: [1, :B, :C], B: [3, 4], C: [5, :B]} ]
groups.each do |group|
p group
wheels = group.transform_values(&:cycle)
res = 20.times.map do
el = wheels[:A].next
el = wheels[el].next until el.i... | 706Intersecting number wheels | 14ruby | jol7x |
$ lua
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
> function conc(a, b, c)
>> return a..c..c..b
>> end
> print(conc("Rosetta", "Code", ":"))
Rosetta::Code
> | 707Interactive programming (repl) | 1lua | s9hq8 |
def jaro(s, t)
return 1.0 if s == t
s_len = s.size
t_len = t.size
match_distance = ([s_len, t_len].max / 2) - 1
s_matches = []
t_matches = []
matches = 0.0
s_len.times do |i|
j_start = [0, i-match_distance].max
j_end = [i+match_distance, t_len-1].min
(j_start.... | 701Jaro similarity | 14ruby | 785ri |
(gen-class:name Animal)
(gen-class:name Dog:extends Animal)
(gen-class:name Cat:extends Animal)
(gen-class:name Lab:extends Dog)
(gen-class:name Collie:extends Dog) | 712Inheritance/Single | 6clojure | cps9b |
null | 711Inheritance/Multiple | 0go | 2aol7 |
class Camera a
class MobilePhone a
class (Camera a, MobilePhone a) => CameraPhone a | 711Inheritance/Multiple | 7groovy | yhx6o |
class Camera a
class MobilePhone a
class (Camera a, MobilePhone a) => CameraPhone a | 711Inheritance/Multiple | 8haskell | az21g |
println "\nSigned 32-bit (failed):"
assert -(-2147483647-1) != 2147483648g
println(-(-2147483647-1))
assert 2000000000 + 2000000000 != 4000000000g
println(2000000000 + 2000000000)
assert -2147483647 - 2147483647 != -4294967294g
println(-2147483647 - 2147483647)
assert 46341 * 46341 != 2147488281g
println(46341 * 46341) | 710Integer overflow | 7groovy | w65el |
package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"os"
) | 708Inverted index | 0go | az51f |
if (typeof bloop !== "undefined") { ... } | 709Introspection | 10javascript | l1icf |
use std::cmp;
pub fn jaro(s1: &str, s2: &str) -> f64 {
let s1_len = s1.len();
let s2_len = s2.len();
if s1_len == 0 && s2_len == 0 { return 1.0; }
let match_distance = cmp::max(s1_len, s2_len) / 2 - 1;
let mut s1_matches = vec![false; s1_len];
let mut s2_matches = vec![false; s2_len];
let m... | 701Jaro similarity | 15rust | jo472 |
object Jaro extends App {
def distance(s1: String, s2: String): Double = {
val s1_len = s1.length
val s2_len = s2.length
if (s1_len == 0 && s2_len == 0) return 1.0
val match_distance = Math.max(s1_len, s2_len) / 2 - 1
val s1_matches = Array.ofDim[Boolean](s1_len)
val... | 701Jaro similarity | 16scala | bd7k6 |
int main()
{
unsigned int i = 0;
while (++i) printf(, i);
return 0;
} | 714Integer sequence | 5c | 8l404 |
uint64_t digit_sum(uint64_t n, uint64_t sum) {
++sum;
while (n > 0 && n % 10 == 0) {
sum -= 9;
n /= 10;
}
return sum;
}
inline bool divisible(uint64_t n, uint64_t d) {
if ((d & 1) == 0 && (n & 1) == 1)
return false;
return n % d == 0;
}
int main() {
setlocale(LC_ALL... | 715Increasing gaps between consecutive Niven numbers | 5c | s9vq5 |
import Data.Int
import Data.Word
import Control.Exception
f x = do
catch (print x) (\e -> print (e :: ArithException))
main = do
f ((- (-2147483647 - 1)) :: Int32)
f ((2000000000 + 2000000000) :: Int32)
f (((-2147483647) - 2147483647) :: Int32)
f ((46341 * 46341) :: Int32)
f ((((-2147483647) - 1) `div` (-... | 710Integer overflow | 8haskell | l1och |
(defn basic-input [fname]
(line-seq (java.io.BufferedReader. (java.io.FileReader. fname)))) | 713Input loop | 6clojure | bdykz |
import Control.Monad
import Data.Char (isAlpha, toLower)
import qualified Data.Map as M
import qualified Data.IntSet as S
import System.Environment (getArgs)
main = do
(files, _: q) <- liftM (break (== "
buildII files >>= mapM_ putStrLn . queryII q
data IIndex = IIndex
[FilePath]
(M.Map... | 708Inverted index | 8haskell | zrxt0 |
public interface Camera{ | 711Inheritance/Multiple | 9java | jo67c |
interface Camera {
val numberOfLenses : Int
}
interface MobilePhone {
fun charge(n : Int) {
if (n >= 0)
battery_level = (battery_level + n).coerceAtMost(100)
}
var battery_level : Int
}
data class CameraPhone(override val numberOfLenses : Int = 1, override var battery_level: Int)... | 711Inheritance/Multiple | 11kotlin | 5xdua |
public class integerOverflow {
public static void main(String[] args) {
System.out.println("Signed 32-bit:");
System.out.println(-(-2147483647-1));
System.out.println(2000000000 + 2000000000);
System.out.println(-2147483647 - 2147483647);
System.out.println(46341 * 46341);
... | 710Integer overflow | 9java | 37wzg |
use strict;
use warnings;
use bigint;
use CLDR::Number 'decimal_formatter';
sub integer_sqrt {
( my $x = $_[0] ) >= 0 or die;
my $q = 1;
while ($q <= $x) {
$q <<= 2
}
my ($z, $r) = ($x, 0);
while ($q > 1) {
$q >>= 2;
my $t = $z - $r - $q;
$r >>= 1;
if ($t >= 0) {
... | 705Isqrt (integer square root) of X | 2perl | tgsfg |
null | 709Introspection | 11kotlin | d51nz |
null | 702Josephus problem | 11kotlin | hi4j3 |
def is_isbn13(n):
n = n.replace('-','').replace(' ', '')
if len(n) != 13:
return False
product = (sum(int(ch) for ch in n[::2])
+ sum(int(ch) * 3 for ch in n[1::2]))
return product% 10 == 0
if __name__ == '__main__':
tests = '''
978-1734314502
978-1734314509
978-1788399081
9... | 704ISBN13 check digit | 3python | s9pq9 |
func jaroWinklerMatch(_ s: String, _ t: String) -> Double {
let s_len: Int = s.count
let t_len: Int = t.count
if s_len == 0 && t_len == 0 {
return 1.0
}
if s_len == 0 || t_len == 0 {
return 0.0
}
var match_distance: Int = 0
if s_len == 1 && t_len == 1 {
match_... | 701Jaro similarity | 17swift | r0ugg |
(map println (next (range))) | 714Integer sequence | 6clojure | f4hdm |
double inf(void) {
return HUGE_VAL;
}
int main() {
printf(, inf());
return 0;
} | 716Infinity | 5c | o2580 |
package main
import "fmt"
type is func() uint64
func newSum() is {
var ms is
ms = func() uint64 {
ms = newSum()
return ms()
}
var msd, d uint64
return func() uint64 {
if d < 9 {
d++
} else {
d = 0
msd = ms()
}
ret... | 715Increasing gaps between consecutive Niven numbers | 0go | ves2m |
function josephus(n, k, m)
local positions={}
for i=1,n do
table.insert(positions, i-1)
end
local i,j=1,1
local s='Execution order: '
while #positions>m do
if j==k then
s=s .. positions[i] .. ', '
table.remove(positions, i)
i=i-1
end
... | 702Josephus problem | 1lua | kngh2 |
def iterated_square_digit(d)
f = Array.new(d+1){|n| (1..n).inject(1,:*)}
g = -> (n) { res = n.digits.sum{|d| d*d}
res==89? 0: res }
table = Array.new(d*81+1){|n| n.zero?? 1: (i=g.call(n))==89? 0: i}
table.collect!{|n| n = table[n] while n>1; n}
z = 0 ... | 703Iterated digits squaring | 14ruby | e3hax |
##Inf
##-Inf
(Double/isInfinite ##Inf) | 716Infinity | 6clojure | tgjfv |
function setmetatables(t,mts) | 711Inheritance/Multiple | 1lua | 4qf5c |
import Control.Monad (guard)
import Text.Printf (printf)
import Data.List (intercalate, unfoldr)
import Data.List.Split (chunksOf)
import Data.Tuple (swap)
nivens :: [Int]
nivens = [1..] >>= \n -> guard (n `rem` digitSum n == 0) >> [n]
where
digitSum = sum . unfoldr (\x -> guard (x > 0) >> pure (swap $ x `quotRem` ... | 715Increasing gaps between consecutive Niven numbers | 8haskell | e39ai |
null | 710Integer overflow | 11kotlin | nubij |
package org.rosettacode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import j... | 708Inverted index | 9java | o2b8d |
package main
import (
"fmt"
"go/ast"
"go/parser"
"strings"
"unicode"
)
func isValidIdentifier(identifier string) bool {
node, err := parser.ParseExpr(identifier)
if err != nil {
return false
}
ident, ok := node.(*ast.Ident)
return ok && ident.Name == identifier
}
type runeRanges struct {
ranges []stri... | 717Idiomatically determine all the characters that can be used for symbols | 0go | yhb64 |
fn digit_square_sum(mut num: usize) -> usize {
let mut sum = 0;
while num!= 0 {
sum += (num% 10).pow(2);
num /= 10;
}
sum
}
fn last_in_chain(num: usize) -> usize {
match num {
1 | 89 => num,
_ => last_in_chain(digit_square_sum(num)),
}
}
fn main() {
let coun... | 703Iterated digits squaring | 15rust | w6ke4 |
import scala.annotation.tailrec
object Euler92 extends App {
override val executionStart = compat.Platform.currentTime
@tailrec
private def calcRec(i: Int): Int = {
@tailrec
def iter0(n: Int, total: Int): Int =
if (n > 0) {
val rest = n % 10
iter0(n / 10, total + rest * rest)
... | 703Iterated digits squaring | 16scala | s91qo |
package main
import (
"fmt"
"math/big"
)
func rank(l []uint) (r big.Int) {
for _, n := range l {
r.Lsh(&r, n+1)
r.SetBit(&r, int(n), 1)
}
return
}
func unrank(n big.Int) (l []uint) {
m := new(big.Int).Set(&n)
for a := m.BitLen(); a > 0; {
m.SetBit(m, a-1, 0)
... | 718Index finite lists of positive integers | 0go | hinjq |
public class NivenNumberGaps { | 715Increasing gaps between consecutive Niven numbers | 9java | hitjm |
def isqrt ( x ):
q = 1
while q <= x:
q *= 4
z,r = x,0
while q > 1:
q /= 4
t,r = z-r-q,r/2
if t >= 0:
z,r = t,r+q
return r
print ' '.join( '%d'%isqrt( n ) for n in xrange( 66 ))
print '\n'.join( '{0:114,} = isqrt( 7^{1:3} )'.format( isqrt( 7**n ),n ) fo... | 705Isqrt (integer square root) of X | 3python | zr0tt |
varid (small {small | large | digit | ' }) / reservedid
conid large {small | large | digit | ' }
reservedid case | class | data | default | deriving | do | else
| foreign | if | import | in | infix | infixl
| infixr | instance | let | module | newtype | of
| then | type | where ... | 717Idiomatically determine all the characters that can be used for symbols | 8haskell | hidju |
import java.util.function.IntPredicate;
import java.util.stream.IntStream;
public class Test {
public static void main(String[] args) throws Exception {
print("Java Identifier start: ", 0, 0x10FFFF, 72,
Character::isJavaIdentifierStart, "%c");
print("Java Identifier part: ... | 717Idiomatically determine all the characters that can be used for symbols | 9java | 5xsuf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.