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/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Ruby
Ruby
class Integer   def popcount digits(2).count(1) #pre Ruby 2.4: self.to_s(2).count("1") end   def evil? self >= 0 && popcount.even? end   end   puts "Powers of 3:", (0...30).map{|n| (3**n).popcount}.join(' ') puts "Evil:" , 0.step.lazy.select(&:evil?).first(30).join(' ') puts "Odious:", 0.step.lazy...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Scheme
Scheme
(define (power-set set) (if (null? set) '(()) (let ((rest (power-set (cdr set)))) (append (map (lambda (element) (cons (car set) element)) rest) rest))))   (display (power-set (list 1 2 3))) (newline)   (display (power-set (list "A" "C" "E"))) (newline)
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Lingo
Lingo
on isPrime (n) if n<=1 or (n>2 and n mod 2=0) then return FALSE sq = sqrt(n) repeat with i = 3 to sq if n mod i = 0 then return FALSE end repeat return TRUE end
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Racket
Racket
  #lang racket (require math) (define (factors n) (append-map (λ (x) (make-list (cadr x) (car x))) (factorize n)))  
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Rust
Rust
fn main() { let mut num = 1u64; let mut vec = Vec::new(); for _ in 0..30 { vec.push(num.count_ones()); num *= 3; } println!("pop count of 3^0, 3^1 ... 3^29:\n{:?}",vec); let mut even = Vec::new(); let mut odd = Vec::new(); num = 1; while even.len() < 30 || odd.len() ...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func array bitset: powerSet (in bitset: baseSet) is func result var array bitset: pwrSet is [] (bitset.value); local var integer: element is 0; var integer: index is 0; var bitset: aSet is bitset.value; begin for element range baseSet do for key index ra...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#SETL
SETL
Pfour := pow({1, 2, 3, 4}); Pempty := pow({}); PPempty := pow(Pempty);   print(Pfour); print(Pempty); print(PPempty);
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Logo
Logo
to prime? :n if :n < 2 [output "false] if :n = 2 [output "true] if equal? 0 modulo :n 2 [output "false] for [i 3 [sqrt :n] 2] [if equal? 0 modulo :n :i [output "false]] output "true end
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Raku
Raku
sub prime-factors ( Int $n where * > 0 ) { return $n if $n.is-prime; return () if $n == 1; my $factor = find-factor( $n ); sort flat ( $factor, $n div $factor ).map: &prime-factors; }   sub find-factor ( Int $n, $constant = 1 ) { return 2 unless $n +& 1; if (my $gcd = $n gcd 6541380665835015) > ...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Scala
Scala
import java.lang.Long.bitCount   object PopCount extends App { val nNumber = 30   def powersThree(start: Long): LazyList[Long] = start #:: powersThree(start * 3L)   println("Population count of 3ⁿ :") println(powersThree(1L).map(bitCount).take(nNumber).mkString(", "))   def series(start: Long): LazyList[Long]...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Sidef
Sidef
var arr = %w(a b c) for i in (0 .. arr.len) { say arr.combinations(i) }
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#LSE64
LSE64
over : 2 pick 2dup : over over even? : 1 & 0 =   # trial n d yields "n d 0/1 false" or "n d+2 true" trial : 2 + true trial : 2dup % 0 = then 0 false trial : 2dup dup * < then 1 false trial-loop : trial &repeat   # prime? n yields flag prime? : 3 trial-loop >flag drop drop prime? : dup even? ...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#REXX
REXX
/*REXX pgm does prime decomposition of a range of positive integers (with a prime count)*/ numeric digits 1000 /*handle thousand digits for the powers*/ parse arg bot top step base add /*get optional arguments from the C.L. */ if bot=='' then do; bot=1; top=100; end ...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func integer: popcount (in integer: n) is return card(bitset(n));   const proc: main is func local var integer: count is 0; var integer: num is 0; begin for num range 0 to 29 do write(popcount(3 ** num) <& " "); end for; writeln; write("evil: ");...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Simula
Simula
SIMSET BEGIN   LINK CLASS LOF_INT(N); INTEGER N;;   LINK CLASS LOF_LOF_INT(H); REF(HEAD) H;;   REF(HEAD) PROCEDURE MAP(P_LI, P_LLI); REF(HEAD) P_LI; REF(HEAD) P_LLI; BEGIN REF(HEAD) V_RESULT; V_RESULT :- NEW HEAD; IF NOT P_LLI.EMPTY THEN BEGIN REF(LOF_...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Lua
Lua
function IsPrime( n ) if n <= 1 or ( n ~= 2 and n % 2 == 0 ) then return false end   for i = 3, math.sqrt(n), 2 do if n % i == 0 then return false end end   return true end
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Ring
Ring
  prime = 18705 decomp(prime)   func decomp nr x = "" for i = 1 to nr if isPrime(i) and nr % i = 0 x = x + string(i) + " * " ok if i = nr x2 = substr(x,1,(len(x)-2)) see string(nr) + " = " + x2 + nl ok next   func isPrime num if (num <= 1) return 0 ok if (num % 2 = 0) and num != ...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Sidef
Sidef
func population_count(n) { n.as_bin.count('1') } say "#{0..29 «**« 3 «call« population_count -> join(' ')}"   var numbers = 60.of { |i| [i, population_count(i)] }   say "Evil: #{numbers.grep{_[1] %% 2}.map{.first}.join(' ')}" say "Odious: #{numbers.grep{_[1] & 1}.map{.first}.join(' ')}"
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Smalltalk
Smalltalk
Collection extend [ power [ ^(0 to: (1 bitShift: self size) - 1) readStream collect: [ :each || i | i := 0. self select: [ :elem | (each bitAt: (i := i + 1)) = 1 ] ] ] ].
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#M2000_Interpreter
M2000 Interpreter
  Inventory Known1=2@, 3@ IsPrime=lambda Known1 (x as decimal) -> { =0=1 if exist(Known1, x) then =1=1 : exit if x<=5 OR frac(x) then {if x == 2 OR x == 3 OR x == 5 then Append Known1, x  : =1=1 Break} if frac(x/2) else exit if frac(x/...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Ruby
Ruby
irb(main):001:0> require 'prime' => true irb(main):003:0> 2543821448263974486045199.prime_division => [[701, 1], [1123, 2], [2411, 1], [1092461, 2]]
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Swift
Swift
func populationCount(n: Int) -> Int { guard n >= 0 else { fatalError() }   return String(n, radix: 2).filter({ $0 == "1" }).count }   let pows = (0...) .lazy .map({ Int(pow(3, Double($0))) }) .map(populationCount) .prefix(30)   let evils = (0...) .lazy .filter({ populationCount(n: $0) & 1 ==...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Standard_ML
Standard ML
fun subsets xs = foldr (fn (x, rest) => rest @ map (fn ys => x::ys) rest) [[]] xs
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Swift
Swift
func powersetFrom<T>(_ elements: Set<T>) -> Set<Set<T>> { guard elements.count > 0 else { return [[]] } var powerset: Set<Set<T>> = [[]] for element in elements { for subset in powerset { powerset.insert(subset.union([element])) } } return powerset }   // Example: powersetFrom([1, 2, 4])
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#M4
M4
define(`testnext', `ifelse(eval($2*$2>$1),1, 1, `ifelse(eval($1%$2==0),1, 0, `testnext($1,eval($2+2))')')') define(`isprime', `ifelse($1,2, 1, `ifelse(eval($1<=1 || $1%2==0),1, 0, `testnext($1,3)')')')   isprime(9) isprime(11)
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Rust
Rust
[package] name = "prime_decomposition" version = "0.1.1" edition = "2018" [dependencies] num-bigint = "0.3.0" num-traits = "0.2.12"
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Symsyn
Symsyn
    | Pop Count 3^i   i if i < 30 (3^i) x popcount x 63 x ~ x $r + $r $s + ' ' $s + i goif endif "' Pop Count 3^i : ' $s " []   | Evil Numbers   i cnt if cnt < 30 popcount i 7 x x:0:1 y if y <> 1 + cnt ~ i $r + $r $e + ' ' $e endif + i ...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Tcl
Tcl
package require Tcl 8.6   proc hammingWeight {n} { tcl::mathop::+ {*}[split [format %llb $n] ""] } for {set n 0;set l {}} {$n<30} {incr n} { lappend l [hammingWeight [expr {3**$n}]] } puts "p3: $l" for {set n 0;set e [set o {}]} {[llength $e]<30||[llength $o]<30} {incr n} { lappend [expr {[hammingWeight $n]...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Tcl
Tcl
proc subsets {l} { set res [list [list]] foreach e $l { foreach subset $res {lappend res [lappend subset $e]} } return $res } puts [subsets {a b c d}]
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Maple
Maple
TrialDivision := proc( n :: integer ) if n <= 1 then false elif n = 2 then true elif type( n, 'even' ) then false else for local i from 3 by 2 while i * i <= n do if irem( n, i ) = 0 then ...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#S-BASIC
S-BASIC
  rem - compute p mod q function mod(p, q = integer) = integer end = p - q * (p/q)   dim integer factors(16) rem log2(maxint) is sufficiently large   comment Find the prime factors of n and store in global array factors (arrays cannot be passed as parameters) and return the number found. If n is prime, it will ...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#UNIX_Shell
UNIX Shell
popcount() { local -i n=$1 (( n < 0 )) && return 1 local ones=0 while (( n > 0 )); do (( ones += n%2 )) (( n /= 2 )) done echo $ones }   popcount_3s=() n=1 for (( i=0; i<30; i++ )); do popcount_3s+=( $(popcount $n) ) (( n *= 3 )) done echo "powers of 3 popcounts: ${popco...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#TXR
TXR
(defun power-set (s) (mappend* (op comb s) (range 0 (length s))))
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
IsPrime[n_Integer] := Block[{}, If[n <= 1, Return[False]]; If[n == 2, Return[True]]; If[Mod[n, 2] == 0, Return[False]]; For[k = 3, k <= Sqrt[n], k += 2, If[Mod[n, k] == 0, Return[False]]]; Return[True]]
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Scala
Scala
import annotation.tailrec import collection.parallel.mutable.ParSeq   object PrimeFactors extends App { def factorize(n: Long): List[Long] = { @tailrec def factors(tuple: (Long, Long, List[Long], Int)): List[Long] = { tuple match { case (1, _, acc, _) => acc case (n, k, a...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#VBA
VBA
Sub Population_count() nmax = 30 b = 3 n = 0: List = "": bb = 1 For i = 0 To nmax - 1 List = List & " " & popcount(bb) bb = bb * b Next 'i Debug.Print "popcounts of the powers of " & b Debug.Print List For j = 0 To 1 If j = 0 Then c = "evil numbers" Else c = "odio...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#UNIX_Shell
UNIX Shell
p() { [ $# -eq 0 ] && echo || (shift; p "$@") | while read r ; do echo -e "$1 $r\n$r"; done }
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#MATLAB
MATLAB
function isPrime = primalityByTrialDivision(n)   if n == 2 isPrime = true; return elseif (mod(n,2) == 0) || (n <= 1) isPrime = false; return end   %First n mod (3 to sqrt(n)) is taken. This will be a vector where the %first element is equal to n mod 3 and the last ele...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Scheme
Scheme
(define (factor number) (define (*factor divisor number) (if (> (* divisor divisor) number) (list number) (if (= (modulo number divisor) 0) (cons divisor (*factor divisor (/ number divisor))) (*factor (+ divisor 1) number)))) (*factor 2 number))   (display (factor 1111111...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#VBScript
VBScript
' Population count - VBScript - 10/05/2019 nmax=30 b=3 n=0: list="": bb=1 For i=0 To nmax-1 list=list & " " & popcount(bb) bb=bb*b Next 'i Msgbox list,,"popcounts of the powers of " & b For j=0 to 1 If j=0 Then c="evil numbers": Else c="odious numbers" n=0: list="": i=0 While n<nmax If (popcount(i) ...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#UnixPipes
UnixPipes
  | cat A a b c   | cat A |\ xargs -n 1 ksh -c 'echo \{`cat A`\}' |\ xargs |\ sed -e 's; ;,;g' \ -e 's;^;echo ;g' \ -e 's;\},;}\\ ;g' |\ ksh |unfold `wc -l A` |\ xargs -n1 -I{} ksh -c 'echo {} |\ unfold 1 |sort -u |xargs' |sort -u   a a b a b c a c b b c c  
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Maxima
Maxima
isprme(n):= catch( for k: 2 thru sqrt(n) do if mod(n, k)=0 then throw(false), true);   map(isprme, [2, 3, 4, 65, 100, 181, 901]); /* [true, true, false, false, false, true, false] */
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Seed7
Seed7
const func array integer: factorise (in var integer: number) is func result var array integer: result is 0 times 0; local var integer: checker is 2; begin while checker * checker <= number do if number rem checker = 0 then result &:= [](checker); number := number div checker; ...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Visual_Basic_.NET
Visual Basic .NET
Imports System.Console, System.Diagnostics   Module Module1   Dim i As Integer, eo As Boolean   Function PopCnt(n As Long) As Integer Return Convert.ToString(n, 2).ToCharArray().Where(Function(x) x = "1").Count() End Function   Sub Aline(a As List(Of Integer), title As String) WriteLine("{0,-8}{1}", tit...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Ursala
Ursala
powerset = ~&NiC+ ~&i&& ~&at^?\~&aNC ~&ahPfatPRXlNrCDrT
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#min
min
(  :n 3 :i n sqrt :m true :p (i m <=) ( (n i mod 0 ==) (m @i false @p) when i 2 + @i ) while p ) :_prime?  ; helper function   ( ( ((2 <) (false)) ((dup even?) (2 ==)) ((true) (_prime?)) ) case ) :prime?
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#SequenceL
SequenceL
isPrime(n) := n = 2 or (n > 1 and none(n mod ([2]++((1...floor(sqrt(n)/2))*2+1)) = 0));   primeFactorization(num) := primeFactorizationHelp(num, []);   primeFactorizationHelp(num, current(1)) := let primeFactors[i] := i when num mod i = 0 and isPrime(i) foreach i within 2 ... num; in curr...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Wren
Wren
import "/big" for BigInt import "/fmt" for Fmt   var popCount = Fn.new { |n| var count = 0 while (n != 0) { n = n & (n - 1) count = count + 1 } return count }   System.print("The population count of the first 30 powers of 3 is:") var p3 = 1 for (i in 0..29) { System.write("%(popCount...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#V
V
[A C E] powerlist =[[A C E] [A C] [A E] [A] [C E] [C] [E] []]
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П0 1 - x#0 34 2 - /-/ x<0 32 ИП0 2 / {x} x#0 34 3 П4 ИП0 ИП4 / {x} x#0 34 КИП4 КИП4 ИП0 КвКор ИП4 - x<0 16 1 С/П 0 С/П
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Sidef
Sidef
say factor(536870911) #=> [233, 1103, 2089] say factor_exp(536870911) #=> [[233, 1], [1103, 1], [2089, 1]]
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#Yabasic
Yabasic
print "Pop count (3^x): "   for i = 0 to 29 print population(3^i); next print "\n"   print "Evil: " EvilOdious(30) print "\n"   print "Odious: " EvilOdious(30, 1) print "\n"   sub EvilOdious(limit, type) local i, count, eo   repeat eo = mod(population(i), 2) if (type and eo) or (not type and...
http://rosettacode.org/wiki/Population_count
Population count
Population count You are encouraged to solve this task according to the task description, using any language you may know. The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer. Population count   is also known as:   pop count   popcount   sideways sum ...
#zkl
zkl
n:=1; do(30){ print(n.num1s,","); n*=3 } println();   println("evil: ",[0..].filter(30,fcn(n){ n.num1s.isEven }).concat(","));   // now, as an iterator aka lazy: println("odious: ",(0).walker(*).tweak( // 0,1,2,3,4... iterator fcn(n){ if(n.num1s.isEven) Void.Skip else n }).walk(30).concat(","));
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#VBA
VBA
Option Base 1 Private Function power_set(ByRef st As Collection) As Collection Dim subset As Collection, pwset As New Collection For i = 0 To 2 ^ st.Count - 1 Set subset = New Collection For j = 1 To st.Count If i And 2 ^ (j - 1) Then subset.Add st(j) Next j pwset.Add...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Ada
Ada
with Ada.Text_IO;   with PDF_Out;   procedure Pinstripe_Printer is use PDF_Out;   package Point_IO is new Ada.Text_Io.Float_IO (Real);   procedure Pinstripe (Doc  : in out Pdf_Out_File; Line_Width  : Real; Line_Height  : Real; ...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#MUMPS
MUMPS
ISPRIME(N) QUIT:(N=2) 1 NEW I,R SET R=N#2 IF R FOR I=3:2:(N**.5) SET R=N#I Q:'R KILL I QUIT R
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Simula
Simula
  EXTERNAL CLASS BIGNUM; BIGNUM BEGIN   CLASS TEXTLIST; BEGIN CLASS TEXTARRAY(N); INTEGER N; BEGIN TEXT ARRAY DATA(1:N); END TEXTARRAY; PROCEDURE EXPAND(N); INTEGER N; BEGIN REF(TEXTARRAY) NEWARR; INTEGER I; NEWARR :- NEW TE...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#VBScript
VBScript
Function Dec2Bin(n) q = n Dec2Bin = "" Do Until q = 0 Dec2Bin = CStr(q Mod 2) & Dec2Bin q = Int(q / 2) Loop Dec2Bin = Right("00000" & Dec2Bin,6) End Function   Function PowerSet(s) arrS = Split(s,",") PowerSet = "{" For i = 0 To 2^(UBound(arrS)+1)-1 If i = 0 Then PowerSet = PowerSet & "{}," Else b...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#Wren
Wren
import "./perm" for Powerset   var sets = [ [1, 2, 3, 4], [], [[]] ] for (set in sets) { System.print("The power set of %(set) is:") System.print(Powerset.list(set)) System.print() }
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#BBC_BASIC
BBC BASIC
PD_RETURNDC = 256 _LOGPIXELSY = 90   DIM pd{lStructSize%, hwndOwner%, hDevMode%, hDevNames%, \ \ hdc%, flags%, nFromPage{l&,h&}, nToPage{l&,h&}, \ \ nMinPage{l&,h&}, nMaxPage{l&,h&}, nCopies{l&,h&}, \ \ hInstance%, lCustData%, lpfnPrintHook%, lpfnSetupHook%, \ \ ...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Go
Go
package main   import ( "github.com/fogleman/gg" "log" "os/exec" "runtime" )   var palette = [2]string{ "FFFFFF", // white "000000", // black }   func pinstripe(dc *gg.Context) { w := dc.Width() h := dc.Height() / 7 for b := 1; b <= 11; b++ { for x, ci := 0, 0; x < w; x, ...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#NetRexx
NetRexx
/* NetRexx */   options replace format comments java crossref savelog symbols nobinary   parse arg nbr rangeBegin rangeEnd .   if nbr = '' | nbr = '.' then do if rangeBegin = '' | rangeBegin = '.' then rangeBegin = 1 if rangeEnd = '' | rangeEnd = '.' then rangeEnd = 100 if rangeEnd > rangeBegin then directi...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Slate
Slate
n@(Integer traits) primesDo: block "Decomposes the Integer into primes, applying the block to each (in increasing order)." [| div next remaining | div: 2. next: 3. remaining: n. [[(remaining \\ div) isZero] whileTrue: [block applyTo: {div}. remaining: remaining // div]. remaining = 1] whileFa...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#XPL0
XPL0
func PowSet(Set, Size); int Set, Size; int N, M, Mask, DoComma; [ChOut(0, ^{); for N:= 0 to 1<<Size -1 do [if N>0 then ChOut(0, ^,); ChOut(0, ^{); Mask:= 1; DoComma:= false; for M:= 0 to Size-1 do [if Mask & N then [if DoComma then ChOut(0, ^,); IntOut(0, Set(M)); ...
http://rosettacode.org/wiki/Power_set
Power set
A   set   is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored. Given a set S, the power set (or pow...
#zkl
zkl
fcn pwerSet(list){ (0).pump(list.len(),List, Utils.Helpers.pickNFrom.fp1(list), T(Void.Write,Void.Write) ) .append(list) }
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Julia
Julia
using FileIO, ImageIO   function getnumberwithprompt(prompt, t::Type) s = "" while (x = tryparse(t, s)) == nothing print("\n", prompt, ": -> ") s = strip(readline()) end return x end   dpi = getnumberwithprompt("Printer DPI (dots per inch)", Int) pwidth = getnumberwithprompt("Printer wid...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Liberty_BASIC
Liberty BASIC
  nomainwin   'paperW = 8.5 ' for US letter paper 'paperH = 11   paperW = 8.2677165 ' for A4 paper paperH = 11.6929134   dpi= 300   prompt "Enter your printer DPI" +chr$( 13) + "(300 is OK for laser one, 360 likely for inkjet)"; dpi   w = paperW *dpi 'pixel size of paper h = paperH *dpi   graphicbox #main.gr,...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#newLISP
newLISP
; Here are some simpler functions to help us:   (define (divisible? larger-number smaller-number) (zero? (% larger-number smaller-number)))   (define (int-root number) (floor (sqrt number)))   (define (even-prime? number) (= number 2))   ; Trial division for odd numbers   (define (find-odd-factor? odd-number) (catc...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Smalltalk
Smalltalk
Integer extend [ primesDo: aBlock [ | div next rest | div := 2. next := 3. rest := self. [ [ rest \\ div == 0 ] whileTrue: [ aBlock value: div. rest := rest // div ]. rest = 1] whileFalse: [ div := next. next :...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#AutoHotkey
AutoHotkey
SoundPlay, %A_WinDir%\Media\tada.wav, wait SoundPlay, %A_WinDir%\Media\Windows XP Startup.wav, wait   ; simulaneous play may require a second script   SoundPlay, %A_WinDir%\Media\tada.wav SoundPlay, Nonexistent ; stop before finishing   SoundSet +10 ; increase volume by 10% Loop, 2 SoundPlay, %A_WinDir%\Media\tad...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Nim
Nim
import gintro/[glib, gobject, gtk, gio, cairo]   const Colors = [[255.0, 255.0, 255.0], [0.0, 0.0, 0.0]]   #---------------------------------------------------------------------------------------------------   proc beginPrint(op: PrintOperation; printContext: PrintContext; data: pointer) = ## Process signal "begin_pr...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Phix
Phix
(load "@lib/ps.l")   (call 'lpr (pdf "pinstripes" (a4) # 595 x 842 dots (for X 595 (gray (if (bit? 1 X) 0 100) (vline X 0 842) ) ) (page) ) )
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#PicoLisp
PicoLisp
(load "@lib/ps.l")   (call 'lpr (pdf "pinstripes" (a4) # 595 x 842 dots (for X 595 (gray (if (bit? 1 X) 0 100) (vline X 0 842) ) ) (page) ) )
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Racket
Racket
  #lang racket/gui   (define parts 4)   (define dc (new printer-dc%)) (send* dc (start-doc "Pinstripe") (start-page))   (define-values [W H] (send dc get-size)) (send dc set-pen "black" 0 'solid) (send dc set-brush "black" 'solid) (define H* (round (/ H parts))) (for ([row parts]) (define Y (* row H*)) (for ([X (in...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Nim
Nim
import sequtils, math   proc prime(a: int): bool = if a == 2: return true if a < 2 or a mod 2 == 0: return false for i in countup(3, sqrt(a.float).int, 2): if a mod i == 0: return false return true   proc prime2(a: int): bool = result = not (a < 2 or any(toSeq(2 .. sqrt(a.float).int), a mod it == 0)...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#SPAD
SPAD
    (1) -> factor 102400   12 2 (1) 2 5 Type: Factored(Integer) (2) -> factor 23193931893819371   (2) 83 3469 71341 1129153 Type: Factored(Integer)    
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Batch_File
Batch File
@echo off  :main cls echo Drag a .wav file there and press enter set /p file1= sndrec32 /embedding /play /close %file1% cls echo Drag a second .wav file and both will play together set /p file2= sndrec32 /embedding /play /close %file1% | sndrec32 /embedding /play /close %file2% echo Thanks pause>nul exit
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#BBC_BASIC
BBC BASIC
SND_LOOP = 8 SND_ASYNC = 1 SND_FILENAME = &20000   PRINT "Playing a MIDI file..." *PLAY C:\windows\media\canyon.mid   WAIT 300 PRINT "Playing the Windows TADA sound quietly..." wave$ = "\windows\media\tada.wav" volume% = 10000 SYS "waveOutSetVolume", -1, volum...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#C.23
C#
using System; using System.Threading; using System.Media;   class Program { static void Main(string[] args) { //load sound file SoundPlayer s1 = new SoundPlayer(); // s1.SoundLocation = file; // or "s1 = new SoundPlayer(file)"   //play s1.Play();   //play for...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Raku
Raku
unit sub MAIN ($dpi = 300, $size = 'letter');   my $filename = './Pinstripe-printer-perl6.png';   my %paper = ( 'letter' => { :width(8.5), :height(11.0) } 'A4' => { :width(8.2677), :height(11.6929)} );   my ($w, $h) = %paper{$size}<width height> »*» $dpi;   # Black. It's all black my @color = (0,0,0),;  ...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Objeck
Objeck
function : IsPrime(n : Int) ~ Bool { if(n <= 1) { return false; };   for(i := 2; i * i <= n; i += 1;) { if(n % i = 0) { return false; }; };   return true; }
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Standard_ML
Standard ML
  val factor = fn n :IntInf.int => let val unfactored = fn (u,_,_) => u val factors = fn (_,f,_) => f val try = fn (_,_,i) => i fun getresult t = unfactored t::(factors t)   fun until done change x = if done x then getresult x else until done change (change x); (* it...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Delphi
Delphi
program PlayRecordedSounds;   {$APPTYPE CONSOLE}   uses MMSystem;   begin sndPlaySound('SoundFile.wav', SND_NODEFAULT OR SND_ASYNC); end.
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Go
Go
package main   import ( "log" "os" "os/exec" )   func main() { args := []string{ "-m", "-v", "0.75", "a.wav", "-v", "0.25", "b.wav", "-d", "trim", "4", "6", "repeat", "5", } cmd := exec.Command("sox", args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr ...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#GUISS
GUISS
Start,Programs,Accessories,Media Player,Menu:File,Open, Doubleclick:Icon:Sound.WAV,Button:OK,Button:Play
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Tcl
Tcl
package require Tk # Allocate a temporary drawing surface canvas .c # Draw the output we want for {set y 0;set dx 1} {$y < 11*72} {incr y 72;incr dx} { for {set x 0;set c 0} {$x < 8.5*72} {incr x $dx;set c [expr {!$c}]} { .c create rectangle $x $y [expr {$x+$dx+1}] [expr {$y+73}] \ -fill [lindex {black white...
http://rosettacode.org/wiki/Pinstripe/Printer
Pinstripe/Printer
The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing gra...
#Wren
Wren
/* gcc -O3 -std=c11 -shared -o printer.so -fPIC -I./include printer.c */   #include <stdlib.h> #include <string.h> #include "dome.h"   static DOME_API_v0* core; static WREN_API_v0* wren;   static const char* source = "" "class Printer {\n" "foreign static printFile(name) \n" "} \n";   void C_printFile(WrenVM* vm) ...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#OCaml
OCaml
let is_prime n = if n = 2 then true else if n < 2 || n mod 2 = 0 then false else let rec loop k = if k * k > n then true else if n mod k = 0 then false else loop (k+2) in loop 3
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Stata
Stata
function factor(n_) { n = n_ a = J(0,2,.) if (n<2) { return(a) } else if (n<4) { return((n,1)) } else { if (mod(n,2)==0) { for (i=0; mod(n,2)==0; i++) n = floor(n/2) a = a\(2,i) }   for (k=3; k*k<=n; k=k+2) { if (mod...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Liberty_BASIC
Liberty BASIC
'Supports .mid and .wav natively 'Midi may be played simultaneously 'with .wav but only one .wav voice 'is supported. Multiple voices can 'be achieved via API or Dlls such 'as FMOD or Wavemix   'to play a .mid and return its length playmidi "my.mid", midiLength   'check where we are in .mid if midipos()<midiLength then...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Julia
Julia
using Distributed, Gtk, LibSndFile, MP3 using FileIO: load   function recordingplayerapp(numfiles=2) # create window and widgets win = GtkWindow("Recorded Sound Player", 400, 400) |> (GtkFrame() |> (vbox = GtkBox(:v))) playprocess = @async(0) filenames = fill("", numfiles) filedurations = zeros(numf...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
a = Import["sound1.flac","FLAC"]; b = Import["sound2.flac","FLAC"];   ListPlay[a, {t, 0, 10}]; ListPlay[b, {t, 0, 10}];   ListPlay[{a,b}, {t, 0, 10}];   Stopping before the end can be done using the GUI or by reducing the parameter range of the ListPlay function.   While[True,ListPlay[{a,b}, {t, 0, 10}];]   ListPlay[{...
http://rosettacode.org/wiki/Pisano_period
Pisano period
The Fibonacci sequence taken modulo 2 is a periodic sequence of period 3 : 0, 1, 1, 0, 1, 1, ... For any integer n, the Fibonacci sequence taken modulo n is periodic and the length of the periodic cycle is referred to as the Pisano period. Prime numbers are straightforward; the Pisano period of a prime number p is si...
#11l
11l
F lcm(m, n) R m I/ gcd(m, n) * n   F get_primes(=n) [Int] r L(d) 2 .. n V q = n I/ d V m = n % d L m == 0 r.append(d) n = q q = n I/ d m = n % d R r   F is_prime(a) I a == 2 R 1B I a < 2 | a % 2 == 0 R 0B L(i) (3 .. Int(sqrt(a))).ste...
http://rosettacode.org/wiki/Primality_by_trial_division
Primality by trial division
Task Write a boolean function that tells whether a given integer is prime. Remember that   1   and all non-positive numbers are not prime. Use trial division. Even numbers greater than   2   may be eliminated right away. A loop from   3   to   √ n    will suffice,   but other loops are allowed. Related tasks ...
#Octave
Octave
function b = isthisprime(n) for r = 1:rows(n) for c = 1:columns(n) b(r,c) = false; if ( n(r,c) == 2 ) b(r,c) = true; elseif ( (n(r,c) < 2) || (mod(n(r,c),2) == 0) ) b(r,c) = false; else b(r,c) = true; for i = 3:2:sqrt(n(r,c)) if ( mod(n(r,c), i) == 0 ) b(r,c) = false; brea...
http://rosettacode.org/wiki/Prime_decomposition
Prime decomposition
The prime decomposition of a number is defined as a list of prime numbers which when all multiplied together, are equal to that number. Example 12 = 2 × 2 × 3, so its prime decomposition is {2, 2, 3} Task Write a function which returns an array or collection which contains the prime decomposition of a given ...
#Swift
Swift
func primeDecomposition<T: BinaryInteger>(of n: T) -> [T] { guard n > 2 else { return [] }   func step(_ x: T) -> T { return 1 + (x << 2) - ((x >> 1) << 1) }   let maxQ = T(Double(n).squareRoot()) var d: T = 1 var q: T = n % 2 == 0 ? 2 : 3   while q <= maxQ && n % q != 0 { q = step(d) d += 1 ...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Nim
Nim
import osproc   let args = ["-m", "-v", "0.75", "a.wav", "-v", "0.25", "b.wav", "-d", "trim", "4", "6", "repeat", "5"] echo execProcess("sox", args = args, options = {poStdErrToStdOut, poUsePath})
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#Phix
Phix
integer xPlaySound = 0   procedure play_sound()--string filename) if platform()=WINDOWS then string filename = join_path({getenv("SYSTEMROOT"),"Media","chord.wav"}) if xPlaySound=0 then atom winmm = open_dll("winmm.dll") xPlaySound = define_c_proc(winmm,"sndPlaySoundA",{C_PTR...
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#PicoLisp
PicoLisp
(call 'sox "-m" "-v" "0.75" "a.wav" "-v" "0.25" "b.wav" "-d" "trim" 4 6 "repeat" 5 )
http://rosettacode.org/wiki/Play_recorded_sounds
Play recorded sounds
Load at least two prerecorded sounds, and demonstrate as many of these features as you can: playing them individually and simultaneously stopping before the end of the sound looping (preferably glitch-free) setting the volume of each sound stereo or 3D positional mixing performing other actions when marked times...
#PureBasic
PureBasic
InitSound() ; We need this to use Sound functions UseOGGSoundDecoder() ; Now we can not only load wav sound files, but also ogg encoded ones. ; With movie library more formats can be played (depends on system) but you cannot ; handle them with Sound functions If Not LoadSound(1,"Path/to/Sound/1.ogg") Or Not LoadSou...
http://rosettacode.org/wiki/Pisano_period
Pisano period
The Fibonacci sequence taken modulo 2 is a periodic sequence of period 3 : 0, 1, 1, 0, 1, 1, ... For any integer n, the Fibonacci sequence taken modulo n is periodic and the length of the periodic cycle is referred to as the Pisano period. Prime numbers are straightforward; the Pisano period of a prime number p is si...
#Factor
Factor
USING: formatting fry grouping io kernel math math.functions math.primes math.primes.factors math.ranges sequences ;   : pisano-period ( m -- n ) [ 0 1 ] dip [ sq <iota> ] [ ] bi '[ drop tuck + _ mod 2dup [ zero? ] [ 1 = ] bi* and ] find 3nip [ 1 + ] [ 1 ] if* ;   : pisano-prime ( p k -- n ) over prime?...