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/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Python
Python
from math import floor from collections import deque from typing import Dict, Generator     def padovan_r() -> Generator[int, None, None]: last = deque([1, 1, 1], 4) while True: last.append(last[-2] + last[-3]) yield last.popleft()   _p, _s = 1.324717957244746025960908854, 1.0453567932525329623 ...
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 ...
#Logo
Logo
to palindrome? :w output equal? :w reverse :w end
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Python
Python
'''Palindrome dates'''   from datetime import datetime from itertools import chain     # palinDay :: Int -> [ISO Date] def palinDay(y): '''A possibly empty list containing the palindromic date for the given year, if such a date exists. ''' s = str(y) r = s[::-1] iso = '-'.join([s, r[0:2], r[2...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Raku
Raku
sub partition(@mask is copy) { my @op; my $last = [+] @mask or return [] xx 1; for @mask.kv -> $k, $v { next unless $v; temp @mask[$k] -= 1; for partition @mask -> @p { @p[$k].push: $last; @op.push: @p; } } return @op; }   .say for reverse part...
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...
#Raku
Raku
sub pascal { [1], { [0, |$_ Z+ |$_, 0] } ... * }   .say for 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 ...
#Action.21
Action!
DEFINE PTR="CARD"   PROC PrintArray(PTR ARRAY a BYTE size) BYTE i   Put('[) FOR i=0 TO size-1 DO IF i>0 THEN Put(' ) FI Print(a(i)) OD Put(']) PutE() RETURN   BYTE FUNC IsBefore(CHAR ARRAY a,b) DEFINE NO_KEY="255" DEFINE KEY_Y="43" DEFINE KEY_N="35" BYTE CH=$02FC ;Internal hardware value for...
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 ...
#Arturo
Arturo
lst: ["violet" "red" "green" "indigo" "blue" "yellow" "orange"] count: 0   findSpot: function [l,e][ if empty? l -> return 0   loop.with:'i l 'item [ answer: input ~"Is |item| greater than |e| [y/n]? " if answer="y" -> return i ] return dec size l ]   sortedLst: new []   loop lst 'elemen...
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...
#AWK
AWK
BEGIN { abc = "abcdefghijklmnopqrstuvwxyz" }   { # Check if this line is an ordered word. ordered = 1 # true left = -1 for (i = 1; i <= length($0); i++) { right = index(abc, substr($0, i, 1)) if (right == 0 || left > right) { ordered = 0 # false break } left = right }   if (ordered) { score = l...
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Quackery
Quackery
( --------------------- Recurrence -------------------- )   [ dup 0 = iff [ drop ' [ ] ] done dup 1 = iff [ drop ' [ 1 ] ] done dip [ [] 0 1 1 ] 2 - times [ dip [ 2dup + ] swap 3 pack dip join unpack ] 3 times join behead drop ] is padovan1 ( n --> [ )   say "...
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Raku
Raku
constant p = 1.32471795724474602596; constant s = 1.0453567932525329623; constant %rules = A => 'B', B => 'C', C => 'AB';   my @pad-recur = 1, 1, 1, -> $c, $b, $ { $b + $c } … *;   my @pad-floor = { floor 1/2 + p ** ($++ - 1) / s } … *;   my @pad-L-sys = 'A', { %rules{$^axiom.comb}.join } … *; my @pad-L-len = @pad-L-s...
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 ...
#Lua
Lua
function ispalindrome(s) return s == string.reverse(s) end
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#QB64
QB64
  'Task ' Write a program which calculates and shows the next 15 palindromic dates ' for those countries which express their dates in the yyyy-mm-dd format ' and for those countries which express their dates int dd-mm-yyyy format ' the user will choose what format to use for calculating Dim dateTest As String, Mounth...
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Raku
Raku
my $start = '1000-01-01';   my @palindate = { state $year = $start.substr(0,4); ++$year; my $m = $year.substr(2, 2).flip; my $d = $year.substr(0, 2).flip; next if not try Date.new("$year-$m-$d"); "$year-$m-$d" } … *;   my $date-today = Date.today; # 2020-02-02   my $k = @palindate.first: {...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#REXX
REXX
//*REXX program displays the ordered partitions as: orderedPartitions(i, j, k, ···). */ call orderedPartitions 2,0,2 /*Note: 2,,2 will also work. */ call orderedPartitions 1,1,1 call orderedPartitions 1,2,0,1 /*Note: 1,2,,1 will also work. */ exit ...
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...
#RapidQ
RapidQ
DEFINT values(100) = {0,1}   INPUT "Number of rows: "; nrows PRINT SPACE$((nrows)*3);" 1" FOR row = 2 TO nrows PRINT SPACE$((nrows-row)*3+1); FOR i = row TO 1 STEP -1 values(i) = values(i) + values(i-1) PRINT FORMAT$("%5d ", values(i)); NEXT i PRINT NEXT row
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 ...
#AutoHotkey
AutoHotkey
data := ["Violet", "Red", "Green", "Indigo", "Blue", "Yellow", "Orange"] result := [], num := 0, Questions :=""   for i, Color1 in data{ found :=false if !result.count(){ result.Push(Color1) continue }   for j, Color2 in result { if (color1 = color2) continue ...
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 ...
#C
C
#include <stdio.h> #include <string.h> #include <stdlib.h>   int interactiveCompare(const void *x1, const void *x2) { const char *s1 = *(const char * const *)x1; const char *s2 = *(const char * const *)x2; static int count = 0; printf("(%d) Is %s <, ==, or > %s? Answer -1, 0, or 1: ", ++count, s1, s2); int re...
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...
#BaCon
BaCon
'Ordered words - improved version OPTION COLLAPSE TRUE   list$ = LOAD$("unixdict.txt")   FOR word$ IN list$ STEP NL$   term$ = EXTRACT$(SORT$(EXPLODE$(word$, 1)), " ")   IF word$ = term$ THEN IF LEN(term$) > MaxLen THEN MaxLen = LEN(term$) result$ = word$ ELIF LEN(term$) ...
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#REXX
REXX
/*REXX pgm computes the Padovan seq. (using 2 methods), and also computes the L─strings.*/ numeric digits 40 /*better precision for Plastic ratio. */ parse arg n nF Ln cL . /*obtain optional arguments from the CL*/ if n=='' | n=="," then n= 20 ...
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 ...
#M4
M4
define(`palindrorev',`ifelse(`$1',invert(`$1'),`yes',`no')')dnl palindrorev(`ingirumimusnocteetconsumimurigni') palindrorev(`this is not palindrome')
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#REXX
REXX
/*REXX program finds & displays the next N palindromic dates starting after 2020─02─02*/ /* ───── */ parse arg n from . /*obtain optional argumets from the CL*/ if n=='' | n=="," then n= 15 ...
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Ring
Ring
  load "stdlib.ring"   dt = 0 num = 0 limit = 15   ? "First 15 palindromic dates:" + nl   while num < limit   dt++ dateStr = adddays(date(),dt) newDate = substr(dateStr,7,4) + substr(dateStr,4,2) + substr(dateStr,1,2) newDate2 = substr(dateStr,7,4) + "-" + substr(dateStr,4,2) + "-" + substr(dateStr,1,2)...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Ruby
Ruby
def partition(mask) return [[]] if mask.empty? [*1..mask.inject(:+)].permutation.map {|perm| mask.map {|num_elts| perm.shift(num_elts).sort } }.uniq end
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Rust
Rust
  use itertools::Itertools;   type NArray = Vec<Vec<Vec<usize>>>;   fn generate_partitions(args: &[usize]) -> NArray { // calculate the sum of all partitions let max = args.iter().sum();   // generate combinations with the given lengths // for each partition let c = args.iter().fold(vec![], |mut acc...
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...
#Red
Red
Red[] pascal-triangle: function [ n [ integer! ] "number of rows" ][ row: make vector! [ 1 ] loop n [ print row left: copy row right: copy row insert left 0 append right 0 row: left + right ] ]
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 ...
#C.2B.2B
C++
#include <algorithm> #include <iostream> #include <vector>   using namespace std;   bool InteractiveCompare(const string& s1, const string& s2) { if(s1 == s2) return false; // don't ask to compare items that are the same static int count = 0; string response; cout << "(" << ++count << ") Is " << s1 << ...
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...
#BBC_BASIC
BBC BASIC
dict% = OPENIN("unixdict.txt") IF dict%=0 ERROR 100, "Failed to open dictionary file"   max% = 2 REPEAT A$ = GET$#dict% IF LENA$ >= max% THEN i% = 0 REPEAT i% += 1 UNTIL ASCMID$(A$,i%) > ASCMID$(A$,i%+1) IF i% = LENA$ THEN IF i%...
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Ruby
Ruby
padovan = Enumerator.new do |y| ar = [1, 1, 1] loop do ar << ar.first(2).sum y << ar.shift end end   P, S = 1.324717957244746025960908854, 1.0453567932525329623 def padovan_f(n) = (P**(n-1) / S + 0.5).floor   puts "Recurrence Padovan: #{padovan.take(20)}" puts "Floor function: #{(0...20).map{|n| pado...
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 ...
#Maple
Maple
  with(StringTools):   IsPalindrome("ingirumimusnocteetconsumimurigni");   IsPalindrome("In girum imus nocte et consumimur igni");   IsPalindrome(LowerCase(DeleteSpace("In girum imus nocte et consumimur igni")));  
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Ruby
Ruby
require 'date'   palindate = Enumerator.new do |yielder| ("2020"..).each do |y| m, d = y.reverse.scan(/../) # let the Y10K kids handle 5 digit years strings = [y, m, d] yielder << strings.join("-") if Date.valid_date?( *strings.map( &:to_i ) ) end end   puts palindate.take(15)
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Rust
Rust
// [dependencies] // chrono = "0.4"   fn is_palindrome(s: &str) -> bool { s.chars().rev().eq(s.chars()) }   fn main() { let mut date = chrono::Utc::today(); let mut count = 0; while count < 15 { if is_palindrome(&date.format("%Y%m%d").to_string()) { println!("{}", date.format("%F"));...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Sidef
Sidef
func part(_, {.is_empty}) { [[]] } func partitions({.is_empty}) { [[]] }   func part(s, args) { gather { s.combinations(args[0], { |*c| part(s - c, args.ft(1)).each{|r| take([c] + r) } }) } }   func partitions(args) { part(@(1..args.sum), args) }   [[],[0,0,0],[1,1,1],[2,0,2]].each { |test_case| ...
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...
#Retro
Retro
2 elements i j : pascalTriangle cr dup [ dup !j 1 swap 1+ [ !i dup putn space @j @i - * @i 1+ / ] iter cr drop ] iter drop ; 13 pascalTriangle
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 ...
#Commodore_BASIC
Commodore BASIC
100 REM SORT BY COMPARISON 110 DIM IN$(6), OU$(6) 120 FOR I=0 TO 6:READ IN$(I): NEXT I 130 DATA VIOLET,RED,GREEN,INDIGO,BLUE,YELLOW,ORANGE 140 OU$(0)=IN$(0):N=1 150 FOR I=1 TO 6 160 : IN$=IN$(I) 180 : GOSUB 390 190 : FOR J=0 TO N-1 200 : OU$ = OU$(J) 210 : GOSUB 340 220 : IF R>=0 THEN 280 230 : FOR K=N TO J+1 STEP ...
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 ...
#F.23
F#
  // Order by pair comparisons. Nigel Galloway: April 23rd., 2021 let clrs=let n=System.Random() in lN2p [|for g in 7..-1..2->n.Next(g)|] [|"Red";"Orange";"Yellow";"Green";"Blue";"Indigo";"Violet"|] let rec fG n g=printfn "Is %s less than %s" n g; match System.Console.ReadLine() with "Yes"-> -1|"No"->1 |_->printfn "Ent...
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...
#Befunge
Befunge
00p30p>_010p120p0>#v0~>>\$::48*\`\"~"`+!>>#v_$:#v_>30g:!#v_1-30p55+0>:30g3+g\1v >0#v _$^#::\p04:<^+>#1^#\p01:p02*g02!`\g01:<@$ _ ,#!>#:<$<^<!:g03$<_^#!`\g00:+< ^<o>\30g2+p40g1+^0p00p03+1*g03!-g00 < < < < < <:>#$:#$00g#<\#<`#<!#<2#$0g#<*#<_
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Rust
Rust
fn padovan_recur() -> impl std::iter::Iterator<Item = usize> { let mut p = vec![1, 1, 1]; let mut n = 0; std::iter::from_fn(move || { let pn = if n < 3 { p[n] } else { p[0] + p[1] }; p[0] = p[1]; p[1] = p[2]; p[2] = pn; n += 1; Some(pn) }) }   fn padovan_f...
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Swift
Swift
import Foundation   class PadovanRecurrence: Sequence, IteratorProtocol { private var p = [1, 1, 1] private var n = 0   func next() -> Int? { let pn = n < 3 ? p[n] : p[0] + p[1] p[0] = p[1] p[1] = p[2] p[2] = pn n += 1 return pn } }   class PadovanFloor: S...
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 ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
PalindromeQ
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Sidef
Sidef
var palindates = gather { for y in (2020 .. 9999) { var (m, d) = Str(y).flip.last(4).split(2)... with ([y,m,d].join('-')) {|t| take(t) if Date.valid(t, "%Y-%m-%d") } } }   say "Count of palindromic dates [2020..9999]: #{palindates.len}"   for a,b in ([ ["First 15:", palin...
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Swift
Swift
import Foundation   func isPalindrome(_ string: String) -> Bool { let chars = string.lazy return chars.elementsEqual(chars.reversed()) }   let format = DateFormatter() format.dateFormat = "yyyyMMdd"   let outputFormat = DateFormatter() outputFormat.dateFormat = "yyyy-MM-dd"   var count = 0 let limit = 15 let ca...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Tcl
Tcl
package require Tcl 8.5 package require struct::set   # Selects all k-sized combinations from a list. # "Borrowed" from elsewhere on RC proc selectCombinationsFrom {k l} { if {$k == 0} {return {}} elseif {$k == [llength $l]} {return [list $l]} set all {} set n [expr {[llength $l] - [incr k -1]}] for {se...
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...
#11l
11l
[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...
#REXX
REXX
/*REXX program displays (or writes to a file) Pascal's triangle (centered/formatted).*/ numeric digits 3000 /*be able to handle gihugeic triangles.*/ parse arg nn . /*obtain the optional argument from CL.*/ if nn=='' | nn=="," then nn= 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 ...
#Factor
Factor
USING: formatting io kernel math.order prettyprint qw sorting ;   qw{ violet red green indigo blue yellow orange } [ "Is %s > %s? (y/n) " printf readln "y" = +gt+ +lt+ ? ] sort .
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 ...
#FreeBASIC
FreeBASIC
  Dim Shared As Byte r, n = 1 Dim Shared As String IN1, OU1 Dim Shared As String IN(6), OU(6) Dim As Byte i, j, k For i = 0 To 6 : Read IN(i) : Next i Data "violet", "red", "green", "indigo", "blue", "yellow", "orange" OU(0) = IN(0)   Sub PrintOrder Print : Print "{"; If n = 1 Then Print OU(n-1);")" : Exit Sub...
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...
#Bracmat
Bracmat
( orderedWords = bow result longestLength word character . 0:?bow & :?result & 0:?longestLength & @( get$(!arg,STR)  :  ? ( [!bow %?word \n [?bow ? & @( !word  : ( ? %@?character <%@!character ? |  ? ...
http://rosettacode.org/wiki/Padovan_sequence
Padovan sequence
The Padovan sequence is similar to the Fibonacci sequence in several ways. Some are given in the table below, and the referenced video shows some of the geometric similarities. Comment Padovan Fibonacci Named after. Richard Padovan Leonardo of Pisa: Fibonacci Recurrence initial values....
#Wren
Wren
import "/big" for BigRat import "/dynamic" for Struct   var padovanRecur = Fn.new { |n| var p = List.filled(n, 1) if (n < 3) return p for (i in 3...n) p[i] = p[i-2] + p[i-3] return p }   var padovanFloor = Fn.new { |n| var p = BigRat.fromDecimal("1.324717957244746025960908854") var s = BigRat.fr...
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 ...
#MATLAB
MATLAB
function trueFalse = isPalindrome(string)   trueFalse = all(string == fliplr(string)); %See if flipping the string produces the original string   if not(trueFalse) %If not a palindrome string = lower(string); %Lower case everything trueFalse = all(string == fliplr(string)); %Test again end  ...
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#UNIX_Shell
UNIX Shell
is_palyndrom_date() { date -d "$1" 1>/dev/null 2>&1 && echo "$1" ; }   for _H in {2..9}; do for _I in {0..9}; do for _J in {0..99}; do is_palyndrom_date ${_H}${_I}`printf "%02d%s" ${_J}`-`printf "%02d%s" ${_J} | rev`-`printf "%02d%s" ${_H}${_I} | rev` done done done  
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#VBA
VBA
  Sub MainPalindromeDates() Const FirstDate As String = "2020-02-02" Const NumberOfDates As Integer = 15 Dim D As String, temp As String, Cpt As Integer temp = Format(DateAdd("d", 1, CDate(FirstDate)), "yyyy-mm-dd") Do D = Replace(temp, "-", "") If IsDatePalindrome(D) Then Debug.Prin...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Ursala
Ursala
#import std #import nat   opart =   -+ ~&art^?\~&alNCNC ^|JalSPfarSPMplrDSL/~& ^DrlPrrPlXXS/~&rt ^DrlrjXS/~&l choices@lrhPX, ^\~& nrange/1+ sum:-0+-
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#Wren
Wren
import "os" for Process   var genPart // recursive so predeclare genPart = Fn.new { |n, res, pos| if (pos == res.count) { var x = List.filled(n.count, null) for (i in 0...x.count) x[i] = [] var i = 0 for (c in res) { x[c].add(i+1) i = i + 1 } S...
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...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program orderlist64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesAR...
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...
#Ring
Ring
  row = 5 for i = 0 to row - 1 col = 1 see left(" ",row-i) for k = 0 to i see "" + col + " " col = col*(i-k)/(k+1) next see nl next  
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 ...
#Go
Go
package main   import ( "fmt" "sort" "strings" )   var count int = 0   func interactiveCompare(s1, s2 string) bool { count++ fmt.Printf("(%d) Is %s < %s? ", count, s1, s2) var response string _, err := fmt.Scanln(&response) return err == nil && strings.HasPrefix(response, "y") }   func m...
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...
#11l
11l
LDX #$02 LDY #$03   LDA ($20,x) ;uses the values stored at $20+x and $21+x as a memory address, and reads the byte at that address. LDA ($20),y ;uses the values store at $20 and $21 as a memory address, and reads the byte at that address + Y.
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...
#Burlesque
Burlesque
ln{so}f[^^{L[}>mL[bx(==)[+(L[)+]f[uN
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 ...
#Maxima
Maxima
palindromep(s) := block([t], t: sremove(" ", sdowncase(s)), sequal(t, sreverse(t)))$   palindromep("Sator arepo tenet opera rotas"); /* true */
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Wren
Wren
import "/fmt" for Fmt import "/date" for Date   var isPalDate = Fn.new { |date| date = date.format(Date.rawDate) return date == date[-1..0] }   Date.default = Date.isoDate System.print("The next 15 palindromic dates in yyyy-mm-dd format after 2020-02-02 are:") var date = Date.new(2020, 2, 2) var count = 0 while...
http://rosettacode.org/wiki/Ordered_partitions
Ordered partitions
In this task we want to find the ordered partitions into fixed-size blocks. This task is related to Combinations in that it has to do with discrete mathematics and moreover a helper function to compute combinations is (probably) needed to solve this task. p a r t i t i o n s ( a r g 1 , a r g 2 , ...
#zkl
zkl
fcn partitions(args){ args=vm.arglist; s:=(1).pump(args.sum(0),List); // (1,2,3,...) fcn(s,args,p){ if(not args) return(T(T)); res:=List(); foreach c in (Utils.Helpers.pickNFrom(args[0],s)){ s0:=s.copy().removeEach(c); foreach r in (self.fcn(s0,args[1,*])){ res.append(T(c).extend(r)) } ...
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 ...
#Ada
Ada
package Tables is   type Table is private;   type Ordering is (Lexicographic, Psionic, ...); -- add others   procedure Sort (It  : in out Table; Order_By  : in Ordering := Lexicographic; Column  : in Positive := 1; Reverse_Or...
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...
#ACL2
ACL2
ACL2 !>(lexorder '(1 2 3) '(1 2 3 4)) T ACL2 !>(lexorder '(1 2 4) '(1 2 3)) NIL
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...
#Action.21
Action!
INT FUNC Compare(INT ARRAY x INT xLen INT ARRAY y INT yLen) INT i,len   len=xLen IF len>yLen THEN len=yLen FI FOR i=0 TO len-1 DO IF x(i)>y(i) THEN RETURN (1) ELSEIF x(i)<y(i) THEN RETURN (-1) FI OD IF xLen>yLen THEN RETURN (1) ELSEIF xLen<yLen THEN RETURN (-1) FI...
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...
#Ruby
Ruby
def pascal(n) raise ArgumentError, "must be positive." if n < 1 yield ar = [1] (n-1).times do ar.unshift(0).push(0) # tack a zero on both ends yield ar = ar.each_cons(2).map(&:sum) end end   pascal(8){|row| puts row.join(" ").center(20)}
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 ...
#Haskell
Haskell
import Control.Monad import Control.Monad.ListM (sortByM, insertByM, partitionM, minimumByM) import Data.Bool (bool) import Data.Monoid import Data.List   -------------------------------------------------------------------------------- isortM, msortM, tsortM :: Monad m => (a -> a -> m Ordering) -> [a] -> m [a]   -- mer...
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 ...
#Java
Java
import java.util.*;   public class SortComp1 { public static void main(String[] args) { List<String> items = Arrays.asList("violet", "red", "green", "indigo", "blue", "yellow", "orange"); List<String> sortedItems = new ArrayList<>(); Comparator<String> interactiveCompare = new Comparator<Str...
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...
#8th
8th
LDX #$02 LDY #$03   LDA ($20,x) ;uses the values stored at $20+x and $21+x as a memory address, and reads the byte at that address. LDA ($20),y ;uses the values store at $20 and $21 as a memory address, and reads the byte at that address + Y.
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...
#6502_Assembly
6502 Assembly
LDX #$02 LDY #$03   LDA ($20,x) ;uses the values stored at $20+x and $21+x as a memory address, and reads the byte at that address. LDA ($20),y ;uses the values store at $20 and $21 as a memory address, and reads the byte at that address + Y.
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...
#Ada
Ada
print 2 + 3 * 5 ; same as 2 + (3 * 5) print 3 * 5 + 2 ; same as 3 * (5 + 2)
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...
#C
C
#include <stdlib.h> #include <string.h> #include <stdio.h> #include <assert.h>     #define MAXLEN 100 typedef char TWord[MAXLEN];     typedef struct Node { TWord word; struct Node *next; } Node;     int is_ordered_word(const TWord word) { assert(word != NULL); int i;   for (i = 0; word[i] != '\0'; i...
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 ...
#MAXScript
MAXScript
fn isPalindrome s = ( local reversed = "" for i in s.count to 1 by -1 do reversed += s[i] return reversed == s )
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#XPL0
XPL0
func Rev(N); int N; [N:= N/10; return rem(0)*10 + N; ];   proc NumOut(N); int N; [if N < 10 then ChOut(0, ^0); IntOut(0, N); ];   int C, Y, M, D, Q, R; [C:= 0; for Y:= 2021 to -1>>1 do for M:= 1 to 12 do for D:= 1 to 28 do [Q:= Y/100; R:= rem(0); if Q = Rev(D) and R = Rev(M) then ...
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#Yabasic
Yabasic
  dateTest$ = "" total = 0 print "Siguientes 15 fechas palindr¢micas al 2020-02-02:" for anno = 2021 to 9999 dateTest$ = ltrim$(str$(anno)) for mes = 1 to 12 if mes < 10 then dateTest$ = dateTest$ + "0" : fi dateTest$ = dateTest$ + ltrim$(str$(mes)) for dia = 1 to 31 if mes =...
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 ...
#ALGOL_68
ALGOL 68
# as the options have distinct types (INT, BOOL and PROC( STRING, STRING )INT) the # # easiest way to support these optional parameters in Algol 68 would be to have an array # # with elements of these types # # See the Named Arguments sample for cases wher...
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...
#Ada
Ada
  with Ada.Text_IO; use Ada.Text_IO; procedure Order is   type IntArray is array (Positive range <>) of Integer; List1 : IntArray := (1, 2, 3, 4, 5); List2 : IntArray := (1, 2, 1, 5, 2, 2); List3 : IntArray := (1, 2, 1, 5, 2); List4 : IntArray := (1, 2, 1, 5, 2);   type Animal is (Rat, Cat, Elephant)...
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...
#Run_BASIC
Run BASIC
input "number of rows? ";r for i = 0 to r - 1 c = 1 print left$(" ",(r*2)-(i*2)); for k = 0 to i print using("####",c); c = c*(i-k)/(k+1) next print next
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 ...
#jq
jq
def inputOption($prompt; $options): def r: $prompt | stderr | input as $in | if $in|test($options) then $in else r end; r;   # Inserts item $x in the array input, which is kept sorted as per user input # assuming it is already sorted. $q is the prompt number. # Input: [$q; $a] # Output: [$qPrime, $aP...
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 ...
#Julia
Julia
const nrequests = [0] const ordering = Dict("violet" => 7, "red" => 1, "green" => 4, "indigo" => 6, "blue" => 5, "yellow" => 3, "orange" => 2)   function tellmeifgt(x, y) nrequests[1] += 1 while true print("Is $x greater than $y? (Y/N) => ") s = strip(readline()) ...
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...
#ALGOL_60
ALGOL 60
print 2 + 3 * 5 ; same as 2 + (3 * 5) print 3 * 5 + 2 ; same as 3 * (5 + 2)
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...
#ALGOL_68
ALGOL 68
print 2 + 3 * 5 ; same as 2 + (3 * 5) print 3 * 5 + 2 ; same as 3 * (5 + 2)
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...
#C.23
C#
using System; using System.Linq; using System.Net;   static class Program { static void Main(string[] args) { WebClient client = new WebClient(); string text = client.DownloadString("http://www.puzzlers.org/pub/wordlists/unixdict.txt"); string[] words = text.Split(new char[] { '\r', '\n'...
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 ...
#min
min
(dup reverse ==) :palindrome? (dup "" split reverse "" join ==) :str-palindrome?   "apple" str-palindrome? puts "racecar" str-palindrome? puts (a b c) palindrome? puts (a b b a) palindrome? puts
http://rosettacode.org/wiki/Palindrome_dates
Palindrome dates
Today   (2020-02-02,   at the time of this writing)   happens to be a palindrome,   without the hyphens,   not only for those countries which express their dates in the   yyyy-mm-dd   format but,   unusually,   also for countries which use the   dd-mm-yyyy   format. Task Write a program which calculates and shows th...
#zkl
zkl
TD,date,n := Time.Date, T(2020,02,02), 15; while(n){ ds:=TD.toYMDString(date.xplode()) - "-"; if(ds==ds.reverse()){ n-=1; println(TD.toYMDString(date.xplode())); } date=TD.addYMD(date,0,0,1); }
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
C
#include <stdio.h>//printf #include <stdlib.h>//qsort #include <math.h>//fabs #include <stdbool.h>//bool data type #include <strings.h>//strcasecmp #include <assert.h>//assert, necessary for random integer selection   unsigned int * seq_len(const unsigned int START, const unsigned int END) { //named after R function of...
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 ...
#11l
11l
F order_disjoint_list_items(&data, items) [Int] itemindices L(item) Set(items) V itemcount = items.count(item) V lastindex = [-1] L(i) 0 .< itemcount lastindex.append(data.index(item, lastindex.last + 1)) itemindices [+]= lastindex[1..] itemindices.sort() L(index, item) zip(...
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 ...
#AppleScript
AppleScript
on sortTable(x) set {sortOrdering, sortColumn, sortReverse} to {sort_lexicographic, 1, false} try set sortOrdering to x's ordering end try try set sortColumn to x's column end try try set sortReverse to x's reverse end try return sortOrdering's sort(x's sequence, sortColumn, sortReverse) end sortTable   s...
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_68
ALGOL 68
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 # OP < = ( []INT a, b )BOOL: IF INT a pos := LWB a; INT b pos := LWB b; BOOL equal := ...
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...
#Rust
Rust
  fn pascal_triangle(n: u64) {   for i in 0..n { let mut c = 1; for _j in 1..2*(n-1-i)+1 { print!(" "); } for k in 0..i+1 { print!("{:2} ", c); c = c * (i-k)/(k+1); } println!(); } }  
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 ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ClearAll[HumanOrderCheck] HumanOrderCheck[opt1_,opt2_]:=ChoiceDialog[Row@{"Is {",opt1,", ", opt2, "} ordered?"},{"Yes"->True,"No"->False}] Sort[{"violet","red","green","indigo","blue","yellow","orange"},HumanOrderCheck]
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 ...
#Nim
Nim
import algorithm, strformat, strutils   let list = ["violet", "red", "green", "indigo", "blue", "yellow", "orange"]   var count = 0   proc comp(x, y: string): int = if x == y: return 0 inc count while true: stdout.write &"{count:>2}) Is {x} less than {y} (y/n)? " let answer = stdin.readLine()[0] case ...
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 ...
#OCaml
OCaml
let () = let count = ref 0 in let mycmp s1 s2 = ( incr count; Printf.printf "(%d) Is %s <, ==, or > %s? Answer -1, 0, or 1: " (!count) s1 s2; read_int () ) in let items = ["violet"; "red"; "green"; "indigo"; "blue"; "yellow"; "orange"] in let sorted = List.sort mycmp items in List.iter (Printf.p...
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...
#ALGOL_W
ALGOL W
print 2 + 3 * 5 ; same as 2 + (3 * 5) print 3 * 5 + 2 ; same as 3 * (5 + 2)
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...
#AppleScript
AppleScript
print 2 + 3 * 5 ; same as 2 + (3 * 5) print 3 * 5 + 2 ; same as 3 * (5 + 2)
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...
#Arturo
Arturo
print 2 + 3 * 5 ; same as 2 + (3 * 5) print 3 * 5 + 2 ; same as 3 * (5 + 2)
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...
#C.2B.2B
C++
#include <algorithm> #include <fstream> #include <iostream> #include <iterator> #include <string> #include <vector>   bool ordered(const std::string &word) { return std::is_sorted(word.begin(), word.end()); // C++11 }   int main() { std::ifstream infile("unixdict.txt"); if (!infile) { std::cerr << "...
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 ...
#MiniScript
MiniScript
isPalindrome = function(s) // convert to lowercase, and strip non-letters stripped = "" for c in s.lower if c >= "a" and c <= "z" then stripped = stripped + c end for   // check palindromity mid = floor(stripped.len/2) for i in range(0, mid) if stripped[i] != stripped[-i - 1] then ...
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.23
C#
using System; using System.Collections.Generic; using System.Linq;   namespace PValueCorrection { class Program { static List<int> SeqLen(int start, int end) { var result = new List<int>(); if (start == end) { for (int i = 0; i < end + 1; ++i) { re...
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 ...
#Aime
Aime
order(list a, b) { integer j; record r; text s;   a.ucall(o_, 0, " ");   o_("| ");   for (, s in b) { r[s] += 1; o_(s, " "); }   o_("->");   j = -1; for (, s in a) { if ((r[s] -= 1) < 0) { o_(" ", s); } else { o_(" ", b[j +=...
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 ...
#AppleScript
AppleScript
---------------------- DISJOINT ORDER --------------------   -- disjointOrder :: String -> String -> String on disjointOrder(m, n) set {ms, ns} to map(my |words|, {m, n})   unwords(flatten(zip(segments(ms, ns), ns & ""))) end disjointOrder     -- segments :: [String] -> [String] -> [String] on segments(ms, ns) ...