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/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #Arturo | Arturo | sortTable: function [tbl][
column: "0"
reversed?: false
unless null? c: <= attr 'column -> column: to :string c
unless null? attr 'reverse -> reversed?: true
result: new sort.by: column map tbl 'r [
to :dictionary flatten couple 0..dec size r r
]
if reversed? -> reverse 'result
... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #ALGOL_W | ALGOL W | begin % compare lists (rows) of integers %
% returns TRUE if there is an element in a that is < the corresponding %
% element in b and all previous elements are equal, FALSE otherwise %
% the bounds of a and b should aLb :: aUb and bLb :: bUb %
logical procedure iLT ( integer array a ( ... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #Aime | Aime | ordl(list a, b)
{
integer i, l, o;
l = min(~a, ~b);
i = 0;
while (i < l) {
if (a[i] != b[i]) {
o = a[i] < b[i];
break;
}
i += 1;
}
i < l ? o : ~a <= ~b;
}
main(void)
{
o_(ordl(list(1, 2), list(1, 2)), "\n");
o_(ordl(list(1e2, 2), li... |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Scala | Scala |
def tri(row: Int): List[Int] =
row match {
case 1 => List(1)
case n: Int => 1 +: ((tri(n - 1) zip tri(n - 1).tail) map { case (a, b) => a + b }) :+ 1
} |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Perl | Perl | #!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/Order_by_pair_comparisons
use warnings;
sub ask
{
while( 1 )
{
print "Compare $a to $b [<,=,>]: ";
<STDIN> =~ /[<=>]/ and return +{qw( < -1 = 0 > 1 )}->{$&};
}
}
my @sorted = sort ask qw( violet red green indigo blue yellow orange );... |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Phix | Phix | integer qn = 0
function ask(string a, b)
qn += 1
printf(1,"%d: Is %s < %s (Y/N)?:",{qn,a,b})
integer ch = upper(wait_key())
printf(1,"%s\n",ch)
return iff(ch='Y'?-1:1)
end function
?custom_sort(ask,split("violet orange red yellow green blue indigo"))
|
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #AWK | AWK |
# Operators are shown in decreasing order of precedence.
# A blank line separates groups of operators with equal precedence.
# All operators are left associative except:
# . assignment operators
# . conditional operator
# . exponentiation
# which are right associative.
#
# ( ) grouping
#
# $ field reference
#... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #BASIC256 | BASIC256 | 3 * 2 + 1 |
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #Clojure | Clojure | (defn is-sorted? [coll]
(not-any? pos? (map compare coll (next coll))))
(defn take-while-eqcount [coll]
(let [n (count (first coll))]
(take-while #(== n (count %)) coll)))
(with-open [rdr (clojure.java.io/reader "unixdict.txt")]
(->> rdr
line-seq
(filter is-sorted?)
(sort-by count >)
... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #Mirah | Mirah | def reverse(s:string)
StringBuilder.new(s).reverse.toString()
end
def palindrome?(s:string)
s.equals(reverse(s))
end
puts palindrome?("anna") # ==> true
puts palindrome?("Erik") # ==> false
puts palindrome?("palindroom-moordnilap") # ==> true
puts nil # ==> null |
http://rosettacode.org/wiki/P-value_correction | P-value correction | Given a list of p-values, adjust the p-values for multiple comparisons. This is done in order to control the false positive, or Type 1 error rate.
This is also known as the "false discovery rate" (FDR). After adjustment, the p-values will be higher but still inside [0,1].
The adjusted p-values are sometimes called "q... | #C.2B.2B | C++ | #include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
std::vector<int> seqLen(int start, int end) {
std::vector<int> result;
if (start == end) {
result.resize(end + 1);
std::iota(result.begin(), result.end(), 1);
} else if (start < end) {
... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Arturo | Arturo | orderDisjoint: function [m,n][
ms: split.words m
ns: split.words n
indexes: new []
loop ns 'item [
idx: index ms item
unless null? idx [
'indexes ++ idx
ms\[idx]: ""
]
]
sort 'indexes
loop.with:'i indexes 'idx ->
ms\[idx]: ns\[i]
... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #AutoHotkey | AutoHotkey | Data := [ {M: "the cat sat on the mat", N: "mat cat"}
, {M: "the cat sat on the mat", N: "cat mat"}
, {M: "A B C A B C A B C", N: "C A C A"}
, {M: "A B C A B D A B E", N: "E A D A"}
, {M: "A B", N: "B"}
, {M: "A B", N: "B A"}
, {M: "A B B A", N: "B A"} ]
for Key, Val in Data
Output .= Val.M " :: " Val.N " -> "... |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #AutoHotkey | AutoHotkey | Gosub start ; create and show the gui
sort_table("Text", column := 2, reverse := 1) ; lexicographic sort
Sleep, 2000
sort_table("Integer", column := 2, reverse := 1) ; numerical sort
Return
start:
Gui, Add, ListView, r20 w200, 1|2|3
data =
(
1,2,3
b,q,z
c,z,z
)
Loop, Parse, data, `n
{
String... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #AppleScript | AppleScript | -- <= for lists
-- compare :: [a] -> [a] -> Bool
on compare(xs, ys)
if length of xs = 0 then
true
else
if length of ys = 0 then
false
else
set {hx, txs} to uncons(xs)
set {hy, tys} to uncons(ys)
if hx = hy then
compare(txs... |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Scheme | Scheme | (define (next-row row)
(map + (cons 0 row) (append row '(0))))
(define (triangle row rows)
(if (= rows 0)
'()
(cons row (triangle (next-row row) (- rows 1)))))
(triangle (list 1) 5)
|
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Python | Python | def _insort_right(a, x, q):
"""
Insert item x in list a, and keep it sorted assuming a is sorted.
If x is already in a, insert it to the right of the rightmost x.
"""
lo, hi = 0, len(a)
while lo < hi:
mid = (lo+hi)//2
q += 1
less = input(f"{q:2}: IS {x:>6} LESS-THAN {a[... |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Quackery | Quackery | [ $ "Is " swap join
$ " before " join
swap join
$ "? (y/n) " join
input $ "y" = ] is askuser
$ "red orange yellow green blue indigo violet"
say "Correct order --> "
dup echo$ cr cr
nest$ shuffle
dup witheach [ echo$ sp ] cr cr
sortwith askuser cr
witheach [ echo$ sp ] cr |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #bc | bc | 3 * 2 + 1 |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #BCPL | BCPL | 3 * 2 + 1 |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #BQN | BQN | 3 * 2 + 1 |
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #CLU | CLU | is_ordered = proc (s: string) returns (bool)
last: char := '\000'
for c: char in string$chars(s) do
if last > c then return(false) end
last := c
end
return(true)
end is_ordered
lines = iter (s: stream) yields (string)
while true do
yield(stream$getl(s))
except when... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #ML | ML | fun to_locase s = implode ` map (c_downcase) ` explode s
fun only_alpha s = implode ` filter (fn x = c_alphabetic x) ` explode s
fun is_palin
( h1 :: t1, h2 :: t2, n = 0 ) = true
| ( h1 :: t1, h2 :: t2, n ) where ( h1 eql h2 ) = is_palin( t1, t2, n - 1)
| ( h1 :: t1, h2 :: t2, n ) = ... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #11l | 11l | F ownCalcPass(password, nonce)
UInt32 result
V start = 1B
L(c) nonce
I c != ‘0’ & start
result = UInt32(Int(password))
start = 0B
S c
‘0’
{}
‘1’
result = rotr(result, 7)
‘2’
result = rotr(result, 4)
‘3’
... |
http://rosettacode.org/wiki/P-value_correction | P-value correction | Given a list of p-values, adjust the p-values for multiple comparisons. This is done in order to control the false positive, or Type 1 error rate.
This is also known as the "false discovery rate" (FDR). After adjustment, the p-values will be higher but still inside [0,1].
The adjusted p-values are sometimes called "q... | #D | D | import std.algorithm;
import std.conv;
import std.math;
import std.stdio;
import std.string;
int[] seqLen(int start, int end) {
int[] result;
if (start == end) {
result.length = end+1;
for (int i; i<result.length; i++) {
result[i] = i+1;
}
} else if (start < end) {
... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Bracmat | Bracmat | ( ( odli
= M N NN item A Z R
. !arg:(?M.?N)
& :?NN
& whl
' ( !N:%?item ?N
& ( !M:?A !item ?Z
& !A (.) !Z:?M
& !NN !item:?NN
|
)
)
& :?R
& whl
' ( !M:?A (.) ?M
& !NN:%?item ?NN
... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #C.2B.2B | C++ |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
template <typename T>
void print(const std::vector<T> v) {
std::cout << "{ ";
for (const auto& e : v) {
std::cout << e << " ";
}
std::cout << "}";
}
template <typename T>
auto orderDisjointArrayItems(std::vector<T> M, std::ve... |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #BASIC | BASIC | 100 DEF PROC sort_table REF t$(), ordering, col, reverse
110 DEFAULT ordering=0, col=1, reverse=0
120 REM implementation of sort not shown
190 END PROC
|
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program orderlist.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*********************************/
/* Initialized data */
/*********************************/
.data
szMess... |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
local
var integer: numRows is 0;
var array integer: values is [] (0, 1);
var integer: row is 0;
var integer: index is 0;
begin
write("Number of rows: ");
readln(numRows);
writeln("1" lpad succ(numRows) * 3);
for row range 2 to numR... |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Raku | Raku | my $ask_count = 0;
sub by_asking ( $a, $b ) {
$ask_count++;
constant $fmt = '%2d. Is %-6s [ less than | greater than | equal to ] %-6s? ( < = > ) ';
constant %o = '<' => Order::Less,
'=' => Order::Same,
'>' => Order::More;
loop {
my $input = prompt sprintf $... |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #REXX | REXX | /*REXX pgm orders some items based on (correct) answers from a carbon─based life form. */
colors= 'violet red green indigo blue yellow orange'
q= 0; #= 0; $=
do j=1 for words(colors); q= inSort( word(colors, j), q)
end /*j*/ ... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Bracmat | Bracmat | SAMPLES>write 18 / 2 * 3 + 7
34
SAMPLES>write 18 / (2 * 3) + 7
10
|
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #C | C | SAMPLES>write 18 / 2 * 3 + 7
34
SAMPLES>write 18 / (2 * 3) + 7
10
|
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #C.2B.2B | C++ | SAMPLES>write 18 / 2 * 3 + 7
34
SAMPLES>write 18 / (2 * 3) + 7
10
|
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. ABC-WORDS.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DICT ASSIGN TO DISK
ORGANIZATION LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD DICT
LABEL RECORD STANDARD
... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #MMIX | MMIX | argc IS $0
argv IS $1
LOC Data_Segment
DataSeg GREG @
LOC @+1000
ItsPalStr IS @-Data_Segment
BYTE "It's palindrome",10,0
LOC @+(8-@)&7
NoPalStr IS @-Data_Segment
BYTE "It is not palindrome",10,0
LOC #100
GREG @
% input: $255 points to w... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #D | D | import std.stdio, std.string, std.conv, std.ascii, std.algorithm;
ulong ownCalcPass(in ulong password, in string nonce)
pure nothrow @safe @nogc
in {
assert(nonce.representation.all!isDigit);
} body {
enum ulong m_1 = 0x_FFFF_FFFF_UL;
enum ulong m_8 = 0x_FFFF_FFF8_UL;
enum ulong m_16 ... |
http://rosettacode.org/wiki/P-value_correction | P-value correction | Given a list of p-values, adjust the p-values for multiple comparisons. This is done in order to control the false positive, or Type 1 error rate.
This is also known as the "false discovery rate" (FDR). After adjustment, the p-values will be higher but still inside [0,1].
The adjusted p-values are sometimes called "q... | #Go | Go | package main
import (
"fmt"
"log"
"math"
"os"
"sort"
"strconv"
"strings"
)
type pvalues = []float64
type iv1 struct {
index int
value float64
}
type iv2 struct{ index, value int }
type direction int
const (
up direction = iota
down
)
// Test also for 'Unknown' cor... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Common_Lisp | Common Lisp | (defun order-disjoint (data order)
(let ((order-b (make-hash-table :test 'equal)))
(loop :for n :in order :do (incf (gethash n order-b 0)))
(loop :for m :in data :collect
(cond ((< 0 (gethash m order-b 0))
(decf (gethash m order-b))
(pop order))
(t m))))) |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #BBC_BASIC | BBC BASIC | DIM table$(100,100)
PROCsort_default(table$())
PROCsort_options(table$(), TRUE, 1, FALSE)
END
DEF PROCsort_options(table$(), ordering%, column%, reverse%)
DEF PROCsort_default(table$()) : LOCAL ordering%, column%, reverse%
REM The sort goes here, controlled by the options
... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #Arturo | Arturo | compareLists: function [a,b][
loop 0..min @[size a, size b] 'i [
if a\[i] < b\[i] -> return true
if a\[i] > b\[i] -> return false
]
return less? size a size b
]
alias.infix '<=> 'compareLists
do [
print [1 2 1 3 2] <=> [1 2 0 4 4 0 0 0]
] |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Sidef | Sidef | func pascal(rows) {
var row = [1]
{ | n|
say row.join(' ')
row = [1, {|i| row[i] + row[i+1] }.map(0 .. n-2)..., 1]
} << 1..rows
}
pascal(10) |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Ruby | Ruby | items = ["violet", "red", "green", "indigo", "blue", "yellow", "orange"]
count = 0
sortedItems = []
items.each {|item|
puts "Inserting '#{item}' into #{sortedItems}"
spotToInsert = sortedItems.bsearch_index{|x|
count += 1
print "(#{count}) Is #{item} < #{x}? "
gets.start_with?('y')
} || sortedItems.le... |
http://rosettacode.org/wiki/Order_by_pair_comparisons | Order by pair comparisons |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Wren | Wren | import "/ioutil" for Input
import "/fmt" for Fmt
// Inserts item x in list a, and keeps it sorted assuming a is already sorted.
// If x is already in a, inserts it to the right of the rightmost x.
var insortRight = Fn.new{ |a, x, q|
var lo = 0
var hi = a.count
while (lo < hi) {
var mid = ((lo + hi... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Cach.C3.A9_ObjectScript | Caché ObjectScript | SAMPLES>write 18 / 2 * 3 + 7
34
SAMPLES>write 18 / (2 * 3) + 7
10
|
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Clojure | Clojure | : \ ? = ~ / ! # $ % & * + - < > @ ^ ` | , ' ; |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #COBOL | COBOL | : \ ? = ~ / ! # $ % & * + - < > @ ^ ` | , ' ; |
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #CoffeeScript | CoffeeScript |
ordered_word = (word) ->
for i in [0...word.length - 1]
return false unless word[i] <= word[i+1]
true
show_longest_ordered_words = (candidates, dict_file_name) ->
words = ['']
for word in candidates
continue if word.length < words[0].length
if ordered_word word
words = [] if word.length > ... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #Modula-2 | Modula-2 | MODULE Palindrome;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
PROCEDURE IsPalindrome(str : ARRAY OF CHAR) : BOOLEAN;
VAR i,m : INTEGER;
VAR buf : ARRAY[0..63] OF CHAR;
BEGIN
i := 0;
m := HIGH(str) - 1;
WHILE i<m DO
IF str[i] # str[m-i] THEN
RETURN... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #Delphi | Delphi |
program OpenWebNet_password;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
function ownCalcPass(password, nonce: string): Cardinal;
begin
var start := True;
var num1 := 0;
var num2 := num1;
var i := password.ToInteger();
var pwd := i;
for var c in nonce do
begin
if c <> '0' then
begin
... |
http://rosettacode.org/wiki/OpenGL | OpenGL |
Task
Display a smooth shaded triangle with OpenGL.
Triangle created using C example compiled with GCC 4.1.2 and freeglut3.
| #Ada | Ada | with Lumen.Window;
with Lumen.Events;
with Lumen.Events.Animate;
with GL;
with GLU;
procedure OpenGL is
The_Window : Lumen.Window.Handle;
Program_Exit : Exception;
-- simply exit this program
procedure Quit_Handler (Event : in Lumen.Events.Event_Data) is
begin
raise Program_Exit;
end;
... |
http://rosettacode.org/wiki/OLE_automation | OLE automation | OLE Automation is an inter-process communication mechanism based on Component Object Model (COM) on Microsoft Windows.
Task
Provide an automation server implementing objects that can be accessed by a client running in a separate process.
The client gets a proxy-object that can call methods on the object.
Th... | #AutoHotkey | AutoHotkey | ahk := comobjactive("ahkdemo.ahk")
ahk.hello("hello world")
py := ComObjActive("python.server")
py.write("hello")
return |
http://rosettacode.org/wiki/P-value_correction | P-value correction | Given a list of p-values, adjust the p-values for multiple comparisons. This is done in order to control the false positive, or Type 1 error rate.
This is also known as the "false discovery rate" (FDR). After adjustment, the p-values will be higher but still inside [0,1].
The adjusted p-values are sometimes called "q... | #Java | Java | import java.util.Arrays;
import java.util.Comparator;
public class PValueCorrection {
private static int[] seqLen(int start, int end) {
int[] result;
if (start == end) {
result = new int[end + 1];
for (int i = 0; i < result.length; ++i) {
result[i] = i + 1;
... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #D | D | import std.stdio, std.string, std.algorithm, std.array, std.range,
std.conv;
T[] orderDisjointArrayItems(T)(in T[] data, in T[] items)
pure /*nothrow*/ @safe {
int[] itemIndices;
foreach (item; items.dup.sort().uniq) {
immutable int itemCount = items.count(item);
assert(data.count(item)... |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #Bracmat | Bracmat | ( ( sortTable
= table ordering column reverse
. !arg
: ( ?table
. ( ? (ordering.?ordering) ?
| ?&lexicographic:?ordering
)
: ( ? (column.?column) ?
| ?&1:?column
)
: ( ? (reverse.?reverse) ?
| ?... |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #C | C | #include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
typedef const char * String;
typedef struct sTable {
String * *rows;
int n_rows,n_cols;
} *Table;
typedef int (*CompareFctn)(String a, String b);
struct {
CompareFctn compare;
int column;
int... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #AutoHotkey | AutoHotkey | List1 := [1,2,1,3,2]
List2 := [1,2,0,4,4,0,0,0]
MsgBox % order(List1, List2)
order(L1, L2){
return L1.MaxIndex() < L2.MaxIndex()
} |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Stata | Stata | function pascal1(n) {
return(comb(J(1,n,0::n-1),J(n,1,0..n-1)))
}
function pascal2(n) {
a = I(n)
a[.,1] = J(n,1,1)
for (i=3; i<=n; i++) {
a[i,2..i-1] = a[i-1,2..i-1]+a[i-1,1..i-2]
}
return(a)
}
function pascal3(n) {
a = J(n,n,0)
for (i=1; i<n; i++) {
a[i+1,i] = i
}
s = p = I(n)
k = 1
for (i=0; i<n; ... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Common_Lisp | Common Lisp | : \ ? = ~ / ! # $ % & * + - < > @ ^ ` | , ' ; |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #D | D | : \ ? = ~ / ! # $ % & * + - < > @ ^ ` | , ' ; |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Delphi | Delphi | : \ ? = ~ / ! # $ % & * + - < > @ ^ ` | , ' ; |
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #Common_Lisp | Common Lisp | (defun orderedp (word)
(reduce (lambda (prev curr)
(when (char> prev curr) (return-from orderedp nil))
curr)
word)
t)
(defun longest-ordered-words (filename)
(let ((result nil))
(with-open-file (s filename)
(loop
with greatest-length = 0
for word = (... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #Modula-3 | Modula-3 | MODULE Palindrome;
IMPORT Text;
PROCEDURE isPalindrome(string: TEXT): BOOLEAN =
VAR len := Text.Length(string);
BEGIN
FOR i := 0 TO len DIV 2 - 1 DO
IF Text.GetChar(string, i) # Text.GetChar(string, (len - i - 1)) THEN
RETURN FALSE;
END;
END;
RETURN TRUE;
END isPalindrome;
END ... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #Go | Go | package main
import (
"fmt"
"strconv"
)
func ownCalcPass(password, nonce string) uint32 {
start := true
num1 := uint32(0)
num2 := num1
i, _ := strconv.Atoi(password)
pwd := uint32(i)
for _, c := range nonce {
if c != '0' {
if start {
num2 = pwd
... |
http://rosettacode.org/wiki/OpenGL | OpenGL |
Task
Display a smooth shaded triangle with OpenGL.
Triangle created using C example compiled with GCC 4.1.2 and freeglut3.
| #AutoHotkey | AutoHotkey | hOpenGL32 := DllCall("LoadLibrary", "Str", "opengl32")
Gui, +LastFound +Resize
hDC := DllCall("GetDC", "uInt", WinExist())
VarSetCapacity(pfd, 40, 0)
NumPut(40, pfd, 0, "uShort")
NumPut(1, pfd, 2, "uShort")
NumPut(37, pfd, 4, "uInt")
NumPut(24, pfd, 9, "uChar")
NumPut(16, pfd, 23, "uChar")
DllCall("SetPixelFormat", "... |
http://rosettacode.org/wiki/OLE_automation | OLE automation | OLE Automation is an inter-process communication mechanism based on Component Object Model (COM) on Microsoft Windows.
Task
Provide an automation server implementing objects that can be accessed by a client running in a separate process.
The client gets a proxy-object that can call methods on the object.
Th... | #Go | Go | package main
import (
"time"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("Word.Application")
word, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.PutProperty(word, "Visible", true)
do... |
http://rosettacode.org/wiki/OLE_automation | OLE automation | OLE Automation is an inter-process communication mechanism based on Component Object Model (COM) on Microsoft Windows.
Task
Provide an automation server implementing objects that can be accessed by a client running in a separate process.
The client gets a proxy-object that can call methods on the object.
Th... | #M2000_Interpreter | M2000 Interpreter |
Module CheckAutomation {
ExitNow=false
Declare WithEvents Alfa "WORD.APPLICATION"
\\ minimize console
Title "Minimized- Waiting", 0
Wait 300
Print "ok"
With Alfa, "Visible", True
Function ALFA_QUIT {
Print "Why you close Word?"
ExitNo... |
http://rosettacode.org/wiki/OLE_automation | OLE automation | OLE Automation is an inter-process communication mechanism based on Component Object Model (COM) on Microsoft Windows.
Task
Provide an automation server implementing objects that can be accessed by a client running in a separate process.
The client gets a proxy-object that can call methods on the object.
Th... | #Phix | Phix | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import win32com.client
from win32com.server.util import wrap, unwrap
from win32com.server.dispatcher import DefaultDebugDispatcher
from ctypes import *
import commands
import pythoncom
import winerror
from win32com.server.exception import Exception
clsid = "{55C2F76F-5136... |
http://rosettacode.org/wiki/P-value_correction | P-value correction | Given a list of p-values, adjust the p-values for multiple comparisons. This is done in order to control the false positive, or Type 1 error rate.
This is also known as the "false discovery rate" (FDR). After adjustment, the p-values will be higher but still inside [0,1].
The adjusted p-values are sometimes called "q... | #Julia | Julia | using MultipleTesting, IterTools, Printf
p = [4.533744e-01, 7.296024e-01, 9.936026e-02, 9.079658e-02, 1.801962e-01,
8.752257e-01, 2.922222e-01, 9.115421e-01, 4.355806e-01, 5.324867e-01,
4.926798e-01, 5.802978e-01, 3.485442e-01, 7.883130e-01, 2.729308e-01,
8.502518e-01, 4.268138e-01, 6.442008e-01, 3.030... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #EchoLisp | EchoLisp |
(lib 'list) ;; for list-delete
(define dataM
'((the cat sat on the mat)
(the cat sat on the mat)
(A B C A B C A B C)
(A B C A B D A B E)
(A B)
(A B)
(A B B A)))
(define orderM
'((mat cat)
(cat mat)
(C A C A)
(E A D A)
(B)
(B A)
(B A)))
(defi... |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #C.2B.2B | C++ | #include <vector>
#include <algorithm>
#include <string>
// helper comparator that is passed to std::sort()
template <class T>
struct sort_table_functor {
typedef bool (*CompFun)(const T &, const T &);
const CompFun ordering;
const int column;
const bool reverse;
sort_table_functor(CompFun o, int c, bool r)... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #AWK | AWK |
# syntax: GAWK -f ORDER_TWO_NUMERICAL_LISTS.AWK
BEGIN {
split("1,2,1,5,2",list1,",")
split("1,2,1,5,2,2",list2,",")
split("1,2,3,4,5",list3,",")
split("1,2,3,4,5",list4,",")
x = compare_array(list1,list2) ? "<" : ">=" ; printf("list1%slist2\n",x)
x = compare_array(list2,list3) ? "<" : ">=" ; p... |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Swift | Swift | func pascal(n:Int)->[Int]{
if n==1{
let a=[1]
print(a)
return a
}
else{
var a=pascal(n:n-1)
var temp=a
for i in 0..<a.count{
if i+1==a.count{
temp.append(1)
break
}
temp[i+1] = a[i]+a[i+1]
... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Eiffel | Eiffel | : \ ? = ~ / ! # $ % & * + - < > @ ^ ` | , ' ; |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Erlang | Erlang | (expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F ... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #F.23 | F# | (expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F ... |
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #Cowgol | Cowgol | include "cowgol.coh";
include "strings.coh";
include "file.coh";
var filename: [uint8] := "unixdict.txt";
# Call a subroutine for every line in a file
interface LineCb(line: [uint8]);
sub ForEachLine(fcb: [FCB], fn: LineCb) is
var linebuf: uint8[256];
var bufptr := &linebuf[0];
var len := FCBExt(fcb);... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #Nanoquery | Nanoquery | def is_palindrome(s)
temp = ""
for char in s
if "abcdefghikjklmnopqrstuvwxyz" .contains. lower(char)
temp += lower(char)
end
end
return list(temp) = list(temp).reverse()
end |
http://rosettacode.org/wiki/One-time_pad | One-time pad | Implement a One-time pad, for encrypting and decrypting messages.
To keep it simple, we will be using letters only.
Sub-Tasks
Generate the data for a One-time pad (user needs to specify a filename and length)
The important part is to get "true random" numbers, e.g. from /dev/random
encryption / decryption ( basic... | #Go | Go | package main
import (
"bufio"
"crypto/rand"
"fmt"
"io/ioutil"
"log"
"math/big"
"os"
"strconv"
"strings"
"unicode"
)
const (
charsPerLine = 48
chunkSize = 6
cols = 8
demo = true // would normally be set to false
)
type fileType int
const ... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #JavaScript | JavaScript |
function calcPass (pass, nonce) {
var flag = true;
var num1 = 0x0;
var num2 = 0x0;
var password = parseInt(pass, 10);
for (var c in nonce) {
c = nonce[c];
if (c!='0') {
if (flag) num2 = password;
flag = false;
}
switch (c) {
case '1':
num1 = num2 & 0xFFFFFF80;
num1 = num1 >>> 7;
nu... |
http://rosettacode.org/wiki/OpenGL | OpenGL |
Task
Display a smooth shaded triangle with OpenGL.
Triangle created using C example compiled with GCC 4.1.2 and freeglut3.
| #BaCon | BaCon | PRAGMA INCLUDE <GL/gl.h> <GL/freeglut.h>
PRAGMA LDFLAGS GL glut
OPTION PARSE FALSE
SUB Triangle
glViewport(0, 0, 640, 480)
glOrtho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0)
glClearColor(0.0, 0.0, 0.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT)
glTranslatef(-15.0, -15.0, 0.0)
glBegin(GL_TRIANGLES... |
http://rosettacode.org/wiki/OLE_automation | OLE automation | OLE Automation is an inter-process communication mechanism based on Component Object Model (COM) on Microsoft Windows.
Task
Provide an automation server implementing objects that can be accessed by a client running in a separate process.
The client gets a proxy-object that can call methods on the object.
Th... | #Python | Python | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import win32com.client
from win32com.server.util import wrap, unwrap
from win32com.server.dispatcher import DefaultDebugDispatcher
from ctypes import *
import commands
import pythoncom
import winerror
from win32com.server.exception import Exception
clsid = "{55C2F76F-5136... |
http://rosettacode.org/wiki/P-value_correction | P-value correction | Given a list of p-values, adjust the p-values for multiple comparisons. This is done in order to control the false positive, or Type 1 error rate.
This is also known as the "false discovery rate" (FDR). After adjustment, the p-values will be higher but still inside [0,1].
The adjusted p-values are sometimes called "q... | #Kotlin | Kotlin | // version 1.1.51
import java.util.Arrays
typealias IAE = IllegalArgumentException
fun seqLen(start: Int, end: Int) =
when {
start == end -> IntArray(end + 1) { it + 1 }
start < end -> IntArray(end - start + 1) { start + it }
else -> IntArray(start - end + 1) { start - it }
... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Elixir | Elixir | defmodule Order do
def disjoint(m,n) do
IO.write "#{Enum.join(m," ")} | #{Enum.join(n," ")} -> "
Enum.chunk(n,2)
|> Enum.reduce({m,0}, fn [x,y],{m,from} ->
md = Enum.drop(m, from)
if x > y and x in md and y in md do
if Enum.find_index(md,&(&1==x)) > Enum.find_index(md,&(&1==y)... |
http://rosettacode.org/wiki/Order_disjoint_list_items | Order disjoint list items |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Factor | Factor | qw{ the cat sat on the mat } qw{ mat cat } make-slots |
http://rosettacode.org/wiki/Optional_parameters | Optional parameters | Task
Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters:
ordering
A function specifying the ordering of strings; lexicographic by default.
column
... | #Clojure | Clojure | (defn sort [table & {:keys [ordering column reverse?]
:or {ordering :lex, column 1}}]
(println table ordering column reverse?))
(sort [1 8 3] :reverse? true)
[1 8 3] :lex 1 true |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #BASIC256 | BASIC256 |
arraybase 1
dim list1(5): dim list2(6): dim list3(5): dim list4(5)
list1 = {1, 2, 1, 5, 2}
list2 = {1, 2, 1, 5, 2, 2}
list3 = {1, 2, 3, 4, 5}
list4 = {1, 2, 3, 4, 5}
if Orden(list1[], list2[]) then print "list1 < list2" else print "list 1>= list2"
if Orden(list2[], list3[]) then print "list2 < list3" else print "li... |
http://rosettacode.org/wiki/Order_two_numerical_lists | Order two numerical lists | sorting
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
She... | #BBC_BASIC | BBC BASIC | DIM list1(4) : list1() = 1, 2, 1, 5, 2
DIM list2(5) : list2() = 1, 2, 1, 5, 2, 2
DIM list3(4) : list3() = 1, 2, 3, 4, 5
DIM list4(4) : list4() = 1, 2, 3, 4, 5
IF FNorder(list1(), list2()) PRINT "list1<list2" ELSE PRINT "list1>=list2"
IF FNorder(list2(), list3()) PRINT "list2<list3"... |
http://rosettacode.org/wiki/Pascal%27s_triangle | Pascal's triangle | Pascal's triangle is an arithmetic and geometric figure often associated with the name of Blaise Pascal, but also studied centuries earlier in India, Persia, China and elsewhere.
Its first few rows look like this:
1
1 1
1 2 1
1 3 3 1
where each element of each row is either 1 or the sum of the two elemen... | #Tcl | Tcl | proc pascal_iterative n {
if {$n < 1} {error "undefined behaviour for n < 1"}
set row [list 1]
lappend rows $row
set i 1
while {[incr i] <= $n} {
set prev $row
set row [list 1]
for {set j 1} {$j < [llength $prev]} {incr j} {
lappend row [expr {[lindex $prev [e... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Factor | Factor | (expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F ... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Forth | Forth | (expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F ... |
http://rosettacode.org/wiki/Operator_precedence | Operator precedence |
This page uses content from Wikipedia. The original article was at Operators in C and C++. 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)
Task
Provide a list of precedence and associativity... | #Fortran | Fortran | (expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F ... |
http://rosettacode.org/wiki/Ordered_words | Ordered words | An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Task[edit]
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have download... | #D | D | void main() {
import std.stdio, std.algorithm, std.range, std.string;
string[] result;
size_t maxLen;
foreach (string word; "unixdict.txt".File.lines) {
word = word.chomp;
immutable len = word.walkLength;
if (len < maxLen || !word.isSorted)
continue;
if (l... |
http://rosettacode.org/wiki/Palindrome_detection | Palindrome detection | A palindrome is a phrase which reads the same backward and forward.
Task[edit]
Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
is a palindrome.
For extra credit:
Support Unicode characters.
Write a second function (possibly as a wrapper to the first) which ... | #Nemerle | Nemerle | using System;
using System.Console;
using Nemerle.Utility.NString; //contains methods Explode() and Implode() which convert string -> list[char] and back
module Palindrome
{
IsPalindrome( text : string) : bool
{
Implode(Explode(text).Reverse()) == text;
}
Main() : void
{
WriteLin... |
http://rosettacode.org/wiki/One-time_pad | One-time pad | Implement a One-time pad, for encrypting and decrypting messages.
To keep it simple, we will be using letters only.
Sub-Tasks
Generate the data for a One-time pad (user needs to specify a filename and length)
The important part is to get "true random" numbers, e.g. from /dev/random
encryption / decryption ( basic... | #Haskell | Haskell | -- To compile into an executable:
-- ghc -main-is OneTimePad OneTimePad.hs
-- To run:
-- ./OneTimePad --help
module OneTimePad (main) where
import Control.Monad
import Data.Char
import Data.Function (on)
import qualified Data.Text as T
import qualified Data.Text.IO ... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #Julia | Julia | function calcpass(passwd, nonce::String)
startflag = true
n1 = 0
n2 = 0
password = parse(Int, passwd)
dact = Dict(
'1' => () -> begin n1 = (n2 & 0xffffff80) >> 7; n2 <<= 25 end,
'2' => () -> begin n1 = (n2 & 0xfffffff0) >> 4; n2 <<= 28 end,
'3' => () -... |
http://rosettacode.org/wiki/OpenWebNet_password | OpenWebNet password | Calculate the password requested by ethernet gateways from the Legrand / Bticino MyHome OpenWebNet home automation system when the user's ip address is not in the gateway's whitelist
Note: Factory default password is '12345'. Changing it is highly recommended !
conversation goes as follows
← *#*1##
→ *99*0##
← *#603... | #Kotlin | Kotlin | // version 1.1.51
fun ownCalcPass(password: Long, nonce: String): Long {
val m1 = 0xFFFF_FFFFL
val m8 = 0xFFFF_FFF8L
val m16 = 0xFFFF_FFF0L
val m128 = 0xFFFF_FF80L
val m16777216 = 0xFF00_0000L
var flag = true
var num1 = 0L
var num2 = 0L
for (c in nonce)... |
http://rosettacode.org/wiki/OpenGL | OpenGL |
Task
Display a smooth shaded triangle with OpenGL.
Triangle created using C example compiled with GCC 4.1.2 and freeglut3.
| #BBC_BASIC | BBC BASIC | *FLOAT64
SYS "LoadLibrary", "OPENGL32.DLL" TO opengl%
SYS "GetProcAddress", opengl%, "wglCreateContext" TO `wglCreateContext`
SYS "GetProcAddress", opengl%, "wglDeleteContext" TO `wglDeleteContext`
SYS "GetProcAddress", opengl%, "wglMakeCurrent" TO `wglMakeCurrent`
SYS "GetProcAd... |
http://rosettacode.org/wiki/One_of_n_lines_in_a_file | One of n lines in a file | A method of choosing a line randomly from a file:
Without reading the file more than once
When substantial parts of the file cannot be held in memory
Without knowing how many lines are in the file
Is to:
keep the first line of the file as a possible choice, then
Read the second line of the file if possible and m... | #11l | 11l | F one_of_n(lines)
V choice = 0
L(line) lines
I random:(0..L.index) == 0
choice = line
R choice
F one_of_n_test(n = 10, trials = 1000000)
V bins = [0] * n
I n != 0
L 1..trials
bins[one_of_n(0 .< n)]++
R bins
print(one_of_n_test()) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.