code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
null | 620Loops/Increment loop index within loop body | 11kotlin | bzskb |
while(1) puts(); | 626Loops/Infinite | 5c | vq52o |
from itertools import chain
prod, sum_, x, y, z, one,three,seven = 1, 0, 5, -5, -2, 1, 3, 7
def _range(x, y, z=1):
return range(x, y + (1 if z > 0 else -1), z)
print(f'list(_range(x, y, z)) = {list(_range(x, y, z))}')
print(f'list(_range(-seven, seven, x)) = {list(_range(-seven, seven, x))}')
for j in chain(_ra... | 619Loops/With multiple ranges | 3python | p38bm |
(def i (ref 1024))
(while (> @i 0)
(println @i)
(dosync (ref-set i (quot @i 2)))) | 625Loops/While | 6clojure | 2x5l1 |
null | 620Loops/Increment loop index within loop body | 1lua | p30bw |
package main
import (
"fmt"
"math/big"
)
var primes = []uint{3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127}
var mersennes = []uint{521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689,
9941, 11213, 19937, 21701, 23209, 44497, 8... | 618Lucas-Lehmer test | 0go | xctwf |
module Main
where
main = printMersennes $ take 45 $ filter lucasLehmer $ sieve [2..]
s mp 1 = 4 `mod` mp
s mp n = ((s mp $ n-1)^2-2) `mod` mp
lucasLehmer 2 = True
lucasLehmer p = s (2^p-1) (p-1) == 0
printMersennes = mapM_ (\x -> putStrLn $ "M" ++ show x) | 618Lucas-Lehmer test | 8haskell | ypg66 |
require 'matrix'
class Matrix
def lu_decomposition
p = get_pivot
tmp = p * self
u = Matrix.zero(row_size).to_a
l = Matrix.identity(row_size).to_a
(0 ... row_size).each do |i|
(0 ... row_size).each do |j|
if j >= i
u[i][j] = tmp[i,j] - (0 ... i).inject(0.0) {|sum... | 615LU decomposition | 14ruby | risgs |
(loop [] (println "SPAM") (recur)) | 626Loops/Infinite | 6clojure | rijg2 |
x, y, z, one, three, seven = 5, -5, -2, 1, 3, 7
enums = (-three).step(3**3, three) +
(-seven).step(seven, x) +
555 .step(550-y, -1) +
22 .step(-28, -three) +
(1927..1939) +
x .step(y, z) +
(11**x) .step(11**x + one)
puts
prod = enums.in... | 619Loops/With multiple ranges | 14ruby | ayi1s |
#![allow(non_snake_case)]
use ndarray::{Array, Axis, Array2, arr2, Zip, NdFloat, s};
fn main() {
println!("Example 1:");
let A: Array2<f64> = arr2(&[
[1.0, 3.0, 5.0],
[2.0, 4.0, 7.0],
[1.0, 1.0, 0.0],
]);
println!("A \n {}", A);
let (L, U, P) = lu_decomp(A);
println!("L ... | 615LU decomposition | 15rust | 7n0rc |
int i;
for(i = 10; i >= 0; --i)
printf(,i); | 627Loops/Downward for | 5c | us5v4 |
def ludic(nmax=100000)
Enumerator.new do |y|
y << 1
ary = *2..nmax
until ary.empty?
y << (n = ary.first)
(0...ary.size).step(n){|i| ary[i] = nil}
ary.compact!
end
end
end
puts , ludic.first(25).to_s
puts , ludic(1000).count
puts , ludic.first(2005).last(6).to_s
ludics = ludic(2... | 611Ludic numbers | 14ruby | 7nnri |
(defn luhn? [cc]
(let [factors (cycle [1 2])
numbers (map #(Character/digit % 10) cc)
sum (reduce + (map #(+ (quot % 10) (mod % 10))
(map * (reverse numbers) factors)))]
(zero? (mod sum 10))))
(doseq [n ["49927398716" "49927398717" "1234567812345678" "1234567812345670"]... | 621Luhn test of credit card numbers | 6clojure | drmnb |
use ntheory qw(is_prime);
$i = 42;
while ($n < 42) {
if (is_prime($i)) {
$n++;
printf "%2d%21s\n", $n, commatize($i);
$i += $i - 1;
}
$i++;
}
sub commatize {
(my $s = reverse shift) =~ s/(.{3})/$1,/g;
$s =~ s/,$//;
$s = reverse $s;
} | 620Loops/Increment loop index within loop body | 2perl | 6bu36 |
const ARRAY_MAX: usize = 25_000;
const LUDIC_MAX: usize = 2100; | 611Ludic numbers | 15rust | jdd72 |
import java.math.BigInteger;
public class Mersenne
{
public static boolean isPrime(int p) {
if (p == 2)
return true;
else if (p <= 1 || p % 2 == 0)
return false;
else {
int to = (int)Math.sqrt(p);
for (int i = 3; i <= to; i += 2)
... | 618Lucas-Lehmer test | 9java | drln9 |
sub compress {
my $uncompressed = shift;
my $dict_size = 256;
my %dictionary = map {chr $_ => chr $_} 0..$dict_size-1;
my $w = "";
my @result;
foreach my $c (split '', $uncompressed) {
my $wc = $w . $c;
if (exists $dictionary{$wc}) {
$w = $wc;
} else {
... | 616LZW compression | 2perl | m1jyz |
puts
story =
until (line = gets).chomp.empty?
story << line
end
story.scan(/(?<=[<]).+?(?=[>])/).uniq.each do |var|
print
story.gsub!(/<
end
puts
puts story | 613Mad Libs | 14ruby | i4uoh |
def isPrime(n):
for x in 2, 3:
if not n% x:
return n == x
d = 5
while d * d <= n:
for x in 2, 4:
if not n% d:
return False
d += x
return True
i = 42
n = 0
while n < 42:
if isPrime(i):
n += 1
print('n = {:2} {:20,}'.... | 620Loops/Increment loop index within loop body | 3python | yp56q |
int i;
for(i = 1; i < 10; i += 2)
printf(, i); | 628Loops/For with a specified step | 5c | gog45 |
object Ludic {
def main(args: Array[String]): Unit = {
println(
s"""|First 25 Ludic Numbers: ${ludic.take(25).mkString(", ")}
|Ludic Numbers <= 1000: ${ludic.takeWhile(_ <= 1000).size}
|2000-2005th Ludic Numbers: ${ludic.slice(1999, 2005).mkString(", ")}
|Triplets <= 250: ${tri... | 611Ludic numbers | 16scala | bzzk6 |
null | 618Lucas-Lehmer test | 10javascript | 6b438 |
i <- 42
primeCount <- 0
while(primeCount < 42)
{
if(gmp::isprime(i) == 2)
{
primeCount <- primeCount + 1
extraCredit <- format(i, big.mark=",", scientific = FALSE)
cat("Prime count:", paste0(primeCount, ";"), "The prime just found was:", extraCredit, "\n")
i <- i + i
}
i <- i + 1
} | 620Loops/Increment loop index within loop body | 13r | tjlfz |
(doseq [x (range 10 -1 -1)] (println x)) | 627Loops/Downward for | 6clojure | 7njr0 |
class LZW
{
function compress($unc) {
$i;$c;$wc;
$w = ;
$dictionary = array();
$result = array();
$dictSize = 256;
for ($i = 0; $i < 256; $i += 1) {
$dictionary[chr($i)] = $i;
}
for ($i = 0; $i < strlen($unc); $i++) {
$c = $unc[... | 616LZW compression | 12php | emta9 |
extern crate regex;
use regex::Regex;
use std::collections::HashMap;
use std::io;
fn main() {
let mut input_line = String::new();
let mut template = String::new();
println!("Please enter a multi-line story template with <parts> to replace, terminated by a blank line.\n");
loop {
io::stdin()
... | 613Mad Libs | 15rust | ng5i4 |
main() {
while(true) {
print("SPAM");
}
} | 626Loops/Infinite | 18dart | yp965 |
object MadLibs extends App{
val input = "<name> went for a walk in the park. <he or she>\nfound a <noun>. <name> decided to take it home."
println(input)
println
val todo = "(<[^>]+>)".r
val replacements = todo.findAllIn(input).toSet.map{found: String =>
found -> readLine(s"Enter a $found ")
}.toMap
... | 613Mad Libs | 16scala | tjrfb |
func printAll(values []int) {
for i, x := range values {
fmt.Printf("Item%d =%d\n", i, x)
}
} | 622Loops/Foreach | 0go | 7n1r2 |
null | 618Lucas-Lehmer test | 11kotlin | 0v6sf |
require 'prime'
limit = 42
i = 42
n = 0
while n < limit do
if i.prime? then
n += 1
puts .ljust(7) + + ,.rjust(19)
i += i
else
i += 1
end
end | 620Loops/Increment loop index within loop body | 14ruby | 9agmz |
int val = 0;
do{
val++;
printf(,val);
}while(val % 6 != 0); | 629Loops/Do-while | 5c | 2wclo |
def beatles = ["John", "Paul", "George", "Ringo"]
for(name in beatles) {
println name
} | 622Loops/Foreach | 7groovy | usjv9 |
import scala.annotation.tailrec
object LoopIncrementWithinBody extends App {
private val (limit, offset) = (42L, 1)
@tailrec
private def loop(i: Long, n: Int): Unit = {
def isPrime(n: Long) =
n > 1 && ((n & 1) != 0 || n == 2) && (n % 3 != 0 || n == 3) &&
((5 to math.sqrt(n).toInt by 2).par fo... | 620Loops/Increment loop index within loop body | 16scala | vqh2s |
import Control.Monad (forM_)
forM_ collect print | 622Loops/Foreach | 8haskell | 8ut0z |
for i in {1..5}
do
for ((j=1; j<=i; j++));
do
echo -n "*"
done
echo
done | 630Loops/For | 4bash | ous8a |
(loop [i 0]
(println i)
(when (< i 10)
(recur (+ 2 i))))
(doseq [i (range 0 12 2)]
(println i)) | 628Loops/For with a specified step | 6clojure | ktkhs |
def compress(uncompressed):
dict_size = 256
dictionary = dict((chr(i), i) for i in range(dict_size))
w =
result = []
for c in uncompressed:
wc = w + c
if wc in dictionary:
w = wc
else:
result.append(dictionary[w])
... | 616LZW compression | 3python | 9ahmf |
package main
import "fmt"
func main() {
for i := 1; ; i++ {
fmt.Print(i)
if i == 10 {
fmt.Println()
break
}
fmt.Print(", ")
}
} | 624Loops/N plus one half | 0go | lw5cw |
for(i in (1..10)) {
print i
if (i == 10) break
print ', '
} | 624Loops/N plus one half | 7groovy | 6bc3o |
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
values := make([][]int, 10)
for i := range values {
values[i] = make([]int, 10)
for j := range values[i] {
values[i][j] = rand.Intn(20) + 1
}
}
outerLoop:
... | 623Loops/Nested | 0go | 9aumt |
final random = new Random()
def a = []
(0..<10).each {
def row = []
(0..<10).each {
row << (random.nextInt(20) + 1)
}
a << row
}
a.each { println it }
println ()
Outer:
for (i in (0..<a.size())) {
for (j in (0..<a[i].size())) {
if (a[i][j] == 20){
println ([i:i, j:j])
... | 623Loops/Nested | 7groovy | zh9t5 |
Iterable<Type> collect;
...
for(Type i:collect){
System.out.println(i);
} | 622Loops/Foreach | 9java | em8a5 |
"alpha beta gamma delta".split(" ").forEach(function (x) {
console.log(x);
}); | 622Loops/Foreach | 10javascript | 0vfsz |
(loop [i 0]
(let [i* (inc i)]
(println i*)
(when-not (zero? (mod i* 6))
(recur i*)))) | 629Loops/Do-while | 6clojure | g854f |
main :: IO ()
main = forM_ [1 .. 10] $ \n -> do
putStr $ show n
putStr $ if n == 10 then "\n" else ", " | 624Loops/N plus one half | 8haskell | 16xps |
import Data.List
breakIncl :: (a -> Bool) -> [a] -> [a]
breakIncl p = uncurry ((. take 1). (++)). break p
taskLLB k = map (breakIncl (==k)). breakIncl (k `elem`) | 623Loops/Nested | 8haskell | bzwk2 |
def compress(uncompressed)
dict_size = 256
dictionary = Hash[ Array.new(dict_size) {|i| [i.chr, i.chr]} ]
w =
result = []
for c in uncompressed.split('')
wc = w + c
if dictionary.has_key?(wc)
w = wc
else
result << dictionary[w]
... | 616LZW compression | 14ruby | lwbcl |
use std::collections::HashMap;
fn compress(data: &[u8]) -> Vec<u32> { | 616LZW compression | 15rust | 2xplt |
null | 622Loops/Foreach | 11kotlin | ktwh3 |
use Math::GMP qw/:constant/;
sub is_prime { Math::GMP->new(shift)->probab_prime(12); }
sub is_mersenne_prime {
my $p = shift;
return 1 if $p == 2;
my $mp = 2 ** $p - 1;
my $s = 4;
$s = ($s * $s - 2) % $mp for 3..$p;
$s == 0;
}
foreach my $p (2 .. 43_112_609) {
print "M$p\n" if is_prime($p) && is_merse... | 618Lucas-Lehmer test | 2perl | 501u2 |
def compress(tc:String) = { | 616LZW compression | 16scala | 50eut |
import java.util.Random;
public class NestedLoopTest {
public static final Random gen = new Random();
public static void main(String[] args) {
int[][] a = new int[10][10];
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[i].length; j++)
a[i][j] = gen.nextInt(... | 623Loops/Nested | 9java | gok4m |
public static void main(String[] args) {
for (int i = 1; ; i++) {
System.out.print(i);
if (i == 10)
break;
System.out.print(", ");
}
System.out.println();
} | 624Loops/N plus one half | 9java | 7nbrj |
null | 623Loops/Nested | 10javascript | ktehq |
int i, j;
for (i = 1; i <= 5; i++) {
for (j = 1; j <= i; j++)
putchar('*');
puts();
} | 630Loops/For | 5c | n48i6 |
function loop_plus_half(start, end) {
var str = '',
i;
for (i = start; i <= end; i += 1) {
str += i;
if (i === end) {
break;
}
str += ', ';
}
return str;
}
alert(loop_plus_half(1, 10)); | 624Loops/N plus one half | 10javascript | p3wb7 |
class LZW {
class func compress(_ uncompressed:String) -> [Int] {
var dict = [String: Int]()
for i in 0 ..< 256 {
let s = String(Unicode.Scalar(UInt8(i)))
dict[s] = i
}
var dictSize = 256
var w = ""
var result = [Int]()
for c in uncom... | 616LZW compression | 17swift | cek9t |
import java.util.Random
fun main(args: Array<String>) {
val r = Random()
val a = Array(10) { IntArray(10) { r.nextInt(20) + 1 } }
println("array:")
for (i in a.indices) println("row $i: " + a[i].asList())
println("search:")
Outer@ for (i in a.indices) {
print("row $i: ")
for (j... | 623Loops/Nested | 11kotlin | 2xgli |
package main
import "fmt"
func main() {
for {
fmt.Printf("SPAM\n")
}
} | 626Loops/Infinite | 0go | s28qa |
null | 624Loops/N plus one half | 11kotlin | usrvc |
while (true) {
println 'SPAM'
} | 626Loops/Infinite | 7groovy | ayw1p |
t={monday=1, tuesday=2, wednesday=3, thursday=4, friday=5, saturday=6, sunday=0, [7]="fooday"}
for key, value in pairs(t) do
print(value, key)
end | 622Loops/Foreach | 1lua | bzxka |
from sys import stdout
from math import sqrt, log
def is_prime ( p ):
if p == 2: return True
elif p <= 1 or p% 2 == 0: return False
else:
for i in range(3, int(sqrt(p))+1, 2 ):
if p% i == 0: return False
return True
def is_mersenne_prime ( p ):
if p == 2:
return True
else:
m_p = ( 1 ... | 618Lucas-Lehmer test | 3python | 48a5k |
forever (putStrLn "SPAM") | 626Loops/Infinite | 8haskell | 9almo |
require(gmp)
n <- 4423
p <- seq(1, n, by = 2)
q <- length(p)
p[1] <- 2
for (k in seq(3, sqrt(n), by = 2))
if (p[(k + 1)/2]!= 0)
p[seq((k * k + 1)/2, q, by = k)] <- 0
p <- p[p > 0]
cat(p[1]," special case M2 == 3\n")
p <- p[-1]
z2 <- gmp::as.bigz(2)
z4 <- z2 * z2
zp <- gmp::as.bigz(p)
zmp <- z2^zp - 1
S <- r... | 618Lucas-Lehmer test | 13r | 2xklg |
i := 1024
for i > 0 {
fmt.Printf("%d\n", i)
i /= 2
} | 625Loops/While | 0go | 16wp5 |
(doseq [i (range 5), j (range (inc i))]
(print "*")
(if (= i j) (println))) | 630Loops/For | 6clojure | 3hfzr |
package main
import (
"fmt"
"strings"
)
const input = `49927398716
49927398717
1234567812345678
1234567812345670`
var t = [...]int{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}
func luhn(s string) bool {
odd := len(s) & 1
var sum int
for i, c := range s {
if c < '0' || c > '9' {
return false... | 621Luhn test of credit card numbers | 0go | ushvt |
int i = 1024
while (i > 0) {
println i
i /= 2
} | 625Loops/While | 7groovy | jdb7o |
import Control.Monad (when)
main = loop 1024
where loop n = when (n > 0)
(do print n
loop (n `div` 2)) | 625Loops/While | 8haskell | tj6f7 |
def checkLuhn(number) {
int total
(number as String).reverse().eachWithIndex { ch, index ->
def digit = Integer.parseInt(ch)
total += (index % 2 ==0) ? digit: [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][digit]
}
total % 10 == 0
} | 621Luhn test of credit card numbers | 7groovy | 9a4m4 |
for i := 10; i >= 0; i-- {
fmt.Println(i)
} | 627Loops/Downward for | 0go | 0v8sk |
t = {}
for i = 1, 20 do
t[i] = {}
for j = 1, 20 do t[i][j] = math.random(20) end
end
function exitable()
for i = 1, 20 do
for j = 1, 20 do
if t[i][j] == 20 then
return i, j
end
end
end
end
print(exitable()) | 623Loops/Nested | 1lua | vqr2x |
import Data.Char (digitToInt)
luhn = (0 ==) . (`mod` 10) . sum . map (uncurry (+) . (`divMod` 10)) .
zipWith (*) (cycle [1,2]) . map digitToInt . reverse | 621Luhn test of credit card numbers | 8haskell | w9ied |
for (i in (10..0)) {
println i
} | 627Loops/Downward for | 7groovy | emwal |
for i = 1, 10 do
io.write(i)
if i == 10 then break end
io.write", "
end | 624Loops/N plus one half | 1lua | 507u6 |
while (true) {
System.out.println("SPAM");
} | 626Loops/Infinite | 9java | tj3f9 |
for (;;) console.log("SPAM"); | 626Loops/Infinite | 10javascript | m1cyv |
import Control.Monad
main :: IO ()
main = forM_ [10,9 .. 0] print | 627Loops/Downward for | 8haskell | cel94 |
int i = 1024;
while(i > 0){
System.out.println(i);
i >>= 1; | 625Loops/While | 9java | 8un06 |
def is_prime ( p )
return true if p == 2
return false if p <= 1 || p.even?
(3 .. Math.sqrt(p)).step(2) do |i|
return false if p % i == 0
end
true
end
def is_mersenne_prime ( p )
return true if p == 2
m_p = ( 1 << p ) - 1
s = 4
(p-2).times { s = (s ** 2 - 2) % m_p }
s == 0
end
precision = 20... | 618Lucas-Lehmer test | 14ruby | riwgs |
var n = 1024;
while (n > 0) {
print(n);
n /= 2;
} | 625Loops/While | 10javascript | f73dg |
extern crate rug;
extern crate primal;
use rug::Integer;
use rug::ops::Pow;
use std::thread::spawn;
fn is_mersenne (p: usize) {
let p = p as u32;
let mut m = Integer::from(1);
m = m << p;
m = Integer::from(&m - 1);
let mut flag1 = false;
for k in 1..10_000 {
let mut flag2 = false;
... | 618Lucas-Lehmer test | 15rust | 7nxrc |
null | 626Loops/Infinite | 11kotlin | o5n8z |
public class Luhn {
public static void main(String[] args) {
System.out.println(luhnTest("49927398716"));
System.out.println(luhnTest("49927398717"));
System.out.println(luhnTest("1234567812345678"));
System.out.println(luhnTest("1234567812345670"));
}
public static boolean ... | 621Luhn test of credit card numbers | 9java | ktxhm |
object LLT extends App {
import Stream._
def primeSieve(s: Stream[Int]): Stream[Int] =
s.head #:: primeSieve(s.tail filter { _ % s.head != 0 })
val primes = primeSieve(from(2))
def mersenne(p: Int): BigInt = (BigInt(2) pow p) - 1
def s(mp: BigInt, p: Int): BigInt = { if (p == 1) 4 else ((s(mp, p - 1) p... | 618Lucas-Lehmer test | 16scala | kt0hk |
mod10check = function(cc) {
return $A(cc).reverse().map(Number).inject(0, function(s, d, i) {
return s + (i % 2 == 1 ? (d == 9 ? 9 : (d * 2) % 9) : d);
}) % 10 == 0;
};
['49927398716','49927398717','1234567812345678','1234567812345670'].each(function(i){alert(mod10check(i))}); | 621Luhn test of credit card numbers | 10javascript | emoao |
null | 625Loops/While | 11kotlin | w9sek |
for (int i = 10; i >= 0; i--) {
System.out.println(i);
} | 627Loops/Downward for | 9java | zh3tq |
for (var i=10; i>=0; --i) print(i); | 627Loops/Downward for | 10javascript | 9acml |
main() {
for (var i = 0; i < 5; i++)
for (var j = 0; j < i + 1; j++)
print("*");
print("\n");
} | 630Loops/For | 18dart | qcexo |
null | 627Loops/Downward for | 11kotlin | i4no4 |
foreach my $i (@collection) {
print "$i\n";
} | 622Loops/Foreach | 2perl | 3klzs |
foreach ($collect as $i) {
echo ;
}
foreach ($collect as $key => $i) {
echo ;
} | 622Loops/Foreach | 12php | p3qba |
null | 621Luhn test of credit card numbers | 11kotlin | gop4d |
func lucasLehmer(_ p: Int) -> Bool {
let m = BigInt(2).power(p) - 1
var s = BigInt(4)
for _ in 0..<p-2 {
s = ((s * s) - 2)% m
}
return s == 0
}
for prime in Eratosthenes(upTo: 70) where lucasLehmer(prime) {
let m = Int(pow(2, Double(prime))) - 1
print("2^\(prime) - 1 = \(m) is prime")
} | 618Lucas-Lehmer test | 17swift | goe49 |
while true do
print("SPAM")
end | 626Loops/Infinite | 1lua | i4dot |
for i := 1; i < 10; i += 2 {
fmt.Printf("%d\n", i)
} | 628Loops/For with a specified step | 0go | i4iog |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.