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/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
next[last_] := Mod[214013 last + 2531011, 2^31]; deal[n_] := Module[{last = n, idx, deck = StringJoin /@ Tuples[{{"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"}, {"C", "D", "H", "S"}}], res = {}}, While[deck != {}, last = next[last]; idx = Mod[BitShiftRight[last, 16],...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Nim
Nim
import sequtils, strutils, os   proc randomGenerator(seed: int): iterator: int = var state = seed return iterator: int = while true: state = (state * 214013 + 2531011) and int32.high yield state shr 16   proc deal(seed: int): seq[int] = const nc = 52 result = toSeq countdown(nc - 1, 0) var rnd...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Racket
Racket
  #lang racket   (provide (contract-out [x 1-to-10/c]))   (define 1-to-10/c (between/c 1 10))   (define x 5)  
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Raku
Raku
subset OneToTen of Int where 1..10;   my OneToTen $n = 5; $n += 6;
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#BCPL
BCPL
get "libhdr"   let weekday(y, m, d) = m<3 -> wd((y-1)/100, (y-1) rem 100, m + 10, d), wd(y/100, y rem 100, m - 2, d) and wd(c, y, m, d) = ((26*m-2)/10 + d + y + y/4 + c/4 - 2 * c + 777) rem 7   let start() be for year = 2008 to 2121 if weekday(year, 12, 25) = 0 do writef("%N...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#360_Assembly
360 Assembly
* CUSIP 07/06/2018 CUSIP CSECT USING CUSIP,R13 base register B 72(R15) skip savearea DC 17F'0' savearea SAVE (14,12) save previous context ST R13,4(R15) link backward ST...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#Action.21
Action!
INCLUDE "D2:CHARTEST.ACT" ;from the Action! Tool Kit   BYTE FUNC Verify(CHAR ARRAY code) BYTE i,c,v CARD sum   IF code(0)#9 THEN RETURN (0) ELSEIF IsDigit(code(1))=0 THEN RETURN (0) FI   sum=0 FOR i=2 TO code(0) DO c=code(i) IF IsDigit(c) THEN v=c-'0 ELSEIF IsAlpha(c) THEN ...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#ABAP
ABAP
  report zdate. data: lv_month type string, lv_weekday type string, lv_date type string, lv_day type c.   call function 'DATE_COMPUTE_DAY' exporting date = sy-datum importing day = lv_day. select single ltx from t247 into lv_month where spras = sy-langu and mnr = sy-datum+4(2).   select singl...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#ALGOL_68
ALGOL 68
BEGIN # returns TRUE if the check digit of s is correct according to the Damm algorithm, # # FALSE otherwise # PROC has valid damm check digit = ( STRING s )BOOL: BEGIN # operation table - as per wikipedia example # [,]INT operation table = ( [,]INT( ( 0, 3, ...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Go
Go
package main   import ( "fmt" "math/big" )   func main() { zero := big.NewInt(0) one := big.NewInt(1) for k := int64(2); k <= 10; k += 2 { bk := big.NewInt(k) fmt.Println("The first 50 Curzon numbers using a base of", k, ":") count := 0 n := int64(1) pow := bi...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#jq
jq
# To take advantage of gojq's arbitrary-precision integer arithmetic: def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);   def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;   # gojq does not currently define _nwise def _nwise($n): def n: if length <= $n then . else .[0:$n] , (.[$n:...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#Delphi
Delphi
  program Cut_a_rectangle;   {$APPTYPE CONSOLE}   uses System.SysUtils;   var grid: array of byte; w, h, len: Integer; cnt: UInt64; next: array of Integer; dir: array of array of Integer = [[0, -1], [-1, 0], [0, 1], [1, 0]];   procedure walk(y, x: Integer); var i, t: Integer; begin if (y = 0) or (y = h)...
http://rosettacode.org/wiki/Cyclops_numbers
Cyclops numbers
A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different ...
#Perl
Perl
use strict; use warnings; use feature 'say'; use ntheory 'is_prime'; use List::AllUtils 'firstidx';   sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }   my @cyclops = 0; for my $exp (0..3) { my @oom = grep { ! /0/ } 10**$exp .. 10**($exp+1)-1; for my $l (@oom) { for my $r (@oom) { ...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"DATELIB"   date$ = "March 7 2009 7:30pm EST"   mjd% = FN_readdate(date$, "mdy", 0) colon% = INSTR(date$, ":") hours% = VAL(MID$(date$, colon%-2)) IF INSTR(date$, "am") IF hours%=12 hours% -= 12 IF INSTR(date$, "pm") IF hours%<>12 hours% += 12 mins% = VAL(M...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#C
C
#include <stdio.h> #include <stdlib.h> #include <time.h>   int main() { struct tm ts; time_t t; const char *d = "March 7 2009 7:30pm EST";   strptime(d, "%B %d %Y %I:%M%p %Z", &ts); /* ts.tm_hour += 12; instead of t += 12*60*60 works too. */ t = mktime(&ts); t += 12*60*60; printf("%s", ctime(&t)); ...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Objeck
Objeck
class FreeCell { function : Main(args : String[]) ~ Nil { Deal(1)->PrintLine(); Deal(617)->PrintLine(); }   function : Deal(seed : Int) ~ String { deck := Deck->New(seed)->ToString(); return "Game #{$seed}:\n{$deck}\n"; } }   class Deck { @cards : Card[];   New(seed : Int) { r := Random-...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Retro
Retro
{{ variable update ---reveal---  : .limited @update &! &@ if update off ;  : to dup 1 10 within [ update on ] [ drop "Out of bounds\n" puts ] if ;  : limited: create 1 , &.limited reclass ; }}
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Ruby
Ruby
Some object-oriented languages won't let you subclass the "basic" data types like integers. Other languages implement those data types as classes, so you can subclass them, no questions asked. Ruby implements numbers as classes (Integer, with its concrete subclasses Fixnum and Bignum), and you can subclass those classe...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Befunge
Befunge
8 >:"2("*+::::4/+\"d"/-\45v @_^#`"y": +1$<_v#%7+1+/*:*< >:#,_>$:.55+,^ >0" ,52 ceD"
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Bracmat
Bracmat
{ Calculate day of week in proleptic Gregorian calendar. Sunday == 0. } ( wday = year month day adjustment mm yy .  !arg:(?year,?month,?day) & div$(14+-1*!month,12):?adjustment & !month+12*!adjustment+-2:?mm & !year+-1*!adjustment:?yy & mod $ (  !day ...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#Ada
Ada
with Ada.Text_IO;   procedure Cusip_Test is use Ada.Text_IO;   subtype Cusip is String (1 .. 9);   function Check_Cusip (Code : Cusip) return Boolean is Sum : Integer := 0; V  : Integer;   begin for I in Code'First .. Code'Last - 1 loop case Code (I) is when '0' .. '9...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Action.21
Action!
DEFINE PTR="CARD"   TYPE Date=[ INT year BYTE month BYTE day]   PTR ARRAY DayOfWeeks(7) PTR ARRAY Months(12)   PROC Init() DayOfWeeks(0)="Sunday" DayOfWeeks(1)="Monday" DayOfWeeks(2)="Tuesday" DayOfWeeks(3)="Wednesday" DayOfWeeks(4)="Thursday" DayOfWeeks(5)="Friday" DayOfWeeks(6)="Saturday" Months(0)...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Ada
Ada
with Ada.Calendar; use Ada.Calendar; with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; with Ada.Text_IO; use Ada.Text_IO;   procedure Date_Format is function Image (Month : Month_Number) return String is begin case Month is when 1 => return "January"; wh...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#APL
APL
damm←{⎕IO←0 tbl←⍉⍪0 3 1 7 5 9 8 6 4 2 tbl⍪← 7 0 9 2 1 5 4 8 6 3 tbl⍪← 4 2 0 6 8 7 1 3 5 9 tbl⍪← 1 7 5 0 9 8 3 7 2 6 tbl⍪← 6 1 2 3 0 4 5 9 7 8 tbl⍪← 3 6 7 4 2 0 9 5 8 1 tbl⍪← 5 8 6 9 7 2 0 1 3 4 tbl⍪← 8 9 4 5 3 6 2 0 1 7 tbl⍪← 9 4 3 8 6 1 7 2 0 5 tbl⍪← 2 5 8 1 4 3 6 7 9 0 0={...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#AppleScript
AppleScript
-- Return a check digit value for the given integer value or numeric string. -- The result is 0 if the input's last digit is already a valid check digit for it. on damm(n) set digits to {n mod 10} set n to n div 10 repeat until (n is 0) set beginning of digits to n mod 10 set n to n div 10 ...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Julia
Julia
isCurzon(n, k) = (BigInt(k)^n + 1) % (k * n + 1) == 0   function printcurzons(klow, khigh) for k in filter(iseven, klow:khigh) n, curzons = 0, Int[] while length(curzons) < 1000 isCurzon(n, k) && push!(curzons, n) n += 1 end println("Curzon numbers with k = $k...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Pascal
Pascal
  program CurzonNumbers; uses SysUtils; const MAX_CURZON_MEG = 100; RC_LINE_LENGTH = 66;   procedure ListCurzonNumbers( base : integer); var k, n, m, x, testBit, maxCurzon : uint64; nrHits : integer; lineOut : string; begin maxCurzon := 1000000*MAX_CURZON_MEG; k := uint64( base); nrHits := 0; n := 0; ...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#Eiffel
Eiffel
  class APPLICATION   create make   feature {NONE} -- Initialization   make -- Finds solution for cut a rectangle up to 10 x 10. local i, j, n: Integer r: GRID do n := 10 from i := 1 until i > n loop from j := 1 until j > i loop if i.bit_and (1) /= 1 or j.b...
http://rosettacode.org/wiki/Cyclops_numbers
Cyclops numbers
A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different ...
#Phix
Phix
with javascript_semantics atom t0 = time() function bump(sequence half) -- add a digit to valid halves -- eg {0} --> {1..9} (no zeroes) -- --> {11..99} ("") -- --> {111..999}, etc sequence res = {} for i=1 to length(half) do integer hi = half[i]*10 for digit=1 to 9 ...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#C.23
C#
class Program { static void Main(string[] args) { CultureInfo ci=CultureInfo.CreateSpecificCulture("en-US"); string dateString = "March 7 2009 7:30pm EST"; string format = "MMMM d yyyy h:mmtt z"; DateTime myDateTime = DateTime.ParseExact(dateString.Replace("EST","+6"),format,ci) ...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Objective-C
Objective-C
#define RMAX32 ((1U << 31) - 1)   //--------------------------------------------------------------------   @interface Rand : NSObject -(instancetype) initWithSeed: (int)seed; -(int) next; @property (nonatomic) long seed; @end   @implementation Rand -(instancetype) initWithSeed: (int)seed { if ((self = [super init])...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Rust
Rust
use std::convert::TryFrom;   mod test_mod { use std::convert::TryFrom; use std::fmt;   // Because the `i8` is not `pub` this cannot be directly constructed // by code outside this module #[derive(Copy, Clone, Debug)] pub struct TwoDigit(i8);   impl TryFrom<i8> for TwoDigit { type Err...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Scala
Scala
class TinyInt(val int: Byte) { import TinyInt._ require(int >= lower && int <= upper, "TinyInt out of bounds.")   override def toString = int.toString }   object TinyInt { val (lower, upper) = (1, 10)   def apply(i: Byte) = new TinyInt(i) }   val test = (TinyInt.lower to TinyInt.upper).map...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#C
C
#include <stdio.h>   /* Calculate day of week in proleptic Gregorian calendar. Sunday == 0. */ int wday(int year, int month, int day) { int adjustment, mm, yy;   adjustment = (14 - month) / 12; mm = month + 12 * adjustment - 2; yy = year - adjustment; return (day + (13 * mm - 1) / 5 + yy + yy / 4 - yy / 100 + yy...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#ALGOL_68
ALGOL 68
BEGIN # returns TRUE if cusip is a valid CUSIP code # OP ISCUSIP = ( STRING cusip )BOOL: IF ( UPB cusip - LWB cusip ) /= 8 THEN # code is wrong length # FALSE ELSE # string is 9 characters long - check it is valid # STRING cusip digits = "01234567...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#ALGOL_68
ALGOL 68
# define the layout of the date/time as provided by the call to local time # STRUCT ( INT sec, min, hour, mday, mon, year, wday, yday, isdst) tm = (6,5,4,3,2,1,7,~,8);   FORMAT # some useful format declarations # ymd repr = $4d,"-"2d,"-"2d$, month repr = $c("January","February","March","April","May","June","July...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#ARM_Assembly
ARM Assembly
.text .global _start @@@ Check if the zero-terminated ASCII string in [r0], @@@ which should contain a decimal number, has a @@@ matching check digit. Zero flag set if true, @@@ check digit returned in r0. damm: mov r1,#0 @ R1 = interim digit ldr r2,=3f @ R2 = table base address 1: ldrb r3,[r0],#1 @ Load byte t...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#Arturo
Arturo
table: [ [0 3 1 7 5 9 8 6 4 2] [7 0 9 2 1 5 4 8 6 3] [4 2 0 6 8 7 1 3 5 9] [1 7 5 0 9 8 3 4 2 6] [6 1 2 3 0 4 5 9 7 8] [3 6 7 4 2 0 9 5 8 1] [5 8 6 9 7 2 0 1 3 4] [8 9 4 5 3 6 2 0 1 7] [9 4 3 8 6 1 7 2 0 5] [2 5 8 1 4 3 6 7 9 0] ]   digits: function [x][map split x => [to :intege...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[CurzonNumberQ] CurzonNumberQ[b_Integer][n_Integer]:=PowerMod[b,n,b n+1]==b n val=Select[Range[100000],CurzonNumberQ[2]]; Take[val,50] val[[1000]]   val=Select[Range[100000],CurzonNumberQ[4]]; Take[val,50] val[[1000]]   val=Select[Range[100000],CurzonNumberQ[6]]; Take[val,50] val[[1000]]   val=Select[Range[1000...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Perl
Perl
use strict; use warnings; use Math::AnyNum 'ipow';   sub curzon { my($base,$cnt) = @_; my($n,@C) = 0; while (++$n) { push @C, $n if 0 == (ipow($base,$n) + 1) % ($base * $n + 1); return @C if $cnt == @C; } }   my $upto = 50; for my $k (<2 4 6 8 10>) { my @C = curzon($k,1000); prin...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Phix
Phix
with javascript_semantics include mpfr.e mpz {pow,z} = mpz_inits(2) for base=2 to 10 by 2 do printf(1,"The first 50 Curzon numbers using a base of %d:\n",base) integer count = 0, n = 1 mpz_set_si(pow,base) while true do mpz_add_ui(z,pow,1) integer d = base*n + 1 if mpz_divisible_...
http://rosettacode.org/wiki/Cyclotomic_polynomial
Cyclotomic polynomial
The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n. Task Find and print the first 30 cyclotomic polynomials. Find and print the order of the first 10...
#C.2B.2B
C++
#include <algorithm> #include <iostream> #include <initializer_list> #include <map> #include <vector>   const int MAX_ALL_FACTORS = 100000; const int algorithm = 2; int divisions = 0;   //Note: Cyclotomic Polynomials have small coefficients. Not appropriate for general polynomial usage. class Term { private: long ...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#Elixir
Elixir
import Integer   defmodule Rectangle do def cut_it(h, w) when is_odd(h) and is_odd(w), do: 0 def cut_it(h, w) when is_odd(h), do: cut_it(w, h) def cut_it(_, 1), do: 1 def cut_it(h, 2), do: h def cut_it(2, w), do: w def cut_it(h, w) do grid = List.duplicate(false, (h + 1) * (w + 1)) t = div(h, 2) * ...
http://rosettacode.org/wiki/Cyclops_numbers
Cyclops numbers
A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different ...
#Raku
Raku
use Lingua::EN::Numbers;   my @cyclops = 0, |flat lazy ^∞ .map: -> $exp { my @oom = (exp($exp, 10) ..^ exp($exp + 1, 10)).grep: { !.contains: 0 } |@oom.hyper.map: { $_ ~ 0 «~« @oom } }   my @prime-cyclops = @cyclops.grep: { .is-prime };   for '', @cyclops, 'prime ', @prime-...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#C.2B.2B
C++
#include <string> #include <iostream> #include <boost/date_time/local_time/local_time.hpp> #include <sstream> #include <boost/date_time/gregorian/gregorian.hpp> #include <vector> #include <boost/algorithm/string.hpp> #include <cstdlib> #include <locale>     int main( ) { std::string datestring ("March 7 2009 7:30pm ...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#OCaml
OCaml
let srnd x = (* since OCaml's built-in int type is at least 31 (note: not 32) bits wide, and this problem takes mod 2^31, it is just enough if we treat it as an unsigned integer, which means taking the logical right shift *) let seed = ref x in fun () -> seed := (!seed * 214013 + 2531011) land 0x7ff...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Sidef
Sidef
subset Integer < Number { .is_int } subset MyIntLimit < Integer { . ~~ (1 ..^ 10) }   class MyInt(value < MyIntLimit) {   method to_s { value.to_s } method get_value { value.get_value }   method ==(Number x) { value == x } method ==(MyInt x) { value == x.value }   method AUTOLOAD(_, name, ...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#C.23
C#
using System;   class Program { static void Main(string[] args) { for (int i = 2008; i <= 2121; i++) { DateTime date = new DateTime(i, 12, 25); if (date.DayOfWeek == DayOfWeek.Sunday) { Console.WriteLine(date.ToString("dd MMM yyyy")); ...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#ALGOL_W
ALGOL W
begin  % returns true if cusip is a valid CUSIP code % logical procedure isCusip ( string(9) value cusip ) ; begin  % returns the base 39 digit corresponding to a character of a CUSIP code % integer procedure cusipDigit( string(1) value cChar ) ; if cChar >= "0" and cChar <= "9...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#AppleScript
AppleScript
use AppleScript version "2.4" use framework "Foundation" use scripting additions     -- isCusip :: String -> Bool on isCusip(s) set cs to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*&#" set ns to mapMaybe(elemIndex(cs), s)   script go on |λ|(f, x) set fx to apply(f, x) (fx div 10) ...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Apex
Apex
  Datetime dtNow = datetime.now(); String strDt1 = dtNow.format('yyyy-MM-dd'); String strDt2 = dtNow.format('EEEE, MMMM dd, yyyy'); system.debug(strDt1); // "2007-11-10" system.debug(strDt2); //"Sunday, November 10, 2007"  
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#AutoHotkey
AutoHotkey
Damm(num){ row := 1, Damm := [[0,3,1,7,5,9,8,6,4,2] ,[7,0,9,2,1,5,4,8,6,3] ,[4,2,0,6,8,7,1,3,5,9] ,[1,7,5,0,9,8,3,4,2,6] ,[6,1,2,3,0,4,5,9,7,8] ,[3,6,7,4,2,0,9,5,8,1] ,[5,8,6,9,7,2,0,1,3,4] ,[8,9,4,5,3,6,2,0,1,7] ,[9,4,3,8,6,1,7,2,0,5] ,[2,5,8,1,4,3,6,7,9,0]] for i, v in S...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Quackery
Quackery
[ number$ space 4 of swap join -5 split nip echo$ ] is rjust ( n --> )   [ 5 times [ 10 times [ behead rjust ] cr ] drop ] is display ( [ --> )   [ temp take over join temp put ] is dax ( [ --> )   [ 2dup ** 1+ ...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Raku
Raku
sub curzon ($base) { lazy (1..∞).hyper.map: { $_ if (exp($_, $base) + 1) %% ($base × $_ + 1) } };   for <2 4 6 8 10> { my $curzon = .&curzon; say "\nFirst 50 Curzon numbers using a base of $_:\n" ~ $curzon[^50].batch(25)».fmt("%4s").join("\n") ~ "\nOne thousandth: " ~ $curzon[999] }
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Rust
Rust
// [dependencies] // rug = "1.15.0"   fn is_curzon(n: u32, k: u32) -> bool { use rug::{Complete, Integer}; (Integer::u_pow_u(k, n).complete() + 1) % (k * n + 1) == 0 }   fn main() { for k in (2..=10).step_by(2) { println!("Curzon numbers with base {k}:"); let mut count = 0; let mut n...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Sidef
Sidef
func is_curzon(n, k) { powmod(k, n, k*n + 1).is_congruent(-1, k*n + 1) && (n > 0) }   for k in (2 .. 10 `by` 2) { say "\nFirst 50 Curzon numbers using a base of #{k}:" say 50.by {|n| is_curzon(n, k) }.join(' ') say ("1000th term: ", 1000.th {|n| is_curzon(n,k) }) }
http://rosettacode.org/wiki/Cyclotomic_polynomial
Cyclotomic polynomial
The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n. Task Find and print the first 30 cyclotomic polynomials. Find and print the order of the first 10...
#C.23
C#
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using IntMap = System.Collections.Generic.Dictionary<int, int>;   public static class CyclotomicPolynomial { public static void Main2() { Console.WriteLine("Task 1: Cyclotomic polynomials for n <= 30:"); for...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#Go
Go
package main   import "fmt"   var grid []byte var w, h, last int var cnt int var next [4]int var dir = [4][2]int{{0, -1}, {-1, 0}, {0, 1}, {1, 0}}   func walk(y, x int) { if y == 0 || y == h || x == 0 || x == w { cnt += 2 return } t := y*(w+1) + x grid[t]++ grid[last-t]++ for i, ...
http://rosettacode.org/wiki/Cyclops_numbers
Cyclops numbers
A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different ...
#REXX
REXX
/*REXX pgm finds 1st N cyclops (Θ) #s, Θ primes, blind Θ primes, palindromic Θ primes*/ parse arg n cols . /*obtain optional argument from the CL.*/ if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/ if cols=='' | cols=="," then cols= 10 ...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#Clojure
Clojure
(import java.util.Date java.text.SimpleDateFormat)   (defn time+12 [s] (let [sdf (SimpleDateFormat. "MMMM d yyyy h:mma zzz")] (-> (.parse sdf s) (.getTime ,) (+ , 43200000) long (Date. ,) (->> , (.format sdf ,)))))
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#COBOL
COBOL
identification division. program-id. date-manipulation.   environment division. configuration section. repository. function all intrinsic.   data division. working-storage section. 01 given-date. 05 filler value z"March 7 2009 7:30p...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#PARI.2FGP
PARI/GP
card(n)=concat(["A","2","3","4","5","6","7","8","9","T","J","Q","K"][n\4+1],["C","D","H","S"][n%4+1]); nextrand()={ (state=(214013*state+2531011)%2^31)>>16 }; deal(seed)={ my(deck=vector(52,n,n-1),t); local(state=seed); forstep(last=52,1,-1, t=nextrand()%last+1; print1(card(deck[t]),if(last%8==5,"\n"," ...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Swift
Swift
struct SmallInt { var value: Int   init(value: Int) { guard value >= 1 && value <= 10 else { fatalError("SmallInts must be in the range [1, 10]") }   self.value = value }   static func +(_ lhs: SmallInt, _ rhs: SmallInt) -> SmallInt { SmallInt(value: lhs.value + rhs.value) } static func -(_ ...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Tcl
Tcl
namespace eval ::myIntType { variable value_cache array set value_cache {} variable type integer variable min 1 variable max 10 variable errMsg "cannot set %s to %s: must be a $type between $min and $max" } proc ::myIntType::declare varname { set ns [namespace current] uplevel [list trac...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#C.2B.2B
C++
#include <boost/date_time/gregorian/gregorian.hpp> #include <iostream>   int main( ) { using namespace boost::gregorian ;   std::cout << "Yuletide holidays must be allowed in the following years:\n" ; for ( int i = 2008 ; i < 2121 ; i++ ) { greg_year gy = i ; date d ( gy, Dec , 25 ) ; ...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#Arturo
Arturo
validCUSIP?: function [cusip][ s: 0 alpha: `A`..`Z`   loop.with:'i chop cusip 'c [ v: 0   case ø when? [numeric? c] -> v: to :integer to :string c when? [in? c alpha] -> v: (index alpha c) + 1 + 9 when? [c = `*`] -> v: 36 when? [c = `@`] -> v: ...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#AppleScript
AppleScript
set {year:y, month:m, day:d, weekday:w} to (current date)   tell (y * 10000 + m * 100 + d) as text to set shortFormat to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8 set longFormat to (w as text) & (", " & m) & (space & d) & (", " & y)   return (shortFormat & linefeed & longFormat)
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#AWK
AWK
# syntax: GAWK -f DAMM_ALGORITHM.AWK BEGIN { damm_init() leng = split("5724,5727,112946",arr,",") # test cases for (i=1; i<=leng; i++) { n = arr[i] printf("%s %s\n",damm_check(n),n) } exit(0) } function damm_check(n, a,i) { a = 0 for (i=1; i<=length(n); i++) { a = substr(d...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Vlang
Vlang
import math.big   fn main() { zero := big.zero_int one := big.one_int for k := i64(2); k <= 10; k += 2 { bk := big.integer_from_i64(k) println("The first 50 Curzon numbers using a base of $k:") mut count := 0 mut n := i64(1) mut pow := big.integer_from_i64(k) ...
http://rosettacode.org/wiki/Curzon_numbers
Curzon numbers
A Curzon number is defined to be a positive integer n for which 2n + 1 is evenly divisible by 2 × n + 1. Generalized Curzon numbers are those where the positive integer n, using a base integer k, satisfy the condition that kn + 1 is evenly divisible by k × n + 1. Base here does not imply the radix of the counting sys...
#Wren
Wren
/* curzon_numbers.wren */   import "./gmp" for Mpz import "./seq" for Lst import "./fmt" for Fmt   for (k in [2, 4, 6, 8, 10]) { System.print("The first 50 Curzon numbers using a base of %(k):") var count = 0 var n = 1 var pow = Mpz.from(k) var curzon50 = [] while (true) { var z = pow + ...
http://rosettacode.org/wiki/Cyclotomic_polynomial
Cyclotomic polynomial
The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n. Task Find and print the first 30 cyclotomic polynomials. Find and print the order of the first 10...
#D
D
import std.algorithm; import std.exception; import std.format; import std.functional; import std.math; import std.range; import std.stdio;   immutable MAX_ALL_FACTORS = 100_000; immutable ALGORITHM = 2;   //Note: Cyclotomic Polynomials have small coefficients. Not appropriate for general polynomial usage.   struct Ter...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#Groovy
Groovy
class CutRectangle { private static int[][] dirs = [[0, -1], [-1, 0], [0, 1], [1, 0]]   static void main(String[] args) { cutRectangle(2, 2) cutRectangle(4, 3) }   static void cutRectangle(int w, int h) { if (w % 2 == 1 && h % 2 == 1) { return }   int[...
http://rosettacode.org/wiki/Cyclops_numbers
Cyclops numbers
A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different ...
#Ruby
Ruby
require 'prime'   NONZEROS = %w(1 2 3 4 5 6 7 8 9)   cyclopes = Enumerator.new do |y| (0..).each do |n| NONZEROS.repeated_permutation(n) do |lside| NONZEROS.repeated_permutation(n) do |rside| y << (lside.join + "0" + rside.join).to_i end end end end   prime_cyclopes = Enumera...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#Crystal
Crystal
time = Time.parse("March 7 2009 7:30pm EST", "%B %-d %Y %l:%M%p", Time::Location.load("EST"))   time += 12.hours puts time # 2009-03-08 07:30:00 -05:00 puts time.in(Time::Location.load("Europe/Berlin")) # 2009-03-08 13:30:00 +01:00  
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#D
D
  import std.stdio; import std.format; import std.datetime; import std.algorithm;   enum months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];   void main() { // input string date = "March 7 2009 7:30pm EST";   // parsing date string ...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Perl
Perl
#!/usr/bin/perl   use strict; use warnings;   use utf8;   sub deal { my $s = shift;   my $rnd = sub { return (($s = ($s * 214013 + 2531011) & 0x7fffffff) >> 16 ); };   my @d; for my $b (split "", "A23456789TJQK") { push @d, map("$_$b", qw/♣ ♦ ♥ ♠/); }   for my $idx (reverse 0...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Toka
Toka
needs quotes { variable update [ update @ [ ! ] [ @ ] ifTrueFalse update off ] is action [ dup >r 0 11 r> within [ update on ] [ drop ." Out of bounds\n " ] ifTrueFalse ] [ ` [ invoke cell-size malloc # ` action compile ` ] invoke is ] } is value:1-10: is to   value:1-10: foo 1 to foo foo .
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#UNIX_Shell
UNIX Shell
typeset -i boundedint function boundedint.set { nameref var=${.sh.name} if (( 1 <= .sh.value && .sh.value <= 10 )); then # stash the valid value as a backup, in case we need to restore it typeset -i var.previous_value=${.sh.value} else print -u2 "value out of bounds" # restor...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Clojure
Clojure
  (import '(java.util GregorianCalendar)) (defn yuletide [start end] (filter #(= (. (new GregorianCalendar % (. GregorianCalendar DECEMBER) 25) get (. GregorianCalendar DAY_OF_WEEK)) (. GregorianCalendar SUNDAY)) (range start (inc end))))   (yuletide 2008 2121)  
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#AutoHotkey
AutoHotkey
Cusip_Check_Digit(cusip){ sum := 0, i := 1, x := StrSplit(cusip) while (i <= 8) { c := x[i] if c is digit v := c else if c is alpha v := Asc(c) - 64 + 9 else if (c = "*") v := 36 else if (c = "@") v := 37 else if (c ...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program dateFormat.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */   /*************************************...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#BASIC
BASIC
10 DEFINT D,I,X,Y: DIM DT(9,9) 20 FOR Y=0 TO 9: FOR X=0 TO 9: READ DT(X,Y): NEXT X,Y 30 INPUT N$: IF N$="" THEN END 40 D=0 50 FOR I=1 TO LEN(N$): D=DT(VAL(MID$(N$,I,1)),D): NEXT I 60 IF D THEN PRINT "FAIL" ELSE PRINT "PASS" 70 GOTO 30 100 DATA 0,3,1,7,5,9,8,6,4,2 110 DATA 7,0,9,2,1,5,4,8,6,3 120 DATA 4,2,0,6,8,7,1,3,5,...
http://rosettacode.org/wiki/Currying
Currying
This page uses content from Wikipedia. The original article was at Currying. 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 Create a simple demonstrative example of Currying in a specific la...
#11l
11l
F addN(n) F adder(x) R x + @=n R adder   V add2 = addN(2) V add3 = addN(3) print(add2(7)) print(add3(7))
http://rosettacode.org/wiki/Cyclotomic_polynomial
Cyclotomic polynomial
The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n. Task Find and print the first 30 cyclotomic polynomials. Find and print the order of the first 10...
#Fermat
Fermat
  &(J=x); {adjoin x as the variable in the polynomials}   Func Cyclotomic(n) = if n=1 then x-1 fi; {first cyclotomic polynomial is x^n-1} r:=x^n-1; {caclu...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#Haskell
Haskell
import qualified Data.Vector.Unboxed.Mutable as V import Data.STRef import Control.Monad (forM_, when) import Control.Monad.ST   dir :: [(Int, Int)] dir = [(1, 0), (-1, 0), (0, -1), (0, 1)]   data Env = Env { w, h, len, count, ret :: !Int, next :: ![Int] }   cutIt :: STRef s Env -> ST s () cutIt env = do e <- readS...
http://rosettacode.org/wiki/Cyclops_numbers
Cyclops numbers
A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different ...
#Sidef
Sidef
func cyclops_numbers(base = 10) { Enumerator({|callback|   var digits = @(1 .. base-1)   for k in (0 .. Inf `by` 2) { digits.variations_with_repetition(k, {|*a| a = (a.first(a.len>>1) + [0] + a.last(a.len>>1)) callback(a.flip.digits2num(base)) ...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#Delphi
Delphi
  program DateManipulation;   {$APPTYPE CONSOLE}   uses SysUtils, DateUtils;   function MonthNumber(aMonth: string): Word; begin //Convert a string value representing the month //to its corresponding numerical value if aMonth = 'January' then Result:= 1 else if aMonth = 'February' then Result:= 2 else if ...
http://rosettacode.org/wiki/Deal_cards_for_FreeCell
Deal cards for FreeCell
Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. (The FreeCell FAQ tells this history.) As the game became popular, Jim H...
#Phix
Phix
with javascript_semantics atom seed function xrnd() seed = and_bits(seed*214013+2531011,#7FFFFFFF) return floor(seed/power(2,16)) end function sequence cards = repeat(0,52) procedure deal(integer game_num) seed = game_num for i=1 to 52 do cards[i] = 52-i end for for i=1 to 51 do ...
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Ursala
Ursala
#import nat   my_number ::   the_number %n -|~bounds.&BZ,~&B+ nleq~~lrlXPrX@G+ ~/the_number bounds|-?(~the_number,<'out of bounds'>!%) bounds  %nW ~bounds.&B?(~bounds,(1,10)!)   add = my_number$[the_number: sum+ ~the_number~~] mul = my_number$[the_number: product+ ~the_number~~]
http://rosettacode.org/wiki/Define_a_primitive_data_type
Define a primitive data type
Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.
#Visual_Basic
Visual Basic
Private mvarValue As Integer   Public Property Let Value(ByVal vData As Integer) If (vData > 10) Or (vData < 1) Then Error 380 'Invalid property value; could also use 6, Overflow Else mvarValue = vData End If End Property   Public Property Get Value() As Integer Value = mvarValue End P...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#CLU
CLU
weekday = proc (d: date) returns (int) y: int := d.year m: int := d.month if m<3 then y, m := y-1, m+10 else m := m-2 end c: int := y/100 y := y//100 z: int := (26*m-2)/10 + d.day + y + y/4 + c/4 - 2*c + 777 return(z//7) end weekday   start_up = proc () po: stream :=...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. 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) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#AWK
AWK
  # syntax: GAWK -f CUSIP.AWK BEGIN { n = split("037833100,17275R102,38259P508,594918104,68389X106,68389X105",arr,",") for (i=1; i<=n; i++) { printf("%9s %s\n",arr[i],cusip(arr[i])) } exit(0) } function cusip(n, c,i,sum,v,x) { # returns: 1=OK, 0=NG, -1=bad data if (length(n) != 9) { ret...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Arturo
Arturo
currentTime: now   print to :string.format: "YYYY-MM-dd" currentTime print to :string.format: "dddd, MMMM dd, YYYY" currentTime
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#AutoHotkey
AutoHotkey
FormatTime, Date1, , yyyy-MM-dd ; "2007-11-10" FormatTime, Date2, , LongDate ; "Sunday, November 10, 2007" MsgBox %Date1% `n %Date2%
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#BCPL
BCPL
get "libhdr"   let damm(ns) = valof $( let dt = table 0,3,1,7,5,9,8,6,4,2, 7,0,9,2,1,5,4,8,6,3, 4,2,0,6,8,7,1,3,5,9, 1,7,5,0,9,8,3,4,2,6, 6,1,2,3,0,4,5,9,7,8, 3,6,7,4,2,0,9,5,8,1, 5,8,6,9,7,2,0,1,3,4, 8,9,4,5,3,6,2,0,1,7, 9,4,3,8,6,1,7,2,0,5, ...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#BQN
BQN
table ← >⟨ 0‿3‿1‿7‿5‿9‿8‿6‿4‿2 7‿0‿9‿2‿1‿5‿4‿8‿6‿3 4‿2‿0‿6‿8‿7‿1‿3‿5‿9 1‿7‿5‿0‿9‿8‿3‿4‿2‿6 6‿1‿2‿3‿0‿4‿5‿9‿7‿8 3‿6‿7‿4‿2‿0‿9‿5‿8‿1 5‿8‿6‿9‿7‿2‿0‿1‿3‿4 8‿9‿4‿5‿3‿6‿2‿0‿1‿7 9‿4‿3‿8‿6‿1‿7‿2‿0‿5 2‿5‿8‿1‿4‿3‿6‿7‿9‿0 ⟩     Digi...
http://rosettacode.org/wiki/Currying
Currying
This page uses content from Wikipedia. The original article was at Currying. 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 Create a simple demonstrative example of Currying in a specific la...
#Ada
Ada
generic type Argument_1 (<>) is limited private; type Argument_2 (<>) is limited private; type Argument_3 (<>) is limited private; type Return_Value (<>) is limited private;   with function Func (A : in Argument_1; B : in Argument_2; C : in Argument_3) retu...
http://rosettacode.org/wiki/Currying
Currying
This page uses content from Wikipedia. The original article was at Currying. 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 Create a simple demonstrative example of Currying in a specific la...
#Aime
Aime
ri(list l) { l[0] = apply.apply(l[0]); } curry(object o) { (o.__count - 1).times(ri, list(o)); } main(void) { o_wbfxinteger.curry()(16)(3)(12)(16)(1 << 30); 0; }  
http://rosettacode.org/wiki/Cyclotomic_polynomial
Cyclotomic polynomial
The nth Cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial of largest degree with integer coefficients that is a divisor of x^n − 1, and is not a divisor of x^k − 1 for any k < n. Task Find and print the first 30 cyclotomic polynomials. Find and print the order of the first 10...
#Go
Go
package main   import ( "fmt" "log" "math" "sort" "strings" )   const ( algo = 2 maxAllFactors = 100000 )   func iabs(i int) int { if i < 0 { return -i } return i }   type term struct{ coef, exp int }   func (t term) mul(t2 term) term { return term{t.coef * t...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#J
J
init=: - {. 1: NB. initial state: 1 square choosen prop=: < {:,~2 ~:/\ ] NB. propagate: neighboring squares (vertically) poss=: I.@,@(prop +. prop"1 +. prop&.|. +. prop&.|."1) keep=: poss -. <:@#@, - I.@, NB. symmetrically valid possibilities N=: <:@-:@#@, NB. how many neighbors to a...