code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
echo time(), ; | 161System time | 12php | ixlov |
(() => {
"use strict"; | 162Sum of elements below main diagonal of matrix | 10javascript | s16qz |
let setA: Set<String> = ["John", "Bob", "Mary", "Serena"]
let setB: Set<String> = ["Jim", "Mary", "John", "Bob"]
println(setA.exclusiveOr(setB)) | 159Symmetric difference | 17swift | juo74 |
>>> while True:
k = float(input('K? '))
print(
% (k, k - 273.15, k * 1.8 - 459.67, k * 1.8))
K? 21.0
21 Kelvin = -252.15 Celsius = -421.87 Fahrenheit = 37.8 Rankine degrees.
K? 222.2
222.2 Kelvin = -50.95 Celsius = -59.71 Fahrenheit = 399.96 Rankine degrees.
K? | 157Temperature conversion | 3python | 26wlz |
convert_Kelvin <- function(K){
if (!is.numeric(K))
stop("\n Input has to be numeric")
return(list(
Kelvin = K,
Celsius = K - 273.15,
Fahreneit = K * 1.8 - 459.67,
Rankine = K * 1.8
))
}
convert_Kelvin(21) | 157Temperature conversion | 13r | mfpy4 |
use strict;
use warnings;
use List::Util qw( sum );
my $matrix =
[[1,3,7,8,10],
[2,4,16,14,4],
[3,1,9,18,11],
[12,14,17,18,20],
[7,1,3,9,5]];
my $lowersum = sum map @{ $matrix->[$_] }[0 .. $_ - 1], 1 .. $
print "lower sum = $lowersum\n"; | 162Sum of elements below main diagonal of matrix | 2perl | zo5tb |
package main
import "fmt"
type pair struct{ x, y int }
func main() { | 163Sum and product puzzle | 0go | f02d0 |
import time
print time.ctime() | 161System time | 3python | glx4h |
import Data.List (intersect)
s1, s2, s3, s4 :: [(Int, Int)]
s1 = [(x, y) | x <- [1 .. 100], y <- [1 .. 100], 1 < x && x < y && x + y < 100]
add, mul :: (Int, Int) -> Int
add (x, y) = x + y
mul (x, y) = x * y
sumEq, mulEq :: (Int, Int) -> [(Int, Int)]
sumEq p = filter (\q -> add q == add p) s1
mulEq p = filter (\q ->... | 163Sum and product puzzle | 8haskell | 4ca5s |
Sys.time() | 161System time | 13r | vy127 |
package org.rosettacode;
import java.util.ArrayList;
import java.util.List;
public class SumAndProductPuzzle {
private final long beginning;
private final int maxSum;
private static final int MIN_VALUE = 2;
private List<int[]> firstConditionExcludes = new ArrayList<>();
private List<int[]> secon... | 163Sum and product puzzle | 9java | czj9h |
from numpy import array, tril, sum
A = [[1,3,7,8,10],
[2,4,16,14,4],
[3,1,9,18,11],
[12,14,17,18,20],
[7,1,3,9,5]]
print(sum(tril(A, -1))) | 162Sum of elements below main diagonal of matrix | 3python | 3i4zc |
mat <- rbind(c(1,3,7,8,10),
c(2,4,16,14,4),
c(3,1,9,18,11),
c(12,14,17,18,20),
c(7,1,3,9,5))
print(sum(mat[lower.tri(mat)])) | 162Sum of elements below main diagonal of matrix | 13r | ds2nt |
(function () {
'use strict'; | 163Sum and product puzzle | 10javascript | 591ur |
module TempConvert
FROM_TEMP_SCALE_TO_K =
{'kelvin' => lambda{|t| t},
'celsius' => lambda{|t| t + 273.15},
'fahrenheit' => lambda{|t| (t + 459.67) * 5/9.0},
'rankine' => lambda{|t| t * 5/9.0},
'delisle' => lambda{|t| 373.15 - t * 2/3.0},
'newton' => lambda{|t| t * 100/33.0 + 273.15... | 157Temperature conversion | 14ruby | umqvz |
object TemperatureConversion extends App {
def kelvinToCelsius(k: Double) = k + 273.15
def kelvinToFahrenheit(k: Double) = k * 1.8 - 459.67
def kelvinToRankine(k: Double) = k * 1.8
if (args.length == 1) {
try {
val kelvin = args(0).toDouble
if (kelvin >= 0) {
println(f"K $kelvin%2.2... | 157Temperature conversion | 16scala | r2ogn |
arr = [
[ 1, 3, 7, 8, 10],
[ 2, 4, 16, 14, 4],
[ 3, 1, 9, 18, 11],
[12, 14, 17, 18, 20],
[ 7, 1, 3, 9, 5]
]
p arr.each_with_index.sum {|row, x| row[0, x].sum} | 162Sum of elements below main diagonal of matrix | 14ruby | ydr6n |
fn main() -> std::io::Result<()> {
print!("Enter temperature in Kelvin to convert: ");
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
match input.trim().parse::<f32>() {
Ok(kelvin) => {
if kelvin < 0.0 {
println!("Negative Kelvin values are no... | 157Temperature conversion | 15rust | 59suq |
t = Time.now
puts t
puts t.to_i
puts t.to_f
puts Time.now.to_r | 161System time | 14ruby | 7vsri |
null | 163Sum and product puzzle | 11kotlin | 3i5z5 |
null | 161System time | 15rust | ju072 |
println(new java.util.Date) | 161System time | 16scala | bgik6 |
function print_count(t)
local cnt = 0
for k,v in pairs(t) do
cnt = cnt + 1
end
print(cnt .. ' candidates')
end
function make_pair(a,b)
local t = {}
table.insert(t, a) | 163Sum and product puzzle | 1lua | 6n439 |
func KtoC(kelvin: Double)->Double{
return kelvin-273.15
}
func KtoF(kelvin: Double)->Double{
return ((kelvin-273.15)*1.8)+32
}
func KtoR(kelvin: Double)->Double{
return ((kelvin-273.15)*1.8)+491.67
}
var k | 157Temperature conversion | 17swift | vyx2r |
package main
import (
"fmt"
"math/big"
"strconv"
"strings"
)
var suffixes = " KMGTPEZYXWVU"
var ggl = googol()
func googol() *big.Float {
g1 := new(big.Float).SetPrec(500)
g1.SetInt64(10000000000)
g := new(big.Float)
g.Set(g1)
for i := 2; i <= 10; i++ {
g.Mul(g, g1)
}
... | 164Suffixation of decimal numbers | 0go | mfgyi |
use List::Util qw(min max first);
sub sufficate {
my($val, $type, $round) = @_;
$type //= 'M';
if ($type =~ /^\d$/) { $round = $type; $type = 'M' }
my $s = '';
if (substr($val,0,1) eq '-') { $s = '-'; $val = substr $val, 1 }
$val =~ s/,//g;
if ($val =~ m/e/i) {
my ($m,$e) = split /[... | 164Suffixation of decimal numbers | 2perl | qptx6 |
use List::Util qw(none);
sub grep_unique {
my($by, @list) = @_;
my @seen;
for (@list) {
my $x = &$by(@$_);
$seen[$x]= defined $seen[$x] ? 0 : join ' ', @$_;
}
grep { $_ } @seen;
}
sub sums {
my($n) = @_;
my @sums;
push @sums, [$_, $n - $_] for 2 .. int $n/2;
@sums;
... | 163Sum and product puzzle | 2perl | prob0 |
import math
import os
def suffize(num, digits=None, base=10):
suffixes = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'X', 'W', 'V', 'U', 'googol']
exponent_distance = 10 if base == 2 else 3
num = num.strip().replace(',', '')
num_sign = num[0] if num[0] in '+-' else ''
num = abs(float(num))
... | 164Suffixation of decimal numbers | 3python | s1zq9 |
import Foundation
var = NSDate()
println() | 161System time | 17swift | r2qgg |
from collections import Counter
def decompose_sum(s):
return [(a,s-a) for a in range(2,int(s/2+1))]
all_pairs = set((a,b) for a in range(2,100) for b in range(a+1,100) if a+b<100)
product_counts = Counter(c*d for c,d in all_pairs)
unique_products = set((a,b) for a,b in all_pairs if product_counts[a*b]==1)
s_pa... | 163Sum and product puzzle | 3python | 17ipc |
def add(x,y) x + y end
def mul(x,y) x * y end
def sumEq(s,p) s.select{|q| add(*p) == add(*q)} end
def mulEq(s,p) s.select{|q| mul(*p) == mul(*q)} end
s1 = (a = *2...100).product(a).select{|x,y| x<y && x+y<100}
s2 = s1.select{|p| sumEq(s1,p).all?{|q| mulEq(s1,q).size!= 1} }
s3 = s2.select{|p| (mulEq(s1,p) & s2).size =... | 163Sum and product puzzle | 14ruby | ehdax |
object ImpossiblePuzzle extends App {
type XY = (Int, Int)
val step0 = for {
x <- 1 to 100
y <- 1 to 100
if 1 < x && x < y && x + y < 100
} yield (x, y)
def sum(xy: XY) = xy._1 + xy._2
def prod(xy: XY) = xy._1 * xy._2
def sumEq(xy: XY) = step0 filter { sum(_) == sum(xy) }
def prodEq(xy: XY) =... | 163Sum and product puzzle | 16scala | s13qo |
enum OP { ADD, SUB, JOIN };
typedef int (*cmp)(const void*, const void*);
struct Expression{
int sum;
int code;
}expressions[NUMBER_OF_EXPRESSIONS];
int expressionsLength = 0;
int compareExpressionBySum(const struct Expression* a, const struct Expression* b){
return a->sum - b->sum;
}
struct CountSum... | 165Sum to 100 | 5c | ixyo2 |
double squaredsum(double *l, int e)
{
int i; double sum = 0.0;
for(i = 0 ; i < e ; i++) sum += l[i]*l[i];
return sum;
}
int main()
{
double list[6] = {3.0, 1.0, 4.0, 1.0, 5.0, 9.0};
printf(, squaredsum(list, 6));
printf(, squaredsum(list, 0));
printf(, squaredsum(NULL, 0));
return 0;
} | 166Sum of squares | 5c | vyj2o |
unsigned long long sum35(unsigned long long limit)
{
unsigned long long sum = 0;
for (unsigned long long i = 0; i < limit; i++)
if (!(i % 3) || !(i % 5))
sum += i;
return sum;
}
int main(int argc, char **argv)
{
unsigned long long limit;
if (argc == 2)
limit = strtoull(... | 167Sum multiples of 3 and 5 | 5c | 9t5m1 |
(defn sum-of-squares [v]
(reduce #(+ %1 (* %2 %2)) 0 v)) | 166Sum of squares | 6clojure | r21g2 |
int wideStrLen(wchar_t* str){
int i = 0;
while(str[i++]!=00);
return i;
}
void processFile(char* fileName,char plainKey, char cipherKey,int flag){
FILE* inpFile = fopen(fileName,);
FILE* outFile;
int i,len, diff = (flag==ENCRYPT)?(int)cipherKey - (int)plainKey:(int)plainKey - (int)cipherKey;
wchar_t str[1000... | 168Substitution cipher | 5c | mfvys |
int SumDigits(unsigned long long n, const int base) {
int sum = 0;
for (; n; n /= base)
sum += n % base;
return sum;
}
int main() {
printf(,
SumDigits(1, 10),
SumDigits(12345, 10),
SumDigits(123045, 10),
SumDigits(0xfe, 16),
SumDigits(0xf0e, 16) );
retur... | 169Sum digits of an integer | 5c | 4cj5t |
(defn sum-mults [n & mults]
(let [pred (apply some-fn
(map #(fn [x] (zero? (mod x %))) mults))]
(->> (range n) (filter pred) (reduce +))))
(println (sum-mults 1000 3 5)) | 167Sum multiples of 3 and 5 | 6clojure | umjvi |
int arg[] = { 1,2,3,4,5 };
int arg_length = sizeof(arg)/sizeof(arg[0]);
int *end = arg+arg_length;
int sum = 0, prod = 1;
int *p;
for (p = arg; p!=end; ++p) {
sum += *p;
prod *= *p;
} | 170Sum and product of an array | 5c | 59ruk |
double Invsqr(double n)
{
return 1 / (n*n);
}
int main (int argc, char *argv[])
{
int i, start = 1, end = 1000;
double sum = 0.0;
for( i = start; i <= end; i++)
sum += Invsqr((double)i);
printf(, sum);
return 0;
} | 171Sum of a series | 5c | qp0xc |
(defn sum-digits [n base]
(let [number (if-not (string? n) (Long/toString n base) n)]
(reduce + (map #(Long/valueOf (str %) base) number)))) | 169Sum digits of an integer | 6clojure | h51jr |
sumOfSquares(list) {
var sum=0;
list.forEach((var n) { sum+=(n*n); });
return sum;
}
main() {
print(sumOfSquares([]));
print(sumOfSquares([1,2,3]));
print(sumOfSquares([10]));
} | 166Sum of squares | 18dart | ydu65 |
package main
import (
"fmt"
"strings"
)
var key = "]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ"
func encode(s string) string {
bs := []byte(s)
for i := 0; i < len(bs); i++ {
bs[i] = key[int(bs[i]) - 32]
}
return string(bs)
}
fu... | 168Substitution cipher | 0go | ajs1f |
(defn sum [vals] (reduce + vals))
(defn product [vals] (reduce * vals)) | 170Sum and product of an array | 6clojure | jub7m |
(reduce + (map #(/ 1.0 % %) (range 1 1001))) | 171Sum of a series | 6clojure | ixdom |
int state[55], si = 0, sj = 0;
int subrand();
void subrand_seed(int p1)
{
int i, j, p2 = 1;
state[0] = p1 % MOD;
for (i = 1, j = 21; i < 55; i++, j += 21) {
if (j >= 55) j -= 55;
state[j] = p2;
if ((p2 = p1 - p2) < 0) p2 += MOD;
p1 = state[j];
}
si = 0;
sj = 24;
for (i = 0; i < 165; i++) subrand();
}
... | 172Subtractive generator | 5c | 3i6za |
import Data.Char (chr)
import Data.Maybe (fromMaybe)
import Data.Tuple (swap)
import System.Environment (getArgs)
data Command = Cipher String | Decipher String | Invalid
alphabet :: String
alphabet = chr <$> [32..126]
cipherMap :: [(Char, Char)]
cipherMap = zip alphabet (shuffle 20 alphabet... | 168Substitution cipher | 8haskell | zo9t0 |
public class SubstitutionCipher {
final static String key = "]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N"
+ "[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ";
static String text = "Here we have to do is there will be a input/source "
+ "file in which we are going to Encrypt the f... | 168Substitution cipher | 9java | owt8d |
package main
import (
"fmt"
"sort"
)
const pow3_8 = 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 | 165Sum to 100 | 0go | gl14n |
int64_t PRIMES[PRIME_COUNT];
size_t primeSize = 0;
bool isPrime(int n) {
size_t i = 0;
for (i = 0; i < primeSize; i++) {
int64_t p = PRIMES[i];
if (n == p) {
return true;
}
if (n % p == 0) {
return false;
}
if (p * p > n) {
br... | 173Successive prime differences | 5c | r2rg7 |
import Control.Monad (replicateM)
import Data.Char (intToDigit)
import Data.List
( find,
group,
intercalate,
nub,
sort,
sortBy,
)
import Data.Monoid ((<>))
import Data.Ord (comparing)
data Sign
= Unsigned
| Plus
| Minus
deriving (Eq, Show)
universe :: [[(Int, Sign)]]
universe =
zip... | 165Sum to 100 | 8haskell | s1tqk |
(defn xpat2-with-seed
"produces an xpat2 function initialized from seed"
[seed]
(let [e9 1000000000
fs (fn [[i j]] [j (mod (- i j) e9)])
s (->> [seed 1] (iterate fs) (map first) (take 55) vec)
rinit (map #(-> % inc (* 34) (mod 55) s) (range 55))
r-atom (atom [54 (int-array rinit)])... | 172Subtractive generator | 6clojure | czl9b |
null | 168Substitution cipher | 11kotlin | xbows |
null | 168Substitution cipher | 1lua | qpix0 |
package rosettacode;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class SumTo100 implements Runnable {
public static void main(String[] args) {
... | 165Sum to 100 | 9java | 178p2 |
(function () {
'use strict'; | 165Sum to 100 | 10javascript | qpfx8 |
const int PRIMES[] = {
2, 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, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293,
... | 174Strong and weak primes | 5c | 8as04 |
sub encode {
my $source = shift;
my $key = shift;
my $out = q();
@ka = split //, $key;
foreach $ch (split //, $source) {
$idx = ord($ch) - 32;
$out .= $ka[$idx];
}
return $out;
}
sub decode {
my $source = shift;
my $key = shift;
my $out = q();
foreach $ch ... | 168Substitution cipher | 2perl | 26glf |
main() {
var list = new List<int>.generate(1000, (i) => i + 1);
num sum = 0;
(list.map((x) => 1.0 / (x * x))).forEach((num e) {
sum += e;
});
print(sum);
} | 171Sum of a series | 18dart | prab8 |
<?php
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$key = 'cPYJpjsBlaOEwRbVZIhQnHDWxMXiCtUToLkFrzdAGymKvgNufeSq';
file_put_contents('output.txt', strtr(file_get_contents('input.txt'), $alphabet, $key));
$source = file_get_contents('input.txt');
$encoded = file_get_contents('output.txt')... | 168Substitution cipher | 12php | s1nqs |
null | 165Sum to 100 | 11kotlin | juw7r |
local expressionsLength = 0
function compareExpressionBySum(a, b)
return a.sum - b.sum
end
local countSumsLength = 0
function compareCountSumsByCount(a, b)
return a.counts - b.counts
end
function evaluate(code)
local value = 0
local number = 0
local power = 1
for k=9,1,-1 do
number = p... | 165Sum to 100 | 1lua | h5xj8 |
package main
import "fmt"
func sieve(limit int) []int {
primes := []int{2}
c := make([]bool, limit+1) | 173Successive prime differences | 0go | nqni1 |
int main( int argc, char ** argv ){
const char * str_a = ;
const char * str_b = ;
const char * str_c = ;
char * new_a = malloc( strlen( str_a ) - 1 );
char * new_b = malloc( strlen( str_b ) - 1 );
char * new_c = malloc( strlen( str_c ) - 2 );
strcpy( new_a, str_a + 1 );
strncpy( new_b, str_b, strlen( ... | 175Substring/Top and tail | 5c | spwq5 |
package main
import (
"fmt"
"os"
) | 172Subtractive generator | 0go | bgpkh |
package main
import "fmt"
func sieve(limit int) []bool {
limit++ | 174Strong and weak primes | 0go | 5mvul |
void show(int *x)
{
int i, j;
for (i = 0; i < 9; i++) {
if (!(i % 3)) putchar('\n');
for (j = 0; j < 9; j++)
printf(j % 3 ? : , *x++);
putchar('\n');
}
}
int trycell(int *x, int pos)
{
int row = pos / 9;
int col = pos % 9;
int i, j, used = 0;
if (pos == 81) return 1;
if (x[pos]) return trycell(x, po... | 176Sudoku | 5c | oeq80 |
import Data.Numbers.Primes (primes)
type Result = [(String, [Int])]
oneMillionPrimes :: Integral p => [p]
oneMillionPrimes = takeWhile (<1_000_000) primes
getGroups :: [Int] -> Result
getGroups [] = []
getGroups ps@(n:x:y:z:xs)
| x-n == 6 && y-x == 4 && z-y == 2 = ("(6 4 2)", [n, x, y, z]) : getGroups (... | 173Successive prime differences | 8haskell | umuv2 |
subtractgen :: Int -> [Int]
subtractgen seed = drop 220 out
where
out = mmod $ r <> zipWith (-) out (drop 31 out)
where
r = take 55 $ shuffle $ cycle $ take 55 s
shuffle x = (:) . head <*> shuffle $ drop 34 x
s = mmod $ seed: 1: zipWith (-) s (tail s)
mmod = fmap (`mod` 10 ^ ... | 172Subtractive generator | 8haskell | dsfn4 |
from string import printable
import random
EXAMPLE_KEY = ''.join(sorted(printable, key=lambda _:random.random()))
def encode(plaintext, key):
return ''.join(key[printable.index(char)] for char in plaintext)
def decode(plaintext, key):
return ''.join(printable[key.index(char)] for char in plaintext)
original... | 168Substitution cipher | 3python | vyr29 |
const char *ca = , *cb = ;
int al = 2, bl = 2;
char *loadfile(const char *fn) {
FILE *f = fopen(fn, );
int l;
char *s;
if (f != NULL) {
fseek(f, 0, SEEK_END);
l = ftell(f);
s = malloc(l+1);
rewind(f);
if (s)
fread(s, 1, l, f);
fclose(f);
}
return s;
}
void stripcomments(char *s) {
... | 177Strip block comments | 5c | 1rjpj |
package main
import "fmt"
var v = []float32{1, 2, .5}
func main() {
var sum float32
for _, x := range v {
sum += x * x
}
fmt.Println(sum)
} | 166Sum of squares | 0go | s1fqa |
import Text.Printf (printf)
import Data.Numbers.Primes (primes)
xPrimes :: (Real a, Fractional b) => (b -> b -> Bool) -> [a] -> [a]
xPrimes op ps@(p1:p2:p3:xs)
| realToFrac p2 `op` (realToFrac (p1 + p3) / 2) = p2: xPrimes op (tail ps)
| otherwise = xPrimes op (tail ps)
main :: IO ()
main = do
printf "First 36 ... | 174Strong and weak primes | 8haskell | xkew4 |
void
subleq(int *code)
{
int ip = 0, a, b, c, nextIP;
char ch;
while(0 <= ip) {
nextIP = ip + 3;
a = code[ip];
b = code[ip + 1];
c = code[ip + 2];
if(a == -1) {
scanf(, &ch);
code[b] = (int)ch;
} else if(b == -1) {
printf(, (char)code[a]);
} else {
code[b] -= code[a];
if(code[b] <= 0)
... | 178Subleq | 5c | t08f4 |
def array = 1..3 | 166Sum of squares | 7groovy | aj81p |
public class StrongAndWeakPrimes {
private static int MAX = 10_000_000 + 1000;
private static boolean[] primes = new boolean[MAX];
public static void main(String[] args) {
sieve();
System.out.println("First 36 strong primes:");
displayStrongPrimes(36);
for ( int n :... | 174Strong and weak primes | 9java | b4hk3 |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SuccessivePrimeDifferences {
private static Integer[] sieve(int limit) {
List<Integer> primes = new ArrayList<>();
primes.add(2);
boolean[] c = new boolean[limit + 1]; | 173Successive prime differences | 9java | mfmym |
user=> (subs "knight" 1)
"night"
user=> (subs "socks" 0 4)
"sock"
user=> (.substring "brooms" 1 5)
"room"
user=> (apply str (rest "knight"))
"night"
user=> (apply str (drop-last "socks"))
"sock"
user=> (apply str (rest (drop-last "brooms")))
"room" | 175Substring/Top and tail | 6clojure | nx8ik |
import java.util.function.IntSupplier;
import static java.util.stream.IntStream.generate;
public class SubtractiveGenerator implements IntSupplier {
static final int MOD = 1_000_000_000;
private int[] state = new int[55];
private int si, sj;
public SubtractiveGenerator(int p1) {
subrandSeed(p1... | 172Subtractive generator | 9java | s10q0 |
(defn comment-strip [txt & args]
(let [args (conj {:delim ["/*" "*/"]} (apply hash-map args))
[opener closer] (:delim args)]
(loop [out "", txt txt, delim-count 0]
(let [[hdtxt resttxt] (split-at (count opener) txt)]
(printf "hdtxt=%8s resttxt=%8s out=%8s txt=%16s delim-count=%s\n" (apply str hdtxt) (a... | 177Strip block comments | 6clojure | qb1xt |
versions :: [[Int] -> Int]
versions =
[ sum . fmap (^ 2)
, sum . ((^ 2) <$>)
, foldr ((+) . (^ 2)) 0
]
main :: IO ()
main =
mapM_ print ((`fmap` [[3, 1, 4, 1, 5, 9], [1 .. 6], [], [1]]) <$> versions) | 166Sum of squares | 8haskell | 9t4mo |
private const val MAX = 10000000 + 1000
private val primes = BooleanArray(MAX)
fun main() {
sieve()
println("First 36 strong primes:")
displayStrongPrimes(36)
for (n in intArrayOf(1000000, 10000000)) {
System.out.printf("Number of strong primes below%,d =%,d%n", n, strongPrimesBelow(n))
}
... | 174Strong and weak primes | 11kotlin | rl4go |
(ns rosettacode.sudoku
(:use [clojure.pprint:only (cl-format)]))
(defn- compatible? [m x y n]
(let [n= #(= n (get-in m [%1 %2]))]
(or (n= y x)
(let [c (count m)]
(and (zero? (get-in m [y x]))
(not-any? #(or (n= y %) (n= % x)) (range c))
(let [zx (* c (quot x c)), zy (* c... | 176Sudoku | 6clojure | t0ifv |
use warnings;
use strict;
use feature qw{ say };
my $string = '123456789';
my $length = length $string;
my @possible_ops = ("" , '+', '-');
{
my @ops;
sub Next {
return @ops = (0) x ($length) unless @ops;
my $i = 0;
while ($i < $length) {
if ($ops[$i]++ > $
... | 165Sum to 100 | 2perl | t8lfg |
int main()
{
char str[100]=;
char *cstr=;
char *dup;
sprintf(str,,cstr,(dup=strdup(str)));
free(dup);
printf(,str);
return 0;
} | 179String prepend | 5c | 233lo |
int ascii (const unsigned char c);
int ascii_ext (const unsigned char c);
unsigned char* strip(unsigned char* str, const size_t n, int ext );
int ascii (const unsigned char c)
{
unsigned char min = 32;
unsigned char max = 126;
if ( c>=min && c<=max ) return 1;
return 0;
}
int ascii_ext (con... | 180Strip control codes and extended characters from a string | 5c | pg4by |
char *rtrim(const char *s)
{
while( isspace(*s) || !isprint(*s) ) ++s;
return strdup(s);
}
char *ltrim(const char *s)
{
char *r = strdup(s);
if (r != NULL)
{
char *fr = r + strlen(s) - 1;
while( (isspace(*fr) || !isprint(*fr) || *fr == 0) && fr >= r) --fr;
*++fr = 0;
}
return r;
}
char *trim... | 181Strip whitespace from a string/Top and tail | 5c | wh7ec |
null | 174Strong and weak primes | 1lua | 72gru |
null | 172Subtractive generator | 11kotlin | aje13 |
Alphabet =
Key =
def encrypt(str) = str.tr(Alphabet, Key)
def decrypt(str) = str.tr(Key, Alphabet)
str = 'All is lost, he thought. Everything is ruined. Its ten past three.'
p encrypted = encrypt(str)
p decrypt(encrypted) | 168Substitution cipher | 14ruby | 59juj |
object SubstitutionCipher extends App {
private val key = "]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N" + "[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ"
private val text =
""""It was still dark, in the early morning hours of the twenty-second of December
| 1946, on the second floor of the house a... | 168Substitution cipher | 16scala | 7vpr9 |
int main()
{
char ch, str[100];
int i;
do{
printf();
fgets(str,100,stdin);
for(i=0;str[i]!=00;i++)
{
if(str[i]=='
{
str[i]=00;
break;
}
}
printf(,str);
printf();
scanf(,&ch);
fflush(stdin);
}while(ch=='y'||ch=='Y');
return 0;
} | 182Strip comments from a string | 5c | ctn9c |
function findspds(primelist, diffs)
local results = {}
for i = 1, #primelist-#diffs do
result = {primelist[i]}
for j = 1, #diffs do
if primelist[i+j] - primelist[i+j-1] == diffs[j] then
result[j+1] = primelist[i+j]
else
result = nil
break
end
end
results[#re... | 173Successive prime differences | 1lua | zozty |
function SubGen(seed)
local n, r, s = 54, {}, { [0]=seed, 1 }
for n = 2,54 do s[n] = (s[n-2] - s[n-1]) % 1e9 end
for n = 0,54 do r[n] = s[(34*(n+1))%55] end
local next = function()
n = (n+1) % 55
r[n] = (r[(n-55)%55] - r[(n-24)%55]) % 1e9
return r[n]
end
for n = 55,219 do next() end
return nex... | 172Subtractive generator | 1lua | ehwac |
(defn str-prepend [a-string, to-prepend]
(str to-prepend a-string)) | 179String prepend | 6clojure | gcc4f |
package main
import "fmt"
func main() {
fmt.Println(s35(1000))
}
func s35(n int) int {
n--
threes := n / 3
fives := n / 5
fifteen := n / 15
threes = 3 * threes * (threes + 1)
fives = 5 * fives * (fives + 1)
fifteen = 15 * fifteen * (fifteen + 1)
n = (threes + fives - fifteen) / ... | 167Sum multiples of 3 and 5 | 0go | eh8a6 |
null | 169Sum digits of an integer | 0go | owf8q |
public class SumSquares
{
public static void main(final String[] args)
{
double sum = 0;
int[] nums = {1,2,3,4,5};
for (int i: nums)
sum += i * i;
System.out.println("The sum of the squares is: " + sum);
}
} | 166Sum of squares | 9java | t8cf9 |
(use 'clojure.string)
(triml " my string ")
=> "my string "
(trimr " my string ")
=> " my string"
(trim " \t\r\n my string \t\r\n ")
=> "my string" | 181Strip whitespace from a string/Top and tail | 6clojure | 8ap05 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.