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/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 ...
#Icon_and_Unicon
Icon and Unicon
procedure main(arglist) every writes(s := !arglist) do write( if palindrome(s) then " is " else " is not", " a palindrome.") 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...
#BASIC
BASIC
  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" dateTest$ = dateTest$ + LTRIM$(STR$(mes)) FOR dia = 1 TO 31 IF mes = 2 ...
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...
#BBC_BASIC
BBC BASIC
INSTALL @lib$ + "DATELIB" DIM B% 8 TestDate%=FN_today REPEAT $B%=FN_date$(TestDate%, "yyyyMMdd") FOR I%=0 TO 3 IF ?(B% + I%) <> ?(B% + 7 - I%) EXIT FOR NEXT IF I%=4 PRINT FN_date$(TestDate%, "yyyy-MM-dd") TestDate%+=1 UNTIL VPOS=15 EN...
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 , ...
#EchoLisp
EchoLisp
  (lib 'list) ;; (combinations L k)   ;; add a combination to each partition in ps (define (pproduct c ps) (for/list ((x ps)) (cons c x)))   ;; apply to any type of set S ;; ns is list of cardinals for each partition ;; for all combinations Ci of n objects from S ;; set S <- LS minus Ci , set n <- next n...
http://rosettacode.org/wiki/Padovan_n-step_number_sequences
Padovan n-step number sequences
As the Fibonacci sequence expands to the Fibonacci n-step number sequences; We similarly expand the Padovan sequence to form these Padovan n-step number sequences. The Fibonacci-like sequences can be defined like this: For n == 2: start: 1, 1 Recurrence: R(n, x) = R(n, x-1) + R(n, x-2); for n ==...
#Rust
Rust
  fn padovan(n: u64, x: u64) -> u64 { if n < 2 { return 0; }   match n { 2 if x <= n + 1 => 1, 2 => padovan(n, x - 2) + padovan(n, x - 3), _ if x <= n + 1 => padovan(n - 1, x), _ => ((x - n - 1)..(x - 1)).fold(0, |acc, value| acc + padovan(n, value)), } } fn main(...
http://rosettacode.org/wiki/Padovan_n-step_number_sequences
Padovan n-step number sequences
As the Fibonacci sequence expands to the Fibonacci n-step number sequences; We similarly expand the Padovan sequence to form these Padovan n-step number sequences. The Fibonacci-like sequences can be defined like this: For n == 2: start: 1, 1 Recurrence: R(n, x) = R(n, x-1) + R(n, x-2); for n ==...
#Sidef
Sidef
func padovan(N) { Enumerator({|callback| var n = 2 var pn = [1, 1, 1] loop { pn << sum(pn[n-N .. (n++-1) -> grep { _ >= 0 }]) callback(pn[-4]) } }) }   for n in (2..8) { say "n = #{n} | #{padovan(n).first(25).join(' ')}" }
http://rosettacode.org/wiki/Padovan_n-step_number_sequences
Padovan n-step number sequences
As the Fibonacci sequence expands to the Fibonacci n-step number sequences; We similarly expand the Padovan sequence to form these Padovan n-step number sequences. The Fibonacci-like sequences can be defined like this: For n == 2: start: 1, 1 Recurrence: R(n, x) = R(n, x-1) + R(n, x-2); for n ==...
#Wren
Wren
import "/fmt" for Fmt   var padovanN // recursive padovanN = Fn.new { |n, t| if (n < 2 || t < 3) return [1] * t var p = padovanN.call(n-1, t) if (n + 1 >= t) return p for (i in n+1...t) { p[i] = 0 for (j in i-2..i-n-1) p[i] = p[i] + p[j] } return p }   var t = 15 System.print("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...
#Perl
Perl
sub pascal { my $rows = shift; my @next = (1); for my $n (1 .. $rows) { print "@next\n"; @next = (1, (map $next[$_]+$next[$_+1], 0 .. $n-2), 1); } }
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....
#11l
11l
V pp = 1.324717957244746025960908854 V ss = 1.0453567932525329623 V Rules = [‘A’ = ‘B’, ‘B’ = ‘C’, ‘C’ = ‘AB’]   F padovan1(n) V r = [1] * min(n, 3) V (a, b, c) = (1, 1, 1) V count = 3 L count < n (a, b, c) = (b, c, a + b) r [+]= c count++ R r   F padovan2(n) V r = [1] * (n > 1) V...
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 ...
#Ioke
Ioke
Text isPalindrome? = method(self chars == self chars reverse)
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...
#C
C
#include <stdbool.h> #include <stdio.h> #include <string.h> #include <time.h>   bool is_palindrome(const char* str) { size_t n = strlen(str); for (size_t i = 0; i + 1 < n; ++i, --n) { if (str[i] != str[n - 1]) return false; } return true; }   int main() { time_t timestamp = time(...
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 , ...
#Elixir
Elixir
defmodule Ordered do def partition([]), do: [[]] def partition(mask) do sum = Enum.sum(mask) if sum == 0 do [Enum.map(mask, fn _ -> [] end)] else Enum.to_list(1..sum) |> permute |> Enum.reduce([], fn perm,acc -> {_, part} = Enum.reduce(mask, {perm,[]}, fn num,{pm,a} -...
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...
#Phix
Phix
sequence row = {} for m = 1 to 13 do row = row & 1 for n=length(row)-1 to 2 by -1 do row[n] += row[n-1] end for printf(1,repeat(' ',(13-m)*2)) for i=1 to length(row) do printf(1," %3d",row[i]) end for puts(1,'\n') end for
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....
#ALGOL_68
ALGOL 68
BEGIN # show members of the Padovan Sequence calculated in various ways # # returns the first n elements of the Padovan sequence by the # # recurance relation: P(n)=P(n-2)+P(n-3) # OP PADOVANI = ( INT n )[]INT: BEGIN [ 0 : n - 1 ]INT p; p[ 0 ] := p[ 1 ] := p[ ...
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 ...
#J
J
isPalin0=: -: |.
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...
#C.23
C#
using System; using System.Linq; using System.Collections.Generic;   public class Program { static void Main() { foreach (var date in PalindromicDates(2021).Take(15)) WriteLine(date.ToString("yyyy-MM-dd")); }   public static IEnumerable<DateTime> PalindromicDates(int startYear) { for (in...
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 , ...
#FreeBASIC
FreeBASIC
Function Perm(x() As Integer) As Boolean Dim As Integer i, j For i = Ubound(x,1)-1 To 0 Step -1 If x(i) < x(i+1) Then Exit For Next i If i < 0 Then Return False j = Ubound(x,1) While x(j) <= x(i) j -= 1 Wend Swap x(i), x(j) i += 1 j = Ubound(x,1) While i < j...
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...
#PHP
PHP
  <?php //Author Ivan Gavryshin @dcc0 function tre($n) { $ck=1; $kn=$n+1;   if($kn%2==0) { $kn=$kn/2; $i=0; } else {   $kn+=1; $kn=$kn/2; $i= 1; }   for ($k = 1; $k <= $kn-1; $k++) { $ck = $ck/$k*($n-$k+1); $arr[] = $ck; echo "+" . $ck ;   }     if ($kn>1) { echo $arr[i]; $arr=array...
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....
#AppleScript
AppleScript
--------------------- PADOVAN NUMBERS --------------------   -- padovans :: [Int] on padovans() script f on |λ|(abc) set {a, b, c} to abc   {a, {b, c, a + b}} end |λ| end script   unfoldr(f, {1, 1, 1}) end padovans     -- padovanFloor :: [Int] on padovanFloor() sc...
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 ...
#Java
Java
public static boolean pali(String testMe){ StringBuilder sb = new StringBuilder(testMe); return testMe.equals(sb.reverse().toString()); }
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...
#C.2B.2B
C++
#include <iostream> #include <string> #include <boost/date_time/gregorian/gregorian.hpp>   bool is_palindrome(const std::string& str) { for (size_t i = 0, j = str.size(); i + 1 < j; ++i, --j) { if (str[i] != str[j - 1]) return false; } return true; }   int main() { using boost::grego...
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 , ...
#GAP
GAP
FixedPartitions := function(arg) local aux; aux := function(i, u) local r, v, w; if i = Size(arg) then return [[u]]; else r := [ ]; for v in Combinations(u, arg[i]) do for w in aux(i + 1, Difference(u, v)) do Add(r, Concatenation([v], w)); od; od; return r; fi; end; return aux(1,...
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 , ...
#Go
Go
package main   import ( "fmt" "os" "strconv" )   func gen_part(n, res []int, pos int) { if pos == len(res) { x := make([][]int, len(n)) for i, c := range res { x[c] = append(x[c], i+1) }   fmt.Println(x) return }   for i := range n { if n[i] == 0 { continue } n[i], res[pos] = n[i]-1, i gen...
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...
#PicoLisp
PicoLisp
(de pascalTriangle (N) (for I N (space (* 2 (- N I))) (let C 1 (for K I (prin (align 3 C) " ") (setq C (*/ C (- I K) K)) ) ) (prinl) ) )
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....
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h>   /* Generate (and memoize) the Padovan sequence using * the recurrence relationship */ int pRec(int n) { static int *memo = NULL; static size_t curSize = 0;   /* grow memoization array when necessary and fill with zeroes */ 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 ...
#JavaScript
JavaScript
function isPalindrome(str) { return str === str.split("").reverse().join(""); }   console.log(isPalindrome("ingirumimusnocteetconsumimurigni"));
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...
#Clojure
Clojure
  (defn valid-date? [[y m d]] (and (<= 1 m 12) (<= 1 d 31)))   (defn date-str [[y m d]] (format "%4d-%02d-%02d" y m d))   (defn yr->date [y] (let [[_ m d] (re-find #"(..)(..)" (apply str (reverse (str y))))] [y (Long. m) (Long. d)]))   (defn palindrome-dates [start-yr n] (->> (iterate inc start-yr) ...
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 , ...
#Groovy
Groovy
def partitions = { int... sizes -> int n = (sizes as List).sum() def perms = n == 0 ? [[]] : (1..n).permutations() Set parts = perms.collect { p -> sizes.collect { s -> (0..<s).collect { p.pop() } as Set } } parts.sort{ a, b -> if (!a) return 0 def comp = [a,b].transpose().find { aa, bb -> a...
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...
#PL.2FI
PL/I
  declare (t, u)(40) fixed binary; declare (i, n) fixed binary;   t,u = 0; get (n); if n <= 0 then return;   do n = 1 to n; u(1) = 1; do i = 1 to n; u(i+1) = t(i) + t(i+1); end; put skip edit ((u(i) do i = 1 to n)) (col(40-2*n), (n+1) f(4)); t = u; end;  
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....
#C.2B.2B
C++
#include <iostream> #include <map> #include <cmath>   // Generate the Padovan sequence using the recurrence // relationship. int pRec(int n) { static std::map<int,int> memo; auto it = memo.find(n); if (it != memo.end()) return it->second;   if (n <= 2) memo[n] = 1; else memo[n] = pRec(n-2) + pRec(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 ...
#jq
jq
def palindrome: explode as $in | ($in|reverse) == $in;
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...
#F.23
F#
// palindrome_dates.fsx open System   let is_palindrome_date = let date_string (date: DateTime) = date.ToString "yyyyMMdd" let is_palindrome s = let rev_string = Seq.rev >> Seq.map string >> String.concat "" s = rev_string s date_string >> is_palindrome   let palindrome_dates = let rec l...
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 , ...
#Haskell
Haskell
import Data.List ((\\))   comb :: Int -> [a] -> [[a]] comb 0 _ = [[]] comb _ [] = [] comb k (x:xs) = map (x:) (comb (k-1) xs) ++ comb k xs   partitions :: [Int] -> [[[Int]]] partitions xs = p [1..sum xs] xs where p _ [] = [[]] p xs (k:ks) = [ cs:rs | cs <- comb k xs, rs <- p (xs \\ cs) ks ] ...
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...
#Potion
Potion
printpascal = (n) : if (n < 1) : 1 print (1) . else : prev = printpascal(n - 1) prev append(0) curr = (1) n times (i): curr append(prev(i) + prev(i + 1)) . "\n" print curr join(", ") print curr . .   printpascal(read number integer)
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....
#Clojure
Clojure
(def padovan (map first (iterate (fn [[a b c]] [b c (+ a b)]) [1 1 1])))   (def pad-floor (let [p 1.324717957244746025960908854 s 1.0453567932525329623] (map (fn [n] (int (Math/floor (+ (/ (Math/pow p (dec n)) s) 0.5)))) (range))))   (def pad-l (iterate (fn f [[c & s]] (case c ...
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 ...
#Jsish
Jsish
/* Palindrome detection, in Jsish */ function isPalindrome(str:string, exact:boolean=true) { if (!exact) { str = str.toLowerCase(); str = str.replace(/[ \t,;:!?.]/g, ''); } return str === str.match(/./g).reverse().join(''); }   ;isPalindrome('BUB'); ;isPalindrome('CUB'); ;isPalindrome('Bub'); ;isPalin...
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...
#Factor
Factor
USING: calendar calendar.format io kernel lists lists.lazy sequences sets ;   : palindrome-dates ( -- list ) 2020 2 2 <date> [ 1 days time+ ] lfrom-by [ timestamp>ymd ] lmap-lazy [ "-" without dup reverse = ] lfilter ;   15 palindrome-dates ltake [ print ] leach
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...
#FreeBASIC
FreeBASIC
  Dim As String dateTest = "" Dim As Integer Pal =0, total = 0 Print "Siguientes 15 fechas palindr¢micas al 2020-02-02:" For anno As Integer = 2021 To 9999 dateTest = Ltrim(Str(anno)) For mes As Integer = 1 To 12 If mes < 10 Then dateTest = dateTest + "0" dateTest += Ltrim(Str(mes)) For ...
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 , ...
#J
J
require'stats' partitions=: ([,] {L:0 (i.@#@, -. [)&;)/"1@>@,@{@({@comb&.> +/\.)
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 , ...
#JavaScript
JavaScript
(function () { 'use strict';   // [n] -> [[[n]]] function partitions(a1, a2, a3) { var n = a1 + a2 + a3;   return combos(range(1, n), n, [a1, a2, a3]); }   function combos(s, n, xxs) { if (!xxs.length) return [[]];   var x = xxs[0], xs = xxs.slice(1);   return mb( choose(s, n, x), ...
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...
#PowerShell
PowerShell
  $Infinity = 1 $NewNumbers = $null $Numbers = $null $Result = $null $Number = $null $Power = $args[0]   Write-Host $Power   For( $i=0; $i -lt $Infinity; $i++ ) { $Numbers = New-Object Object[] 1 $Numbers[0] = $Power For( $k=0; $k -lt $NewNumbers.Length; $k++ ) { ...
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...
#11l
11l
V words = File(‘unixdict.txt’).read().split("\n") V ordered = words.filter(word -> word == sorted(word).join(‘’)) V maxlen = max(ordered, key' w -> w.len).len V maxorderedwords = ordered.filter(word -> word.len == :maxlen) print(maxorderedwords.join(‘ ’))
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....
#Delphi
Delphi
  program Padovan_sequence;   {$APPTYPE CONSOLE}   uses System.SysUtils, Velthuis.BigDecimals, Boost.Generics.Collection;   type TpFn = TFunc<Integer, Integer>;   var RecMemo: TDictionary<Integer, Integer>; lSystemMemo: TDictionary<Integer, string>;   function pRec(n: Integer): Integer; begin if RecMemo.H...
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 ...
#Julia
Julia
palindrome(s) = s == reverse(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...
#Go
Go
package main   import ( "fmt" "time" )   func reverse(s string) string { chars := []rune(s) for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 { chars[i], chars[j] = chars[j], chars[i] } return string(chars) }   func main() { const ( layout = "20060102" layout2 = "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 , ...
#jq
jq
# Generate a stream of the distinct combinations of r items taken from the input array. def combination(r): if r > length or r < 0 then empty elif r == length then . else ( [.[0]] + (.[1:]|combination(r-1))), ( .[1:]|combination(r)) end;   # Input: a mask, that is, an array of lengths. # Output: a stre...
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 , ...
#Julia
Julia
  using Combinatorics   function masked(mask, lis) combos = [] idx = 1 for step in mask if(step < 1) push!(combos, Array{Int,1}[]) else push!(combos, sort(lis[idx:idx+step-1])) idx += step end end Array{Array{Int, 1}, 1}(combos) end   funct...
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...
#Prolog
Prolog
pascal(N) :- pascal(1, N, [1], [[1]|X]-X, L), maplist(my_format, L).   pascal(Max, Max, L, LC, LF) :- !, make_new_line(L, NL), append_dl(LC, [NL|X]-X, LF-[]).   pascal(N, Max, L, NC, LF) :- build_new_line(L, NL), append_dl(NC, [NL|X]-X, NC1), N1 is N+1, pascal(N1, Max, NL, NC1, LF).   build_new_line(L, R) :- ...
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...
#Action.21
Action!
CHAR ARRAY line(256)   BYTE FUNC IsOrderedWord(CHAR ARRAY word) BYTE len,i   len=word(0) IF len<=1 THEN RETURN (1) FI   FOR i=1 TO len-1 DO IF word(i)>word(i+1) THEN RETURN (0) FI OD RETURN (1)   BYTE FUNC FindLongestOrdered(CHAR ARRAY fname) BYTE max,dev=[1]   max=0 Close(dev) Open(de...
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....
#Factor
Factor
USING: L-system accessors io kernel make math math.functions memoize prettyprint qw sequences ;   CONSTANT: p 1.324717957244746025960908854 CONSTANT: s 1.0453567932525329623   : pfloor ( m -- n ) 1 - p swap ^ s /f .5 + >integer ;   MEMO: precur ( m -- n ) dup 3 < [ drop 1 ] [ [ 2 - precur ] [ 3 - precur ] bi + ...
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....
#Go
Go
package main   import ( "fmt" "math" "math/big" "strings" )   func padovanRecur(n int) []int { p := make([]int, n) p[0], p[1], p[2] = 1, 1, 1 for i := 3; i < n; i++ { p[i] = p[i-2] + p[i-3] } return p }   func padovanFloor(n int) []int { var p, s, t, u = new(big.Rat), new...
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 ...
#k
k
is_palindrome:{x~|x}
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...
#Haskell
Haskell
import Data.Time.Calendar (Day, fromGregorianValid) import Data.List.Split (chunksOf) import Data.List (unfoldr) import Data.Tuple (swap) import Data.Bool (bool) import Data.Maybe (mapMaybe)   palinDates :: [Day] palinDates = mapMaybe palinDay [2021 .. 9999]   palinDay :: Integer -> Maybe Day palinDay y = fromGregorian...
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 , ...
#Kotlin
Kotlin
// version 1.1.3   fun nextPerm(perm: IntArray): Boolean { val size = perm.size var k = -1 for (i in size - 2 downTo 0) { if (perm[i] < perm[i + 1]) { k = i break } } if (k == -1) return false // last permutation for (l in size - 1 downTo k) { if...
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...
#PureBasic
PureBasic
Procedure pascaltriangle( n.i)   For i= 0 To n c = 1 For k=0 To i Print(Str( c)+" ") c = c * (i-k)/(k+1); Next ;k PrintN(" "); nächste zeile Next ;i   EndProcedure   OpenConsole() Parameter.i = Val(ProgramParameter(0)) pascaltriangle(Parameter); Input()
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...
#Ada
Ada
  with Ada.Text_IO, Ada.Containers.Indefinite_Vectors; use Ada.Text_IO;   procedure Ordered_Words is package Word_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type => Positive, Element_Type => String); use Word_Vectors; File : File_Type; Ordered_Words : Vector; Max_Length : Positive := ...
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....
#Haskell
Haskell
-- list of Padovan numbers using recurrence pRec = map (\(a,_,_) -> a) $ iterate (\(a,b,c) -> (b,c,a+b)) (1,1,1)   -- list of Padovan numbers using self-referential lazy lists pSelfRef = 1 : 1 : 1 : zipWith (+) pSelfRef (tail pSelfRef)   -- list of Padovan numbers generated from floor function pFloor = map f [0..] ...
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 ...
#Kotlin
Kotlin
// version 1.1.2   /* These functions deal automatically with Unicode as all strings are UTF-16 encoded in Kotlin */   fun isExactPalindrome(s: String) = (s == s.reversed())   fun isInexactPalindrome(s: String): Boolean { var t = "" for (c in s) if (c.isLetterOrDigit()) t += c t = t.toLowerCase() return...
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...
#Java
Java
  import java.time.LocalDate; import java.time.format.DateTimeFormatter;   public class PalindromeDates {   public static void main(String[] args) { LocalDate date = LocalDate.of(2020, 2, 3); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); DateTimeFormatter formatterDa...
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 , ...
#Lua
Lua
--- Create a list {1,...,n}. local function range(n) local res = {} for i=1,n do res[i] = i end return res end   --- Return true if the element x is in t. local function isin(t, x) for _,x_t in ipairs(t) do if x_t == x then return true end end return false end   --- Return the sublist from index u...
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...
#Python
Python
def pascal(n): """Prints out n rows of Pascal's triangle. It returns False for failure and True for success.""" row = [1] k = [0] for x in range(max(n,0)): print row row=[l+r for l,r in zip(row+k,k+row)] return n>=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...
#Aime
Aime
integer ordered(data s) { integer a, c, p;   a = 1;   p = -1; for (, c in s) { if (c < p) { a = 0; break; } else { p = c; } }   a; }   integer main(void) { file f; text s; index x;   f.affix("unixdict.txt");   while ...
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....
#J
J
  padovanSeq=: (],+/@(_2 _3{]))^:([-3:)&1 1 1   realRoot=. {:@(#~ ]=|)@;@p. padovanNth=: 0.5 <.@+ (realRoot _23 23 _2 1) %~ (realRoot _1 _1 0 1)^<:   padovanL=: rplc&('A';'B'; 'B';'C'; 'C';'AB')@]^:[&'A' seqLen=. #@(-.&' ')"1  
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....
#JavaScript
JavaScript
(() => { "use strict";   // ----------------- PADOVAN NUMBERS -----------------   // padovans :: [Int] const padovans = () => { // Non-finite series of Padovan numbers, // defined in terms of recurrence relations. const f = ([a, b, c]) => [ a, [b, c, a + b...
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 ...
#LabVIEW
LabVIEW
val .ispal = f len(.s) > 0 and .s == s2s .s, len(.s)..1   val .tests = h{ "": false, "z": true, "aha": true, "αηα": true, "αννα": true, "αννασ": false, "sees": true, "seas": false, "deified": true, "solo": false, "solos": true, "amanaplanacanalpanama": true, "a man a ...
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...
#JavaScript
JavaScript
/** * Adds zeros for 1 digit days/months * @param date: string */ const addMissingZeros = date => (/^\d$/.test(date) ? `0${date}` : date);   /** * Formats a Date to a string. If readable is false, * string is only numbers (used for comparison), else * is a human readable date. * @param date: Date * @param reada...
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 , ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
w[partitions_]:=Module[{s={},t=Total@partitions,list=partitions,k}, n=Length[list]; While[n>0,s=Join[s,{Take[t,(k=First[list])]}];t=Drop[t,k];list=Rest[list];n--]; s] m[p_]:=(Sort/@#)&/@(w[#,p]&/@Permutations[Range@Total[p]])//Union
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 , ...
#Nim
Nim
import algorithm, math, sequtils, strutils   type Partition = seq[seq[int]]     func isIncreasing(s: seq[int]): bool = ## Return true if the sequence is sorted in increasing order. var prev = 0 for val in s: if prev >= val: return false prev = val result = true     iterator partitions(lengths: varargs[i...
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...
#q
q
  pascal:{(x-1){0+':x,0}\1} pascal 5 1 1 1 1 2 1 1 3 3 1 1 4 6 4 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...
#ALGOL_68
ALGOL 68
PROC ordered = (STRING s)BOOL: BEGIN FOR i TO UPB s - 1 DO IF s[i] > s[i+1] THEN return false FI OD; TRUE EXIT return false: FALSE END;   IF FILE input file; STRING file name = "unixdict.txt"; open(input file, file name, stand in channel) /= 0 THEN print(("Unable to open file """ + file name + "...
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....
#jq
jq
# Output: first $n Padovans def padovanRecur($n): [range(0;$n) | 1] as $p | if $n < 3 then $p else reduce range(3;$n) as $i ($p; .[$i] = .[$i-2] + .[$i-3]) end;   # Output: first $n Padovans def padovanFloor($n): { p: 1.324717957244746025960908854, s: 1.0453567932525329623, pow: 1 } | reduce ran...
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....
#Julia
Julia
""" Recursive Padovan """ rPadovan(n) = (n < 4) ? one(n) : rPadovan(n - 3) + rPadovan(n - 2)   """ Floor function calculation Padovan """ function fPadovan(n)::Int p, s = big"1.324717957244746025960908854", big"1.0453567932525329623" return Int(floor(p^(n-2) / s + .5)) end   """ LSystem Padovan """ function lis...
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 ...
#langur
langur
val .ispal = f len(.s) > 0 and .s == s2s .s, len(.s)..1   val .tests = h{ "": false, "z": true, "aha": true, "αηα": true, "αννα": true, "αννασ": false, "sees": true, "seas": false, "deified": true, "solo": false, "solos": true, "amanaplanacanalpanama": true, "a man a ...
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...
#Julia
Julia
using Dates   function datepalindromes(nextcount=20) println("Date palindromes:") count, d = 0, Date(1000, 1, 1) for year in 2021:9200 try dig = digits(year) month = 10 * dig[1] + dig[2] day = 10 * dig[3] + dig[4] d = Date(year, month, day) cat...
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...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
today = DateList[Today]; res = {}; i = 0; While[Length[res] < 15, date = DatePlus[today, i]; ds = DateString[date, {"Year", "Month", "Day"}]; If[PalindromeQ[ds], AppendTo[res, date] ]; i++; ] Column[DateString[#, {"Year", "-", "Month", "-", "Day"}] & /@ res]
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 , ...
#Perl
Perl
use Thread 'async'; use Thread::Queue;   sub make_slices { my ($n, @avail) = (shift, @{ +shift });   my ($q, @part, $gen); $gen = sub { my $pos = shift; # where to start in the list if (@part == $n) { # we accumulated enough for a pa...
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...
#Qi
Qi
  (define iterate _ _ 0 -> [] F V N -> [V|(iterate F (F V) (1- N))])   (define next-row R -> (MAPCAR + [0|R] (append R [0])))   (define pascal N -> (iterate next-row [1] N))  
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...
#APL
APL
result←longest_ordered_words file_path   f←file_path ⎕NTIE 0 ⍝ open file text←⎕NREAD f 'char8' ⍝ read vector of 8bit chars ⎕NUNTIE f ⍝ close file   lines←text⊂⍨~text∊(⎕UCS 10 13) ⍝ split into lines (\r\n)   ⍝ filter only words with ordered characters ordered_words←lines/⍨{(⍳∘≢≡⍋...
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....
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ClearAll[Padovan1,a,p,s] p=N[Surd[((9+Sqrt[69])/18),3]+Surd[((9-Sqrt[69])/18),3],200]; s=1.0453567932525329623; Padovan1[nmax_Integer]:=RecurrenceTable[{a[n+1]==a[n-1]+a[n-2],a[0]==1,a[1]==1,a[2]==1},a,{n,0,nmax-1}] Padovan2[nmax_Integer]:=With[{},Floor[p^Range[-1,nmax-2]/s+1/2]] Padovan1[20] Padovan2[20] Padovan1[64]=...
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....
#Nim
Nim
import sequtils, strutils, tables   const P = 1.324717957244746025960908854 S = 1.0453567932525329623   Rules = {'A': "B", 'B': "C", 'C': "AB"}.toTable     iterator padovan1(n: Natural): int {.closure.} = ## Yield the first "n" Padovan values using recurrence relation. for _ in 1..min(n, 3): yield 1 var a, ...
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 ...
#Lasso
Lasso
define ispalindrome(text::string) => {   local(_text = string(#text)) // need to make copy to get rid of reference issues   #_text -> replace(regexp(`(?:$|\W)+`), -ignorecase)   local(reversed = string(#_text)) #reversed -> reverse   return #_text == #reversed }   ispalindrome('Tätatät') // works with high ascii i...
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...
#Nim
Nim
import strformat, times   func digits(n: int): seq[int] = var n = n while n != 0: result.add n mod 10 n = n div 10   echo "First 15 palindrome dates after 2020-02-02:" var count = 0 var year = 2021 while count != 15: let d = year.digits let monthNum = 10 * d[0] + d[1] let dayNum = 10 * d[2] + d[3] i...
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...
#Perl
Perl
use Time::Piece; my $d = Time::Piece->strptime("2020-02-02", "%Y-%m-%d");   for (my $k = 1 ; $k <= 15 ; $d += Time::Piece::ONE_DAY) { my $s = $d->strftime("%Y%m%d"); if ($s eq reverse($s) and ++$k) { print $d->strftime("%Y-%m-%d\n"); } }
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 , ...
#Phix
Phix
with javascript_semantics requires("1.0.2") function partitions(sequence s) integer l = length(s), N = sum(s) sequence pset = {}, -- eg s==={2,0,2} -> {1,1,3,3} rn = repeat(0,l) -- "" -> {{0,0},{},{0,0}} for i=1 to l do pset &= repeat(i,s[i]) rn[i] = repeat(0,s[i]) end for...
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...
#Quackery
Quackery
[ over size - space swap of swap join ] is justify ( $ n --> )   [ witheach [ number$ 5 justify echo$ ] cr ] is echoline ( [ --> )   [ [] 0 rot 0 join witheach [ tuck + rot join swap ] drop ] is nextline ( [ --> [...
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...
#AppleScript
AppleScript
use AppleScript version "2.3.1" -- Mac OS 10.9 (Mavericks) or later — for these 'use' commands. use sorter : script "Insertion sort" -- https://www.rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AppleScript. use scripting additions   on longestOrderedWords(wordList) script o property allWords : word...
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....
#Perl
Perl
use strict; use warnings; use feature <state say>; use List::Lazy 'lazy_list';   my $p = 1.32471795724474602596; my $s = 1.0453567932525329623; my %rules = (A => 'B', B => 'C', C => 'AB');   my $pad_recur = lazy_list { state @p = (1, 1, 1, 2); push @p, $p[1]+$p[2]; shift @p };   sub pad_floor { int 1/2 + $p**($_<3 ? 1 ...
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 ...
#Liberty_BASIC
Liberty BASIC
print isPalindrome("In girum imus nocte et consumimur igni") print isPalindrome(removePunctuation$("In girum imus nocte et consumimur igni", "S")) print isPalindrome(removePunctuation$("In girum imus nocte et consumimur igni", "SC"))   function isPalindrome(string$) isPalindrome = 1 for i = 1 to int(len(string$...
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...
#Phix
Phix
with javascript_semantics include builtins\timedate.e sequence res = {} for d=2021 to 9999 do string s = sprintf("%4d",d), t = reverse(s) s &= "-"&t[1..2]&"-"&t[3..4] sequence td = parse_date_string(s, {"YYYY-MM-DD"}) if timedate(td) then res = append(res,s) end if end for printf(1,"Count of...
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 , ...
#PicoLisp
PicoLisp
(de partitions (Args) (let Lst (range 1 (apply + Args)) (recur (Args Lst) (ifn Args '(NIL) (mapcan '((L) (mapcar '((R) (cons L R)) (recurse (cdr Args) (diff Lst L)) ) ) (comb (car Args) Ls...
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 , ...
#Python
Python
from itertools import combinations   def partitions(*args): def p(s, *args): if not args: return [[]] res = [] for c in combinations(s, args[0]): s0 = [x for x in s if x not in c] for r in p(s0, *args[1:]): res.append([c] + r) return res s ...
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...
#R
R
pascalTriangle <- function(h) { for(i in 0:(h-1)) { s <- "" for(k in 0:(h-i)) s <- paste(s, " ", sep="") for(j in 0:i) { s <- paste(s, sprintf("%3d ", choose(i, j)), sep="") } print(s) } }
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...
#Arturo
Arturo
ordered?: function [w]-> w = join sort split w   words: read.lines relative "unixdict.txt" ret: new [] loop words 'wrd [ if ordered? wrd -> 'ret ++ #[w: wrd l: size wrd] ]   sort.descending.by: 'l 'ret maxl: get first ret 'l print sort map select ret 'x -> maxl = x\l 'x -> x\w
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....
#Phix
Phix
with javascript_semantics sequence padovan = {1,1,1} function padovanr(integer n) while length(padovan)<n do padovan &= padovan[$-2]+padovan[$-1] end while return padovan[n] end function constant p = 1.324717957244746025960908854, s = 1.0453567932525329623 function padovana(integer 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 ...
#LiveCode
LiveCode
function palindrome txt exact if exact is empty or exact is not false then set caseSensitive to true --default is false else replace space with empty in txt put lower(txt) into txt end if return txt is reverse(txt) end palindrome   function reverse str repeat with i = the ...
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...
#PureBasic
PureBasic
NewList pdates.s()   Procedure.b IsLeap(y.i) ProcedureReturn Bool( y % 4 = 0 ) & Bool( y % 100 <> 0 ) | Bool( y % 400 = 0 ) EndProcedure   If OpenConsole("")=0 : End 1 : EndIf   For j=2021 To 9999 For m=1 To 12 tm2=28+1*IsLeap(j) For t=1 To 31 If m=2 And t>tm2 : Break : EndIf If (m=4 Or m=...
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 , ...
#Racket
Racket
  #lang racket (define (comb k xs) (cond [(zero? k) (list (cons '() xs))] [(null? xs) '()] [else (append (for/list ([cszs (comb (sub1 k) (cdr xs))]) (cons (cons (car xs) (car cszs)) (cdr cszs))) (for/list ([cszs (comb k (cdr xs))]) ...
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...
#Racket
Racket
#lang racket   (define (pascal n) (define (next-row current-row) (map + (cons 0 current-row) (append current-row '(0)))) (reverse (for/fold ([triangle '((1))]) ([row (in-range 1 n)]) (cons (next-row (first triangle)) triangle))))      
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 ...
#11l
11l
F user_cmp(String a, b) R Int(input(‘IS #6 <, ==, or > #6 answer -1, 0 or 1:’.format(a, b)))   V items = ‘violet red green indigo blue yellow orange’.split(‘ ’) V ans = sorted(items, key' cmp_to_key(user_cmp)) print("\n"ans.join(‘ ’))
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...
#AutoHotkey
AutoHotkey
  MaxLen=0 Loop, Read, UnixDict.txt ; Assigns A_LoopReadLine to each line of the file { thisword := A_LoopReadLine ; Just for readability blSort := isSorted(thisWord) ; reduce calls to IsSorted to improve performance ThisLen := StrLen(ThisWord) ; reduce calls to StrLen to improve performance ...