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/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... | #Ada | Ada | generic
type Element is (<>);
with function Image(E: Element) return String;
package Set_Cons is
type Set is private;
-- constructor and manipulation functions for type Set
function "+"(E: Element) return Set;
function "+"(Left, Right: Element) return Set;
function "+"(Left: Set; Right: Element... |
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... | #APL | APL | ((0+.=⍳|⊢)¨∘(⍳2÷⍨2∘*)⍳⍳)15 |
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... | #Arturo | Arturo | firstNumWithDivisors: function [n][
i: 0
while ø [
if n = size factors i -> return i
i: i+1
]
]
print map 1..15 => firstNumWithDivisors |
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
| #Groovy | Groovy | def sha256Hash = { text ->
java.security.MessageDigest.getInstance("SHA-256").digest(text.bytes)
.collect { String.format("%02x", it) }.join('')
} |
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 ... | #AutoHotkey | AutoHotkey | MAX := 15
next := 1, i := 1
while (next <= MAX)
if (next = countDivisors(A_Index))
Res.= A_Index ", ", next++
MsgBox % "The first " MAX " terms of the sequence are:`n" Trim(res, ", ")
return
countDivisors(n){
while (A_Index**2 <= n)
if !Mod(n, A_Index)
count += (A_Index = n/A_Index) ? 1 : 2
return count
} |
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 ... | #AWK | AWK |
# syntax: GAWK -f SEQUENCE_SMALLEST_NUMBER_GREATER_THAN_PREVIOUS_TERM_WITH_EXACTLY_N_DIVISORS.AWK
# converted from Kotlin
BEGIN {
limit = 15
printf("first %d terms:",limit)
n = 1
while (n <= limit) {
if (n == count_divisors(++i)) {
printf(" %d",i)
n++
}
}
printf("\n... |
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... | #Haxe | Haxe | import haxe.crypto.Sha1;
class Main {
static function main() {
var sha1 = Sha1.encode("Rosetta Code");
Sys.println(sha1);
}
} |
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... | #J | J | require '~addons/ide/qt/qt.ijs'
getsha1=: 'sha1'&gethash_jqtide_
getsha1 'Rosetta Code'
48c98f7e5a6e736d790ab740dfc3f51a61abe2b5 |
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... | #Liberty_BASIC | Liberty BASIC |
n=1000000 '1000000 would take several minutes
print "Testing ";n;" times"
if not(check(n, 0.05)) then print "Test failed" else print "Test passed"
end
'function check(n, delta) is defined at
'http://rosettacode.org/wiki/Verify_distribution_uniformity/Naive#Liberty_BASIC
function GENERATOR()
'GENERATOR = i... |
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... | #Lua | Lua | dice5 = function() return math.random(5) end
function dice7()
x = dice5() * 5 + dice5() - 6
if x > 20 then return dice7() end
return x%7 + 1
end |
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... | #REXX | REXX | /*REXX program finds and displays various kinds of sexy and unsexy primes less than N.*/
parse arg N endU end2 end3 end4 end5 . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 1000035 - 1 /*Not specified? Then use the default.*/
if endU=='' | endU=="," then endU= 10 ... |
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... | #Free_Pascal | Free Pascal | // The FPC (FreePascal compiler) discards the program header
// (except in ISO-compliant “compiler modes”).
program showAsciiTable(output);
const
columnsTotal = 6;
type
// The hash indicates a char-data type.
asciiCharacter = #32..#127;
asciiCharacters = set of asciiCharacter;
var
character: asciiCharacter;
... |
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:
*
* *
* *
* * * *
* *
* * * *
... | #PARI.2FGP | PARI/GP | Sierpinski(n)={
my(s=2^n-1);
forstep(y=s,0,-1,
for(i=1,y,print1(" "));
for(x=0,s-y,
print1(if(bitand(x,y)," ","*"))
);
print()
)
};
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:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #J | J | N=:3
(a:(<1;1)}3 3$<)^:N' ' |
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... | #Lua | Lua | 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) |
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... | #Maple | Maple | a := proc(bool)
printf("a is called->%s\n", bool):
return bool:
end proc:
b := proc(bool)
printf("b is called->%s\n", bool):
return bool:
end proc:
for i in [true, false] do
for j in [true, false] do
printf("calculating x := a(i) and b(j)\n"):
x := a(i) and b(j):
printf("calculating x := a(i) or b(j)\n"):
... |
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... | #Phix | Phix | with javascript_semantics
function comb(sequence pool, integer needed, sequence res={}, integer done=0, sequence chosen={})
if needed=0 then -- got a full set
sequence {a,b,c} = chosen
if not find_any({3,5,6},flatten(sq_or_bits(sq_or_bits(a,b),c))) then
res = append(res,chosen)
... |
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... | #Aime | Aime | display(list l)
{
for (integer i, record r in l) {
text u, v;
o_text(i ? ", {" : "{");
for (u in r) {
o_(v, u);
v = ", ";
}
o_text("}");
}
o_text("\n");
}
intersect(record r, record u)
{
trap_q(r_vcall, r, r_put, 1, record().copy(u), ... |
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... | #AutoHotkey | AutoHotkey | SetConsolidation(sets){
arr2 := [] , arr3 := [] , arr4 := [] , arr5 := [], result:=[]
; sort each set individually
for i, obj in sets
{
arr1 := []
for j, v in obj
arr1[v] := true
arr2.push(arr1)
}
; sort by set's first item
for i, obj in arr2
for k, v in obj
{
arr3[k . i] := obj
break
}
... |
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... | #AutoHotkey | AutoHotkey | max := 15
seq := [], n := 0
while (n < max)
if ((k := countDivisors(A_Index)) <= max) && !seq[k]
seq[k] := A_Index, n++
for i, v in seq
res .= v ", "
MsgBox % "The first " . max . " terms of the sequence are:`n" Trim(res, ", ")
return
countDivisors(n){
while (A_Index**2 <= n)
if !Mod(n, A_Index)
count += A_... |
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
| #Halon | Halon | $var = "Rosetta code";
echo sha2($var, 256); |
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
| #Haskell | Haskell | import Data.Char (ord)
import Crypto.Hash.SHA256 (hash)
import Data.ByteString (unpack, pack)
import Text.Printf (printf)
main = putStrLn $ -- output to terminal
concatMap (printf "%02x") $ -- to hex string
unpack $ -- to array of Word8
hash $ ... |
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 ... | #C | C | #include <stdio.h>
#define MAX 15
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;
... |
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... | #Java | Java | /* SHA-1 hash in Jsish */
var str = 'Rosetta code';
puts(Util.hash(str, {type:'sha1'}));
/*
=!EXPECTSTART!=
b18c883f4da750164b5af362ea9b9f27f90904b4
=!EXPECTEND!=
*/ |
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... | #Jsish | Jsish | /* SHA-1 hash in Jsish */
var str = 'Rosetta code';
puts(Util.hash(str, {type:'sha1'}));
/*
=!EXPECTSTART!=
b18c883f4da750164b5af362ea9b9f27f90904b4
=!EXPECTEND!=
*/ |
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... | #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
Def long i, calls, max, min
s=stack:=random(1,5),random(1,5), random(1,5), random(1,5), random(1,5), random(1,5), random(1,5)
z=0: for i=1 to 7 { z+=stackitem(s, i)}
dice7=lambda z, s -> {
=((z-1) mod 7)+1 : stack s {z-=Number : data random(1,5): z+=Stackitem(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... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | sevenFrom5Dice := (tmp$ = 5*RandomInteger[{1, 5}] + RandomInteger[{1, 5}] - 6;
If [tmp$ < 21, 1 + Mod[tmp$ , 7], sevenFrom5Dice]) |
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... | #Nim | Nim | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc... |
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... | #Ring | Ring |
load "stdlib.ring"
primes = []
for n = 1 to 100
if isprime(n)
add(primes,n)
ok
next
see "Sexy prime pairs under 100:" + nl + nl
for n = 1 to len(primes)-1
for m = n + 1 to len(primes)
if primes[m] - primes[n] = 6
see "(" + primes[n] + " " + primes[m] + ")" + nl
ok
... |
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... | #Ruby | Ruby |
require 'prime'
prime_array, sppair2, sppair3, sppair4, sppair5 = Array.new(5) {Array.new()} # arrays for prime numbers and index number to array for each pair.
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 pr... |
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... | #Frink | Frink | a = ["32 Space"]
for i = 33 to 126
a.push["$i " + char[i]]
a.push["127 Delete"]
println[formatTableBoxed[columnize[a,8].transpose[], "left"]] |
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:
*
* *
* *
* * * *
* *
* * * *
... | #Pascal | Pascal | program Sierpinski;
function ipow(b, n : Integer) : Integer;
var
i : Integer;
begin
ipow := 1;
for i := 1 to n do
ipow := ipow * b
end;
function truth(a : Char) : Boolean;
begin
if a = '*' then
truth := true
else
truth := false
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:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Java | Java | 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++) {
... |
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... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | a[in_] := (Print["a"]; in)
b[in_] := (Print["b"]; in)
a[False] && b[True]
a[True] || b[False] |
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... | #MATLAB_.2F_Octave | MATLAB / Octave | function x=a(x)
printf('a: %i\n',x);
end;
function x=b(x)
printf('b: %i\n',x);
end;
a(1) && b(1)
a(0) && b(1)
a(1) || b(1)
a(0) || b(1) |
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... | #Picat | Picat | import util.
import cp.
%
% Solve the task in the description.
%
go ?=>
sets(1,Sets,SetLen,NumSets),
print_cards(Sets),
set_puzzle(Sets,SetLen,NumSets,X),
print_sol(Sets,X),
nl,
fail, % check for other solutions
nl.
go => true.
%
% Generate and solve a random instance with NumCards cards,
% giving exa... |
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... | #Prolog | Prolog | do_it(N) :-
card_sets(N, Cards, Sets),
!,
format('Cards: ~n'),
maplist(print_card, Cards),
format('~nSets: ~n'),
maplist(print_set, Sets).
print_card(Card) :- format(' ~p ~p ~p ~p~n', Card).
print_set(Set) :- maplist(print_card, Set), nl.
n(9,4).
n(12,6).
card_sets(N, Cards, Sets) :-
n(N,L),
repeat,
ra... |
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 | #C | C | #include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#define LIMIT 15
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] *... |
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... | #Bracmat | Bracmat | ( ( consolidate
= a m z mm za zm zz
. ( removeNumFactors
= a m z
. !arg:?a+#%*?m+?z
& !a+!m+removeNumFactors$!z
| !arg
)
& !arg
: ?a
%?`m
( %?z
& !m
: ?
... |
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... | #C | C | #include <stdio.h>
#define s(x) (1U << ((x) - 'A'))
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;
... |
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... | #AWK | AWK |
# syntax: GAWK -f SEQUENCE_SMALLEST_NUMBER_WITH_EXACTLY_N_DIVISORS.AWK
# converted from Kotlin
BEGIN {
limit = 15
printf("first %d terms:",limit)
i = 1
n = 0
while (n < limit) {
k = count_divisors(i)
if (k <= limit && seq[k-1]+0 == 0) {
seq[k-1] = i
n++
}
i+... |
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
| #Haxe | Haxe | import haxe.crypto.Sha256;
class Main {
static function main() {
var sha256 = Sha256.encode("Rosetta code");
Sys.println(sha256);
}
} |
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
| #J | J | require '~addons/ide/qt/qt.ijs'
getsha256=: 'sha256'&gethash_jqtide_ |
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 ... | #C.2B.2B | C++ | #include <iostream>
#define MAX 15
using namespace std;
int count_divisors(int n) {
int count = 0;
for (int i = 1; i * i <= n; ++i) {
if (!(n % i)) {
if (i == n / i)
count++;
else
count += 2;
}
}
return count;
}
int main() {... |
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 ... | #Dyalect | Dyalect | func countDivisors(n) {
var count = 0
var i = 1
while i * i <= n {
if n % i == 0 {
if i == n / i {
count += 1
} else {
count += 2
}
}
i += 1
}
return count
}
let max = 15
print("The first \(max) terms of th... |
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... | #Julia | Julia | using Nettle
testdict = Dict("abc" => "a9993e364706816aba3e25717850c26c9cd0d89d",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" =>
"84983e441c3bd26ebaae4aa1f95129e5e54670f1",
"a" ^ 1_000_000 => "34aa973cd4c4daa4f61eeb2bdbad27316534016f",)
for (text, e... |
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... | #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-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
} |
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... | #OCaml | OCaml | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dic... |
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... | #PARI.2FGP | PARI/GP | dice5()=random(5)+1;
dice7()={
my(t);
while((t=dice5()*5+dice5()) > 21,);
(t+2)\3
}; |
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... | #Rust | Rust | // [dependencies]
// primal = "0.2"
// circular-queue = "0.2.5"
use circular_queue::CircularQueue;
fn main() {
let max = 1000035;
let max_group_size = 5;
let diff = 6;
let max_groups = 5;
let max_unsexy = 10;
let sieve = primal::Sieve::new(max + diff);
let mut group_count = vec![0; max... |
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... | #Scala | Scala | /* We could reduce the number of functions through a polymorphism since we're trying to retrieve sexy N-tuples (pairs, triplets etc...)
but one practical solution would be to use the Shapeless library for this purpose; here we only use built-in Scala packages. */
object SexyPrimes {
/** Check if an input number... |
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... | #F.C5.8Drmul.C3.A6 | Fōrmulæ |
include "NSLog.incl"
local fn ASCIITable as CFStringRef
'~'1
NSinteger i
CFStringRef temp
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
for i = 32 to 127
temp = fn StringWithFormat( @"%c", i )
if i == 32 then temp = @"Spc"
if i == 127 then temp = @"Del"
MutableStringAppendString( mutStr, fn Str... |
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:
*
* *
* *
* * * *
* *
* * * *
... | #Perl | Perl | 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; |
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:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #JavaScript | JavaScript | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Sierpinski Carpet</title>
<script type='text/javascript'>
var black_char = "#";
var white_char = " ";
var SierpinskiCarpet = function(siz... |
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... | #Modula-2 | Modula-2 | MODULE ShortCircuit;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
PROCEDURE a(v : BOOLEAN) : BOOLEAN;
VAR buf : ARRAY[0..63] OF CHAR;
BEGIN
FormatString(" # Called function a(%b)\n", buf, v);
WriteString(buf);
RETURN v
END a;
PROCEDURE b(v : BOOLEAN) : BOO... |
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... | #Python | Python | #!/usr/bin/python
from itertools import product, combinations
from random import sample
## Major constants
features = [ 'green purple red'.split(),
'one two three'.split(),
'oval diamond squiggle'.split(),
'open striped solid'.split() ]
deck = list(product(list(range(3)), re... |
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 | #C.2B.2B | C++ | #include <iostream>
#include <vector>
std::vector<int> smallPrimes;
bool is_prime(size_t test) {
if (test < 2) {
return false;
}
if (test % 2 == 0) {
return test == 2;
}
for (size_t d = 3; d * d <= test; d += 2) {
if (test % d == 0) {
return false;
}
... |
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... | #C.23 | C# | using System;
using System.Linq;
using System.Collections.Generic;
public class SetConsolidation
{
public static void Main()
{
var setCollection1 = new[] {new[] {"A", "B"}, new[] {"C", "D"}};
var setCollection2 = new[] {new[] {"A", "B"}, new[] {"B", "D"}};
var setCollection3 = new[] {n... |
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... | #BCPL | BCPL | get "libhdr"
manifest $( LENGTH = 15 $)
let divisors(n) = valof
$( let count = 0 and i = 1
while i*i <= n
$( if n rem i = 0 then
count := count + (i = n/i -> 1, 2)
i := i + 1
$)
resultis count
$)
let sequence(n, seq) be
$( let found = 0 and i = 1
for i=1 to n do seq!i :... |
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... | #C | C | #include <stdio.h>
#define MAX 15
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... |
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
| #Java | Java |
const crypto = require('crypto');
const msg = 'Rosetta code';
const hash = crypto.createHash('sha256').update(msg).digest('hex');
console.log(hash);
|
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
| #JavaScript | JavaScript |
const crypto = require('crypto');
const msg = 'Rosetta code';
const hash = crypto.createHash('sha256').update(msg).digest('hex');
console.log(hash);
|
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 ... | #F.23 | F# |
// Nigel Galloway: November 19th., 2017
let fN g=[1..(float>>sqrt>>int)g]|>List.fold(fun Σ n->if g%n>0 then Σ else if g/n=n then Σ+1 else Σ+2) 0
let A069654=let rec fG n g=seq{match g-fN n with 0->yield n; yield! fG(n+1)(g+1) |_->yield! fG(n+1)g} in fG 1 1
A069654 |> Seq.take 28|>Seq.iter(printf "%d "); printfn ""
... |
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... | #Lasso | Lasso | cipher_digest('Rosetta Code', -digest='SHA1',-hex=true) |
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... | #Liberty_BASIC | Liberty BASIC |
'--------------------------------------------------------------------------------
' FAST SHA1 CALCULATION BASED ON MS ADVAPI32.DLL BY CRYPTOMAN '
' BASED ON SHA256 EXAMPLE BY RICHARD T. RUSSEL AUTHOR OF LBB '
' http://lbb.conforums.com/ ... |
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... | #Pascal | Pascal |
unit UConverter;
(*
Defines a converter object to output uniformly distributed random integers 1..7,
given a source of uniformly distributed random integers 1..5.
*)
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..... |
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... | #Sidef | Sidef | var limit = 1e6+35
var primes = limit.primes
say "Total number of primes <= #{limit.commify} is #{primes.len.commify}."
say "Sexy k-tuple primes <= #{limit.commify}:\n"
(2..5).each {|k|
var groups = []
primes.each {|p|
var group = (1..^k -> map {|j| 6*j + p })
if (group.all{.is_prime} && (g... |
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... | #FutureBasic | FutureBasic |
include "NSLog.incl"
local fn ASCIITable as CFStringRef
'~'1
NSinteger i
CFStringRef temp
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
for i = 32 to 127
temp = fn StringWithFormat( @"%c", i )
if i == 32 then temp = @"Spc"
if i == 127 then temp = @"Del"
MutableStringAppendString( mutStr, fn Str... |
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:
*
* *
* *
* * * *
* *
* * * *
... | #Phix | Phix | procedure sierpinski(integer n)
integer lim = power(2,n)-1
for y=lim to 0 by -1 do
puts(1,repeat(' ',y))
for x=0 to lim-y do
puts(1,iff(and_bits(x,y)?" ":"* "))
end for
puts(1,"\n")
end for
end procedure
for i=1 to 5 do
sierpinski(i)
end for
|
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:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #jq | jq |
def inCarpet(x; y):
x as $x | y as $y |
if $x == -1 or $y == -1 then "\n"
elif $x == 0 or $y == 0 then "*"
elif ($x % 3) == 1 and ($y % 3) == 1 then " "
else inCarpet($x/3 | floor; $y/3 | floor)
end;
def ipow(n):
. as $in | reduce range(0;n) as $i (1; . * $in);
def carpet(n):
(3|ipow(n)) as $powe... |
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... | #MUMPS | MUMPS | SSEVAL1(IN)
WRITE !,?10,$STACK($STACK,"PLACE")
QUIT IN
SSEVAL2(IN)
WRITE !,?10,$STACK($STACK,"PLACE")
QUIT IN
SSEVAL3
NEW Z
WRITE "1 AND 1"
SET Z=$$SSEVAL1(1) SET:Z Z=Z&$$SSEVAL2(1)
WRITE !,$SELECT(Z:"TRUE",1:"FALSE")
WRITE !!,"0 AND 1"
SET Z=$$SSEVAL1(0) SET:Z Z=Z&$$SSEVAL2(1)
WRITE !,$SELECT(Z:"TRUE",1:"FA... |
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... | #Nanoquery | Nanoquery | def short_and(bool1, bool2)
global a
global b
if a(bool1)
if b(bool2)
return true
else
return false
end
else
return false
end
end
def short_or(bool1, bool2)
if a(bool1)
return true
else
if b(bool2)
return 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... | #Racket | Racket |
#lang racket
(struct card [bits name])
(define cards
(for/list ([C '(red green purple )] [Ci '(#o0001 #o0002 #o0004)]
#:when #t
[S '(oval squiggle diamond)] [Si '(#o0010 #o0020 #o0040)]
#:when #t
[N '(one two three )] [Ni '(#o0100 #o0200 #o0400)]... |
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... | #Raku | Raku | enum Color (red => 0o1000, green => 0o2000, purple => 0o4000);
enum Count (one => 0o100, two => 0o200, three => 0o400);
enum Shape (oval => 0o10, squiggle => 0o20, diamond => 0o40);
enum Style (solid => 0o1, open => 0o2, striped => 0o4);
my @deck = Color.enums X Count.enums X Shape.enums X Style.enu... |
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... | #11l | 11l | F primes_upto(limit)
V is_prime = [0B]*2 [+] [1B]*(limit - 1)
L(n) 0 .< Int(limit ^ 0.5 + 1.5)
I is_prime[n]
L(i) (n*n..limit).step(n)
is_prime[i] = 0B
R enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)
print(primes_upto(100)) |
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 | #D | D | import std.bigint;
import std.math;
import std.stdio;
bool isPrime(long test) {
if (test == 2) {
return true;
}
if (test % 2 == 0) {
return false;
}
for (long d = 3 ; d * d <= test; d += 2) {
if (test % d == 0) {
return false;
}
}
return true;
}
... |
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... | #Clojure | Clojure | (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? ... |
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... | #C.2B.2B | C++ | #include <iostream>
#define MAX 15
using namespace std;
int count_divisors(int n) {
int count = 0;
for (int i = 1; i * i <= n; ++i) {
if (!(n % i)) {
if (i == n / i)
count++;
else
count += 2;
}
}
return count;
}
int main() {... |
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
| #Jsish | Jsish | /* SHA-256 hash in Jsish */
var str = 'Rosetta code';
puts(Util.hash(str, {type:'sha256'}));
/*
=!EXPECTSTART!=
764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
=!EXPECTEND!=
*/ |
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
| #Julia | Julia | msg = "Rosetta code"
using Nettle
digest = hexdigest("sha256", msg)
# native
using SHA
digest1 = join(num2hex.(sha256(msg)))
@assert digest == digest1 |
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 ... | #Factor | Factor | USING: io kernel math math.primes.factors prettyprint sequences ;
: next ( n num -- n' num' )
[ 2dup divisors length = ] [ 1 + ] do until [ 1 + ] dip ;
: A069654 ( n -- seq )
[ 2 1 ] dip [ [ next ] keep ] replicate 2nip ;
"The first 15 terms of the sequence are:" print 15 A069654 . |
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 ... | #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
print 1;" "; 'special cas... |
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... | #Lingo | Lingo | crypto = xtra("Crypto").new()
put crypto.cx_sha1_string("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... | #LiveCode | LiveCode | command shaRosettaCode
local shex, sha1
put sha1Digest("Rosetta Code") into sha1
get binaryDecode("H*",sha1,shex)
put shex
end shaRosettaCode |
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... | #Perl | Perl | 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;
|
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... | #Phix | Phix | function dice5()
return rand(5)
end function
function dice7()
while true do
integer r = dice5()*5+dice5()-3 -- ( ie 3..27, but )
if r<24 then return floor(r/3) end if -- (only 3..23 useful)
end while
end function
|
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... | #Wren | Wren | import "/fmt" for Fmt
import "/math" for Int
var printHelper = Fn.new { |cat, le, lim, max|
var cle = Fmt.commatize(le)
var clim = Fmt.commatize(lim)
if (cat != "unsexy primes") cat = "sexy prime " + cat
System.print("Number of %(cat) less than %(clim) = %(cle)")
var last = (le < max) ? le : max
... |
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... | #Go | Go | 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, ... |
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:
*
* *
* *
* * * *
* *
* * * *
... | #Phixmonti | Phixmonti | def sierpinski
2 swap power 1 - var lim
lim 0 -1 3 tolist for
var y
32 y 1 + repeat print
0 lim y - 2 tolist for
y bitand if 32 32 chain else "* " endif print
endfor
nl
endfor
enddef
5 for
sierpinski
endfor |
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:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Julia | Julia | function sierpinski(n::Integer, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
t = fill(" ", size(x))
x = [x x x; x t x; x x x]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
sierpinski(2, "#") ... |
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... | #Nemerle | Nemerle | using System.Console;
class ShortCircuit
{
public static a(x : bool) : bool
{
WriteLine("a");
x
}
public static b(x : bool) : bool
{
WriteLine("b");
x
}
public static Main() : void
{
def t = true;
def f = false;
WriteLine("T... |
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... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
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() i... |
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... | #REXX | REXX | /*REXX program finds and displays "sets" (solutions) for the SET puzzle (game). */
parse arg game seed . /*get optional # cards to deal and seed*/
if game=='' | game=="," then game= 9 /*Not specified? Then use the default.*/
if seed=='' | seed=="," then seed= 77 ... |
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... | #360_Assembly | 360 Assembly | * Sieve of Eratosthenes
ERATOST CSECT
USING ERATOST,R12
SAVEAREA B STM-SAVEAREA(R15)
DC 17F'0'
DC CL8'ERATOST'
STM STM R14,R12,12(R13) save calling context
ST R13,4(R15)
ST R15,8(R13)
LR R12,R15 set addessab... |
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 | C |
#include <gmp.h>
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);
... |
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 | #Factor | Factor | USING: combinators formatting fry kernel lists lists.lazy
lists.lazy.examples literals math math.functions math.primes
math.primes.factors math.ranges sequences ;
IN: rosetta-code.nth-n-div
CONSTANT: primes $[ 100 nprimes ]
: prime ( m -- n ) 1 - [ primes nth ] [ ^ ] bi ;
: (non-prime) ( m quot -- n )
'[
... |
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 | #FreeBASIC | FreeBASIC | Dim As Integer n, num, pnum
Dim As Ulongint m, p
Dim As Ulongint limit = 18446744073709551615
Print "The first 15 terms of OEIS:A073916 are:"
For n = 1 To 15
num = 0
For m = 1 To limit
pnum = 0
For p = 1 To limit
If (m Mod p = 0) Then pnum += 1
Next p
If pnum = n Th... |
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... | #Common_Lisp | Common Lisp | (defun consolidate (ss)
(labels ((comb (cs s)
(cond ((null s) cs)
((null cs) (list s))
((null (intersection s (first cs)))
(cons (first cs) (comb (rest cs) s)))
((consolidate (cons (union s (first cs)) (rest cs)))))))
(reduc... |
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... | #Cowgol | Cowgol | include "cowgol.coh";
const AMOUNT := 15;
typedef I is uint16;
sub divisors(n: I): (count: I) is
var i: I := 1;
count := 0;
while i*i <= n loop
if n%i == 0 then
if n/i == i then
count := count + 1;
else
count := count + 2;
en... |
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... | #F.23 | F# |
// Find Antı-Primes plus. Nigel Galloway: April 9th., 2019
// Increasing the value 14 will increase the number of anti-primes plus found
let fI=primes|>Seq.take 14|>Seq.map bigint|>List.ofSeq
let N=Seq.reduce(*) fI
let fG g=Seq.unfold(fun ((n,i,e) as z)->Some(z,(n+1,i+1,(e*g)))) (1,2,g)
let fE n i=n|>Seq.collect(fun... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.