code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
is_leap_year ()
{
declare -i year=$1
echo -n "$year ($2)-> "
if (( $year % 4 == 0 ))
then
if (( $year % 400 == 0 ))
then
echo "This is a leap year"
else
if (( $year % 100 == 0 ))
then
echo "This is not a... | 657Leap year | 4bash | qcnxu |
package main
import (
"fmt"
"sort"
)
type matrix [][]int | 658Latin Squares in reduced form | 0go | 7ipr2 |
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Monoid ((<>))
triangles
:: (Map.Map Int Int -> Int -> Int -> Int -> Int -> Maybe Int)
-> Int
-> [(Int, Int, Int)]
triangles f n =
let mapRoots = Map.fromList $ ((,) =<< (^ 2)) <$> [1 .. n]
in Set.elems $
foldr
(\... | 655Law of cosines - triples | 8haskell | 5sbug |
def leo( n:Int, n1:Int=1, n2:Int=1, addnum:Int=1 ) : BigInt = n match {
case 0 => n1
case 1 => n2
case n => leo(n - 1, n1, n2, addnum) + leo(n - 2, n1, n2, addnum) + addnum
}
{
println( "The first 25 Leonardo Numbers:")
(0 until 25) foreach { n => print( leo(n) + " " ) }
println( "\n\nThe first 25 Fibonacci Num... | 651Leonardo numbers | 16scala | kfohk |
import Data.List (permutations, (\\))
import Control.Monad (foldM, forM_)
latinSquares :: Eq a => [a] -> [[[a]]]
latinSquares [] = []
latinSquares set = map reverse <$> squares
where
squares = foldM addRow firstRow perm
perm = tail (groupedPermutations set)
firstRow = pure <$> set
addRow tbl rows = [... | 658Latin Squares in reduced form | 8haskell | 8vf0z |
public class LawOfCosines {
public static void main(String[] args) {
generateTriples(13);
generateTriples60(10000);
}
private static void generateTriples(int max) {
for ( int coeff : new int[] {0, -1, 1} ) {
int count = 0;
System.out.printf("Max side length%... | 655Law of cosines - triples | 9java | 91gmu |
null | 652Left factorials | 11kotlin | 13npd |
package main
import "fmt" | 653Linear congruential generator | 0go | pzobg |
struct Leonardo: Sequence, IteratorProtocol {
private let add: Int
private var n0: Int
private var n1: Int
init(n0: Int = 1, n1: Int = 1, add: Int = 1) {
self.n0 = n0
self.n1 = n1
self.add = add
}
mutating func next() -> Int? {
let n = n0
n0 = n1
... | 651Leonardo numbers | 17swift | g8x49 |
typedef struct {
uint16_t index;
char last_char, first_char;
} Ref;
Ref* longest_path_refs;
size_t longest_path_refs_len;
Ref* refs;
size_t refs_len;
size_t n_solutions;
const char** longest_path;
size_t longest_path_len;
void search(size_t curr_len) {
if (curr_len == longest_path_refs_len) {
... | 659Last letter-first letter | 5c | eysav |
unsigned int lpd(unsigned int n) {
if (n<=1) return 1;
int i;
for (i=n-1; i>0; i--)
if (n%i == 0) return i;
}
int main() {
int i;
for (i=1; i<=100; i++) {
printf(, lpd(i));
if (i % 10 == 0) printf();
}
return 0;
} | 660Largest proper divisor of n | 5c | x90wu |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class LatinSquaresInReducedForm {
public static void main(String[] args) {
System.out.printf("Reduced latin squares of order 4:%n");
for ( LatinSquare square : getReducedLatinSquares(4) ... | 658Latin Squares in reduced form | 9java | ey0a5 |
(() => {
'use strict'; | 655Law of cosines - triples | 10javascript | uqkvb |
bsd = tail . iterate (\n -> (n * 1103515245 + 12345) `mod` 2^31)
msr = map (`div` 2^16) . tail . iterate (\n -> (214013 * n + 2531011) `mod` 2^31)
main = do
print $ take 10 $ bsd 0
print $ take 10 $ msr 0 | 653Linear congruential generator | 8haskell | fr2d1 |
int main()
{
int num = 9876432,diff[] = {4,2,2,2},i,j,k=0;
char str[10];
start:snprintf(str,10,,num);
for(i=0;str[i+1]!=00;i++){
if(str[i]=='0'||str[i]=='5'||num%(str[i]-'0')!=0){
num -= diff[k];
k = (k+1)%4;
goto start;
}
for(j=i+1;str[j]!=00;j++)
if(str[i]==str[j]){
num -= diff[k... | 661Largest number divisible by its digits | 5c | yb96f |
int frequency[26];
int ch;
FILE* txt_file = fopen (, );
for (ch = 0; ch < 26; ch++)
frequency[ch] = 0;
while (1) {
ch = fgetc(txt_file);
if (ch == EOF) break;
if ('a' <= ch && ch <= 'z')
frequency[ch-'a']++;
else if ('A' <= ch && ch <= 'Z')
frequency[ch-'A']++;
} | 662Letter frequency | 5c | vxu2o |
null | 652Left factorials | 1lua | a6d1v |
typealias Matrix = MutableList<MutableList<Int>>
fun dList(n: Int, sp: Int): Matrix {
val start = sp - 1 | 658Latin Squares in reduced form | 11kotlin | kfeh3 |
null | 655Law of cosines - triples | 11kotlin | zj2ts |
[(x,y,z) for x in xrange(1,n+1) for y in xrange(x,n+1) for z in xrange(y,n+1) if x**2 + y**2 == z**2] | 650List comprehensions | 3python | 5swux |
int is_leap_year(int year)
{
return (!(year % 4) && year % 100 || !(year % 400)) ? 1 : 0;
}
int main()
{
int test_case[] = {1900, 1994, 1996, 1997, 2000}, key, end, year;
for (key = 0, end = sizeof(test_case)/sizeof(test_case[0]); key < end; ++key) {
year = test_case[key];
printf(, year, (i... | 657Leap year | 5c | 02fst |
(ns rosetta-code.last-letter-first-letter
(:require clojure.string))
(defn by-first-letter
"Returns a map from letters to a set of words that start with that letter"
[words]
(into {} (map (fn [[k v]]
[k (set v)]))
(group-by first words)))
(defn longest-path-from
"Find a longest pat... | 659Last letter-first letter | 6clojure | 02nsj |
function solve(angle, maxlen, filter)
local squares, roots, solutions = {}, {}, {}
local cos2 = ({[60]=-1,[90]=0,[120]=1})[angle]
for i = 1, maxlen do squares[i], roots[i^2] = i^2, i end
for a = 1, maxlen do
for b = a, maxlen do
local lhs = squares[a] + squares[b] + cos2*a*b
local c = roots[lhs]... | 655Law of cosines - triples | 1lua | 3hvzo |
x = (0:10)
> x^2
[1] 0 1 4 9 16 25 36 49 64 81 100
> Reduce(function(y,z){return (y+z)},x)
[1] 55
> x[x[(0:length(x))]%% 2==0]
[1] 0 2 4 6 8 10 | 650List comprehensions | 13r | lepce |
import java.util.stream.IntStream;
import static java.util.stream.IntStream.iterate;
public class LinearCongruentialGenerator {
final static int mask = (1 << 31) - 1;
public static void main(String[] args) {
System.out.println("BSD:");
randBSD(0).limit(10).forEach(System.out::println);
... | 653Linear congruential generator | 9java | 026se |
(require '[clojure.string:as str])
(def the_base 16)
(def digits (rest (range the_base)))
(def primes [])
(for [n digits] (if (= 1 (count (filter (fn[m] (and (< m n) (= 0 (mod n m)))) digits)) ) (def primes (conj primes n))))
(defn duplicity [n p partial] (if (= 0 (mod n p)) (duplicity (/ n p) p (conj partial ... | 661Largest number divisible by its digits | 6clojure | 2wul1 |
use strict;
use warnings;
my $n = 0;
my $count;
our @perms;
while( ++$n <= 7 )
{
$count = 0;
@perms = perm( my $start = join '', 1 .. $n );
find( $start );
print "order $n size $count total @{[$count * fact($n) * fact($n-1)]}\n\n";
}
sub find
{
@_ >= $n and return $count += ($n != 4) || print join "... | 658Latin Squares in reduced form | 2perl | 3hczs |
(println (sort-by second >
(frequencies (map #(java.lang.Character/toUpperCase %)
(filter #(java.lang.Character/isLetter %) (slurp "text.txt")))))) | 662Letter frequency | 6clojure | ro7g2 |
use utf8;
binmode STDOUT, "utf8:";
use Sort::Naturally;
sub triples {
my($n,$angle) = @_;
my(@triples,%sq);
$sq{$_**2}=$_ for 1..$n;
for $a (1..$n-1) {
for $b ($a+1..$n) {
my $ab = $a*$a + $b*$b;
my $cos = $angle == 60 ? $ab - $a * $b :
$angle == 120 ? $ab + $a ... | 655Law of cosines - triples | 2perl | btsk4 |
use 5.010;
use strict;
use warnings;
use bigint;
sub leftfact {
my ($n) = @_;
state $cached = 0;
state $factorial = 1;
state $leftfact = 0;
if( $n < $cached ) {
($cached, $factorial, $leftfact) = (0, 1, 0);
}
while( $n > $cached ) {
$leftfact += $factorial;
$factorial *= ++$cached;
}
return $leftfact;
}... | 652Left factorials | 2perl | mp7yz |
(defn leap-year? [y]
(and (zero? (mod y 4)) (or (pos? (mod y 100)) (zero? (mod y 400))))) | 657Leap year | 6clojure | dgynb |
typedef int bool;
int next_in_cycle(int *c, int len, int index) {
return c[index % len];
}
void kolakoski(int *c, int *s, int clen, int slen) {
int i = 0, j, k = 0;
while (TRUE) {
s[i] = next_in_cycle(c, clen, k);
if (s[k] > 1) {
for (j = 1; j < s[k]; ++j) {
if ... | 663Kolakoski sequence | 5c | uquv4 |
uint64_t factorial(uint64_t n) {
uint64_t res = 1;
if (n == 0) return res;
while (n > 0) res *= n--;
return res;
}
uint64_t lah(uint64_t n, uint64_t k) {
if (k == 1) return factorial(n);
if (k == n) return 1;
if (k > n) return 0;
if (k < 1 || n < 1) return 0;
return (factorial(n) * ... | 664Lah numbers | 5c | g0545 |
package main
import "fmt"
func largestProperDivisor(n int) int {
for i := 2; i*i <= n; i++ {
if n%i == 0 {
return n / i
}
}
return 1
}
func main() {
fmt.Println("The largest proper divisors for numbers in the interval [1, 100] are:")
fmt.Print(" 1 ")
for n := 2; n... | 660Largest proper divisor of n | 0go | leucw |
def dList(n, start):
start -= 1
a = range(n)
a[start] = a[0]
a[0] = start
a[1:] = sorted(a[1:])
first = a[1]
r = []
def recurse(last):
if (last == first):
for j,v in enumerate(a[1:]):
if j + 1 == v:
... | 658Latin Squares in reduced form | 3python | 6kl3w |
null | 653Linear congruential generator | 11kotlin | eyda4 |
import Data.List.Split (chunksOf)
import Text.Printf (printf)
lpd :: Int -> Int
lpd 1 = 1
lpd n = head [x | x <- [n -1, n -2 .. 1], n `mod` x == 0]
main :: IO ()
main =
(putStr . unlines . map concat . chunksOf 10) $
printf "%3d" . lpd <$> [1 .. 100] | 660Largest proper divisor of n | 8haskell | 13wps |
n = 20
r = ((1..n).flat_map { |x|
(x..n).flat_map { |y|
(y..n).flat_map { |z|
[[x, y, z]].keep_if { x * x + y * y == z * z }}}})
p r | 650List comprehensions | 14ruby | g8q4q |
package main
import "fmt"
var g = [][]int{
0: {1},
1: {2},
2: {0},
3: {1, 2, 4},
4: {3, 5},
5: {2, 6},
6: {5},
7: {4, 6, 7},
}
func main() {
fmt.Println(kosaraju(g))
}
func kosaraju(g [][]int) []int { | 665Kosaraju | 0go | q9exz |
int catcmp(const void *a, const void *b)
{
char ab[32], ba[32];
sprintf(ab, , *(int*)a, *(int*)b);
sprintf(ba, , *(int*)b, *(int*)a);
return strcmp(ba, ab);
}
void maxcat(int *a, int len)
{
int i;
qsort(a, len, sizeof(int), catcmp);
for (i = 0; i < len; i++)
printf(, a[i]);
putchar('\n');
}
int main(void)
{... | 666Largest int from concatenated ints | 5c | n50i6 |
int gcd(int m, int n)
{
int tmp;
while(m) { tmp = m; m = n % m; n = tmp; }
return n;
}
int lcm(int m, int n)
{
return m / gcd(m, n) * n;
}
int main()
{
printf(, lcm(21,35));
return 0;
} | 667Least common multiple | 5c | ji570 |
def printSquare(a)
for row in a
print row,
end
print
end
def dList(n, start)
start = start - 1
a = Array.new(n) {|i| i}
a[0], a[start] = a[start], a[0]
a[1..] = a[1..].sort
first = a[1]
r = []
recurse = lambda {|last|
if last == first then
... | 658Latin Squares in reduced form | 14ruby | mpvyj |
N = 13
def method1(N=N):
squares = [x**2 for x in range(0, N+1)]
sqrset = set(squares)
tri90, tri60, tri120 = (set() for _ in range(3))
for a in range(1, N+1):
a2 = squares[a]
for b in range(1, a + 1):
b2 = squares[b]
c2 = a2 + b2
if c2 in sqrset:
... | 655Law of cosines - triples | 3python | pz0bm |
fn pyth(n: u32) -> impl Iterator<Item = [u32; 3]> {
(1..=n).flat_map(move |x| {
(x..=n).flat_map(move |y| {
(y..=n).filter_map(move |z| {
if x.pow(2) + y.pow(2) == z.pow(2) {
Some([x, y, z])
} else {
None
}
... | 650List comprehensions | 15rust | rosg5 |
local RNG = {
new = function(class, a, c, m, rand)
local self = setmetatable({}, class)
local state = 0
self.rnd = function()
state = (a * state + c) % m
return rand and rand(state) or state
end
self.seed = function(new_seed)
state = new_seed % m
end
return self
end
}... | 653Linear congruential generator | 1lua | wmfea |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.IntConsumer;
import java.util.stream.Collectors;
public class Kosaraju {
static class Recursive<I> {
I func;
}
... | 665Kosaraju | 9java | fgidv |
typedef struct{
int row, col;
}cell;
int ROW,COL,SUM=0;
unsigned long raiseTo(int base,int power){
if(power==0)
return 1;
else
return base*raiseTo(base,power-1);
}
cell* kroneckerProduct(char* inputFile,int power){
FILE* fp = fopen(inputFile,);
int i,j,k,l;
unsigned long prod... | 668Kronecker product based fractals | 5c | a3j11 |
package main
import (
"fmt"
"strings"
)
var pokemon = `audino bagon baltoy...67 names omitted...`
func main() { | 659Last letter-first letter | 0go | 91vmt |
package main
import (
"fmt"
"strconv"
"strings"
)
func divByAll(num int, digits []byte) bool {
for _, digit := range digits {
if num%int(digit-'0') != 0 {
return false
}
}
return true
}
func main() {
magic := 9 * 8 * 7
high := 9876432 / magic * magic
fo... | 661Largest number divisible by its digits | 0go | 13ep5 |
(defn gcd
[a b]
(if (zero? b)
a
(recur b, (mod a b))))
(defn lcm
[a b]
(/ (* a b) (gcd a b)))
(defn lcmv [& v] (reduce lcm v)) | 667Least common multiple | 6clojure | 1zjpy |
inputs <- cbind(combn(1:13, 2), rbind(seq_len(13), seq_len(13)))
inputs <- cbind(A = inputs[1, ], B = inputs[2, ])[sort.list(inputs[1, ]),]
Pythagoras <- inputs[, "A"]^2 + inputs[, "B"]^2
AtimesB <- inputs[, "A"] * inputs[, "B"]
CValues <- sqrt(cbind("C (90)" = Pythagoras,
"C (60)" = Pythagoras - ... | 655Law of cosines - triples | 13r | jnw78 |
def pythagoranTriangles(n: Int) = for {
x <- 1 to 21
y <- x to 21
z <- y to 21
if x * x + y * y == z * z
} yield (x, y, z) | 650List comprehensions | 16scala | hdoja |
class Leap {
bool leapYear(num year) {
return (year% 400 == 0) || (( year% 100!= 0) && (year% 4 == 0));
bool isLeapYear(int year) =>
(year% 4 == 0) && ((year% 100!= 0) || (year% 400 == 0)); | 657Leap year | 18dart | a601h |
null | 665Kosaraju | 11kotlin | 82q0q |
package main
import "fmt"
func nextInCycle(c []int, index int) int {
return c[index % len(c)]
}
func kolakoski(c []int, slen int) []int {
s := make([]int, slen)
i, k := 0, 0
for {
s[i] = nextInCycle(c, k)
if s[k] > 1 {
for j := 1; j < s[k]; j++ {
i++
... | 663Kolakoski sequence | 0go | 020sk |
import Data.List
import qualified Data.ByteString.Char8 as B
allPokemon :: [B.ByteString]
allPokemon = map B.pack $ words
"audino bagon baltoy banette bidoof braviary bronzor carracosta charmeleon \
\cresselia croagunk darmanitan deino emboar emolga exeggcute gabite \
\girafarig gulpin haxorus heatmor hea... | 659Last letter-first letter | 8haskell | btek2 |
import Data.List (maximumBy, permutations, delete)
import Data.Ord (comparing)
import Data.Bool (bool)
unDigits :: [Int] -> Int
unDigits = foldl ((+) . (10 *)) 0
ds :: [Int]
ds = [1, 2, 3, 4, 6, 7, 8, 9]
lcmDigits :: Int
lcmDigits = foldr1 lcm ds
sevenDigits :: [[Int]]
sevenDigits = (`delete` ds) <$> [1, 4, 7]
... | 661Largest number divisible by its digits | 8haskell | t73f7 |
use strict;
use warnings;
use ntheory 'divisors';
use List::AllUtils <max natatime>;
sub proper_divisors {
my $n = shift;
return 1 if $n == 0;
my @d = divisors($n);
pop @d;
@d;
}
my @range = 1 .. 100;
print "GPD for $range[0] through $range[-1]:\n";
my $iter = natatime 10, @range;
while( my @batch = $iter->... | 660Largest proper divisor of n | 2perl | 8vn0w |
from itertools import islice
def lfact():
yield 0
fact, summ, n = 1, 0, 1
while 1:
fact, summ, n = fact*n, summ + fact, n + 1
yield summ
print('first 11:\n %r'% [lf for i, lf in zip(range(11), lfact())])
print('20 through 110 (inclusive) by tens:')
for lf in islice(lfact(), 20, 111, 10):
... | 652Left factorials | 3python | 91jmf |
struct s_env {
unsigned int n, i;
size_t size;
void *sample;
};
void s_of_n_init(struct s_env *s_env, size_t size, unsigned int n)
{
s_env->i = 0;
s_env->n = n;
s_env->size = size;
s_env->sample = malloc(n * size);
}
void sample_set_i(struct s_env *s_env, unsigned int i, void *item)
{
... | 669Knuth's algorithm S | 5c | iuwo2 |
function write_array(a)
io.write("[")
for i=0,#a do
if i>0 then
io.write(", ")
end
io.write(tostring(a[i]))
end
io.write("]")
end
function kosaraju(g) | 665Kosaraju | 1lua | ovs8h |
import Data.List (group)
import Control.Monad (forM_)
replicateAtLeastOne :: Int -> a -> [a]
replicateAtLeastOne n x = x: replicate (n-1) x
zipWithLazy :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWithLazy f ~(x:xs) ~(y:ys) = f x y: zipWithLazy f xs ys
kolakoski :: [Int] -> [Int]
kolakoski items = s
where s = concat $... | 663Kolakoski sequence | 8haskell | cac94 |
library(gmp)
left_factorial <- function(n) {
if (n == 0) return(0)
result <- as.bigz(0)
adder <- as.bigz(1)
for (k in 1:n) {
result <- result + adder
adder <- adder * k
}
result
}
digit_count <- function(n) {
nchar(as.character(n))
}
for (n in 0:10) {
cat("!",n," = ",sep = "")
cat(as.character(left_fa... | 652Left factorials | 13r | 3h4zt |
package main
import (
"fmt"
"math/big"
)
var (
p = map[int]int{1: 0}
lvl = [][]int{[]int{1}}
)
func path(n int) []int {
if n == 0 {
return []int{}
}
for {
if _, ok := p[n]; ok {
break
}
var q []int
for _, x := range lvl[0] {
... | 670Knuth's power tree | 0go | scbqa |
use strict;
use warnings;
use feature 'say';
sub kosaraju {
our(%k) = @_;
our %g = ();
our %h;
my $i = 0;
$g{$_} = $i++ for sort keys %k;
$h{$g{$_}} = $_ for keys %g;
our(%visited, @stack, @transpose, @connected);
sub visit {
my($u) = @_;
unless ($visited{$u... | 665Kosaraju | 2perl | 4sv5d |
import java.util.Arrays;
public class Kolakoski {
private static class Crutch {
final int len;
int[] s;
int i;
Crutch(int len) {
this.len = len;
s = new int[len];
i = 0;
}
void repeat(int count) {
for (int j = 0; j < ... | 663Kolakoski sequence | 9java | zjztq |
int main(int c, char *v[])
{
int days[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int m, y, w;
if (c < 2 || (y = atoi(v[1])) <= 1700) return 1;
days[1] -= (y % 4) || (!(y % 100) && (y % 400));
w = y * 365 + (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400 + 6;
for(m = 0; m < 12; m++) {
w = (w + days[m]) % 7;
pri... | 671Last Friday of each month | 5c | 9pnm1 |
package main
import (
"fmt"
"math/big"
)
func main() {
limit := 100
last := 12
unsigned := true
l := make([][]*big.Int, limit+1)
for n := 0; n <= limit; n++ {
l[n] = make([]*big.Int, limit+1)
for k := 0; k <= limit; k++ {
l[n][k] = new(big.Int)
}
... | 664Lah numbers | 0go | iu8og |
(defn maxcat [coll]
(read-string
(apply str
(sort (fn [x y]
(apply compare
(map read-string [(str y x) (str x y)])))
coll))))
(prn (map maxcat [[1 34 3 98 9 76 45 4] [54 546 548 60]])) | 666Largest int from concatenated ints | 6clojure | 3jdzr |
public class LynchBell {
static String s = "";
public static void main(String args[]) { | 661Largest number divisible by its digits | 9java | 8vi06 |
grouped = (1..13).to_a.repeated_permutation(3).group_by do |a,b,c|
sumaabb, ab = a*a + b*b, a*b
case c*c
when sumaabb then 90
when sumaabb - ab then 60
when sumaabb + ab then 120
end
end
grouped.delete(nil)
res = grouped.transform_values{|v| v.map(&:sort).uniq }
res.each do |k,v|
puts
put... | 655Law of cosines - triples | 14ruby | a6o1s |
typedef struct{
double x,y;
}point;
void kochCurve(point p1,point p2,int times){
point p3,p4,p5;
double theta = pi/3;
if(times>0){
p3 = (point){(2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3};
p5 = (point){(2*p2.x+p1.x)/3,(2*p2.y+p1.y)/3};
p4 = (point){p3.x + (p5.x - p3.x)*cos(theta) + (p5.y - p3.y)*sin(theta),p3.y - (p5... | 672Koch curve | 5c | mboys |
(defn s-of-n-fn-creator [n]
(fn [[sample iprev] item]
(let [i (inc iprev)]
(if (<= i n)
[(conj sample item) i]
(let [r (rand-int i)]
(if (< r n)
[(assoc sample r item) i]
[sample i]))))))
(def s-of-3-fn (s-of-n-fn-creator 3))
(->> #(reduce s-of-3-fn [[] 0]... | 669Knuth's algorithm S | 6clojure | z78tj |
class PowerTree {
private static Map<Integer, Integer> p = new HashMap<>()
private static List<List<Integer>> lvl = new ArrayList<>()
static {
p[1] = 0
List<Integer> temp = new ArrayList<Integer>()
temp.add 1
lvl.add temp
}
private static List<Integer> path(int n) ... | 670Knuth's power tree | 7groovy | a3r1p |
int main(){
char input[100],output[100];
int i,j,k,l,rowA,colA,rowB,colB,rowC,colC,startRow,startCol;
double **matrixA,**matrixB,**matrixC;
printf();
fscanf(stdin,,input);
printf();
fscanf(stdin,,output);
FILE* inputFile = fopen(input,);
fscanf(inputFile,,&rowA,&colA);
matrixA = (double**)malloc(rowA * ... | 673Kronecker product | 5c | 4s35t |
null | 663Kolakoski sequence | 11kotlin | i5io4 |
import Text.Printf (printf)
import Control.Monad (when)
factorial :: Integral n => n -> n
factorial 0 = 1
factorial n = product [1..n]
lah :: Integral n => n -> n -> n
lah n k
| k == 1 = factorial n
| k == n = 1
| k > n = 0
| k < 1 || n < 1 = 0
| otherwise = f n `div` f k `div` factorial (n - k)
wher... | 664Lah numbers | 8haskell | vwl2k |
null | 659Last letter-first letter | 9java | g8h4m |
def lpd(n):
for i in range(n-1,0,-1):
if n%i==0: return i
return 1
for i in range(1,101):
print(.format(lpd(i)), end=i%10==0 and '\n' or '') | 660Largest proper divisor of n | 3python | oud81 |
main() {
int x=8;
int y=12;
int z= gcd(x,y);
var lcm=(x*y)/z;
print('$lcm');
}
int gcd(int a,int b)
{
if(b==0)
return a;
if(b!=0)
return gcd(b,a%b);
} | 667Least common multiple | 18dart | ux9vs |
typealias F1 = (Int) -> [(Int, Int, Int)]
typealias F2 = (Int) -> Bool
func pythagoreanTriples(n: Int) -> [(Int, Int, Int)] {
(1...n).flatMap({x in
(x...n).flatMap({y in
(y...n).filter({z in
x * x + y * y == z * z
} as F2).map({ (x, y, $0) })
} as F1)
} as F1)
}
print(pythagoreanTriple... | 650List comprehensions | 17swift | 40x5g |
use strict;
package LCG;
use overload '0+' => \&get;
use integer;
sub gen_bsd { (1103515245 * shift() + 12345) % (1 << 31) }
sub gen_ms {
my $s = (214013 * shift() + 2531011) % (1 << 31);
$s, $s / (1 << 16)
}
sub set { $_[0]->{seed} = $_[1] }
sub get {
my $o = shift;
($o->{seed}, my $r) = $o->{meth}->($o->{s... | 653Linear congruential generator | 2perl | caj9a |
module Rosetta.PowerTree
( Natural
, powerTree
, power
) where
import Data.Foldable (toList)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Data.List (foldl')
import Data.Sequence (Seq (..), (|... | 670Knuth's power tree | 8haskell | 9pdmo |
def kosaraju(g):
class nonlocal: pass
size = len(g)
vis = [False]*size
l = [0]*size
nonlocal.x = size
t = [[]]*size
def visit(u):
if not vis[u]:
vis[u] = True
for v in g[u]:
visit(v)
t[v] = t[v] + [u]
non... | 665Kosaraju | 3python | g0u4h |
function next_in_cycle(c,length,index)
local pos = index % length
return c[pos]
end
function kolakoski(c,s,clen,slen)
local i = 0
local k = 0
while true do
s[i] = next_in_cycle(c,clen,k)
if s[k] > 1 then
for j=1,s[k]-1 do
i = i + 1
if i =... | 663Kolakoski sequence | 1lua | n4ni8 |
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
public class LahNumbers {
public static void main(String[] args) {
System.out.println("Show the unsigned Lah numbers up to n = 12:");
for ( int n = 0 ; n <= 12 ; n++ ) {
System.out.printf("%5s", n);
... | 664Lah numbers | 9java | yk36g |
const endsWith = word => word[word.length - 1];
const getCandidates = (words, used) => words.filter(e => !used.includes(e));
const buildLookup = words => {
const lookup = new Map();
words.forEach(e => {
const start = e[0];
lookup.set(start, [...(lookup.get(start) || []), e]);
});
return lookup;
};
... | 659Last letter-first letter | 10javascript | kfahq |
null | 661Largest number divisible by its digits | 11kotlin | wmqek |
function isDivisible(n)
local t = n
local a = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
while t ~= 0 do
local r = t % 10
if r == 0 then
return false
end
if n % r ~= 0 then
return false
end
if a[r + 1] > 0 then
return false
end... | 661Largest number divisible by its digits | 1lua | x9swz |
largest_proper_divisor <- function(n){
if(n == 1) return(1)
lpd = 1
for(i in seq(1, n-1, 1)){
if(n%% i == 0)
lpd = i
}
message(paste0("The largest proper divisor of ", n, " is ", lpd))
return(lpd)
}
for (i in 1:100){
largest_proper_divisor(i)
} | 660Largest proper divisor of n | 13r | qc8xs |
left_fact = Enumerator.new do |y|
f, lf = 1, 0
1.step do |n|
y << lf
lf += f
f *= n
end
end | 652Left factorials | 14ruby | lekcl |
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PowerTree {
private static Map<Integer, Integer> p = new HashMap<>();
private static List<List<Integer>> lvl = new ArrayList<>();
static {
p.put(1, 0);
... | 670Knuth's power tree | 9java | trsf9 |
package main
import "fmt"
type matrix [][]int
func (m1 matrix) kroneckerProduct(m2 matrix) matrix {
m := len(m1)
n := len(m1[0])
p := len(m2)
q := len(m2[0])
rtn := m * p
ctn := n * q
r := make(matrix, rtn)
for i := range r {
r[i] = make([]int, ctn) | 668Kronecker product based fractals | 0go | mbfyi |
sub kolakoski {
my($terms,@seed) = @_;
my @k;
my $k = $seed[0] == 1 ? 1 : 0;
if ($k == 1) { @k = (1, split //, (($seed[1]) x $seed[1])) }
else { @k = ($seed[0]) x $seed[0] }
do {
$k++;
push @k, ($seed[$k % @seed]) x $k[$k];
} until $terms <= @k;
@k[0..$terms-1]
}
... | 663Kolakoski sequence | 2perl | rorgd |
(use '[clj-time.core:only [last-day-of-the-month day-of-week minus days]]
'[clj-time.format:only [unparse formatters]])
(defn last-fridays [year]
(let [last-days (map #(last-day-of-the-month year %) (range 1 13 1))
dow (map day-of-week last-days)
relation (zipmap last-days dow)]
(map #(m... | 671Last Friday of each month | 6clojure | ux3vi |
#[cfg(target_pointer_width = "64")]
type USingle = u32;
#[cfg(target_pointer_width = "64")]
type UDouble = u64;
#[cfg(target_pointer_width = "64")]
const WORD_LEN: i32 = 32;
#[cfg(not(target_pointer_width = "64"))]
type USingle = u16;
#[cfg(not(target_pointer_width = "64"))]
type UDouble = u32;
#[cfg(not(target_pointe... | 652Left factorials | 15rust | 2wblt |
<?php
function bsd_rand($seed) {
return function() use (&$seed) {
return $seed = (1103515245 * $seed + 12345) % (1 << 31);
};
}
function msvcrt_rand($seed) {
return function() use (&$seed) {
return ($seed = (214013 * $seed + 2531011) % (1 << 31)) >> 16;
};
}
$lcg = bsd_rand(0);
echo ;
... | 653Linear congruential generator | 12php | x9tw5 |
import Reflex
import Reflex.Dom
import Data.Map as DM (Map, fromList)
import Data.Text (Text, pack)
import Data.List (transpose)
main :: IO ()
main = mainWidget $ do
elAttr "h1" ("style" =: "color:black") $ text "Kroneker Product Based Fractals"
elAttr "a" ("href" =: "http://rosettacode.org/wiki/Kronecker_produ... | 668Kronecker product based fractals | 8haskell | kd4h0 |
import java.math.BigInteger
fun factorial(n: BigInteger): BigInteger {
if (n == BigInteger.ZERO) return BigInteger.ONE
if (n == BigInteger.ONE) return BigInteger.ONE
var prod = BigInteger.ONE
var num = n
while (num > BigInteger.ONE) {
prod *= num
num--
}
return prod
}
fun l... | 664Lah numbers | 11kotlin | fgndo |
null | 659Last letter-first letter | 11kotlin | 2w4li |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.