task_url stringlengths 30 116 | task_name stringlengths 2 86 | task_description stringlengths 0 14.4k | language_url stringlengths 2 53 | language_name stringlengths 1 52 | code stringlengths 0 61.9k |
|---|---|---|---|---|---|
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #Kotlin | Kotlin | // version 1.0.6
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-256")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
} |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Go | Go | 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... |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #Lua | Lua | #!/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 |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #PicoLisp | PicoLisp | (de dice5 ()
(rand 1 5) )
(de dice7 ()
(use R
(until (> 21 (setq R (+ (* 5 (dice5)) (dice5) -6))))
(inc (% R 7)) ) ) |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #PureBasic | PureBasic | Procedure dice5()
ProcedureReturn Random(4) + 1
EndProcedure
Procedure dice7()
Protected x
x = dice5() * 5 + dice5() - 6
If x > 20
ProcedureReturn dice7()
EndIf
ProcedureReturn x % 7 + 1
EndProcedure |
http://rosettacode.org/wiki/Sexy_primes | Sexy primes |
This page uses content from Wikipedia. The original article was at Sexy_prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In mathematics, sexy primes are prime numbers that differ from each ot... | #XPL0 | XPL0 | func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
int CU, C2, C3, C4, C5, N, I;
int Unsexy(10), Pairs(5), Trips(5), Quads(5), Quins(... |
http://rosettacode.org/wiki/Sexy_primes | Sexy primes |
This page uses content from Wikipedia. The original article was at Sexy_prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In mathematics, sexy primes are prime numbers that differ from each ot... | #zkl | zkl | var [const] BI=Import("zklBigNum"); // libGMP
const N=1_000_035, M=N+24; // M allows prime group to span N, eg N=100, (97,103)
const OVR=6; // 6 if prime group can NOT span N, else 0
ps,p := Data(M+50).fill(0), BI(1); // slop at the end (for reverse wrap around)
while(p.nextPrime()<=M){ ps[p]=1 } // bitmap of primes
... |
http://rosettacode.org/wiki/Show_ASCII_table | Show ASCII table | Task
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioin... | #Groovy | Groovy | 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)
}
... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #PHP | PHP | <?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 ... |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Kotlin | Kotlin | // version 1.1.2
fun inCarpet(x: Int, y: Int): Boolean {
var xx = x
var yy = y
while (xx != 0 && yy != 0) {
if (xx % 3 == 1 && yy % 3 == 1) return false
xx /= 3
yy /= 3
}
return true
}
fun carpet(n: Int) {
val power = Math.pow(3.0, n.toDouble()).toInt()
for(i in 0... |
http://rosettacode.org/wiki/Short-circuit_evaluation | Short-circuit evaluation | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Assume functions a and b return boolean values, and further, the execution of function b takes considerable resources without side effects, an... | #Nim | Nim | proc a(x): bool =
echo "a called"
result = x
proc b(x): bool =
echo "b called"
result = x
let x = a(false) and b(true) # echoes "a called"
let y = a(true) or b(true) # echoes "a called" |
http://rosettacode.org/wiki/Short-circuit_evaluation | Short-circuit evaluation | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Assume functions a and b return boolean values, and further, the execution of function b takes considerable resources without side effects, an... | #Objeck | Objeck | class ShortCircuit {
function : a(a : Bool) ~ Bool {
"a"->PrintLine();
return a;
}
function : b(b : Bool) ~ Bool {
"b"->PrintLine();
return b;
}
function : Main(args : String[]) ~ Nil {
result := a(false) & b(false);
"F and F = {$result}"->PrintLine();
result := a(false) | b(fa... |
http://rosettacode.org/wiki/Set_puzzle | Set puzzle | Set Puzzles are created with a deck of cards from the Set Game™. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up.
There are 81 cards in a deck.
Each card contains a unique variation of the following four features: color, symbol, number and shading.
there are... | #Ruby | Ruby | COLORS = %i(red green purple) #use [:red, :green, :purple] in Ruby < 2.0
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 = ca... |
http://rosettacode.org/wiki/Set_of_real_numbers | Set of real numbers | All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where a ≤ b. There are actually four cases for the meaning of "between", depending on open or closed boundary:
[a, b]: {x | a ≤ x and x ≤ b }
(a, b): {x | ... | #C | C | #include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
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,
} Range... |
http://rosettacode.org/wiki/Sieve_of_Eratosthenes | Sieve of Eratosthenes | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer.
Task
Implement the Sieve of Eratosthenes algorithm, with the only allowed... | #6502_Assembly | 6502 Assembly | ERATOS: STA $D0 ; value of n
LDA #$00
LDX #$00
SETUP: STA $1000,X ; populate array
ADC #$01
INX
CPX $D0
BPL SET
JMP SETUP
SET: LDX #$02
SIEVE: LDA $1000,X ; find non-zero
INX
CPX $D0
BPL SIEVED
CMP #$00
... |
http://rosettacode.org/wiki/Sequence_of_primorial_primes | Sequence of primorial primes | The sequence of primorial primes is given as the increasing values of n where primorial(n) ± 1 is prime.
Noting that the n'th primorial is defined as the multiplication of the smallest n primes, the sequence is of the number of primes, in order that when multiplied together is one-off being a prime number itself.
T... | #C.2B.2B | C++ | #include <cstdint>
#include <iostream>
#include <sstream>
#include <gmpxx.h>
typedef mpz_class integer;
bool is_probably_prime(const integer& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 25) != 0;
}
bool is_prime(unsigned int n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2... |
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #Go | Go | 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 {
i... |
http://rosettacode.org/wiki/Set_consolidation | Set consolidation | Given two sets of items then if any item is common to any set then the result of applying consolidation to those sets is a set of sets whose contents is:
The two input sets if no common item exists between the two input sets of items.
The single set that is the union of the two input sets if they share a common item... | #D | D | import std.stdio, std.algorithm, std.array;
dchar[][] consolidate(dchar[][] sets) @safe {
foreach (set; sets)
set.sort();
foreach (i, ref si; sets[0 .. $ - 1]) {
if (si.empty)
continue;
foreach (ref sj; sets[i + 1 .. $])
if (!sj.empty && !si.setIntersection(sj... |
http://rosettacode.org/wiki/Sequence:_smallest_number_with_exactly_n_divisors | Sequence: smallest number with exactly n divisors | Calculate the sequence where each term an is the smallest natural number that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: nth number with exactly... | #Factor | Factor | USING: fry kernel lists lists.lazy math math.primes.factors
prettyprint sequences ;
: A005179 ( -- list )
1 lfrom [
1 swap '[ dup divisors length _ = ] [ 1 + ] until
] lmap-lazy ;
15 A005179 ltake list>array . |
http://rosettacode.org/wiki/Sequence:_smallest_number_with_exactly_n_divisors | Sequence: smallest number with exactly n divisors | Calculate the sequence where each term an is the smallest natural number that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: nth number with exactly... | #FreeBASIC | FreeBASIC | #define UPTO 15
function divisors(byval n as ulongint) as uinteger
'find the number of divisors of an integer
dim as integer r = 2, i
for i = 2 to n\2
if n mod i = 0 then r += 1
next i
return r
end function
dim as ulongint i = 2
dim as integer n, nfound = 1, sfound(UPTO) = {1}
while nf... |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #Lasso | Lasso | // The following will return a list of all the cipher
// algorithms supported by the installation of Lasso
cipher_list
// With a -digest parameter the method will limit the returned list
// to all of the digest algorithms supported by the installation of Lasso
cipher_list(-digest)
// return the SHA-256 digest. Dep... |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #Lua | Lua | #!/usr/bin/lua
require "sha2"
print(sha2.sha256hex("Rosetta code")) |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Haskell | Haskell | 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`... |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #J | J |
sieve=: 3 :0
NB. sieve y returns a vector of y boxes.
NB. In each box is an array of 2 columns.
NB. The first column is the factor tally
NB. and the second column is a number with
NB. that many factors.
NB. Rather than factoring, the algorithm
NB. counts prime seive cell hits.
NB. The boxes are not ordered b... |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #Maple | Maple | with(StringTools):
Hash("Ars longa, vita brevis",method="SHA1");
# "e640d285242886eb96ab80cbf858389b3df52f43" |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Hash["Rosetta code","SHA1","HexString"] |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Python | Python | 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() |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Quackery | Quackery | [ 5 random 1+ ] is dice5 ( --> n )
[ dice5 5 *
dice5 + 6 -
[ table
0 0 0 0 1
1 1 2 2 2
3 3 3 4 4
4 5 5 5 6
6 6 7 7 7 ]
dup 0 = iff
drop again ] is dice7 ( --> n ) |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #R | R | dice5 <- function(n=1) sample(5, n, replace=TRUE) |
http://rosettacode.org/wiki/Show_ASCII_table | Show ASCII table | Task
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioin... | #Haskell | Haskell | import Data.Char (chr)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
----------------------- ASCII TABLE ----------------------
asciiTable :: String
asciiTable =
unlines $
(printf "%-12s" =<<)
<$> transpose
(chunksOf 16 $ asciiEntry <$> [32 .. 127])
... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Picat | Picat | go =>
foreach(N in 1..4)
sierpinski(N),
nl
end,
nl.
sierpinski(N) =>
Size = 2**N,
foreach(Y in Size-1..-1..0)
printf("%s", [' ' : _I in 1..Y]),
foreach(X in 0..Size-Y-1)
printf("%s ", cond(X /\ Y == 0, "*", " "))
end,
nl
end. |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Lua | Lua | 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... |
http://rosettacode.org/wiki/Short-circuit_evaluation | Short-circuit evaluation | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Assume functions a and b return boolean values, and further, the execution of function b takes considerable resources without side effects, an... | #OCaml | OCaml | let a r = print_endline " > function a called"; r
let b r = print_endline " > function b called"; r
let test_and b1 b2 =
Printf.printf "# testing (%b && %b)\n" b1 b2;
ignore (a b1 && b b2)
let test_or b1 b2 =
Printf.printf "# testing (%b || %b)\n" b1 b2;
ignore (a b1 || b b2)
let test_this test =
test t... |
http://rosettacode.org/wiki/Set_puzzle | Set puzzle | Set Puzzles are created with a deck of cards from the Set Game™. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up.
There are 81 cards in a deck.
Each card contains a unique variation of the following four features: color, symbol, number and shading.
there are... | #Rust | Rust |
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_index... |
http://rosettacode.org/wiki/Set_puzzle | Set puzzle | Set Puzzles are created with a deck of cards from the Set Game™. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up.
There are 81 cards in a deck.
Each card contains a unique variation of the following four features: color, symbol, number and shading.
there are... | #Tailspin | Tailspin |
def deck: [ { by 1..3 -> (colour: $),
by 1..3 -> (symbol: $),
by 1..3 -> (number: $),
by 1..3 -> (shading: $)}
];
templates deal
@: $deck;
[ 1..$ -> \($@deal::length -> SYS::randomInt -> ^@deal($ + 1) !\)] !
end deal
templates isSet
def set : $;
[ $(1).colour::raw + $(2).colour::raw + $(3).col... |
http://rosettacode.org/wiki/Set_of_real_numbers | Set of real numbers | All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where a ≤ b. There are actually four cases for the meaning of "between", depending on open or closed boundary:
[a, b]: {x | a ≤ x and x ≤ b }
(a, b): {x | ... | #C.23 | C# | using System;
namespace RosettaCode.SetOfRealNumbers
{
public class Set<TValue>
{
public Set(Predicate<TValue> contains)
{
Contains = contains;
}
public Predicate<TValue> Contains
{
get;
private set;
}
public Set<T... |
http://rosettacode.org/wiki/Sieve_of_Eratosthenes | Sieve of Eratosthenes | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer.
Task
Implement the Sieve of Eratosthenes algorithm, with the only allowed... | #68000_Assembly | 68000 Assembly | *-----------------------------------------------------------
* Title : BitSieve
* Written by : G. A. Tippery
* Date : 2014-Feb-24, 2013-Dec-22
* Description: Prime number sieve
*-----------------------------------------------------------
ORG $1000
** ---- Generic macros ---- **
PUSH MACRO
MOVE.L \... |
http://rosettacode.org/wiki/Sequence_of_primorial_primes | Sequence of primorial primes | The sequence of primorial primes is given as the increasing values of n where primorial(n) ± 1 is prime.
Noting that the n'th primorial is defined as the multiplication of the smallest n primes, the sequence is of the number of primes, in order that when multiplied together is one-off being a prime number itself.
T... | #Clojure | Clojure |
(ns example
(:gen-class))
; Lazy Sequence of primes (starting with number 2)
(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)
(.is... |
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #Haskell | Haskell | 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 =... |
http://rosettacode.org/wiki/Set_consolidation | Set consolidation | Given two sets of items then if any item is common to any set then the result of applying consolidation to those sets is a set of sets whose contents is:
The two input sets if no common item exists between the two input sets of items.
The single set that is the union of the two input sets if they share a common item... | #EchoLisp | EchoLisp |
;; utility : make a set of sets from a list
(define (make-set* s)
(or (when (list? s) (make-set (map make-set* s))) s))
;; union of all sets which intersect - O(n^2)
(define (make-big ss)
(make-set
(for/list ((u ss))
(for/fold (big u) ((v ss)) #:when (set-intersect? big v) (set-union big v)))))
;; remove set... |
http://rosettacode.org/wiki/Sequence:_smallest_number_with_exactly_n_divisors | Sequence: smallest number with exactly n divisors | Calculate the sequence where each term an is the smallest natural number that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: nth number with exactly... | #Go | Go | 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... |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Hash["Rosetta code","SHA256","HexString"] |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #min | min | "Rosetta code" sha256 puts! |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Java | Java | 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 ... |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #min | min | "Rosetta Code" sha1 puts! |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #Neko | Neko | /**
SHA-1 in Neko
Tectonics:
nekoc SHA-1.neko
neko SHA-1
*/
var SHA1 = $loader.loadprim("std@make_sha1", 3);
var base_encode = $loader.loadprim("std@base_encode", 2);
var msg = "Rosetta Code";
var result = SHA1(msg, 0, $ssize(msg));
/* Output in lowercase hex */
$print(base_encode(result, "0123456789abcde... |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Racket | Racket |
#lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
|
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Raku | Raku | my $d5 = 1..5;
sub d5() { $d5.roll; } # 1d5
sub d7() {
my $flat = 21;
$flat = 5 * d5() - d5() until $flat < 21;
$flat % 7 + 1;
}
# Testing
my @dist;
my $n = 1_000_000;
my $expect = $n / 7;
loop ($_ = $n; $n; --$n) { @dist[d7()]++; }
say "Expect\t",$expect.fmt("%.3f");
for @dist.kv -> $i, $v {
s... |
http://rosettacode.org/wiki/Show_ASCII_table | Show ASCII table | Task
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioin... | #IS-BASIC | IS-BASIC | 100 TEXT 80
110 FOR R=0 TO 15
120 FOR C=32+R TO 112+R STEP 16
130 PRINT USING "###":C;:PRINT ": ";CHR$(C),
140 NEXT
150 PRINT
160 NEXT |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #PicoLisp | PicoLisp | (de sierpinski (N)
(let (D '("*") S " ")
(do N
(setq
D (conc
(mapcar '((X) (pack S X S)) D)
(mapcar '((X) (pack X " " X)) D) )
S (pack S S) ) )
D ) )
(mapc prinl (sierpinski 4)) |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Liberty_BASIC | Liberty BASIC | NoMainWin
WindowWidth = 508
WindowHeight = 575
Open "Sierpinski Carpets" For Graphics_nsb_nf As #g
#g "Down; TrapClose [halt]"
'labels
#g "Place 90 15;\Order 0"
#g "Place 340 15;\Order 1"
#g "Place 90 286;\Order 2"
#g "Place 340 286;\Order 3"
'carpets
Call carpet 5, 20, 243, 0
Call carpet 253, 20, 243, 1
Cal... |
http://rosettacode.org/wiki/Short-circuit_evaluation | Short-circuit evaluation | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Assume functions a and b return boolean values, and further, the execution of function b takes considerable resources without side effects, an... | #Ol | Ol |
(define (a x)
(print " (a) => " x)
x)
(define (b x)
(print " (b) => " x)
x)
; and
(print " -- and -- ")
(for-each (lambda (x y)
(print "let's evaluate '(a as " x ") and (b as " y ")':")
(let ((out (and (a x) (b y))))
(print " result is " out)))
'(#t #t #f #f)
'(#t #f #... |
http://rosettacode.org/wiki/Set_puzzle | Set puzzle | Set Puzzles are created with a deck of cards from the Set Game™. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up.
There are 81 cards in a deck.
Each card contains a unique variation of the following four features: color, symbol, number and shading.
there are... | #Tcl | Tcl | # Generate random integer uniformly on range [0..$n-1]
proc random n {expr {int(rand() * $n)}}
# Generate a shuffled deck of all cards; the card encoding was stolen from the
# Perl6 solution. This is done once and then used as a constant. Note that the
# rest of the code assumes that all cards in the deck are unique.... |
http://rosettacode.org/wiki/Set_of_real_numbers | Set of real numbers | All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where a ≤ b. There are actually four cases for the meaning of "between", depending on open or closed boundary:
[a, b]: {x | a ≤ x and x ≤ b }
(a, b): {x | ... | #C.2B.2B | C++ | #include <cassert>
#include <functional>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
enum RangeType {
CLOSED,
BOTH_OPEN,
LEFT_OPEN,
RIGHT_OPEN
};
class RealSet {
private:
double low, high;
double interval = 0.00001;
std::function<bool(double)> predicate;
public:
... |
http://rosettacode.org/wiki/Sieve_of_Eratosthenes | Sieve of Eratosthenes | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer.
Task
Implement the Sieve of Eratosthenes algorithm, with the only allowed... | #8086_Assembly | 8086 Assembly | MAXPRM: equ 5000 ; Change this value for more primes
cpu 8086
bits 16
org 100h
section .text
erato: mov cx,MAXPRM ; Initialize array (set all items to prime)
mov bp,cx ; Keep a copy in BP
mov di,sieve
mov al,1
rep stosb
;;; Sieve
mov bx,sieve ; Set base register to array
inc cx ; CX=1 (CH=0, CL=1); CX was ... |
http://rosettacode.org/wiki/Sequence_of_primorial_primes | Sequence of primorial primes | The sequence of primorial primes is given as the increasing values of n where primorial(n) ± 1 is prime.
Noting that the n'th primorial is defined as the multiplication of the smallest n primes, the sequence is of the number of primes, in order that when multiplied together is one-off being a prime number itself.
T... | #EchoLisp | EchoLisp |
(lib 'timer) ;; for (every (proc t) interval)
(lib 'bigint)
;; memoize primorial
(define p1000 (cons 1 (primes 1000))) ; remember first 1000 primes
(define (primorial n)
(if(zero? n) 1
(* (list-ref p1000 n) (primorial (1- n)))))
(remember 'primorial)
(define N 0)
;; search one at a time
(define (searc... |
http://rosettacode.org/wiki/Sequence_of_primorial_primes | Sequence of primorial primes | The sequence of primorial primes is given as the increasing values of n where primorial(n) ± 1 is prime.
Noting that the n'th primorial is defined as the multiplication of the smallest n primes, the sequence is of the number of primes, in order that when multiplied together is one-off being a prime number itself.
T... | #Factor | Factor | USING: kernel lists lists.lazy math math.primes prettyprint
sequences ;
: pprime? ( n -- ? )
nprimes product [ 1 + ] [ 1 - ] bi [ prime? ] either? ;
10 1 lfrom [ pprime? ] <lazy-filter> ltake list>array . |
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #J | J |
A073916=: {{
if.1 p: y do. (p:^x:)y-1 return.
elseif.1|y do.
f= *:
else.
f=. ]
end. r=.i.0
off=. 1
while. y>#r do.
r=. r,f off+I.y=*/|:1+_ q:f off+i.y
off=. off+y
end.
(y-1){r
}}"0
|
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #Java | Java |
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) =... |
http://rosettacode.org/wiki/Set_consolidation | Set consolidation | Given two sets of items then if any item is common to any set then the result of applying consolidation to those sets is a set of sets whose contents is:
The two input sets if no common item exists between the two input sets of items.
The single set that is the union of the two input sets if they share a common item... | #Egison | Egison |
(define $consolidate
(lambda [$xss]
(match xss (multiset (set char))
{[<cons <cons $m $xs>
<cons <cons ,m $ys>
$rss>>
(consolidate {(unique/m char {m @xs @ys}) @rss})]
[_ xss]})))
(test (consolidate {{'H' 'I' 'K'} {'A' 'B'} {'C' 'D'} {'D' 'B'} {'F' 'G' 'H... |
http://rosettacode.org/wiki/Set_consolidation | Set consolidation | Given two sets of items then if any item is common to any set then the result of applying consolidation to those sets is a set of sets whose contents is:
The two input sets if no common item exists between the two input sets of items.
The single set that is the union of the two input sets if they share a common item... | #Ela | Ela | open list
merge [] ys = ys
merge (x::xs) ys | x `elem` ys = merge xs ys
| else = merge xs (x::ys)
consolidate (_::[])@xs = xs
consolidate (x::xs) = conso [x] (consolidate xs)
where conso xs [] = xs
conso (x::xs)@r (y::ys) | intersect x y <> [] = conso ((merge x... |
http://rosettacode.org/wiki/Sequence:_smallest_number_with_exactly_n_divisors | Sequence: smallest number with exactly n divisors | Calculate the sequence where each term an is the smallest natural number that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: nth number with exactly... | #Haskell | Haskell | import Data.List (find, group, sort)
import Data.Maybe (mapMaybe)
import Data.Numbers.Primes (primeFactors)
------------------------- A005179 ------------------------
a005179 :: [Int]
a005179 =
mapMaybe
( \n ->
find
((n ==) . succ . length . properDivisors)
[1 ..]
)
[1 ..]
... |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA256('Rosetta code', '764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA256(m... |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #jq | jq |
# The number of prime factors (as in prime factorization)
def numfactors:
. as $num
| reduce range(1; 1 + sqrt|floor) as $i (null;
if ($num % $i) == 0
then ($num / $i) as $r
| if $i == $r then .+1 else .+2 end
else .
end );
# Output: a stream
def A06954:
foreach range(1; i... |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Julia | Julia | using Primes
function numfactors(n)
f = [one(n)]
for (p,e) in factor(n)
f = reduce(vcat, [f*p^j for j in 1:e], init=f)
end
length(f)
end
function A06954(N)
println("First $N terms of OEIS sequence A069654: ")
k = 0
for i in 1:N
j = k
while (j += 1) > 0
... |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Kotlin | Kotlin | // Version 1.3.21
const val MAX = 15
fun countDivisors(n: Int): Int {
var count = 0
var i = 1
while (i * i <= n) {
if (n % i == 0) {
count += if (i == n / i) 1 else 2
}
i++
}
return count
}
fun main() {
println("The first $MAX terms of the sequence are:"... |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) pub... |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #REXX | REXX | /*REXX program simulates a 7─sided die based on a 5─sided throw for a number of trials. */
parse arg trials sample seed . /*obtain optional arguments from the CL*/
if trials=='' | trials="," then trials= 1 /*Not specified? Then use the default.*/
if sample=='' | sample="," then sample= 100000... |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Ring | Ring |
# Project : Seven-sided dice from five-sided dice
for n = 1 to 20
d = dice7()
see "" + d + " "
next
see nl
func dice7()
x = dice5() * 5 + dice5() - 6
if x > 20
return dice7()
ok
dc = x % 7 + 1
return dc
func dice5()
rnd = random... |
http://rosettacode.org/wiki/Show_ASCII_table | Show ASCII table | Task
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioin... | #J | J | 32}._129}.a.
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
NB. A are the decimal ASCII values
[A =: 10 |."1 ] 12 ": |: _16 [\ 32 }. i. 128
32 48 64 80 96 112
33 49 65 81 ... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #PL.2FI | PL/I | sierpinski: procedure options (main); /* 2010-03-30 */
declare t (79,79) char (1);
declare (i, j, k) fixed binary;
declare (y, xs, ys, xll, xrr, ixrr, limit) fixed binary;
t = ' ';
xs = 40; ys = 1;
/* Make initial triangle */
call make_triangle (xs, ys);
y = ys + 4;
xll = xs-4; xrr = xs+4;
... |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | full={{1,1,1},{1,0,1},{1,1,1}}
empty={{0,0,0},{0,0,0},{0,0,0}}
n=3;
Grid[Nest[ArrayFlatten[#/.{0->empty,1->full}]&,{{1}},n]//.{0->" ",1->"#"}] |
http://rosettacode.org/wiki/Short-circuit_evaluation | Short-circuit evaluation | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Assume functions a and b return boolean values, and further, the execution of function b takes considerable resources without side effects, an... | #ooRexx | ooRexx | Parse Version v
Say 'Version='v
If a() | b() Then Say 'a and b are true'
If \a() | b() Then Say 'Surprise'
Else Say 'ok'
If a(), b() Then Say 'a is true'
If \a(), b() Then Say 'Surprise'
Else Say 'ok: \a() is false'
Select
When \a(), b() Then Say 'Surprise'
Otherwise Say 'ok: ... |
http://rosettacode.org/wiki/Set_puzzle | Set puzzle | Set Puzzles are created with a deck of cards from the Set Game™. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up.
There are 81 cards in a deck.
Each card contains a unique variation of the following four features: color, symbol, number and shading.
there are... | #Wren | Wren | import "/dynamic" for Enum
import "/trait" for Comparable
import "/fmt" for Fmt
import "/str" for Str
import "/math" for Nums
import "/sort" for Sort
import "random" for Random
var Color = Enum.create("Color", ["RED", "GREEN", "PURPLE"])
var Symbol = Enum.create("Symbol", ["OVAL", "SQUIGGLE", "DIAMOND"])
var Nu... |
http://rosettacode.org/wiki/Set_of_real_numbers | Set of real numbers | All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where a ≤ b. There are actually four cases for the meaning of "between", depending on open or closed boundary:
[a, b]: {x | a ≤ x and x ≤ b }
(a, b): {x | ... | #Clojure | Clojure | (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]
#(an... |
http://rosettacode.org/wiki/Set | Set |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A set is a collection of elements, without duplicates and without order.
Task
Show each of these set operations:
Set creation
Test m ∈ S -- "m is an... | #11l | 11l | V s1 = Set([1, 2, 3, 4])
V s2 = Set([3, 4, 5, 6])
print(s1.union(s2))
print(s1.intersection(s2))
print(s1.difference(s2))
print(s1 < s1)
print(Set([3, 1]) < s1)
print(s1 <= s1)
print(Set([3, 1]) <= s1)
print(Set([3, 2, 4, 1]) == s1)
print(s1 == s2)
print(2 C s1)
print(10 !C s1)
print(Set([1, 2, 3, 4, 5]) > s1)
print(Se... |
http://rosettacode.org/wiki/Send_an_unknown_method_call | Send an unknown method call | Task
Invoke an object method where the name of the method to be invoked can be generated at run time.
Related tasks
Respond to an unknown method call.
Runtime evaluation
| #AutoHotkey | AutoHotkey | obj := {mA: Func("mA"), mB: Func("mB"), mC: Func("mC")}
InputBox, methodToCall, , Which method should I call?
obj[methodToCall].()
mA(){
MsgBox Method A
}
mB(){
MsgBox Method B
}
mC(){
MsgBox Method C
}
|
http://rosettacode.org/wiki/Sieve_of_Eratosthenes | Sieve of Eratosthenes | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer.
Task
Implement the Sieve of Eratosthenes algorithm, with the only allowed... | #8th | 8th |
with: n
\ create a new buffer which will function as a bit vector
: bit-vec SED: n -- b
dup 3 shr swap 7 band if 1+ then b:new b:clear ;
\ given a buffer, sieving prime, and limit, cross off multiples
\ of the sieving prime.
: +composites SED: b n n -- b
>r dup sqr rot \ want: -- n index b
repeat
... |
http://rosettacode.org/wiki/Sequence_of_primorial_primes | Sequence of primorial primes | The sequence of primorial primes is given as the increasing values of n where primorial(n) ± 1 is prime.
Noting that the n'th primorial is defined as the multiplication of the smallest n primes, the sequence is of the number of primes, in order that when multiplied together is one-off being a prime number itself.
T... | #Fortran | Fortran | PROGRAM PRIMORIALP !Simple enough, with some assistants.
USE PRIMEBAG !Some prime numbers are wanted.
USE BIGNUMBERS !Just so.
TYPE(BIGNUM) B !I'll have one.
INTEGER MAXF !Largest factor to consider by direct division.
PARAMETER (MAXF = 18000000) !Some determination.
INTEGE... |
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #jq | jq | def count(stream): reduce stream as $i (0; .+1);
# To maintain precision:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
def primes: 2, (range(3; infinite; 2) | select(is_prime));
# divisors as an unsorted stream
def divisors:
if . == 1 then 1
else . as $n
| label $out
| range(1; $n) as ... |
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #Julia | Julia | using Primes
function countdivisors(n)
f = [one(n)]
for (p, e) in factor(n)
f = reduce(vcat, [f * p ^ j for j in 1:e], init = f)
end
length(f)
end
function nthwithndivisors(N)
parray = findall(primesmask(100 * N))
for i = 1:N
if isprime(i)
println("$i : ", BigInt(... |
http://rosettacode.org/wiki/Sequence:_nth_number_with_exactly_n_divisors | Sequence: nth number with exactly n divisors | Calculate the sequence where each term an is the nth that has n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A073916
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: smallest number with exactly n divisors | #Kotlin | Kotlin | // Version 1.3.21
import java.math.BigInteger
import kotlin.math.sqrt
const val MAX = 33
fun isPrime(n: Int) = BigInteger.valueOf(n.toLong()).isProbablePrime(10)
fun generateSmallPrimes(n: Int): List<Int> {
val primes = mutableListOf<Int>()
primes.add(2)
var i = 3
while (primes.size < n) {
... |
http://rosettacode.org/wiki/Set_consolidation | Set consolidation | Given two sets of items then if any item is common to any set then the result of applying consolidation to those sets is a set of sets whose contents is:
The two input sets if no common item exists between the two input sets of items.
The single set that is the union of the two input sets if they share a common item... | #Elixir | Elixir | defmodule RC do
def set_consolidate(sets, result\\[])
def set_consolidate([], result), do: result
def set_consolidate([h|t], result) do
case Enum.find(t, fn set -> not MapSet.disjoint?(h, set) end) do
nil -> set_consolidate(t, [h | result])
set -> set_consolidate([MapSet.union(h, set) | t -- [set]... |
http://rosettacode.org/wiki/Sequence:_smallest_number_with_exactly_n_divisors | Sequence: smallest number with exactly n divisors | Calculate the sequence where each term an is the smallest natural number that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
Related tasks
Sequence: smallest number greater than previous term with exactly n divisors
Sequence: nth number with exactly... | #JavaScript | JavaScript | (() => {
'use strict';
// a005179 :: () -> [Int]
const a005179 = () =>
fmapGen(
n => find(
compose(
eq(n),
succ,
length,
properDivisors
)
)(enumFrom(1)).Just
... |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #NewLISP | NewLISP | ;; using the crypto module from http://www.newlisp.org/code/modules/crypto.lsp.html
;; (import native functions from the crypto library, provided by OpenSSL)
(module "crypto.lsp")
(crypto:sha256 "Rosetta Code") |
http://rosettacode.org/wiki/SHA-256 | SHA-256 | SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details.
Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
| #Nim | Nim | import nimcrypto
echo sha256.digest("Rosetta code") |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | res = {#, DivisorSigma[0, #]} & /@ Range[100000];
highest = 0;
filter = {};
Do[
If[r[[2]] == highest + 1,
AppendTo[filter, r[[1]]];
highest = r[[2]]
]
,
{r, res}
]
Take[filter, 15] |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Nim | Nim | import strformat
const MAX = 15
func countDivisors(n: int): int =
var i = 1
var count = 0
while i * i <= n:
if n mod i == 0:
if i == n div i:
inc count
else:
inc count, 2
inc i
count
var i, next = 1
echo fmt"The first {MAX} terms of the sequence are:"
while next <= MAX... |
http://rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors | Sequence: smallest number greater than previous term with exactly n divisors | Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Task
Show here, on this page, at least the first 15 terms of the sequence.
See also
OEIS:A069654
Related tasks
Sequence: smallest number with exactly n divisors
Sequence: nth ... | #Pascal | Pascal | program AntiPrimesPlus;
{$IFDEF FPC}
{$MODE Delphi}
{$ELSE}
{$APPTYPE CONSOLE} // delphi
{$ENDIF}
uses
sysutils,math;
const
MAX =32;
function getDividersCnt(n:Uint32):Uint32;
// getDividersCnt by dividing n into its prime factors
// aka n = 2250 = 2^1*3^2*5^3 has (1+1)*(2+1)*(3+1)= 24 dividers
var
divi,quot... |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #NewLISP | NewLISP | ;; using the crypto module from http://www.newlisp.org/code/modules/crypto.lsp.html
;; (import native functions from the crypto library, provided by OpenSSL)
(module "crypto.lsp")
(crypto:sha1 "Rosetta Code") |
http://rosettacode.org/wiki/SHA-1 | SHA-1 | SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.
A US government... | #Nim | Nim | import std/sha1
echo secureHash("Rosetta Code") |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Ruby | Ruby | 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} |
http://rosettacode.org/wiki/Seven-sided_dice_from_five-sided_dice | Seven-sided dice from five-sided dice | Task
(Given an equal-probability generator of one of the integers 1 to 5
as dice5), create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers, and check the distribution for at least one million calls using the function created in Simple R... | #Scala | Scala | 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)
} |
http://rosettacode.org/wiki/Show_ASCII_table | Show ASCII table | Task
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequency
Letter frequency
Jewels and stones
I before E except after C
Bioin... | #Java | Java |
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 {
... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #PL.2FM | PL/M | 100H:
DECLARE ORDER LITERALLY '4';
/* CP/M BDOS CALL */
BDOS: PROCEDURE (FN, ARG);
DECLARE FN BYTE, ARG ADDRESS;
GO TO 5;
END BDOS;
PUT$CHAR: PROCEDURE (CHAR);
DECLARE CHAR BYTE;
CALL BDOS(2, CHAR);
END PUT$CHAR;
/* PRINT SIERPINSKI TRIANGLE */
DECLARE (X, Y, SIZE) BYTE;
SIZE = SHL(1, ORDER);
... |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #MATLAB | MATLAB | n = 3;
c = string('#');
for k = 1 : n
c = [c + c + c, c + c.replace('#', ' ') + c, c + c + c];
end
disp(c.join(char(10))) |
http://rosettacode.org/wiki/Short-circuit_evaluation | Short-circuit evaluation | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Assume functions a and b return boolean values, and further, the execution of function b takes considerable resources without side effects, an... | #Oz | Oz | declare
fun {A Answer}
AnswerS = {Value.toVirtualString Answer 1 1}
in
{System.showInfo " % Called function {A "#AnswerS#"} -> "#AnswerS}
Answer
end
fun {B Answer}
AnswerS = {Value.toVirtualString Answer 1 1}
in
{System.showInfo " % Called function {B "#AnswerS#"} -> "#AnswerS}
... |
http://rosettacode.org/wiki/Set_puzzle | Set puzzle | Set Puzzles are created with a deck of cards from the Set Game™. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up.
There are 81 cards in a deck.
Each card contains a unique variation of the following four features: color, symbol, number and shading.
there are... | #zkl | zkl | const nDraw=9, nGoal=(nDraw/2); // Basic
var [const] UH=Utils.Helpers; // baked in stash of goodies
deck:=Walker.cproduct("red green purple".split(), // Cartesian product of 4 lists of lists
"one two three".split(), // T(1,2,3) (ie numbers) also works
"oval squiggle diamond".split(),
"solid open striped".spli... |
http://rosettacode.org/wiki/Send_email | Send email | Task
Write a function to send an email.
The function should have parameters for setting From, To and Cc addresses; the Subject, and the message text, and optionally fields for the server name and login details.
If appropriate, explain what notifications of problems/success are given.
Solutions using libraries or f... | #Ada | Ada | with AWS.SMTP, AWS.SMTP.Client, AWS.SMTP.Authentication.Plain;
with Ada.Text_IO;
use Ada, AWS;
procedure Sendmail is
Status : SMTP.Status;
Auth : aliased constant SMTP.Authentication.Plain.Credential :=
SMTP.Authentication.Plain.Initialize ("id", "password");
Isp : SMTP.Receiver;
begin
Isp :=
... |
http://rosettacode.org/wiki/Set_of_real_numbers | Set of real numbers | All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where a ≤ b. There are actually four cases for the meaning of "between", depending on open or closed boundary:
[a, b]: {x | a ≤ x and x ≤ b }
(a, b): {x | ... | #Common_Lisp | Common Lisp | (deftype set== (a b) `(real ,a ,b))
(deftype set<> (a b) `(real (,a) (,b)))
(deftype set=> (a b) `(real ,a (,b)))
(deftype set<= (a b) `(real (,a) ,b))
(deftype set-union (s1 s2) `(or ,s1 ,s2))
(deftype set-intersection (s1 s2) `(and ,s1 ,s2))
(deftype set-diff (s1 s2) `(and ,s1 (not ,s2)))
(defun in-set-p (x set)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.