code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
function a(i) print "Function a(i) called." return i end function b(i) print "Function b(i) called." return i end i = true x = a(i) and b(i); print "" y = a(i) or b(i); print "" i = false x = a(i) and b(i); print "" y = a(i) or b(i)
284Short-circuit evaluation
1lua
jcv71
import Data.Char (ord) import Crypto.Hash.SHA256 (hash) import Data.ByteString (unpack, pack) import Text.Printf (printf) main = putStrLn $ concatMap (printf "%02x") $ unpack $ hash $ pack $ ...
290SHA-256
8haskell
60x3k
int count_divisors(int n) { int i, count = 0; for (i = 1; i * i <= n; ++i) { if (!(n % i)) { if (i == n / i) count++; else count += 2; } } return count; } int main() { int i, next = 1; printf(, MAX); for (i = 1; next <=...
293Sequence: smallest number greater than previous term with exactly n divisors
5c
60a32
var str = 'Rosetta code'; puts(Util.hash(str, {type:'sha1'}));
289SHA-1
9java
rm6g0
require 'prime' prime_array, sppair2, sppair3, sppair4, sppair5 = Array.new(5) {Array.new()} unsexy, i, start = [2], 0, Time.now Prime.each(1_000_100) {|prime| prime_array.push prime} while prime_array[i] < 1_000_035 i+=1 unsexy.push(i) if prime_array[(i+1)..(i+2)].include?(prime_array[i]+6) == false && prime_ar...
286Sexy primes
14ruby
cnd9k
public static boolean inCarpet(long x, long y) { while (x!=0 && y!=0) { if (x % 3 == 1 && y % 3 == 1) return false; x /= 3; y /= 3; } return true; } public static void carpet(final int n) { final double power = Math.pow(3,n); for(long i = 0; i < power; i++) { ...
283Sierpinski carpet
9java
hl5jm
int smallPrimes[LIMIT]; static void sieve() { int i = 2, j; int p = 5; smallPrimes[0] = 2; smallPrimes[1] = 3; while (i < LIMIT) { for (j = 0; j < i; j++) { if (smallPrimes[j] * smallPrimes[j] <= p) { if (p % smallPrimes[j] == 0) { p += 2; ...
294Sequence: nth number with exactly n divisors
5c
ldqcy
typedef unsigned int bitset; int consolidate(bitset *x, int len) { int i, j; for (i = len - 2; i >= 0; i--) for (j = len - 1; j > i; j--) if (x[i] & x[j]) x[i] |= x[j], x[j] = x[--len]; return len; } void show_sets(bitset *x, int len) { bitset b; while(len--) { for (b = 'A'; b <= 'Z'; b++) if (x[le...
295Set consolidation
5c
79drg
null
289SHA-1
11kotlin
vtd21
null
286Sexy primes
15rust
ldfcc
object SexyPrimes { def isPrime(n: Int): Boolean = ! ((2 until n-1) exists (n % _ == 0)) && n > 1 def getSexyPrimesPairs (primes : List[Int]) = { primes .map(n => if(primes.contains(n+6)) (n, n+6)) .filter(p => p != ()) .map{ case (a,b) => (a.toString.toInt, b.toString.toInt)} } ...
286Sexy primes
16scala
uz3v8
sub sierpinski { my ($n) = @_; my @down = '*'; my $space = ' '; foreach (1..$n) { @down = (map("$space$_$space", @down), map("$_ $_", @down)); $space = "$space$space"; } return @down; } print "$_\n" foreach sierpinski 4;
278Sierpinski triangle
2perl
7c7rh
<!DOCTYPE html PUBLIC "-
283Sierpinski carpet
10javascript
a4j10
from itertools import product, combinations from random import sample features = [ 'green purple red'.split(), 'one two three'.split(), 'oval diamond squiggle'.split(), 'open striped solid'.split() ] deck = list(product(list(range(3)), repeat=4)) dealt = 9 def printcard(card...
291Set puzzle
3python
46f5k
int count_divisors(int n) { int i, count = 0; for (i = 1; i * i <= n; ++i) { if (!(n % i)) { if (i == n / i) count++; else count += 2; } } return count; } int main() { int i, k, n, seq[MAX]; for (i = 0; i < MAX; ++i) seq[i]...
296Sequence: smallest number with exactly n divisors
5c
fw7d3
const crypto = require('crypto'); const msg = 'Rosetta code'; const hash = crypto.createHash('sha256').update(msg).digest('hex'); console.log(hash);
290SHA-256
9java
nabih
const crypto = require('crypto'); const msg = 'Rosetta code'; const hash = crypto.createHash('sha256').update(msg).digest('hex'); console.log(hash);
290SHA-256
10javascript
3swz0
(defn consolidate-linked-sets [sets] (apply clojure.set/union sets)) (defn linked? [s1 s2] (not (empty? (clojure.set/intersection s1 s2)))) (defn consolidate [& sets] (loop [seeds sets sets sets] (if (empty? seeds) sets (let [s0 (first seeds) linked (filter #(linked? s0...
295Set consolidation
6clojure
pu6bd
sub dice5 { 1+int rand(5) } sub dice7 { while(1) { my $d7 = (5*dice5()+dice5()-6) % 8; return $d7 if $d7; } } my %count7; my $n = 1000000; $count7{dice7()}++ for 1..$n; printf "%s:%5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
292Seven-sided dice from five-sided dice
2perl
moxyz
package main import "fmt" func main() { for i := 0; i < 16; i++ { for j := 32 + i; j < 128; j += 16 { k := string(j) switch j { case 32: k = "Spc" case 127: k = "Del" } fmt.Printf("%3d:%-3s ", j, k) ...
288Show ASCII table
0go
60s3p
int main(void) { mpz_t p, s; mpz_init_set_ui(p, 1); mpz_init_set_ui(s, 1); for (int n = 1, i = 0; i < 20; n++) { mpz_nextprime(s, s); mpz_mul(p, p, s); mpz_add_ui(p, p, 1); if (mpz_probab_prime_p(p, 25)) { mpz_sub_ui(p, p, 1); gmp_printf(, n); ...
297Sequence of primorial primes
5c
0k2st
null
290SHA-256
11kotlin
shrq7
package main import "fmt" func countDivisors(n int) int { count := 0 for i := 1; i*i <= n; i++ { if n%i == 0 { if i == n/i { count++ } else { count += 2 } } } return count } func main() { const max = 15 fmt.Pr...
293Sequence: smallest number greater than previous term with exactly n divisors
0go
pumbg
#!/usr/bin/lua local sha1 = require "sha1" for i, str in ipairs{"Rosetta code", "Rosetta Code"} do print(string.format("SHA-1(%q) =%s", str, sha1(str))) end
289SHA-1
1lua
uzfvl
class ShowAsciiTable { static void main(String[] args) { for (int i = 32; i <= 127; i++) { if (i == 32 || i == 127) { String s = i == 32 ? "Spc": "Del" printf("%3d:%s ", i, s) } else { printf("%3d:%c ", i, i) } ...
288Show ASCII table
7groovy
dean3
<?php function sierpinskiTriangle($order) { $char = ' $n = 1 << $order; $line = array(); for ($i = 0 ; $i <= 2 * $n ; $i++) { $line[$i] = ' '; } $line[$n] = $char; for ($i = 0 ; $i < $n ; $i++) { echo implode('', $line), PHP_EOL; $u = $char; for ($j = $n - $i...
278Sierpinski triangle
12php
fxfdh
null
283Sierpinski carpet
11kotlin
46c57
COLORS = %i(red green purple) SYMBOLS = %i(oval squiggle diamond) NUMBERS = %i(one two three) SHADINGS = %i(solid open striped) DECK = COLORS.product(SYMBOLS, NUMBERS, SHADINGS) def get_all_sets(hand) hand.combination(3).select do |candidate| grouped_features = candidate.flatten.group_by{|f| f} grouped...
291Set puzzle
14ruby
rmzgs
struct RealSet { bool(*contains)(struct RealSet*, struct RealSet*, double); struct RealSet *left; struct RealSet *right; double low, high; }; typedef enum { CLOSED, LEFT_OPEN, RIGHT_OPEN, BOTH_OPEN, } RangeType; double length(struct RealSet *self) { const double interval = 0.00001;...
298Set of real numbers
5c
de4nv
package main import ( "fmt" "math" "math/big" ) var bi = new(big.Int) func isPrime(n int) bool { bi.SetUint64(uint64(n)) return bi.ProbablyPrime(0) } func generateSmallPrimes(n int) []int { primes := make([]int, n) primes[0] = 2 for i, count := 3, 1; count < n; i += 2 { if is...
294Sequence: nth number with exactly n divisors
0go
x72wf
#!/usr/bin/lua require "sha2" print(sha2.sha256hex("Rosetta code"))
290SHA-256
1lua
0k7sd
import Text.Printf (printf) sequence_A069654 :: [(Int,Int)] sequence_A069654 = go 1 $ (,) <*> countDivisors <$> [1..] where go t ((n,c):xs) | c == t = (t,n):go (succ t) xs | otherwise = go t xs countDivisors n = foldr f 0 [1..floor $ sqrt $ realToFrac n] where f x r | n `mod` ...
293Sequence: smallest number greater than previous term with exactly n divisors
8haskell
fwkd1
from random import randint def dice5(): return randint(1, 5) def dice7(): r = dice5() + dice5() * 5 - 6 return (r% 7) + 1 if r < 21 else dice7()
292Seven-sided dice from five-sided dice
3python
9iqmf
dice5 <- function(n=1) sample(5, n, replace=TRUE)
292Seven-sided dice from five-sided dice
13r
3sazt
import Data.Char (chr) import Data.List (transpose) import Data.List.Split (chunksOf) import Text.Printf (printf) asciiTable :: String asciiTable = unlines $ (printf "%-12s" =<<) <$> transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127]) asciiEntry :: Int -> String asciiEntry n | null k = k | ...
288Show ASCII table
8haskell
jc97g
local function carpet(n, f) print("n = " .. n) local function S(x, y) if x==0 or y==0 then return true elseif x%3==1 and y%3==1 then return false end return S(x//3, y//3) end for y = 0, 3^n-1 do for x = 0, 3^n-1 do io.write(f(S(x, y))) end print() end print() end for n = 0, 4 ...
283Sierpinski carpet
1lua
gyl4j
use itertools::Itertools; use rand::Rng; const DECK_SIZE: usize = 81; const NUM_ATTRIBUTES: usize = 4; const ATTRIBUTES: [&[&str]; NUM_ATTRIBUTES] = [ &["red", "green", "purple"], &["one", "two", "three"], &["oval", "squiggle", "diamond"], &["solid", "open", "striped"], ]; fn get_random_card_indexes(n...
291Set puzzle
15rust
793rc
(ns example (:gen-class)) (def primes (iterate #(.nextProbablePrime %) (biginteger 2))) (defn primorial-prime? [v] " Test if value is a primorial prime " (let [a (biginteger (inc v)) b (biginteger (dec v))] (or (.isProbablePrime a 16) (.isProbablePrime b 16)))) (println (take 20 (keep-index...
297Sequence of primorial primes
6clojure
degnb
import Control.Monad (guard) import Math.NumberTheory.ArithmeticFunctions (divisorCount) import Math.NumberTheory.Primes (Prime, unPrime) import Math.NumberTheory.Primes.Testing (isPrime) calc :: Integer -> [(Integer, Integer)] calc n = ...
294Sequence: nth number with exactly n divisors
8haskell
y8a66
package main import "fmt" func countDivisors(n int) int { count := 0 for i := 1; i*i <= n; i++ { if n%i == 0 { if i == n/i { count++ } else { count += 2 } } } return count } func main() { const max = 15 seq :=...
296Sequence: smallest number with exactly n divisors
0go
jcd7d
public class AntiPrimesPlus { static int count_divisors(int n) { int count = 0; for (int i = 1; i * i <= n; ++i) { if (n % i == 0) { if (i == n / i) count++; else count += 2; } } return c...
293Sequence: smallest number greater than previous term with exactly n divisors
9java
0k4se
import java.math.BigInteger; import java.util.ArrayList; import java.util.List; public class SequenceNthNumberWithExactlyNDivisors { public static void main(String[] args) { int max = 45; smallPrimes(max); for ( int n = 1; n <= max ; n++ ) { System.out.printf("A073916(%d) =%s%n...
294Sequence: nth number with exactly n divisors
9java
dejn9
import Data.List (find, group, sort) import Data.Maybe (mapMaybe) import Data.Numbers.Primes (primeFactors) a005179 :: [Int] a005179 = mapMaybe ( \n -> find ((n ==) . succ . length . properDivisors) [1 ..] ) [1 ..] main :: IO () main = print $ take 15 a005179 properDivi...
296Sequence: smallest number with exactly n divisors
8haskell
op58p
null
293Sequence: smallest number greater than previous term with exactly n divisors
11kotlin
egla4
(ns rosettacode.real-set) (defn >=|<= [lo hi] #(<= lo % hi)) (defn >|< [lo hi] #(< lo % hi)) (defn >=|< [lo hi] #(and (<= lo %) (< % hi))) (defn >|<= [lo hi] #(and (< lo %) (<= % hi))) (def some-fn) (def every-pred) (defn ([s1] s1) ([s1 s2] #(and (s1 %) (not (s2 %)))) ([s1 s2 s3] #(and (s1 %)...
298Set of real numbers
6clojure
60h3q
null
294Sequence: nth number with exactly n divisors
11kotlin
0k5sf
(() => { 'use strict';
296Sequence: smallest number with exactly n divisors
10javascript
8bu0l
require './distcheck.rb' def d5 1 + rand(5) end def d7 loop do d55 = 5*d5 + d5 - 6 return (d55 % 7 + 1) if d55 < 21 end end distcheck(1_000_000) {d5} distcheck(1_000_000) {d7}
292Seven-sided dice from five-sided dice
14ruby
ld0cl
import scala.util.Random object SevenSidedDice extends App { private val rnd = new Random private def seven = { var v = 21 def five = 1 + rnd.nextInt(5) while (v > 20) v = five + five * 5 - 6 1 + v % 7 } println("Random number from 1 to 7: " + seven) }
292Seven-sided dice from five-sided dice
16scala
53nut
public class ShowAsciiTable { public static void main(String[] args) { for ( int i = 32 ; i <= 127 ; i++ ) { if ( i == 32 || i == 127 ) { String s = i == 32 ? "Spc" : "Del"; System.out.printf("%3d:%s ", i, s); } else { Syst...
288Show ASCII table
9java
uztvv
import java.util.Arrays; public class OEIS_A005179 { static int count_divisors(int n) { int count = 0; for (int i = 1; i * i <= n; ++i) { if (n % i == 0) { if (i == n / i) count++; else count += 2; } ...
296Sequence: smallest number with exactly n divisors
9java
wr9ej
use strict; use warnings; use ntheory 'divisors'; print "First 15 terms of OEIS: A069654\n"; my $m = 0; for my $n (1..15) { my $l = $m; while (++$l) { print("$l "), $m = $l, last if $n == divisors($l); } }
293Sequence: smallest number greater than previous term with exactly n divisors
2perl
cnq9a
(() => { "use strict";
288Show ASCII table
10javascript
79mrd
(import '[java.util Date]) (import '[clojure.lang Reflector]) (def date1 (Date.)) (def date2 (Date.)) (def method "equals") (Reflector/invokeMethod date1 method (object-array [date2])) (eval `(. date1 ~(symbol method) date2))
299Send an unknown method call
6clojure
0kcsj
package main import ( "fmt" "math/big" ) func main() { one := big.NewInt(1) pm := big.NewInt(1)
297Sequence of primorial primes
0go
uzqvt
use strict; use warnings; use bigint; use ntheory <nth_prime is_prime divisors>; my $limit = 20; print "First $limit terms of OEIS:A073916\n"; for my $n (1..$limit) { if ($n > 4 and is_prime($n)) { print nth_prime($n)**($n-1) . ' '; } else { my $i = my $x = 0; while (1) { ...
294Sequence: nth number with exactly n divisors
2perl
53ou2
package main import "fmt" type set map[string]bool var testCase = []set{ set{"H": true, "I": true, "K": true}, set{"A": true, "B": true}, set{"C": true, "D": true}, set{"D": true, "B": true}, set{"F": true, "G": true, "H": true}, } func main() { fmt.Println(consolidate(testCase)) } func con...
295Set consolidation
0go
de7ne
static const char *payload_text[] = { , to , from , cc , , , , , , , , , , NULL }; struct upload_status { int lines_read; }; static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp) { struct upload_status *upload_ctx = (struct upload_status *)userp; const...
300Send email
5c
x76wu
package main import ( "fmt" "reflect" ) type example struct{}
299Send an unknown method call
0go
9ibmt
import Data.List (scanl1, elemIndices, nub) primes :: [Integer] primes = 2: filter isPrime [3,5 ..] isPrime :: Integer -> Bool isPrime = isPrime_ primes where isPrime_ :: [Integer] -> Integer -> Bool isPrime_ (p:ps) n | p * p > n = True | n `mod` p == 0 = False | otherwise = isPrime_ ps n ...
297Sequence of primorial primes
8haskell
wrmed
def divisors(n): divs = [1] for ii in range(2, int(n ** 0.5) + 3): if n% ii == 0: divs.append(ii) divs.append(int(n / ii)) divs.append(n) return list(set(divs)) def is_prime(n): return len(divisors(n)) == 2 def primes(): ii = 1 while True: ii += 1 ...
294Sequence: nth number with exactly n divisors
3python
46i5k
import Data.List (intersperse, intercalate) import qualified Data.Set as S consolidate :: Ord a => [S.Set a] -> [S.Set a] consolidate = foldr comb [] where comb s_ [] = [s_] comb s_ (s:ss) | S.null (s `S.intersection` s_) = s: comb s_ ss | otherwise = comb (s `S.union` s_) ss main :: IO () ...
295Set consolidation
8haskell
538ug
null
296Sequence: smallest number with exactly n divisors
11kotlin
bvzkb
sub a { print 'A'; return $_[0] } sub b { print 'B'; return $_[0] } sub test { for my $op ('&&','||') { for (qw(1,1 1,0 0,1 0,0)) { my ($x,$y) = /(.),(.)/; print my $str = "a($x) $op b($y)", ': '; eval $str; print "\n"; } } } test();
284Short-circuit evaluation
2perl
fwsd7
class Example { def foo(value) { "Invoked with '$value'" } } def example = new Example() def method = "foo" def arg = "test value" assert "Invoked with 'test value'" == example."$method"(arg)
299Send an unknown method call
7groovy
zqrt5
import java.math.BigInteger; public class PrimorialPrimes { final static int sieveLimit = 1550_000; static boolean[] notPrime = sieve(sieveLimit); public static void main(String[] args) { int count = 0; for (int i = 1; i < 1000_000 && count < 20; i++) { BigInteger b = primori...
297Sequence of primorial primes
9java
k2fhm
import java.util.*; public class SetConsolidation { public static void main(String[] args) { List<Set<Character>> h1 = hashSetList("AB", "CD"); System.out.println(consolidate(h1)); List<Set<Character>> h2 = hashSetList("AB", "BD"); System.out.println(consolidateR(h2)); Li...
295Set consolidation
9java
9iemu
use strict ; use warnings ; use Digest::SHA qw( sha256_hex ) ; my $digest = sha256_hex my $phrase = "Rosetta code" ; print "SHA-256('$phrase'): $digest\n" ;
290SHA-256
2perl
uzdvr
use Digest::SHA qw(sha1_hex); print sha1_hex('Rosetta Code'), "\n";
289SHA-1
2perl
0kjs4
(require '[postal.core:refer [send-message]]) (send-message {:host "smtp.gmail.com" :ssl true :user your_username :pass your_password} {:from "you@yourdomain.com" :to ["your_friend@example.com"] :cc ["bob@builder.com" "dora@explorer.co...
300Send email
6clojure
opl8j
import java.lang.reflect.Method; class Example { public int foo(int x) { return 42 + x; } } public class Main { public static void main(String[] args) throws Exception { Object example = new Example(); String name = "foo"; Class<?> clazz = example.getClass(); Method meth = clazz.getMethod(na...
299Send an unknown method call
9java
gys4m
example = new Object; example.foo = function(x) { return 42 + x; }; name = "foo"; example[name](5) # => 47
299Send an unknown method call
10javascript
k2nhq
null
297Sequence of primorial primes
11kotlin
gy84d
(() => { 'use strict';
295Set consolidation
10javascript
uz0vb
<?php echo hash('sha256', 'Rosetta code');
290SHA-256
12php
8bj0m
def divisors(n): divs = [1] for ii in range(2, int(n ** 0.5) + 3): if n% ii == 0: divs.append(ii) divs.append(int(n / ii)) divs.append(n) return list(set(divs)) def sequence(max_n=None): previous = 0 n = 0 while True: n += 1 ii = previous ...
293Sequence: smallest number greater than previous term with exactly n divisors
3python
ldscv
<?php $string = 'Rosetta Code'; echo sha1( $string ), ; ?>
289SHA-1
12php
53tus
null
288Show ASCII table
11kotlin
9iomh
package main import ( "fmt" "strings" ) func main() { s := "abracadabra" ss := []byte(s) var ixs []int for ix, c := range s { if c == 'a' { ixs = append(ixs, ix) } } repl := "ABaCD" for i := 0; i < 5; i++ { ss[ixs[i]] = repl[i] } s = stri...
301Selectively replace multiple instances of a character within a string
0go
15dp5
package main import "fmt" type Set func(float64) bool func Union(a, b Set) Set { return func(x float64) bool { return a(x) || b(x) } } func Inter(a, b Set) Set { return func(x float64) bool { return a(x) && b(x) } } func Diff(a, b Set) Set { return func(x float64) bool { return a(x) && !b(x) } } func...
298Set of real numbers
0go
79or2
null
299Send an unknown method call
11kotlin
2fali
local example = { } function example:foo (x) return 42 + x end local name = "foo" example[name](example, 5)
299Send an unknown method call
1lua
vte2x
def isPrime(n) return false if n < 2 return n == 2 if n % 2 == 0 return n == 3 if n % 3 == 0 k = 5 while k * k <= n return false if n % k == 0 k = k + 2 end return true end def getSmallPrimes(numPrimes) smallPrimes = [2] count = 0 n = 3 while count < numPri...
294Sequence: nth number with exactly n divisors
14ruby
rmdgs
divisorCount <- function(n) length(Filter(function(x) n %% x == 0, seq_len(n %/% 2))) + 1 A06954 <- function(terms) { out <- 1 while((resultCount <- length(out)) != terms) { n <- resultCount + 1 out[n] <- out[resultCount] while(divisorCount(out[n]) != n) out[n] <- out[n] + 1 } out } print(A06954(1...
293Sequence: smallest number greater than previous term with exactly n divisors
13r
y8e6h
use strict; use warnings; use feature 'say'; sub transmogrify { my($str, %sub) = @_; for my $l (keys %sub) { $str =~ s/$l/$_/ for split '', $sub{$l}; $str =~ s/_/$l/g; } $str } my $word = 'abracadabra'; say "$word -> " . transmogrify $word, 'a' => 'AB_CD', 'r' => '_F', 'b' => 'E';
301Selectively replace multiple instances of a character within a string
2perl
ldbc5
import Data.List import Data.Maybe data BracketType = OpenSub | ClosedSub deriving (Show, Enum, Eq, Ord) data RealInterval = RealInterval {left :: BracketType, right :: BracketType, lowerBound :: Double, upperBound :: Double} deriving (Eq) type RealSet = [RealInterval] posInf = 1.0/0.0 :: Double negInf...
298Set of real numbers
8haskell
8b20z
use ntheory ":all"; my $i = 0; for (1..1e6) { my $n = pn_primorial($_); if (is_prime($n-1) || is_prime($n+1)) { print "$_\n"; last if ++$i >= 20; } }
297Sequence of primorial primes
2perl
na4iw
null
295Set consolidation
11kotlin
zqkts
use strict; use warnings; use ntheory 'divisors'; print "First 15 terms of OEIS: A005179\n"; for my $n (1..15) { my $l = 0; while (++$l) { print "$l " and last if $n == divisors($l); } }
296Sequence: smallest number with exactly n divisors
2perl
60b36
import hashlib h = hashlib.sha1() h.update(bytes(, encoding=)) h.hexdigest()
289SHA-1
3python
8bh0o
null
288Show ASCII table
1lua
cni92
def sierpinski(n): d = [] for i in xrange(n): sp = * (2 ** i) d = [sp+x+sp for x in d] + [x++x for x in d] return d print .join(sierpinski(4))
278Sierpinski triangle
3python
jlj7p
from collections import defaultdict rep = {'a': {1: 'A', 2: 'B', 4: 'C', 5: 'D'}, 'b': {1: 'E'}, 'r': {2: 'F'}} def trstring(oldstring, repdict): seen, newchars = defaultdict(lambda:1, {}), [] for c in oldstring: i = seen[c] newchars.append(repdict[c][i] if c in repdict and i in repdict[c] els...
301Selectively replace multiple instances of a character within a string
3python
2fplz
package Example; sub new { bless {} } sub foo { my ($self, $x) = @_; return 42 + $x; } package main; my $name = "foo"; print Example->new->$name(5), "\n";
299Send an unknown method call
2perl
sh9q3
null
295Set consolidation
1lua
3sbzo
def divisors(n): divs = [1] for ii in range(2, int(n ** 0.5) + 3): if n% ii == 0: divs.append(ii) divs.append(int(n / ii)) divs.append(n) return list(set(divs)) def sequence(max_n=None): n = 0 while True: n += 1 ii = 0 if max_n is not Non...
296Sequence: smallest number with exactly n divisors
3python
y8p6q
>>> import hashlib >>> hashlib.sha256( .encode() ).hexdigest() '764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf' >>>
290SHA-256
3python
53fux
library(digest) input <- "Rosetta code" cat(digest(input, algo = "sha256", serialize = FALSE), "\n")
290SHA-256
13r
ldoce
require 'prime' def num_divisors(n) n.prime_division.inject(1){|prod, (_p,n)| prod *= (n + 1) } end seq = Enumerator.new do |y| cur = 0 (1..).each do |i| if num_divisors(i) == cur + 1 then y << i cur += 1 end end end p seq.take(15)
293Sequence: smallest number greater than previous term with exactly n divisors
14ruby
vt82n
library(digest) input <- "Rosetta Code" cat(digest(input, algo = "sha1", serialize = FALSE), "\n")
289SHA-1
13r
x7gw2