code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
null | 610Magic 8-ball | 11kotlin | p36b6 |
typedef unsigned uint;
typedef struct { uint i, v; } filt_t;
uint* ludic(uint min_len, uint min_val, uint *len)
{
uint cap, i, v, active = 1, nf = 0;
filt_t *f = calloc(cap = 2, sizeof(*f));
f[1].i = 4;
for (v = 1; ; ++v) {
for (i = 1; i < active && --f[i].i; i++);
if (i < active)
f[i].i = f[i].v;
else... | 611Ludic numbers | 5c | 2xxlo |
math.randomseed(os.time())
answers = {
"It is certain.", "It is decidedly so.", "Without a doubt.", "Yes, definitely.", "You may rely on it.",
"As I see it, yes.", "Most likely.", "Outlook good.", "Signs point to yes.", "Yes.",
"Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot pred... | 610Magic 8-ball | 1lua | 16ypo |
import Foundation
import Numerics
import QDBMP
public typealias Color = (red: UInt8, green: UInt8, blue: UInt8)
public class BitmapDrawer {
public let imageHeight: Int
public let imageWidth: Int
var grid: [[Color?]]
private let bmp: OpaquePointer
public init(height: Int, width: Int) {
self.imageHeigh... | 607Mandelbrot set | 17swift | drknh |
(defn ints-from [n]
(cons n (lazy-seq (ints-from (inc n)))))
(defn drop-nth [n seq]
(cond
(zero? n) seq
(empty? seq) []
:else (concat (take (dec n) seq) (lazy-seq (drop-nth n (drop n seq))))))
(def ludic ((fn ludic
([] (ludic 1))
([n] (ludic n (ints-from (inc n))))
([n [f & r]] (co... | 611Ludic numbers | 6clojure | goo4f |
(ns lychrel.core
(require [clojure.string :as s])
(require [clojure.set :as set-op])
(:gen-class))
(defn palindrome? "Returns true if given number is a palindrome (number on base 10)"
[number]
(let [number-str (str number)]
(= number-str (s/reverse number-str))))
(defn delete-leading-zeros
"Delete lea... | 612Lychrel numbers | 6clojure | xc9wk |
@a = ('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely',
'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good',
'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later',
'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again',
"Don't be... | 610Magic 8-ball | 2perl | yp16u |
typedef struct {
char *data;
size_t alloc;
size_t length;
} dstr;
inline int dstr_space(dstr *s, size_t grow_amount)
{
return s->length + grow_amount < s->alloc;
}
int dstr_grow(dstr *s)
{
s->alloc *= 2;
char *attempt = realloc(s->data, s->alloc);
if (!attempt) return 0;
else s->data ... | 613Mad Libs | 5c | w9yec |
<?php
$fortunes = array(
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
);
function cli_prompt( $prompt='> ', $default=false ) {
do {
echo $prompt;
$cmd = chop( fgets( STDIN ) );
} while ( empty( $default ) and empty( $cmd ) );
return $cmd?: $default;
}
$question = cli_prompt( 'What ... | 610Magic 8-ball | 12php | aym12 |
int luckyOdd[LUCKY_SIZE];
int luckyEven[LUCKY_SIZE];
void compactLucky(int luckyArray[]) {
int i, j, k;
for (i = 0; i < LUCKY_SIZE; i++) {
if (luckyArray[i] == 0) {
j = i;
break;
}
}
for (j = i + 1; j < LUCKY_SIZE; j++) {
if (luckyArray[j] > 0) {
... | 614Lucky and even lucky numbers | 5c | cep9c |
(ns magic.rosetta
(:require [clojure.string:as str]))
(defn mad-libs
"Write a program to create a Mad Libs like story.
The program should read an arbitrary multiline story from input.
The story will be terminated with a blank line.
Then, find each replacement to be made within the story,
... | 613Mad Libs | 6clojure | 8u205 |
import random
s = ('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes, definitely',
'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good',
'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later',
'Better not tell you now', 'Cannot predict now', 'Concentrate and ask agai... | 610Magic 8-ball | 3python | m1ayh |
eight_ball <- function()
{
responses <- c("It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs point to yes", "Yes",
"Reply hazy, try again", "Ask again la... | 610Magic 8-ball | 13r | zhkth |
typedef double **mat;
void mat_zero(mat x, int n) { for_ij x[i][j] = 0; }
mat mat_new(_dim)
{
mat x = malloc(sizeof(double*) * n);
x[0] = malloc(sizeof(double) * n * n);
for_i x[i] = x[0] + n * i;
_zero(x);
return x;
}
mat mat_copy(void *s, _dim)
{
mat x = mat_new(n);
for_ij x[i][j] = ((double (*)[n])s)... | 615LU decomposition | 5c | lwpcy |
package main
import (
"flag"
"fmt"
"math"
"math/big"
"os"
)
var maxRev = big.NewInt(math.MaxUint64 / 10) | 612Lychrel numbers | 0go | 6bk3p |
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
)
const luckySize = 60000
var luckyOdd = make([]int, luckySize)
var luckyEven = make([]int, luckySize)
func init() {
for i := 0; i < luckySize; i++ {
luckyOdd[i] = i*2 + 1
luckyEven[i] = i*2 + 2
}
}
func filterLu... | 614Lucky and even lucky numbers | 0go | w96eg |
void* mem_alloc(size_t item_size, size_t n_item)
{
size_t *x = calloc(1, sizeof(size_t)*2 + n_item * item_size);
x[0] = item_size;
x[1] = n_item;
return x + 2;
}
void* mem_extend(void *m, size_t new_n)
{
size_t *x = (size_t*)m - 2;
x = realloc(x, sizeof(size_t) * 2 + *x * new_n);
if (new_n > x[1])
me... | 616LZW compression | 5c | zh4tx |
module Main where
import Data.List
procLychrel :: Integer -> [Integer]
procLychrel a = a: pl a
where
pl n =
let s = n + reverseInteger n
in if isPalindrome s
then [s]
else s: pl s
isPalindrome :: Integer -> Bool
isPalindrome n =
let s = show n
in (s ... | 612Lychrel numbers | 8haskell | jdn7g |
package main
import "fmt" | 611Ludic numbers | 0go | qllxz |
import System.Environment
import Text.Regex.Posix
data Lucky = Lucky | EvenLucky
helpMessage :: IO ()
helpMessage = do
putStrLn " what is displayed (on a single line)"
putStrLn " argument(s) (optional verbiage is encouraged)"
putStrLn "======================|========... | 614Lucky and even lucky numbers | 8haskell | 6bj3k |
class EightBall
def initialize
print
puts
@responses = [, ,
, ,
, ,
, ,
, ,
, ,
,
,
, ,
... | 610Magic 8-ball | 14ruby | cew9k |
extern crate rand;
use rand::prelude::*;
use std::io;
fn main() {
let answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Signs poi... | 610Magic 8-ball | 15rust | lwxcc |
import Data.List (unfoldr, genericSplitAt)
ludic :: [Integer]
ludic = 1: unfoldr (\xs@(x:_) -> Just (x, dropEvery x xs)) [2 ..]
where
dropEvery n = concatMap tail . unfoldr (Just . genericSplitAt n)
main :: IO ()
main = do
print $ take 25 ludic
(print . length) $ takeWhile (<= 1000) ludic
print $ take 6 $... | 611Ludic numbers | 8haskell | m11yf |
typedef int bool;
typedef struct {
int start, stop, incr;
const char *comment;
} S;
S examples[9] = {
{-2, 2, 1, },
{-2, 2, 0, },
{-2, 2, -1, },
{-2, 2, 10, },
{2, -2, 1, },
{2, 2, 1, },
{2, 2, -1, },
{2, 2, 0, },
{0, 0, 0, }
};
int main() {
int i, j, c;
bool empty... | 617Loops/Wrong ranges | 5c | 6bg32 |
import java.math.BigInteger;
import java.util.*;
public class Lychrel {
static Map<BigInteger, Tuple> cache = new HashMap<>();
static class Tuple {
final Boolean flag;
final BigInteger bi;
Tuple(boolean f, BigInteger b) {
flag = f;
bi = b;
}
}
... | 612Lychrel numbers | 9java | usqvv |
import scala.util.Random
object Magic8Ball extends App {
val shake: () => String = {
val answers = List(
"It is certain.", "It is decidedly so.", "Without a doubt.",
"Yes definitely.", "You may rely on it.", "As I see it, yes.",
"Most likely.", "Outlook good.", "Yes.", "Signs point to yes.",
... | 610Magic 8-ball | 16scala | us0v8 |
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class LuckyNumbers {
private static int MAX = 200000;
private static List<Integer> luckyEven = luckyNumbers(MAX, true);
private static List<Integer> luckyOdd = luckyNumbers(MAX, false);
public static void main(Str... | 614Lucky and even lucky numbers | 9java | nguih |
(defn make-dict []
(let [vals (range 0 256)]
(zipmap (map (comp #'list #'char) vals) vals)))
(defn compress [#^String text]
(loop [t (seq text)
r '()
w '()
dict (make-dict)
s 256]
(let [c (first t)]
(if c
(let [wc (cons c w)]
(if (get dict wc)
... | 616LZW compression | 6clojure | 9ahma |
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
)
func main() {
pat := regexp.MustCompile("<.+?>")
if len(os.Args) != 2 {
fmt.Println("usage: madlib <story template file>")
return
}
b, err := ioutil.ReadFile(os.Args[1])
if e... | 613Mad Libs | 0go | ce19g |
function luckyNumbers(opts={}) {
opts.even = opts.even || false;
if (typeof opts.through == 'number') opts.through = [0, opts.through];
let out = [],
x = opts.even ? 2 : 1,
max = opts.range ? opts.range[1] * 3
: opts.through ? opts.through[1] * 12
: opts.nth ? opts.nth * 15
... | 614Lucky and even lucky numbers | 10javascript | 3k7z0 |
import System.IO (stdout, hFlush)
import System.Environment (getArgs)
import qualified Data.Map as M (Map, lookup, insert, empty)
getLines :: IO [String]
getLines = reverse <$> getLines_ []
where
getLines_ xs = do
line <- getLine
case line of
[] -> return xs
_ -> getLines_ $ line: x... | 613Mad Libs | 8haskell | p3tbt |
import java.util.ArrayList;
import java.util.List;
public class Ludic{
public static List<Integer> ludicUpTo(int n){
List<Integer> ludics = new ArrayList<Integer>(n);
for(int i = 1; i <= n; i++){ | 611Ludic numbers | 9java | f77dv |
null | 614Lucky and even lucky numbers | 11kotlin | s29q7 |
package main
import "fmt"
type matrix [][]float64
func zero(n int) matrix {
r := make([][]float64, n)
a := make([]float64, n*n)
for i := range r {
r[i] = a[n*i : n*(i+1)]
}
return r
}
func eye(n int) matrix {
r := zero(n)
for i := range r {
r[i][i] = 1
}
return ... | 615LU decomposition | 0go | xc6wf |
null | 612Lychrel numbers | 11kotlin | 9a1mh |
const makeArr = (s, e) => new Array(e + 1 - s).fill(s).map((e, i) => e + i);
const filterAtInc = (arr, n) => arr.filter((e, i) => (i + 1) % n);
const makeLudic = (arr, result) => {
const iter = arr.shift();
result.push(iter);
return arr.length ? makeLudic(filterAtInc(arr, iter), result) : result;
};
const l... | 611Ludic numbers | 10javascript | ypp6r |
int lucas_lehmer(unsigned long p)
{
mpz_t V, mp, t;
unsigned long k, tlim;
int res;
if (p == 2) return 1;
if (!(p&1)) return 0;
mpz_init_set_ui(t, p);
if (!mpz_probab_prime_p(t, 25))
{ mpz_clear(t); return 0; }
if (p < 23)
{ mpz_clear(t); return (p != 11); }
mpz_init(... | 618Lucas-Lehmer test | 5c | lwhcy |
import Data.List
import Data.Maybe
import Text.Printf
mmult :: Num a => [[a]] -> [[a]] -> [[a]]
mmult a b = [ [ sum $ zipWith (*) ak bj | ak <- (transpose a) ] | bj <- b ]
nth mA i j = (mA !! j) !! i
idMatrixPart n m k = [ [if (i==j) then 1 else 0 | i <- [1..n]] | j <- [k..m]]
idMatrix n = idMatrixPart n n 1
perm... | 615LU decomposition | 8haskell | ypj66 |
use Perl6::GatherTake;
sub luck {
my($a,$b) = @_;
gather {
my $i = $b;
my(@taken,@rotor,$j);
take 0;
push @taken, take $a;
while () {
for ($j = 0; $j < @rotor; $j++) {
--$rotor[$j] or last;
}
if ($j < @rotor) {
$rotor[$j] = $taken[$j+1];
}... | 614Lucky and even lucky numbers | 2perl | uswvr |
import java.util.*;
public class MadLibs {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
String name, gender, noun;
System.out.print("Enter a name: ");
name = input.next();
System.out.print("He or she: ");
gender = input.next();
... | 613Mad Libs | 9java | ri8g0 |
long prod = 1L, sum = 0L;
void process(int j) {
sum += abs(j);
if (labs(prod) < (1 << 27) && j) prod *= j;
}
long ipow(int n, uint e) {
long pr = n;
int i;
if (e == 0) return 1L;
for (i = 2; i <= e; ++i) pr *= n;
return pr;
}
int main() {
int j;
const int x = 5, y = -5, z = -2;
... | 619Loops/With multiple ranges | 5c | 7nwrg |
package main
import "fmt"
type S struct {
start, stop, incr int
comment string
}
var examples = []S{
{-2, 2, 1, "Normal"},
{-2, 2, 0, "Zero increment"},
{-2, 2, -1, "Increments away from stop value"},
{-2, 2, 10, "First increment is beyond stop value"},
{2, -2, 1, "Start more tha... | 617Loops/Wrong ranges | 0go | p3ibg |
null | 611Ludic numbers | 11kotlin | 8uu0q |
import Data.List
main = putStrLn $ showTable True '|' '-' '+' table
table = [["start","stop","increment","Comment","Code","Result/Analysis"]
,["-2","2","1","Normal","[-2,-1..2] or [-2..2]",show [-2,-1..2]]
,["-2","2","0","Zero increment","[-2,-2..2]","Infinite loop of -2 <=> repeat -2"]
,["-2"... | 617Loops/Wrong ranges | 8haskell | f7vd1 |
(defn prime? [i]
(cond (< i 4) (>= i 2)
(zero? (rem i 2)) false
:else (not-any? #(zero? (rem i %)) (range 3 (inc (Math/sqrt i))))))))
(defn mersenne? [p] (or (= p 2)
(let [mp (dec (bit-shift-left 1 p))]
(loop [n 3 s 4]
(if (> n p)
(zero? s)
(recur (inc n) (rem (- (* ... | 618Lucas-Lehmer test | 6clojure | 48a5o |
from __future__ import print_function
def lgen(even=False, nmax=1000000):
start = 2 if even else 1
n, lst = 1, list(range(start, nmax + 1, 2))
lenlst = len(lst)
yield lst[0]
while n < lenlst and lst[n] < lenlst:
yield lst[n]
n, lst = n + 1, [j for i,j in enumerate(lst, 1) if i% lst[... | 614Lucky and even lucky numbers | 3python | 50xux |
import static java.util.Arrays.stream;
import java.util.Locale;
import static java.util.stream.IntStream.range;
public class Test {
static double dotProduct(double[] a, double[] b) {
return range(0, a.length).mapToDouble(i -> a[i] * b[i]).sum();
}
static double[][] matrixMul(double[][] A, double[... | 615LU decomposition | 9java | drun9 |
use strict;
use warnings;
use English;
use Const::Fast;
use Math::AnyNum qw(:overload);
const my $n_max => 10_000;
const my $iter_cutoff => 500;
my(@seq_dump, @seed_lychrels, @related_lychrels);
for (my $n=1; $n<=$n_max; $n++) {
my @seq = lychrel_sequence($n);
if ($iter_cutoff == scalar @seq) {
... | 612Lychrel numbers | 2perl | w9me6 |
null | 613Mad Libs | 11kotlin | vqw21 |
null | 611Ludic numbers | 1lua | o558h |
import java.util.ArrayList;
import java.util.List;
public class LoopsWrongRanges {
public static void main(String[] args) {
runTest(new LoopTest(-2, 2, 1, "Normal"));
runTest(new LoopTest(-2, 2, 0, "Zero increment"));
runTest(new LoopTest(-2, 2, -1, "Increments away from stop value"));
... | 617Loops/Wrong ranges | 9java | 0vyse |
const mult=(a, b)=>{
let res = new Array(a.length);
for (let r = 0; r < a.length; ++r) {
res[r] = new Array(b[0].length);
for (let c = 0; c < b[0].length; ++c) {
res[r][c] = 0;
for (let i = 0; i < a[0].length; ++i)
res[r][c] += a[r][i] * b[i][c];
}
}
return res;
}
const lu = (ma... | 615LU decomposition | 10javascript | 6b738 |
null | 617Loops/Wrong ranges | 11kotlin | emfa4 |
def generator(even=false, nmax=1000000)
start = even? 2: 1
Enumerator.new do |y|
n = 1
ary = [0] + (start..nmax).step(2).to_a
y << ary[n]
while (m = ary[n+=1]) < ary.size
y << m
(m...ary.size).step(m){|i| ary[i]=nil}
ary.compact!
end
... | 614Lucky and even lucky numbers | 14ruby | gos4q |
for $i (
[ -2, 2, 1],
[ -2, 2, 0],
[ -2, 2, -1],
[ -2, 2, 10],
[ 2, -2, 1],
[ 2, 2, 1],
[ 2, 2, -1],
[ 2, 2, 0],
[ 0, 0, 0],
) {
$iter = gen_seq(@$i);
printf "start:%3d stop:%3d incr:%3d | ", @$i;
... | 617Loops/Wrong ranges | 2perl | ceh9a |
struct LuckyNumbers: Sequence, IteratorProtocol {
let even: Bool
let through: Int
private var drainI = 0
private var n = 0
private var lst: [Int]
init(even: Bool = false, through: Int = 1_000_000) {
self.even = even
self.through = through
self.lst = Array(stride(from: even? 2: 1, through: thro... | 614Lucky and even lucky numbers | 17swift | 48q5g |
null | 615LU decomposition | 11kotlin | 0v9sf |
int is_prime(long long n) {
if (n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
long long d = 5;
while (d * d <= n) {
if (n % d == 0) return 0;
d += 2;
if (n % d == 0) return 0;
d += 4;
}
return 1;
}
int main() {
long long i;
int n;
setlocal... | 620Loops/Increment loop index within loop body | 5c | f7cd3 |
package main
import (
"fmt"
"log"
"strings"
) | 616LZW compression | 0go | ktohz |
import re
from itertools import islice
data = '''
start stop increment Comment
-2 2 1 Normal
-2 2 0 Zero increment
-2 2 -1 Increments away from stop value
-2 2 10 First increment is beyond stop value
2 -2 1 Start more than stop: positive increment
2 2 1 Start equal stop: positive increment
2 ... | 617Loops/Wrong ranges | 3python | lwkcv |
function luhn_validate
{
num=$1
shift 1
len=${
is_odd=1
sum=0
for((t = len - 1; t >= 0; --t)) {
digit=${num:$t:1}
if [[ $is_odd -eq 1 ]]; then
sum=$(( sum + $digit ))
else
sum=$(( $sum + ( $digit != 9? ( ( 2 * $digit ) % 9 ): 9 ) ))
fi
... | 621Luhn test of credit card numbers | 4bash | qldxu |
def compress = { text ->
def dictionary = (0..<256).inject([:]) { map, ch -> map."${(char)ch}" = ch; map }
def w = '', compressed = []
text.each { ch ->
def wc = "$w$ch"
if (dictionary[wc]) {
w = wc
} else {
compressed << dictionary[w]
dictionary[w... | 616LZW compression | 7groovy | gox46 |
from __future__ import print_function
def add_reverse(num, max_iter=1000):
i, nums = 0, {num}
while True:
i, num = i+1, num + reverse_int(num)
nums.add(num)
if reverse_int(num) == num or i >= max_iter:
break
return nums
def reverse_int(num):
return int(str(num)[::-... | 612Lychrel numbers | 3python | xc9wr |
package main
import "fmt"
func pow(n int, e uint) int {
if e == 0 {
return 1
}
prod := n
for i := uint(2); i <= e; i++ {
prod *= n
}
return prod
}
func abs(n int) int {
if n >= 0 {
return n
}
return -n
}
func commatize(n int) string {
s := fmt.Sprintf(... | 619Loops/With multiple ranges | 0go | drcne |
seq(from = -2, to = 2, by = 1)
seq(from = -2, to = 2, by = 0)
seq(from = -2, to = 2, by = -1)
seq(from = -2, to = 2, by = 10)
seq(from = 2, to = -2, by = 1)
seq(from = 2, to = 2, by = 1)
seq(from = 2, to = 2, by = -1)
seq(from = 2, to = 2, by = 0)
seq(from = 0, to = 0, by = 0) | 617Loops/Wrong ranges | 13r | ypr6h |
import Data.List (elemIndex, tails)
import Data.Maybe (fromJust)
doLZW :: Eq a => [a] -> [a] -> [Int]
doLZW _ [] = []
doLZW as (x:xs) = lzw (return <$> as) [x] xs
where
lzw a w [] = [fromJust $ elemIndex w a]
lzw a w (x:xs)
| w_ `elem` a = lzw a w_ xs
| otherwise = fromJust (elemIndex w a): lzw (... | 616LZW compression | 8haskell | ng2ie |
library(gmp)
library(magrittr)
cache <- NULL
cache_reset <- function() { cache <<- new.env(TRUE, emptyenv()) }
cache_set <- function(key, value) { assign(key, value, envir = cache) }
cache_get <- function(key) { get(key, envir = cache, inherits = FALSE) }
cache_has_key <- function(key) { exists(key, envir = cache, in... | 612Lychrel numbers | 13r | 163pn |
use warnings;
use strict;
my $template = shift;
open my $IN, '<', $template or die $!;
my $story = do { local $/ ; <$IN> };
my %blanks;
undef $blanks{$_} for $story =~ m/<(.*?)>/g;
for my $blank (sort keys %blanks) {
print "$blank: ";
chomp (my $replacement = <>);
$blanks{$blank} = $replacement;
}
$stor... | 613Mad Libs | 2perl | 0vls4 |
def (prod, sum, x, y, z, one, three, seven) = [1, 0, +5, -5, -2, 1, 3, 7]
for (
j in (
((-three) .. (3**3) ).step(three)
+ ((-seven) .. (+seven) ).step(x)
+ (555 .. (550-y) )
+ (22 .. (-28) ).step(three) | 619Loops/With multiple ranges | 7groovy | 0v3sh |
use warnings;
use strict;
use feature qw{ say };
{ my @ludic = (1);
my $max = 3;
my @candidates;
sub sieve {
my $l = shift;
for (my $i = 0; $i <= $
splice @candidates, $i, 1;
}
}
sub ludic {
my ($type, $n) = @_;
die "Arg0 Type must be 'count' ... | 611Ludic numbers | 2perl | 4885d |
loop :: (b -> a -> b) -> b -> [[a]] -> b
loop = foldl . foldl
example = let
x = 5
y = -5
z = -2
one = 1
three = 3
seven = 7
in
loop
(
\(sum, prod) j ->
(
sum + abs j,
if abs prod < 2^27 && j /= 0
then prod * j else prod
)
)
(0,... | 619Loops/With multiple ranges | 8haskell | 50pug |
examples = [
[ -2, 2, 1],
[ -2, 2, 0],
[ -2, 2, -1],
[ -2, 2, 10],
[ 2, -2, 1],
[ 2, 2, 1],
[ 2, 2, -1],
[ 2, 2, 0],
[ 0, 0, 0]
]
examples.each do |start, stop, step|
as = (start..stop).step(step)
puts
e... | 617Loops/Wrong ranges | 14ruby | vqp2n |
...
const char *list[] = {,,,,};
int ix;
for(ix=0; ix<LIST_SIZE; ix++) {
printf(, list[ix]);
} | 622Loops/Foreach | 5c | drynv |
import java.util.*;
public class LZW {
public static List<Integer> compress(String uncompressed) { | 616LZW compression | 9java | ql6xa |
import java.util.ArrayList;
import java.util.List;
public class LoopsWithMultipleRanges {
private static long sum = 0;
private static long prod = 1;
public static void main(String[] args) {
long x = 5;
long y = -5;
long z = -2;
long one = 1;
long three = 3;
... | 619Loops/With multiple ranges | 9java | 9armu |
null | 616LZW compression | 10javascript | i4lol |
int main() {
int a[10][10], i, j;
srand(time(NULL));
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
a[i][j] = rand() % 20 + 1;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
printf(, a[i][j]);
if (a[i][j] == 20)
goto Done;
... | 623Loops/Nested | 5c | em0av |
(doseq [item collection] (println item)) | 622Loops/Foreach | 6clojure | 6b23q |
require 'set'
def add_reverse(num, max_iter=1000)
(1..max_iter).each_with_object(Set.new([num])) do |_,nums|
num += reverse_int(num)
nums << num
return nums if palindrome?(num)
end
end
def palindrome?(num)
num == reverse_int(num)
end
def reverse_int(num)
num.to_s.reverse.to_i
end
def split_roots... | 612Lychrel numbers | 14ruby | s2lqw |
null | 619Loops/With multiple ranges | 11kotlin | zhvts |
int main()
{
int i;
for (i = 1; i <= 10; i++) {
printf(, i);
printf(i == 10 ? : );
}
return 0;
} | 624Loops/N plus one half | 5c | xc8wu |
use List::Util qw(sum);
for $test (
[[1, 3, 5],
[2, 4, 7],
[1, 1, 0]],
[[11, 9, 24, 2],
[ 1, 5, 2, 6],
[ 3, 17, 18, 1],
[ 2, 5, 7, 1]]
) {
my($P, $AP, $L, $U) = lu(@$test);
say_it('A matrix', @$test);
say_it('P matrix', @$P);
say_it('AP matrix', @$AP);
sa... | 615LU decomposition | 2perl | 50wu2 |
[package]
name = "lychrel"
version = "0.1.0"
authors = ["monsieursquirrel"]
[dependencies]
num = "0.1.27" | 612Lychrel numbers | 15rust | 0v2sl |
package main
import(
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func isPrime(n uint64) bool {
if n % 2 == 0 {
return n == 2
}
if n % 3 == 0 {
return n == 3
}
d := uint64(5)
for d * d <= n {
if n % d == 0 {
return false
}
... | 620Loops/Increment loop index within loop body | 0go | jdw7d |
null | 616LZW compression | 11kotlin | 16dpd |
import scala.collection.mutable.LinkedHashMap
val range = 1 to 10000
val maxIter = 500;
def lychrelSeq( seed:BigInt ) : Stream[BigInt] = {
def reverse( v:BigInt ) = BigInt(v.toString.reverse)
def isPalindromic( v:BigInt ) = { val s = (v + reverse(v)).toString; s == s.reverse }
def loop( v:BigInt ):Stream[BigI... | 612Lychrel numbers | 16scala | i45ox |
import Data.List
import Control.Monad (guard)
isPrime :: Int -> Bool
isPrime n
| n <= 3 = n > 1
| n `mod` 2 == 0 || n `mod` 3 == 0 = False
| otherwise = l2 5 n
where l2 d n = x > n || l3 d n
where x = d * d
l3 d n
| n `mod` d == 0 = False
| n ... | 620Loops/Increment loop index within loop body | 8haskell | o568p |
use constant one => 1;
use constant three => 3;
use constant seven => 7;
use constant x => 5;
use constant yy => -5;
use constant z => -2;
my $prod = 1;
sub from_to_by {
my($begin,$end,$skip) = @_;
my $n = 0;
grep{ !($n++ % abs $skip) } $begin <= $end ? $begin..$end : reverse $end..$begi... | 619Loops/With multiple ranges | 2perl | bz0k4 |
(apply str (interpose ", " (range 1 11)))
(loop [n 1]
(printf "%d" n)
(if (< n 10)
(do
(print ", ")
(recur (inc n))))) | 624Loops/N plus one half | 6clojure | o5f8j |
int i = 1024;
while(i > 0) {
printf(, i);
i /= 2;
} | 625Loops/While | 5c | ypc6f |
(ns nested)
(defn create-matrix [width height]
(for [_ (range width)]
(for [_ (range height)]
(inc (rand-int 20)))))
(defn print-matrix [matrix]
(loop [[row & rs] matrix]
(when (= (loop [[x & xs] row]
(println x)
(cond (= x 20):stop
xs (recur xs)
... | 623Loops/Nested | 6clojure | 0vdsj |
local function compress(uncompressed) | 616LZW compression | 1lua | ayf1v |
from pprint import pprint
def matrixMul(A, B):
TB = zip(*B)
return [[sum(ea*eb for ea,eb in zip(a,b)) for b in TB] for a in A]
def pivotize(m):
n = len(m)
ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)]
for j in xrange(n):
row = max(xrange(j, n), key=lambda i: abs(m[i][j]... | 615LU decomposition | 3python | 48x5k |
import BigInt
public struct Lychrel<T: ReversibleNumeric & CustomStringConvertible>: Sequence, IteratorProtocol {
@usableFromInline
let seed: T
@usableFromInline
var done = false
@usableFromInline
var n: T
@usableFromInline
var iterations: T
@inlinable
public init(seed: T, iterations: T = 500) ... | 612Lychrel numbers | 17swift | qlcxg |
public class LoopIncrementWithinBody {
static final int LIMIT = 42;
static boolean isPrime(long n) {
if (n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
long d = 5;
while (d * d <= n) {
if (n % d == 0) return false;
d += 2;
if (n % ... | 620Loops/Increment loop index within loop body | 9java | w9nej |
library(Matrix)
A <- matrix(c(1, 3, 5, 2, 4, 7, 1, 1, 0), 3, 3, byrow=T)
dim(A) <- c(3, 3)
expand(lu(A)) | 615LU decomposition | 13r | 2x1lg |
import re
template = '''<name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home.'''
def madlibs(template):
print('The story template is:\n' + template)
fields = sorted(set( re.findall('<[^>]+>', template) ))
values = input('\nInput a comma-separated list of words... | 613Mad Libs | 3python | 8u20o |
def ludic(nmax=100000):
yield 1
lst = list(range(2, nmax + 1))
while lst:
yield lst[0]
del lst[::lst[0]]
ludics = [l for l in ludic()]
print('First 25 ludic primes:')
print(ludics[:25])
print(
% sum(1 for l in ludics if l <= 1000))
print()
print(ludics[2000-1: 2005])
n = 250
triplet... | 611Ludic numbers | 3python | goo4h |
String loopPlusHalf(start, end) {
var result = '';
for(int i = start; i <= end; i++) {
result += '$i';
if(i == end) {
break;
}
result += ', ';
}
return result;
}
void main() {
print(loopPlusHalf(1, 10));
} | 624Loops/N plus one half | 18dart | bzek1 |
int luhn(const char* cc)
{
const int m[] = {0,2,4,6,8,1,3,5,7,9};
int i, odd = 1, sum = 0;
for (i = strlen(cc); i--; odd = !odd) {
int digit = cc[i] - '0';
sum += odd ? digit : m[digit];
}
return sum % 10 == 0;
}
int main()
{
const char* cc[] = {
,
,
,
,
0
};
int i;
for (i = 0; cc[i]; i++)
... | 621Luhn test of credit card numbers | 5c | 0vtst |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.