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/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 ...
#Wren
Wren
import "/math" for Int import "/seq" for Lst import "/fmt" for Fmt import "/str" for Str   var findFirst = Fn.new { |list| var i = 0 for (n in list) { if (n > 1e7) return [n, i] i = i + 1 } }   var ranges = [0..0, 101..909, 11011..99099, 1110111..9990999, 111101111..119101111] var cyclops ...
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.
#EchoLisp
EchoLisp
  (define my-date (string->date "March 7 2009 7:30 pm EST")) → Sun Mar 08 2009 01:30:00 GMT+0100 (CET)   (date-add! my-date (* 12 3600)) → Sun Mar 08 2009 13:30:00 GMT+0100 (CET) (string->date my-date)   (date->string my-date) → "8/3/2009 13:30:00" ;; human localized, Paris time.  
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.
#Erlang
Erlang
  -module( date_manipulation ).   -export( [task/0] ).   task() -> {Date_time, TZ} = date_time_tz_from_string( "March 7 2009 7:30pm EST" ), Seconds1 = calendar:datetime_to_gregorian_seconds( Date_time ), Seconds2 = calendar:datetime_to_gregorian_seconds( {calendar:gregorian_days_to_date(0), {12, 0, 0}} ), Date_time...
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...
#PHP
PHP
class FreeCell_Deal {   protected $deck = array( 'AC', 'AD', 'AH', 'AS', '2C', '2D', '2H', '2S', '3C', '3D', '3H', '3S', '4C', '4D', '4H', '4S', '5C', '5D', '5H', '5S', '6C', '6D', '6H', '6S', '7C', '7D', '7H', '7S', '8C', '8D', '8H', '8S', '9C', '9D', '9H', '9S', 'TC', 'TD', 'TH',...
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_.NET
Visual Basic .NET
Structure LimitedInt Implements IComparable, IComparable(Of LimitedInt), IConvertible, IEquatable(Of LimitedInt), IFormattable   Private Const MIN_VALUE = 1 Private Const MAX_VALUE = 10   Shared ReadOnly MinValue As New LimitedInt(MIN_VALUE) Shared ReadOnly MaxValue As New LimitedInt(MAX_VALUE)   ...
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 ...
#COBOL
COBOL
  program-id. dec25. data division. working-storage section. 1 work-date. 2 yr pic 9(4) value 2008. 2 mo-da pic 9(4) value 1225. *> Dec 25 1 wk-date redefines work-date pic 9(8). 1 binary. 2 int-date pic 9(8). 2 dow pic 9(4). procedure div...
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...
#BCPL
BCPL
get "libhdr"   let validcusip(c) = valof $( let sum = 0 unless c%0 = 9 resultis false for i = 1 to 8 do $( let v = ( 2 - (i & 1) ) * valof $( test '0' <= c%i <= '9' then resultis c%i - '0' or test 'A' <= c%i <= 'Z' then resultis 10 + c%i - 'A' ...
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...
#C
C
  #include<stdlib.h> #include<stdio.h>   int cusipCheck(char str[10]){ int sum=0,i,v;   for(i=0;i<8;i++){ if(str[i]>='0'&&str[i]<='9') v = str[i]-'0'; else if(str[i]>='A'&&str[i]<='Z') v = (str[i] - 'A' + 10); else if(str[i]=='*') v = 36; else if(str[i]=='@') v = 37; else if(str[i]=='#') 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
#AutoIt
AutoIt
  #include <Date.au3>   $iYear = 2007 $iMonth = 11 $iDay = 10   ConsoleWrite(StringFormat('%4d-%02d-%02d', $iYear, $iMonth, $iDay) & @LF)   $iWeekDay = _DateToDayOfWeekISO($iYear, $iMonth, $iDay) ConsoleWrite(StringFormat('%s, %s %02d, %4d', _GetLongDayLocale($iWeekDay), _GetLongMonthLocale($iMonth), $iDay, $iYear) & @...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#ALGOL_68
ALGOL 68
BEGIN # find Cullen and Woodall numbers and determine which are prime # # a Cullen number n is n2^2 + 1, Woodall number is n2^n - 1 # PR read "primes.incl.a68" PR # include prime utilities # PR precision 800 PR # set number of digits for Algol 68G LONG LONG INT # # returns the nth...
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.
#C
C
#include <stdbool.h> #include <stddef.h> #include <stdio.h>   bool damm(unsigned char *input, size_t length) { static const unsigned char table[10][10] = { {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}, ...
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...
#ALGOL_68
ALGOL 68
# Raising a function to a power #   MODE FUN = PROC (REAL) REAL; PROC pow = (FUN f, INT n, REAL x) REAL: f(x) ** n; OP ** = (FUN f, INT n) FUN: pow (f, n, );   # Example: sin (3 x) = 3 sin (x) - 4 sin^3 (x) (follows from DeMoivre's theorem) #   REAL x = read real; print ((new line, sin (3 * x), 3 * sin (x) - 4 * (sin...
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...
#AppleScript
AppleScript
-- curry :: (Script|Handler) -> Script on curry(f) script on |λ|(a) script on |λ|(b) |λ|(a, b) of mReturn(f) end |λ| end script end |λ| end script end curry     -- TESTS --------------------------------------------------...
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...
#Haskell
Haskell
import Data.List import Data.Numbers.Primes (primeFactors)   negateVar p = zipWith (*) p $ reverse $ take (length p) $ cycle [1,-1]   lift p 1 = p lift p n = intercalate (replicate (n-1) 0) (pure <$> p)   shortDiv :: [Integer] -> [Integer] -> [Integer] shortDiv p1 (_:p2) = unfoldr go (length p1 - length p2, p1) where...
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...
#Java
Java
import java.util.*;   public class CutRectangle {   private static int[][] dirs = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};   public 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) ...
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 ...
#XPL0
XPL0
func IsCyclops(N); \Return 'true' if N is a cyclops number int N, I, J, K; char A(9); [I:= 0; \parse digits into array A repeat N:= N/10; A(I):= rem(0); I:= I+1; until N=0; if (I&1) = 0 then return false; \must have odd number of digits K:= I>>1; if A(K) # 0 then return false; ...
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.
#Euphoria
Euphoria
  --Date Manipulation task from Rosetta Code wiki --User:Lnettnay   include std/datetime.e   datetime dt   dt = new(2009, 3, 7, 19, 30) dt = add(dt, 12, HOURS) printf(1, "%s EST\n", {format(dt, "%B %d %Y %I:%M %p")})  
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.
#F.23
F#
open System   let main() = let est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time") let date = DateTime.Parse("March 7 2009 7:30pm -5" ) let date_est = TimeZoneInfo.ConvertTime( date, est) let date2 = date.AddHours(12.0) let date2_est = TimeZoneInfo.ConvertTime( date2, est) Console.WriteLine...
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...
#PicoLisp
PicoLisp
(setq *MsSeed 11982)   (de msRand () (>> 16 (setq *MsSeed (& (+ 2531011 (* 214013 *MsSeed)) `(dec (** 2 31))) ) ) )   (let L (make (for Num (range 13 1) (for Suit '((32 . "♠") (31 . "♥") (31 . "♦") (32 . "♣")) (link (cons (get '`(chop "A23456789TJQK") Num) Suit)) ) ) ) ...
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...
#PureBasic
PureBasic
#MaxCardNum = 51 ;zero-based count of cards in a deck Global deckSize Global Dim cards(#MaxCardNum) ;card with highest index is at the top of deck   Procedure RNG(seed.q = -1) Static state.q If seed >= 0 state = seed Else state = (state * 214013 + 2531011) % (1 << 31) ProcedureReturn state >> 16 E...
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_FoxPro
Visual FoxPro
LOCAL o As BoundedInt o = NEWOBJECT("BoundedInt") DO WHILE NOT o.lHasError o.nValue = o.nValue + 2 && will get as far as 9.  ? o.nValue ENDDO   DEFINE CLASS BoundedInt As Custom nValue = 1 && default value lHasError = .F.   PROCEDURE nValue_Assign(tnValue) *!* This method will check the parameter and if *!* it i...
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.
#Wren
Wren
class TinyInt { construct new(n) { if (!(n is Num && n.isInteger && n >= 1 && n <= 10)) { Fiber.abort("Argument must be an integer between 1 and 10.") } _n = n }   n { _n }   +(other) { TinyInt.new(_n + other.n) } -(other) { TinyInt.new(_n - other.n) } *(other...
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 ...
#CoffeeScript
CoffeeScript
december = 11 # gotta love Date APIs :) sunday = 0 for year in [2008..2121] xmas = new Date year, december, 25 console.log year if xmas.getDay() is sunday
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...
#C.23
C#
using System; using System.Collections.Generic;   namespace CUSIP { class Program { static bool IsCusip(string s) { if (s.Length != 9) return false; int sum = 0; for (int i = 0; i <= 7; i++) { char c = s[i];   int v; 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
#AWK
AWK
$ awk 'BEGIN{t=systime();print strftime("%Y-%m-%d",t)"\n"strftime("%A, %B %d, %Y",t)}' 2009-05-15 Friday, May 15, 2009
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
#BaCon
BaCon
' Date format n = NOW PRINT YEAR(n), MONTH(n), DAY(n) FORMAT "%ld-%02ld-%02ld\n" PRINT WEEKDAY$(n), MONTH$(n), DAY(n), YEAR(n) FORMAT "%s, %s %02ld, %ld\n"
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Arturo
Arturo
cullen: function [n]-> inc n * 2^n   woodall: function [n]-> dec n * 2^n   print ["First 20 cullen numbers:" join.with:" " to [:string] map 1..20 => cullen] print ["First 20 woodall numbers:" join.with:" " to [:string] map 1..20 => woodall]
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#AWK
AWK
  # syntax: GAWK -f CULLEN_AND_WOODALL_NUMBERS.AWK BEGIN { start = 1 stop = 20 printf("Cullen %d-%d:",start,stop) for (n=start; n<=stop; n++) { printf(" %d",n*(2^n)+1) } printf("\n") printf("Woodall %d-%d:",start,stop) for (n=start; n<=stop; n++) { printf(" %d",n*(2^n)-1) ...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#BASIC
BASIC
print "First 20 Cullen numbers:"   for n = 1 to 20 num = n * (2^n)+1 print int(num); " "; next   print : print print "First 20 Woodall numbers:"   for n = 1 to 20 num = n * (2^n)-1 print int(num); " "; next n end
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.
#C.23
C#
using System;   namespace DammAlgorithm { class Program { static int[,] 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}, ...
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...
#BQN
BQN
Plus3 ← 3⊸+ Plus3_1 ← +⟜3   •Show Plus3 1 •Show Plus3_1 1
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...
#C
C
  #include<stdarg.h> #include<stdio.h>   long int factorial(int n){ if(n>1) return n*factorial(n-1); return 1; }   long int sumOfFactorials(int num,...){ va_list vaList; long int sum = 0;   va_start(vaList,num);   while(num--) sum += factorial(va_arg(vaList,int));   va_end(vaList);   return sum; }   int mai...
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...
#J
J
cyclo=: {{<.-:1+(++) p. 1;^0j2p1* y%~1+I.1=y+.1+i.y}}
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...
#Julia
Julia
  const count = [0] const dir = [[0, -1], [-1, 0], [0, 1], [1, 0]]   function walk(y, x, h, w, grid, len, next) if y == 0 || y == h || x == 0 || x == w count[1] += 2 return end t = y * (w + 1) + x grid[t + 1] += UInt8(1) grid[len - t + 1] += UInt8(1) for i in 1:4 if grid[...
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.
#Factor
Factor
USING: calendar calendar.english calendar.format calendar.parser combinators io kernel math math.parser sequences splitting unicode ; IN: rosetta-code.date-manipulation   ! e.g. "7:30pm" -> 19 30 : parse-hm ( str -- hours minutes ) ":" split first2 [ digit? ] partition [ [ string>number ] bi@ ] dip "pm" = [ [ 1...
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.
#Fantom
Fantom
  fansh> d := DateTime.fromLocale("March 7 2009 7:30pm EST", "MMMM D YYYY h:mmaa zzz") fansh> d 2009-03-07T19:30:00-05:00 EST fansh> d + 12hr 2009-03-08T07:30:00-05:00 EST fansh> (d+12hr).toTimeZone(TimeZone("London")) // the extra credit! 2009-03-08T12:30:00Z London  
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...
#Python
Python
    def randomGenerator(seed=1): max_int32 = (1 << 31) - 1 seed = seed & max_int32   while True: seed = (seed * 214013 + 2531011) & max_int32 yield seed >> 16   def deal(seed): nc = 52 cards = list(range(nc - 1, -1, -1)) rnd = randomGenerator(seed) for i, r in zip(range(nc), ...
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 ...
#ColdFusion
ColdFusion
  <cfloop from = "2008" to = "2121" index = "i"> <cfset myDate = createDate(i, 12, 25) /> <cfif dayOfWeek(myDate) eq 1> December 25th falls on a Sunday in <cfoutput>#i#</cfoutput><br /> </cfif> </cfloop>  
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 ...
#Common_Lisp
Common Lisp
(loop for year from 2008 upto 2121 when (= 6 (multiple-value-bind (second minute hour date month year day-of-week dst-p tz) (decode-universal-time (encode-universal-time 0 0 0 25 12 year)) (declare (ignore second minute hour date month year dst-p tz)) ...
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...
#C.2B.2B
C++
#include <iostream> #include <vector>   bool isCusip(const std::string& s) { if (s.size() != 9) return false;   int sum = 0; for (int i = 0; i <= 7; ++i) { char c = s[i];   int v; if ('0' <= c && c <= '9') { v = c - '0'; } else if ('A' <= c && c <= 'Z') { ...
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#11l
11l
T SD sum = 0.0 sum2 = 0.0 n = 0.0   F ()(x) .sum += x .sum2 += x ^ 2 .n += 1.0 R sqrt(.sum2 / .n - (.sum / .n) ^ 2)   V sd_inst = SD() L(value) [2, 4, 4, 4, 5, 5, 7, 9] print(value‘ ’sd_inst(value))
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
#BASIC
BASIC
#include "vbcompat.bi"   DIM today As Double = Now()   PRINT Format(today, "yyyy-mm-dd") PRINT Format(today, "dddd, mmmm d, yyyy")
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
#Batch_File
Batch File
  @echo off setlocal enabledelayedexpansion :: Define arrays of days/months we'll need set daynames=Monday Tuesday Wednesday Thursday Friday Saturday Sunday set monthnames=January February March April May June July August September October November December :: Separate the output of the 'date /t' command (outputs in ...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#F.23
F#
  // Cullen and Woodall numbers. Nigel Galloway: January 14th., 2022 let Cullen,Woodall=let fG n (g:int)=(bigint g)*2I**g+n in fG 1I, fG -1I Seq.initInfinite((+)1>>Cullen)|>Seq.take 20|>Seq.iter(printf "%A "); printfn "" Seq.initInfinite((+)1>>Woodall)|>Seq.take 20|>Seq.iter(printf "%A "); printfn "" Seq.initInfinite((...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Factor
Factor
USING: arrays kernel math math.vectors prettyprint ranges sequences ;   20 [1..b] [ dup 2^ * 1 + ] map dup 2 v-n 2array simple-table.
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Go
Go
package main   import ( "fmt" big "github.com/ncw/gmp" )   func cullen(n uint) *big.Int { one := big.NewInt(1) bn := big.NewInt(int64(n)) res := new(big.Int).Lsh(one, n) res.Mul(res, bn) return res.Add(res, one) }   func woodall(n uint) *big.Int { res := cullen(n) return res.Sub(res,...
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.
#C.2B.2B
C++
#include <sstream>   const int TABLE[][10] = { {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...
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...
#C.23
C#
public delegate int Plus(int y); public delegate Plus CurriedPlus(int x); public static CurriedPlus plus = delegate(int x) {return delegate(int y) {return x + y;};}; static void Main() { int sum = plus(3)(4); // sum = 7 int sum2= plus(2)(plus(3)(4)) // sum2 = 9 }
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...
#C.2B.2B
C++
shared void run() {   function divide(Integer x, Integer y) => x / y;   value partsOf120 = curry(divide)(120);   print("half of 120 is ``partsOf120(2)`` a third is ``partsOf120(3)`` and a quarter is ``partsOf120(4)``"); }
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...
#Java
Java
  import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap;   public class CyclotomicPolynomial {   @SuppressWarnings("unused") private static int divisions = 0; private static int a...
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...
#Kotlin
Kotlin
// version 1.0.6   object RectangleCutter { private var w: Int = 0 private var h: Int = 0 private var len: Int = 0 private var cnt: Long = 0   private lateinit var grid: ByteArray private val next = IntArray(4) private val dir = arrayOf( intArrayOf(0, -1), intArrayOf(-1, 0), ...
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.
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   #include "vbcompat.bi"   Sub split (s As String, sepList As String, result() As String, removeEmpty As Boolean = False) If s = "" OrElse sepList = "" Then Redim result(0) result(0) = s Return End If Dim As Integer i, j, count = 0, empty = 0, length Dim As Integer position(Len...
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...
#R
R
## Linear congruential generator code not original - ## copied from ## http://www.rosettacode.org/wiki/Linear_congruential_generator#R ## altered to allow seed as an argument   library(gmp) # for big integers   rand_MS <- function(n = 1, seed = 1) { a <- as.bigz(214013) c <- as.bigz(2531011) m <- as.bigz(2^31) ...
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...
#Racket
Racket
#lang racket   (module Linear_congruential_generator racket  ;; taken from http://rosettacode.org/wiki/Linear_congruential_generator#Racket  ;; w/o BSD generator (require racket/generator) (provide ms-rand) (define (ms-update state_n) (modulo (+ (* 214013 state_n) 2531011) (expt 2 31))) (d...
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 ...
#Component_Pascal
Component Pascal
  MODULE DayOfWeek; IMPORT DevCommanders, TextMappers, Dates, StdLog;   PROCEDURE XmastOnSun(s,e: INTEGER); VAR i: INTEGER; d: Dates.Date; BEGIN i := s;d.day := 25;d.month := 12; WHILE i < e DO d.year := i; IF Dates.DayOfWeek(d) = Dates.sunday THEN StdLog.Int(i);StdLog.Ln END; INC(i) END END XmastOnSun;...
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...
#Cach.C3.A9_ObjectScript
Caché ObjectScript
Class Utils.Check [ Abstract ] {   ClassMethod CUSIP(x As %String) As %Boolean { SET x=$TRANSLATE(x," ") // https://leiq.bus.umich.edu/res_codes_cusip.htm IF x'?8UNP1N QUIT 0 SET cd=$EXTRACT(x,*), x=$EXTRACT(x,1,*-1), t=0 FOR i=1:1:$LENGTH(x) { SET n=$EXTRACT(x,i) IF n'=+n SET n=$CASE(n,"*":36,"@":37,"#":38,:$...
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...
#Clojure
Clojure
  (defn- char->value "convert the given char c to a value used to calculate the cusip check sum" [c] (let [int-char (int c)] (cond (and (>= int-char (int \0)) (<= int-char (int \9))) (- int-char 48) (and (>= int-char (int \A)) (<= int-char (int \Z))) (- int-char 55) (= c \*) 36 (= c \@...
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#360_Assembly
360 Assembly
******** Standard deviation of a population STDDEV CSECT USING STDDEV,R13 SAVEAREA B STM-SAVEAREA(R15) DC 17F'0' DC CL8'STDDEV' STM STM R14,R12,12(R13) ST R13,4(R15) ST R15,8(R13) LR R13,R15 SR R8,R8 s=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
#BBC_BASIC
BBC BASIC
daysow$ = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" months$ = "January February March April May June " + \ \ "July August September October November December"   date$ = TIME$ dayow% = (INSTR(daysow$, MID$(date$,1,3)) + 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
#Beads
Beads
// time_to_str(format, time, city, lang) // format directives: // [sun] - abbreviated weekday, e.g. Sun // [sunday] - full weekday name, e.g. Sunday // [jan] - abbrev month // [january] - full month // [day] - day of the month 1, 2, ..31 // [day2] - day of the month as tw...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Haskell
Haskell
findCullen :: Int -> Integer findCullen n = toInteger ( n * 2 ^ n + 1 )   cullens :: [Integer] cullens = map findCullen [1 .. 20]   woodalls :: [Integer] woodalls = map (\i -> i - 2 ) cullens   main :: IO ( ) main = do putStrLn "First 20 Cullen numbers:" print cullens putStrLn "First 20 Woodall numbers:" pr...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Julia
Julia
using Lazy using Primes   cullen(n, two = BigInt(2)) = n * two^n + 1 woodall(n, two = BigInt(2)) = n * two^n - 1 primecullens = @>> Lazy.range() filter(n -> isprime(cullen(n))) primewoodalls = @>> Lazy.range() filter(n -> isprime(woodall(n)))   println("First 20 Cullen numbers: ( n × 2**n + 1)\n", [cullen(n, 2) for n i...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Lua
Lua
function T(t) return setmetatable(t, {__index=table}) end table.range = function(t,n) local s=T{} for i=1,n do s[i]=i end return s end table.map = function(t,f) local s=T{} for i=1,#t do s[i]=f(t[i]) end return s end   function cullen(n) return (n<<n)+1 end print("First 20 Cullen numbers:") print(T{}:range(20):map(cull...
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.
#Cach.C3.A9_ObjectScript
Caché ObjectScript
Class Utils.Check [ Abstract ] {   ClassMethod Damm(num As %Integer, mode As %Integer = 1) As %Integer { TRY { I mode=0 RETURN ..Damm(num,2)=0 S res=0, str=num S 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], ...
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.
#Clojure
Clojure
(def tbl [[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]]...
http://rosettacode.org/wiki/Currency
Currency
Task Show how to represent currency in a simple example, using a data type that represent exact values of dollars and cents. Note The IEEE 754 binary floating point representations of numbers like   2.86   and   .0765   are not exact. For this example, data will be two items with prices in dollars and cents, a qu...
#11l
11l
F currency(units, subunits) R BigInt(units) * 100 + subunits   F currency_from_str(s) V (units, subunits) = s.split(‘.’) R BigInt(units) * 100 + Int(subunits)   F percentage(a, num, denom) R (a * num * 10 I/ denom + 5) I/ 10   F to_str(c) R String(c I/ 100)‘’‘.#02’.format(c % 100)   V hamburgers = curren...
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...
#Ceylon
Ceylon
shared void run() {   function divide(Integer x, Integer y) => x / y;   value partsOf120 = curry(divide)(120);   print("half of 120 is ``partsOf120(2)`` a third is ``partsOf120(3)`` and a quarter is ``partsOf120(4)``"); }
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...
#Clojure
Clojure
(def plus-a-hundred (partial + 100)) (assert (= (plus-a-hundred 1) 101))  
http://rosettacode.org/wiki/Create_an_object_at_a_given_address
Create an object at a given address
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#6502_Assembly
6502 Assembly
sta $1900 stx $1901 sty $1902
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...
#Julia
Julia
using Primes, Polynomials   # memoize cache for recursive calls const cyclotomics = Dict([1 => Poly([big"-1", big"1"]), 2 => Poly([big"1", big"1"])])   # get all integer divisors of an integer, except itself function divisors(n::Integer) f = [one(n)] for (p, e) in factor(n) f = reduce(vcat, [f * p^j 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...
#Lua
Lua
function array1D(w, d) local t = {} for i=1,w do table.insert(t, d) end return t end   function array2D(h, w, d) local t = {} for i=1,h do table.insert(t, array1D(w, d)) end return t end   function push(s, v) s[#s + 1] = v end   function pop(s) return table.remove...
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.
#Frink
Frink
  ### MMM dd yyyy h:mma ### d = parseDate["March 7 2009 7:30pm EST"] println[d + 12 hours -> Eastern] println[d + 12 hours -> Switzerland] // Extra credit  
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.
#FunL
FunL
import time.{TimeZone, Date, SimpleDateFormat, Hour}   pattern = SimpleDateFormat( 'MMMM d yyyy h:mma zzz' ) date = pattern.parse( 'March 7 2009 7:30pm EST' ) later = Date( date.getTime() + 12 Hour ) println( pattern.format(later) ) // Eastern Daylight Time pattern.setTimeZone( TimeZone.getTimeZone('America/Los_Ange...
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...
#Raku
Raku
sub dealgame ($game-number = 1) { sub ms-lcg-method($seed = $game-number) { ( 214013 * $seed + 2531011 ) % 2**31 }   # lazy list of the random sequence my @ms-lcg = |(&ms-lcg-method ... *).map: * +> 16;   constant CardBlock = '🂠'.ord; my @deck = gather for flat(1..11,13,14) X+ (48,32...0) -> $off {...
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 ...
#Cowgol
Cowgol
include "cowgol.coh";   sub weekday(year: uint16, month: uint8, day: uint8): (wd: uint8) is if month < 3 then month := month + 10; year := year - 1; else month := month - 2; end if; var c := year / 100; var y := year % 100; var z := (26 * month as uint16 - 2) / 10; z ...
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 ...
#D
D
void main() { import std.stdio, std.range, std.algorithm, std.datetime;   writeln("Christmas comes on a Sunday in the years:\n", iota(2008, 2122) .filter!(y => Date(y, 12, 25).dayOfWeek == DayOfWeek.sun)); }
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...
#CLU
CLU
valid_cusip = proc (s: string) returns (bool) own chars: string := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#" if string$size(s) ~= 9 then return(false) end sum: int := 0 for i: int in int$from_to(1,8) do v: int := string$indexc(s[i], chars)-1 if v<0 then return(false) end if i//2=...
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...
#Common_Lisp
Common Lisp
(defun char->value (c) (cond ((digit-char-p c 36)) ((char= c #\*) 36) ((char= c #\@) 37) ((char= c #\#) 38) (t (error "Invalid character: ~A" c))))   (defun cusip-p (cusip) (and (= 9 (length cusip)) (loop for i from 1 to 8 for c across cusip for v = (...
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#Action.21
Action!
INCLUDE "H6:REALMATH.ACT"   REAL sum,sum2 INT count   PROC Calc(REAL POINTER x,sd) REAL tmp1,tmp2,tmp3   RealAdd(sum,x,tmp1)  ;tmp1=sum+x RealAssign(tmp1,sum)  ;sum=sum+x RealMult(x,x,tmp1)  ;tmp1=x*x RealAdd(sum2,tmp1,tmp2)  ;tmp2=sum2+x*x RealAssign(tmp2,sum2)  ;sum2=sum2+x*x count==+...
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
#C
C
#include <stdlib.h> #include <stdio.h> #include <time.h> #define MAX_BUF 50   int main(void) { char buf[MAX_BUF]; time_t seconds = time(NULL); struct tm *now = localtime(&seconds); const char *months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "Septem...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Perl
Perl
use strict; use warnings; use bigint; use ntheory 'is_prime'; use constant Inf => 1e10;   sub cullen { my($n,$c) = @_; ($n * 2**$n) + $c; }   my($m,$n);   ($m,$n) = (20,0); print "First $m Cullen numbers:\n"; print do { $n < $m ? (++$n and cullen($_,1) . ' ') : last } for 1 .. Inf;   ($m,$n) = (20,0); print "\...
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.
#CLU
CLU
% Verify that the Damm check digit of a string of digits is correct. % Signals 'bad_format' if the string contains non-digits. damm = proc (s: string) returns (bool) signals (bad_format) ai = array[int] aai = array[ai] own damm_table: aai := aai$[0: ai$[0: 0,3,1,7,5,9,8,6,4,2], ai$[0: 7,0,9...
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.
#Cowgol
Cowgol
include "cowgol.coh";   # Damm test on number given as ASCII string # Returns check digit sub damm(num: [uint8]): (chk: uint8) is var table: uint8[] := { 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...
http://rosettacode.org/wiki/Currency
Currency
Task Show how to represent currency in a simple example, using a data type that represent exact values of dollars and cents. Note The IEEE 754 binary floating point representations of numbers like   2.86   and   .0765   are not exact. For this example, data will be two items with prices in dollars and cents, a qu...
#Ada
Ada
with Ada.Text_IO;   procedure Currency is type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0; package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);   hamburger_cost : constant := 5.50; milkshake_cost : constant := 2.86; tax_rate : constant := 0.0765;   total_cost : constant := hamburger_...
http://rosettacode.org/wiki/Currency
Currency
Task Show how to represent currency in a simple example, using a data type that represent exact values of dollars and cents. Note The IEEE 754 binary floating point representations of numbers like   2.86   and   .0765   are not exact. For this example, data will be two items with prices in dollars and cents, a qu...
#ALGOL_68
ALGOL 68
BEGIN # currency calculations # # simple fixed point type, LONG INT is 64-bit in Algol 68G # MODE FIXED = STRUCT( LONG INT value , INT decimals , INT fraction modulus ...
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...
#Common_Lisp
Common Lisp
(defun curry (function &rest args-1) (lambda (&rest args-2) (apply function (append args-1 args-2))))  
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...
#Crystal
Crystal
add_things = ->(x1 : Int32, x2 : Int32, x3 : Int32) { x1 + x2 + x3 } add_curried = add_things.partial(2, 3) add_curried.call(4) #=> 9   def add_two_things(x1) return ->(x2 : Int32) { ->(x3 : Int32) { x1 + x2 + x3 } } end add13 = add_two_things(3).call(10) add13.call(5) #=> 18
http://rosettacode.org/wiki/Create_an_object_at_a_given_address
Create an object at a given address
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#68000_Assembly
68000 Assembly
MOVE.L #$12345678,$100000
http://rosettacode.org/wiki/Create_an_object_at_a_given_address
Create an object at a given address
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#8086_Assembly
8086 Assembly
.model small ;specify memory model to use .stack 1024 ;set up stack   .data ;data segment   UserRam BYTE 256 DUP (0) ;allocate 256 bytes of user RAM, initialized to zero.   tempByte equ UserRam ...
http://rosettacode.org/wiki/Create_an_object_at_a_given_address
Create an object at a given address
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Action.21
Action!
DEFINE FIRST="12345" DEFINE SECOND="54321" DEFINE PTR="CARD"   PROC Main() PTR base,copy=base   PrintF("Address of base variable: %H%E",@base) PrintF("Address of copy variable: %H%E",@copy) PutE()   PrintF("Assign %U value to base variable%E",FIRST) base=FIRST PrintF("Value of base variable: %U%E",base) ...
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...
#Kotlin
Kotlin
import java.util.TreeMap import kotlin.math.abs import kotlin.math.pow import kotlin.math.sqrt   private const val algorithm = 2   fun main() { println("Task 1: cyclotomic polynomials for n <= 30:") for (i in 1..30) { val p = cyclotomicPolynomial(i) println("CP[$i] = $p") } println()   ...
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...
#Nim
Nim
import strformat   var w, h: int grid: seq[byte] next: array[4, int] count: int   const Dirs = [[0, -1], [-1, 0], [0, 1], [1, 0]]   template odd(n: int): bool = (n and 1) != 0   #------------------------------------------------------------------------------   proc walk(y, x: int) =   if y == 0 or y == h or x ...
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.
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "fmt" "time" )   const taskDate = "March 7 2009 7:30pm EST" const taskFormat = "January 2 2006 3:04pm MST"   func main() { if etz, err := time.LoadLocation("US/Eastern"); err == nil { time.Local = etz } fmt.Println("Input: ", taskDate) t, err := time.P...
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...
#REXX
REXX
/*REXX program deals cards for a specific FreeCell solitaire card game (0 ──► 32767).*/ numeric digits 15 /*ensure enough digits for the random #*/ parse arg game cols . /*obtain optional arguments from the CL*/ if game=='' | game=="," then game=1 ...
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 ...
#Delphi
Delphi
procedure IsXmasSunday(fromyear, toyear: integer); var i: integer; TestDate: TDateTime; outputyears: string; begin outputyears := ''; for i:= fromyear to toyear do begin TestDate := EncodeDate(i,12,25); if dayofweek(TestDate) = 1 then begin outputyears := outputyears + inttostr(i) + ' '; end; ...
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...
#D
D
import std.stdio;   void main(string[] args) { writeln("CUSIP Verdict"); foreach(arg; args[1..$]) { writefln("%9s : %s", arg, isValidCusip(arg) ? "Valid" : "Invalid"); } }   class IllegalCharacterException : Exception { this(string msg) { super(msg); } }   bool isValidCusip(str...
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#Ada
Ada
  with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; with Ada.Text_IO; use Ada.Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with Ada.Integer_Text_IO; ...
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
#C.23
C#
using System;   namespace RosettaCode.DateFormat { class Program { static void Main(string[] args) { DateTime today = DateTime.Now.Date; Console.WriteLine(today.ToString("yyyy-MM-dd")); Console.WriteLine(today.ToString("dddd, MMMMM d, yyyy")); } } ...
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
#C.2B.2B
C++
// Display the current date in the formats of "2007-11-10" // and "Sunday, November 10, 2007".   #include <vector> #include <string> #include <iostream> #include <ctime>   /** Return the current date in a string, formatted as either ISO-8601 * or "Weekday-name, Month-name Day, Year". * * The date is initialized w...
http://rosettacode.org/wiki/Cullen_and_Woodall_numbers
Cullen and Woodall numbers
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers o...
#Phix
Phix
with javascript_semantics atom t0 = time() include mpfr.e procedure cullen(mpz r, integer n) mpz_ui_pow_ui(r,2,n) mpz_mul_si(r,r,n) mpz_add_si(r,r,1) end procedure procedure woodall(mpz r, integer n) cullen(r,n) mpz_sub_si(r,r,2) end procedure sequence c = {}, w = {} mpz z = mpz_init() for i=1 ...