code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
import 'dart:math';
String lcsRecursion(String a, String b) {
int aLen = a.length;
int bLen = b.length;
if (aLen == 0 || bLen == 0) {
return "";
} else if (a[aLen-1] == b[bLen-1]) {
return lcsRecursion(a.substring(0,aLen-1),b.substring(0,bLen-1)) + a[aLen-1];
} else {
var x = lcsRecursion(a, b.s... | 637Longest common subsequence | 18dart | can9e |
int main()
{
char *a = malloc(2), *b = 0, *x, c;
int cnt, len = 1;
for (sprintf(a, ); (b = realloc(b, len * 2 + 1)); a = b, b = x) {
puts(x = a);
for (len = 0, cnt = 1; (c = *a); ) {
if (c == *++a)
cnt++;
else if (c) {
len += sprintf(b + len, , cnt, c);
cnt = 1;
}
}
}
return 0;
} | 642Look-and-say sequence | 5c | 8vr04 |
null | 633Longest common substring | 11kotlin | jnu7r |
10.downto(0) do |i|
puts i
end | 627Loops/Downward for | 14ruby | hfkjx |
revision =
elements = (
)
def report():
items = elements.split()
print(f)
print(f)
print(f)
if __name__ == :
report() | 641Long literals, with continuations | 3python | bt9kr |
null | 638List rooted trees | 11kotlin | n41ij |
import java.util.LinkedList;
import java.util.List;
public class LongPrimes
{
private static void sieve(int limit, List<Integer> primes)
{
boolean[] c = new boolean[limit];
for (int i = 0; i < limit; i++)
c[i] = false; | 635Long primes | 9java | i5eos |
loop {puts } | 626Loops/Infinite | 14ruby | jdk7x |
fn main() {
for i in (0..=10).rev() {
println!("{}", i);
}
} | 627Loops/Downward for | 15rust | ktbh5 |
char ch = 'z'; | 643Literals/String | 5c | sl5q5 |
elements = %w(
hydrogen helium lithium beryllium
boron carbon nitrogen oxygen
fluorine neon sodium magnesium
aluminum silicon phosphorous sulfur
chlorine argon potassium calcium
scandium titanium vanadium chromium
manganese i... | 641Long literals, with continuations | 14ruby | 13lpw |
tree_list = {}
offset = {}
function init()
for i=1,32 do
if i == 2 then
table.insert(offset, 1)
else
table.insert(offset, 0)
end
end
end
function append(t)
local v = 1 | (t << 1)
table.insert(tree_list, v)
end
function show(t, l)
while l > 0 do
... | 638List rooted trees | 1lua | dganq |
0.
0.0
.0
1e3
1e-300
6.02E+23 | 639Literals/Floating point | 0go | 2wnl7 |
fun main() {
val has53Weeks = { year: Int -> LocalDate.of(year, 12, 28).get(WeekFields.ISO.weekOfYear()) == 53 }
println("Long years this century:")
(2000..2100).filter(has53Weeks)
.forEach { year -> print("$year ")}
} | 636Long year | 11kotlin | x9jws |
char a1[] = {'a','b','c'};
char a2[] = {'A','B','C'};
int a3[] = {1,2,3};
int main(void) {
for (int i = 0; i < 3; i++) {
printf(, a1[i], a2[i], a3[i]);
}
} | 644Loop over multiple arrays simultaneously | 5c | oug80 |
import fileinput
def longer(a, b):
try:
b[len(a)-1]
return False
except:
return True
longest, lines = '', ''
for x in fileinput.input():
if longer(x, longest):
lines, longest = x, x
elif not longer(longest, x):
lines += x
print(lines, end='') | 632Longest string challenge | 3python | slaq9 |
fn main() {
loop {
println!("SPAM");
}
} | 626Loops/Infinite | 15rust | hfbj2 |
for(i <- 10 to 0 by -1) println(i) | 627Loops/Downward for | 16scala | 16apf |
use strict;
use warnings;
use feature 'say';
sub bagchain {
my($x, $n, $bb, $start) = @_;
return [@$x] unless $n;
my @sets;
$start //= 0;
for my $i ($start .. @$bb-1) {
my($c, $s) = @{$$bb[$i]};
push @sets, bagchain([$$x[0] + $c, $$x[1] . $s], $n-$c, $bb, $i) if $c <= $n
}
... | 638List rooted trees | 2perl | 7imrh |
int main(void)
{
printf(,
( (727 == 0x2d7) &&
(727 == 01327) ) ? : );
return 0;
} | 645Literals/Integer | 5c | 13ypj |
println 1.00f | 639Literals/Floating point | 7groovy | ybs6o |
main = print [0.1,23.3,35e-1,56E+2,14.67e1] | 639Literals/Floating point | 8haskell | a6u1g |
null | 635Long primes | 11kotlin | qckx1 |
while (true)
println("SPAM") | 626Loops/Infinite | 16scala | p3abj |
[\h \e \l \l \o]
\uXXXX
\\ | 643Literals/String | 6clojure | n4jik |
user=> 2r1001
9
user=> 8r64
52
user=> 064
52
user=> 16r4b
75
user=> 0x4b
75
user=> | 645Literals/Integer | 6clojure | qc2xt |
(defn digits-seq
"Returns a seq of the digits of a number (L->R)."
[n]
(loop [digits (), number n]
(if (zero? number) (seq digits)
(recur (cons (mod number 10) digits)
(quot number 10)))))
(defn join-digits
"Converts a digits-seq back in to a number."
[ds]
(reduce (fn [n d] (+ (*... | 642Look-and-say sequence | 6clojure | frbdm |
use strict ;
use warnings ;
sub longestCommonSubstr {
my $first = shift ;
my $second = shift ;
my %firstsubs = findSubstrings ( $first );
my %secondsubs = findSubstrings ( $second ) ;
my @commonsubs ;
foreach my $subst ( keys %firstsubs ) {
if ( exists $secondsubs{ $subst } ) {
push ( @common... | 633Longest common substring | 2perl | t78fg |
n = 1024
while n > 0:
print n
n | 625Loops/While | 3python | 2x5lz |
void longmulti(const char *a, const char *b, char *c)
{
int i = 0, j = 0, k = 0, n, carry;
int la, lb;
if (!strcmp(a, ) || !strcmp(b, )) {
c[0] = '0', c[1] = '\0';
return;
}
if (a[0] == '-') { i = 1; k = !k; }
if (b[0] == '-') { j = 1; k = !k; }
if (i || j) {
if (k) c[0] = '-';
longmulti(a + i, ... | 646Long multiplication | 5c | t7jf4 |
def bags(n,cache={}):
if not n: return [(0, )]
upto = sum([bags(x) for x in range(n-1, 0, -1)], [])
return [(c+1, '('+s+')') for c,s in bagchain((0, ), n-1, upto)]
def bagchain(x, n, bb, start=0):
if not n: return [x]
out = []
for i in range(start, len(bb)):
c,s = bb[i]
if c <= n: out += bagchain((x[0] + c... | 638List rooted trees | 3python | jn97p |
1. | 639Literals/Floating point | 9java | jnm7c |
use strict;
use warnings;
use DateTime;
for my $century (19 .. 21) {
for my $year ($century*100 .. ++$century*100 - 1) {
print "$year " if DateTime->new(year => $year, month => 12, day => 28)->week_number > 52
}
print "\n";
} | 636Long year | 2perl | 2wtlf |
BEGIN {
v = [ ]
m = 0
}
n = $_.length
if n == m then
v <<= $_
elsif n > m then
v = [$_]
m = n
end
END {
v.each { |s| puts s }
} | 632Longest string challenge | 14ruby | 8vw01 |
use strict;
sub lis {
my @l = map [], 1 .. @_;
push @{$l[0]}, +$_[0];
for my $i (1 .. @_-1) {
for my $j (0 .. $i - 1) {
if ($_[$j] < $_[$i] and @{$l[$i]} < @{$l[$j]} + 1) {
$l[$i] = [ @{$l[$j]} ];
}
}
push @{$l[$i]}, $_[$i];
}
my ($max... | 631Longest increasing subsequence | 2perl | pzjb0 |
package main
import "fmt"
func main() {
for i := 1; i <= 10; i++ {
fmt.Printf("%d", i)
if i%5 == 0 {
fmt.Printf("\n")
continue
}
fmt.Printf(", ")
}
} | 634Loops/Continue | 0go | slpqa |
for (i in 1..10) {
print i
if (i % 5 == 0) {
println ()
continue
}
print ', '
} | 634Loops/Continue | 7groovy | a671p |
i <- 1024L
while(i > 0)
{
print(i)
i <- i%/% 2
} | 625Loops/While | 13r | m1ly4 |
package main
import "fmt"
func main() {
for i := 1; i <= 5; i++ {
for j := 1; j <= i; j++ {
fmt.Printf("*")
}
fmt.Printf("\n")
}
} | 630Loops/For | 0go | ro5gm |
val d: Double = 1.0
val d2: Double = 1.234e-10
val f: Float = 728832f
val f2: Float = 728832F | 639Literals/Floating point | 11kotlin | 5stua |
function isLongYear($year) {
return (53 == strftime('%V', gmmktime(0,0,0,12,28,$year)));
}
for ($y=1995; $y<=2045; ++$y) {
if (isLongYear($y)) {
printf(, $y);
}
} | 636Long year | 12php | slkqs |
(doseq [s (map #(str %1 %2 %3) "abc" "ABC" "123")]
(println s)) | 644Loop over multiple arrays simultaneously | 6clojure | t7kfv |
use std::cmp::Ordering;
use std::io::BufRead; | 632Longest string challenge | 15rust | oux83 |
import Control.Monad (forM)
main = forM [1..10] out
where
out x | x `mod` 5 == 0 = print x
| otherwise = (putStr . (++", ") . show) x | 634Loops/Continue | 8haskell | 91fmo |
for(i in (1..6)) {
for(j in (1..i)) {
print '*'
}
println ()
} | 630Loops/For | 7groovy | vxc28 |
3.14159
314.159E-2 | 639Literals/Floating point | 1lua | 40z5c |
use ntheory qw/divisors powmod is_prime/;
sub is_long_prime {
my($p) = @_;
return 0 unless is_prime($p);
for my $d (divisors($p-1)) {
return $d+1 == $p if powmod(10, $d, $p) == 1;
}
0;
}
print "Long primes 500:\n";
print join(' ', grep {is_long_prime($_) } 1 .. 500), "\n\n";
for my $n (5... | 635Long primes | 2perl | vx320 |
val longest = scala.io.Source.fromFile(args.head).getLines.toIterable.groupBy(_.length).max._2
println(longest mkString "\n") | 632Longest string challenge | 16scala | dg0ng |
<?php
class Node {
public $val;
public $back = NULL;
}
function lis($n) {
$pileTops = array();
foreach ($n as $x) {
$low = 0; $high = count($pileTops)-1;
while ($low <= $high) {
$mid = (int)(($low + $high) / 2);
if ($pileTops[$mid]->val >= $x)
... | 631Longest increasing subsequence | 12php | ybt61 |
TREE_LIST = []
OFFSET = []
for i in 0..31
if i == 1 then
OFFSET << 1
else
OFFSET << 0
end
end
def append(t)
TREE_LIST << (1 | (t << 1))
end
def show(t, l)
while l > 0
l = l - 1
if t % 2 == 1 then
print '('
else
print ')'
end
... | 638List rooted trees | 14ruby | kflhg |
void print_logic(int a, int b)
{
printf(, a && b);
printf(, a || b);
printf(, !a);
} | 647Logical operations | 5c | 2wwlo |
'''Long Year?'''
from datetime import date
def longYear(y):
'''True if the ISO year y has 53 weeks.'''
return 52 < date(y, 12, 28).isocalendar()[1]
def main():
'''Longer (53 week) years in the range 2000-2100'''
for year in [
x for x in range(2000, 1 + 2100)
if longYear(x... | 636Long year | 3python | vxz29 |
func lcs(a, b string) string {
aLen := len(a)
bLen := len(b)
if aLen == 0 || bLen == 0 {
return ""
} else if a[aLen-1] == b[bLen-1] {
return lcs(a[:aLen-1], b[:bLen-1]) + string(a[aLen-1])
}
x := lcs(a, b[:bLen-1])
y := lcs(a[:aLen-1], b)
if len(x) > len(y) {
retu... | 637Longest common subsequence | 0go | oup8q |
def lcs(xstr, ystr) {
if (xstr == "" || ystr == "") {
return "";
}
def x = xstr[0];
def y = ystr[0];
def xs = xstr.size() > 1 ? xstr[1..-1]: "";
def ys = ystr.size() > 1 ? ystr[1..-1]: "";
if (x == y) {
return (x + lcs(xs, ys));
}
def lcs1 = lcs(xstr, ys);
... | 637Longest common subsequence | 7groovy | x97wl |
for(int i = 1;i <= 10; i++){
System.out.print(i);
if(i % 5 == 0){
System.out.println();
continue;
}
System.out.print(", ");
} | 634Loops/Continue | 9java | t70f9 |
s1 =
s2 =
len1, len2 = len(s1), len(s2)
ir, jr = 0, -1
for i1 in range(len1):
i2 = s2.find(s1[i1])
while i2 >= 0:
j1, j2 = i1, i2
while j1 < len1 and j2 < len2 and s2[j2] == s1[j1]:
if j1-i1 >= jr-ir:
ir, jr = i1, j1
j1 += 1; j2 += 1
i2 = s2.find... | 633Longest common substring | 3python | zjott |
>>> def luhn(n):
r = [int(ch) for ch in str(n)][::-1]
return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2]))% 10 == 0
>>> for n in (49927398716, 49927398717, 1234567812345678, 1234567812345670):
print(n, luhn(n)) | 621Luhn test of credit card numbers | 3python | drmn1 |
i = 1024
while i > 0 do
puts i
i /= 2
end | 625Loops/While | 14ruby | usgvz |
my $val = 0;
do {
$val++;
print "$val\n";
} while ($val % 6); | 629Loops/Do-while | 2perl | 40u5d |
import Control.Monad
main = do
forM_ [1..5] $ \i -> do
forM_ [1..i] $ \j -> do
putChar '*'
putChar '\n' | 630Loops/For | 8haskell | 02xs7 |
(defn logical [a b]
(prn (str "a and b is " (and a b)))
(prn (str "a or b is " (or a b)))
(prn (str "not a is " (not a))))
(logical true false) | 647Logical operations | 6clojure | g884f |
require 'date'
def long_year?(year = Date.today.year)
Date.new(year, 12, 28).cweek == 53
end
(2020..2030).each{|year| puts } | 636Long year | 14ruby | 5s6uj |
extern crate time; | 636Long year | 15rust | 40y5u |
longest xs ys = if length xs > length ys then xs else ys
lcs [] _ = []
lcs _ [] = []
lcs (x:xs) (y:ys)
| x == y = x: lcs xs ys
| otherwise = longest (lcs (x:xs) ys) (lcs xs (y:ys)) | 637Longest common subsequence | 8haskell | 2wfll |
var output = "";
for (var i = 1; i <= 10; i++) {
output += i;
if (i % 5 == 0) {
print(output);
output = "";
continue;
}
output += ", ";
} | 634Loops/Continue | 10javascript | mpdyv |
while true {
println("SPAM")
} | 626Loops/Infinite | 17swift | 7nhrq |
fn main() {
let mut n: i32 = 1024;
while n > 0 {
println!("{}", n);
n /= 2;
}
} | 625Loops/While | 15rust | 50ruq |
for i in stride(from: 10, through: 0, by: -1) {
println(i)
} | 627Loops/Downward for | 17swift | jdh74 |
import java.time.temporal.TemporalAdjusters.firstInMonth
import java.time.temporal.{ChronoField, IsoFields}
import java.time.{DayOfWeek, LocalDate, Month}
import scala.util.{Failure, Try}
private object LongYear extends App {
private val (currentCentury, maxWeekNumber) = (LocalDate.now().getYear / 100, ChronoField.... | 636Long year | 16scala | 7icr9 |
$val = 0;
do {
$val++;
print ;
} while ($val % 6 != 0); | 629Loops/Do-while | 12php | i58ov |
.5;
0.5;
1.23345e10;
1.23445e-10;
100_000_000; | 639Literals/Floating point | 2perl | ouk8x |
.12
0.1234
1.2e3
7E-10 | 639Literals/Floating point | 12php | g8342 |
def sieve(limit):
primes = []
c = [False] * (limit + 1)
p = 3
while True:
p2 = p * p
if p2 > limit: break
for i in range(p2, limit, 2 * p): c[i] = True
while True:
p += 2
if not c[p]: break
for i in range(3, limit, 2):
if not c[i... | 635Long primes | 3python | uq6vd |
def longest_increasing_subsequence(X):
N = len(X)
P = [0] * N
M = [0] * (N+1)
L = 0
for i in range(N):
lo = 1
hi = L
while lo <= hi:
mid = (lo+hi)
if (X[M[mid]] < X[i]):
lo = mid+1
else:
hi = mid-1
newL ... | 631Longest increasing subsequence | 3python | 13hpc |
null | 634Loops/Continue | 11kotlin | oue8z |
is.luhn <- function(cc){
numbers <- as.numeric(rev(unlist(strsplit(cc,""))))
(sum(numbers[seq(1,length(numbers),by=2)]) + sum({numbers[seq(2,length(numbers),by=2)]*2 ->.; .%%10 +.%/%10})) %% 10 == 0
}
sapply(c("49927398716","49927398717","1234567812345678","1234567812345670"),is.luhn) | 621Luhn test of credit card numbers | 13r | 8uz0x |
var i = 1024
while (i > 0) {
println(i)
i /= 2
} | 625Loops/While | 16scala | rihgn |
func isLongYear(_ year: Int) -> Bool {
let year1 = year - 1
let p = (year + (year / 4) - (year / 100) + (year / 400))% 7
let p1 = (year1 + (year1 / 4) - (year1 / 100) + (year1 / 400))% 7
return p == 4 || p1 == 3
}
for range in [1900...1999, 2000...2099, 2100...2199] {
print("\(range): \(range.filter(isLongY... | 636Long year | 17swift | uq3vg |
public static String lcs(String a, String b){
int aLen = a.length();
int bLen = b.length();
if(aLen == 0 || bLen == 0){
return "";
}else if(a.charAt(aLen-1) == b.charAt(bLen-1)){
return lcs(a.substring(0,aLen-1),b.substring(0,bLen-1))
+ a.charAt(aLen-1);
}else{
St... | 637Longest common subsequence | 9java | 6k03z |
def longest_common_substring(a,b)
lengths = Array.new(a.length){Array.new(b.length, 0)}
greatestLength = 0
output =
a.each_char.with_index do |x,i|
b.each_char.with_index do |y,j|
next if x!= y
lengths[i][j] = (i.zero? || j.zero?)? 1: lengths[i-1][j-1] + 1
if lengths[i][j] > greatestLengt... | 633Longest common substring | 14ruby | 6kn3t |
FLOAT
: '.' DIGITS (Exponent)?
| DIGITS '.' Exponent
| DIGITS ('.' (DIGITS (Exponent)?)? | Exponent)
;
DIGITS: ( '0' .. '9' )+;
Exponent
: ('e' | 'E') ( '+' | '-' )? DIGITS
; | 639Literals/Floating point | 3python | i5bof |
const isLongYear = (year: number): boolean => {
const jan1: Date = new Date(year, 0, 1);
const dec31: Date = new Date(year, 11, 31);
return (4 == jan1.getDay() || 4 == dec31.getDay())
}
for (let y: number = 1995; y <= 2045; y++) {
if (isLongYear(y)) {
console.log(y)
}
} | 636Long year | 20typescript | wm7eu |
function lcs(a, b) {
var aSub = a.substr(0, a.length - 1);
var bSub = b.substr(0, b.length - 1);
if (a.length === 0 || b.length === 0) {
return '';
} else if (a.charAt(a.length - 1) === b.charAt(b.length - 1)) {
return lcs(aSub, bSub) + a.charAt(a.length - 1);
} else {
var x = lcs(a, bSub);
v... | 637Longest common subsequence | 10javascript | ledcf |
fn longest_common_substring(s1: &str, s2: &str) -> String {
let s1_chars: Vec<char> = s1.chars().collect();
let s2_chars: Vec<char> = s2.chars().collect();
let mut lcs = "".to_string();
for i in 0..s1_chars.len() {
for j in 0..s2_chars.len() {
if s1_chars[i] == s2_chars[j] {
... | 633Longest common substring | 15rust | ybd68 |
def longestCommonSubstringsOptimizedPureFP(left: String, right: String): Option[Set[String]] =
if (left.nonEmpty && right.nonEmpty) {
val (shorter, longer) =
if (left.length < right.length) (left, right)
else (right, left)
@scala.annotation.tailrec
def recursive(
indexLonger: Int = 0,
... | 633Longest common substring | 16scala | caz93 |
2.3
3.
2f64
1_000.2_f32 | 639Literals/Floating point | 14ruby | dg1ns |
package main
import "fmt"
import "math/rand"
import "time"
func main() {
rand.Seed(time.Now().UnixNano())
for {
a := rand.Intn(20)
fmt.Println(a)
if a == 10 {
break
}
b := rand.Intn(20)
fmt.Println(b)
}
} | 640Loops/Break | 0go | btckh |
func lComSubStr<
S0: Sliceable, S1: Sliceable, T: Equatable where
S0.Generator.Element == T, S1.Generator.Element == T,
S0.Index.Distance == Int, S1.Index.Distance == Int
>(w1: S0, _ w2: S1) -> S0.SubSlice {
var (len, end) = (0, 0)
let empty = Array(Repeat(count: w2.count + 1, repeatedValue: 0))
v... | 633Longest common substring | 17swift | 3hiz2 |
ch := 'z'
ch = 122 | 643Literals/String | 0go | vx82m |
2.3 | 639Literals/Floating point | 15rust | frad6 |
1. | 639Literals/Floating point | 16scala | 3hxzy |
System: I7-6700HQ, 3.5 GHz, Linux Kernel 5.6.17
Run as: $ ruby longprimes.rb | 635Long primes | 14ruby | 40m5p |
null | 635Long primes | 15rust | g894o |
final random = new Random()
while (true) {
def random1 = random.nextInt(20)
print random1
if (random1 == 10) break
print ' '
println random.nextInt(20)
} | 640Loops/Break | 7groovy | ro3gh |
for i = 1, 10 do
io.write( i )
if i % 5 == 0 then
io.write( "\n" )
else
io.write( ", " )
end
end | 634Loops/Continue | 1lua | i5wot |
val = 0
while True:
val +=1
print val
if val% 6 == 0: break | 629Loops/Do-while | 3python | g854h |
def string = 'Able was I' | 643Literals/String | 7groovy | mpwy5 |
"abcdef" == "abc\
\def"
"abc\ndef" == "abc\n\
\def" | 643Literals/String | 8haskell | eylai |
object LongPrimes extends App {
def primeStream = LazyList.from(3, 2)
.filter(p => (3 to math.sqrt(p).ceil.toInt by 2).forall(p % _ > 0))
def longPeriod(p: Int): Boolean = {
val mstart = 10 % p
@annotation.tailrec
def iter(mod: Int, period: Int): Int = {
val mod1 = (... | 635Long primes | 16scala | jn27i |
null | 637Longest common subsequence | 11kotlin | dgenz |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.