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/Deconvolution/2D%2B
Deconvolution/2D+
This task is a straightforward generalization of Deconvolution/1D to higher dimensions. For example, the one dimensional case would be applicable to audio signals, whereas two dimensions would pertain to images. Define the discrete convolution in d {\displaystyle {\mathit {d}}} dimensions of two functions ...
#Tcl
Tcl
package require Tcl 8.5 namespace path {::tcl::mathfunc ::tcl::mathop}   # Utility to extract the number of dimensions of a matrix proc rank m { for {set rank 0} {[llength $m] > 1} {incr rank} { set m [lindex $m 0] } return $rank }   # Utility to get the size of a matrix, as a list of lengths proc size m {...
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "fmt" "math" "math/rand" "os" "strconv" "time" )   const sSuits = "CDHS" const sNums = "A23456789TJQK" const rMax32 = math.MaxInt32   var seed = 1   func rnd() int { seed = (seed*214013 + 2531011) & rMax32 return seed >> 16 }   func deal(s int) []int { seed = ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Python
Python
  # from https://en.wikipedia.org/wiki/De_Bruijn_sequence   def de_bruijn(k, n): """ de Bruijn sequence for alphabet k and subsequences of length n. """ try: # let's see if k can be cast to an integer; # if so, make our alphabet a list _ = int(k) alphabet = list(map(s...
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.
#Modula-3
Modula-3
TYPE MyInt = [1..10];
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.
#Nim
Nim
type MyInt = range[1..10]   var x: MyInt = 5   x = x + 6 # Runtime error: unhandled exception: value out of range: 11 notin 1 .. 10 [RangeDefect]   x = 12 # Compile-time error: conversion from int literal(12) to MyInt is invalid
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#POV-Ray
POV-Ray
camera { perspective location <0.0 , .8 ,-3.0> look_at 0 aperture .1 blur_samples 20 variance 1/100000 focal_point 0}   light_source{< 3,3,-3> color rgb 1}   sky_sphere { pigment{ color rgb <0,.2,.5>}}   plane {y,-5 pigment {color rgb .54} normal {hexagon} }   difference { sphere { 0,1 } sphere { <-1,1,-1>,...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Python
Python
import sys, math, collections   Sphere = collections.namedtuple("Sphere", "cx cy cz r") V3 = collections.namedtuple("V3", "x y z")   def normalize((x, y, z)): len = math.sqrt(x**2 + y**2 + z**2) return V3(x / len, y / len, z / len)   def dot(v1, v2): d = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z return -d if 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 ...
#ALGOL_68
ALGOL 68
# example from: http://www.xs4all.nl/~jmvdveer/algol.html - GPL # INT sun=0 # , mon=1, tue=2, wed=3, thu=4, fri=5, sat=6 #;   PROC day of week = (INT year, month, day) INT: ( # Day of the week by Zeller’s Congruence algorithm from 1887 # INT y := year, m := month, d := day, c; IF m <= 2 THEN m +:= 12; y -:= 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 ...
#ALGOL_68
ALGOL 68
BEGIN # show cyclops numbers - numbers with a 0 in the middle and no other 0 digits # INT max prime = 100 000; # sieve the primes to max prime # PR read "primes.incl.a68" PR []BOOL prime = PRIMESIEVE max prime; # returns TRUE if c is prime, FALSE otherwise # PROC have a prime = ( INT c )BOOL: ...
http://rosettacode.org/wiki/Deconvolution/2D%2B
Deconvolution/2D+
This task is a straightforward generalization of Deconvolution/1D to higher dimensions. For example, the one dimensional case would be applicable to audio signals, whereas two dimensions would pertain to images. Define the discrete convolution in d {\displaystyle {\mathit {d}}} dimensions of two functions ...
#Ursala
Ursala
#import std #import nat   break = ~&r**+ zipt*+ ~&lh*~+ ~&lzyCPrX|\+ -*^|\~&tK33 :^/~& 0!*t   band = pad0+ ~&rSS+ zipt^*D(~&r,^lrrSPT/~&ltK33tx zipt^/~&r ~&lSNyCK33+ zipp0)^/~&rx ~&B->NlNSPC ~&bt   deconv = # takes a natural number n to the n-dimensional deconvolution function   ~&?\math..div! iota; ~&!*; @h|\; (~&al^?...
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...
#Go
Go
package main   import ( "fmt" "math" "math/rand" "os" "strconv" "time" )   const sSuits = "CDHS" const sNums = "A23456789TJQK" const rMax32 = math.MaxInt32   var seed = 1   func rnd() int { seed = (seed*214013 + 2531011) & rMax32 return seed >> 16 }   func deal(s int) []int { seed = ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Racket
Racket
#lang racket   (define (de-bruijn k n) (define a (make-vector (* k n) 0)) (define seq '()) (define (db t p) (cond [(> t n) (when (= (modulo n p) 0) (set! seq (cons (call-with-values (thunk (vector->values a 1 (add1 p))) ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Raku
Raku
# Generate the sequence my $seq;   for ^100 { my $a = .fmt: '%02d'; next if $a.substr(1,1) < $a.substr(0,1); $seq ~= ($a.substr(0,1) == $a.substr(1,1)) ?? $a.substr(0,1) !! $a; for +$a ^..^ 100 { next if .fmt('%02d').substr(1,1) <= $a.substr(0,1); $seq ~= sprintf "%s%02d", $a, $_ ; }...
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.
#OCaml
OCaml
exception Out_of_bounds   type 'a bounds = { min: 'a; max: 'a }   type 'a bounded = { value: 'a; bounds: 'a bounds }   let mk_bounds ~min ~max = { min=min; max=max } ;; (** val mk_bounds : min:'a -> max:'a -> 'a bounds *)   let check_bounds ~value ~bounds = if value < bounds.min || value > bounds.max then raise O...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Q
Q
  / https://en.wikipedia.org/wiki/BMP_file_format / BITMAPINFOHEADER / RGB24   / generate a header   genheader:{[w;h] 0x424d, "x"$(f2i4[54+4*h*w],0,0,0,0,54,0,0,0,40,0,0,0, f2i4[h],f2i4[w],1,0,24,0,0,0,0,0, f2i4[h*((w*3)+((w*3)mod 4))], 19,11,0,0,19,11,0,0,0,0,0,0,0,0,...
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 ...
#ALGOL_W
ALGOL W
begin % find years where Christmas day falls on a Sunday % integer procedure Day_of_week ( integer value d, m, y ); begin integer j, k, mm, yy; mm := m; yy := y; if mm <= 2 then begin mm := mm + 12; yy := yy - 1; end...
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 ...
#ALGOL-M
ALGOL-M
  BEGIN   % CALCULATE P MOD Q % INTEGER FUNCTION MOD(P, Q); INTEGER P, Q; BEGIN MOD := P - Q * (P / Q); END;   COMMENT RETURN DAY OF WEEK (SUN=0, MON=1, ETC.) FOR A GIVEN GREGORIAN CALENDAR DATE USING ZELLER'S CONGRUENCE; INTEGER FUNCTION DAYOFWEEK(MO, DA, YR); INTEGER MO, DA, YR; BEGIN INTEGER Y, C, Z; IF M...
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 ...
#Arturo
Arturo
cyclops?: function [n][ digs: digits n all? @[ -> odd? size digs -> zero? digs\[(size digs)/2] -> 1 = size match to :string n "0" ] ]   blind: function [x][ s: to :string x half: (size s)/2 to :integer (slice s 0 dec half)++(slice s inc half dec size s) ]   findFirst50:...
http://rosettacode.org/wiki/Deconvolution/2D%2B
Deconvolution/2D+
This task is a straightforward generalization of Deconvolution/1D to higher dimensions. For example, the one dimensional case would be applicable to audio signals, whereas two dimensions would pertain to images. Define the discrete convolution in d {\displaystyle {\mathit {d}}} dimensions of two functions ...
#Wren
Wren
import "/complex" for Complex import "/fmt" for Fmt   var fft2 // recursive fft2 = Fn.new { |buf, out, n, step, start| if (step < n) { fft2.call(out, buf, n, step*2, start) fft2.call(out, buf, n, step*2, start + step) var j = 0 while (j < n) { var t = (Complex.imagMinusOn...
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...
#Groovy
Groovy
  class FreeCell{ int seed   List<String> createDeck(){ List<String> suits = ['♣','♦','♥','♠'] List<String> values = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'] return [suits,values].combinations{suit,value -> "$suit$value"} }   int random() { seed = (214013 * ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#REXX
REXX
/*REXX pgm calculates the de Bruijn sequence for all pin numbers (4 digit decimals). */ $= /*initialize the de Bruijn sequence. */ #=10; lastNode= (#-2)(#-2)(#-1)(#-2) /*this number is formed when this # ···*/ ...
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.
#ooRexx
ooRexx
/* REXX ---------------------------------------------------------------- * 21.06.2014 Walter Pachl * implements a data type tinyint that can have an integer value 1..10 * 22.06.2014 WP corrected by Rony Flatscher to handle arithmetic *---------------------------------------------------------------------*/ a=.tinyint~ne...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Racket
Racket
  #lang racket (require plot) (plot3d (polar3d (λ (φ θ) (real-part (- (sin θ) (sqrt (- (sqr 1/3) (sqr (cos θ))))))) #:samples 100 #:line-style 'transparent #:color 9) #:altitude 60 #:angle 80 #:height 500 #:width 400 #:x-min -1/2 #:x-max 1/2 #:y-min -1/2 #:y-max 1/2 ...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Raku
Raku
class sphere { has $.cx; # center x coordinate has $.cy; # center y coordinate has $.cz; # center z coordinate has $.r; # radius }   my $depth = 255; # image color depth   my $width = my $height = 255; # dimensions of generated .pgm; must be odd   my $s = ($width - 1)/2; # scaled dimension to build ge...
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 ...
#APL
APL
⍝ Based on the simplified calculation of Zeller's congruence, since Christmas is after March 1st, no adjustment is required. ⎕IO ← 0 ⍝ Indices are 0-based y ← 2008 + ⍳114 ⍝ Years from 2008 to 2121 ⍝ Simplified Zeller function operating on table of dates formatted as 114 rows and 3 columns of (day, mon...
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 ...
#AWK
AWK
  # syntax: GAWK -f CYCLOPS_NUMBERS.AWK BEGIN { n = 0 limit = 50 while (A134808_cnt < limit || A134809_cnt < limit || A329737_cnt < limit || A136098_cnt < limit) { leng = length(n) if (leng ~ /[13579]$/) { middle_col = int(leng/2)+1 if (substr(n,middle_col,1) == 0 && gsub(/0/,"&"...
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...
#Haskell
Haskell
import Data.Int import Data.Bits import Data.List import Data.Array.ST import Control.Monad import Control.Monad.ST import System.Environment   srnd :: Int32 -> [Int] srnd = map (fromIntegral . flip shiftR 16) . tail . iterate (\x -> (x * 214013 + 2531011) .&. maxBound)   deal :: Int32 -> [String] deal s = runST...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Ruby
Ruby
def deBruijn(k, n) alphabet = "0123456789" @a = Array.new(k * n, 0) @seq = []   def db(k, n, t, p) if t > n then if n % p == 0 then temp = @a[1 .. p] @seq.concat temp end else @a[t] = @a[t - p] db(k, n, t + 1...
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.
#Oz
Oz
declare I in I::1#10 I = {Pow 2 4}
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#REXX
REXX
/*REXX program displays a sphere with another sphere subtracted where it's superimposed.*/ call deathStar 2, .5, v3('-50 30 50') exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ 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 ...
#AppleScript
AppleScript
set ChristmasSundays to {} set Christmas to (current date) set month of Christmas to December set day of Christmas to 25 repeat with |year| from 2008 to 2121 set year of Christmas to |year| if weekday of Christmas is Sunday then set end of ChristmasSundays to |year| end repeat ChristmasSundays
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 ...
#F.23
F#
  // Cyclop numbers. Nigel Galloway: June 25th., 2021 let rec fG n g=seq{yield! g|>Seq.collect(fun i->g|>Seq.map(fun g->n*i+g)); yield! fG(n*10)(fN g)} let cyclops=seq{yield 0; yield! fG 100 [1..9]} let primeCyclops,blindCyclops=cyclops|>Seq.filter isPrime,Seq.zip(fG 100 [1..9])(fG 10 [1..9])|>Seq.filter(fun(n,g)->isPr...
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.
#11l
11l
V format_str = ‘%B %d %Y %I:%M%p’ print((time:strptime(‘March 7 2009 7:30pm’, format_str) + TimeDelta(hours' 12)).strftime(format_str))
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...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) # freecelldealer freecelldealer(\A[1] | &null) # seed from command line end   procedure newDeck() #: return a new unshuffled deck every D := list(52) & i := 0 & r := !"A23456789TJQK" & s := !"CDHS" do D[i +:= 1] := r || s # initial deck AC AD ... KS re...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Visual_Basic_.NET
Visual Basic .NET
Imports System.Text   Module Module1   ReadOnly DIGITS As String = "0123456789"   Function DeBruijn(k As Integer, n As Integer) As String Dim alphabet = DIGITS.Substring(0, k) Dim a(k * n) As Byte Dim seq As New List(Of Byte) Dim db As Action(Of Integer, Integer) = Sub(t As Integ...
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.
#Pascal
Pascal
type naturalTen = 1..10;
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.
#Perl
Perl
package One_To_Ten; use Carp qw(croak); use Tie::Scalar qw(); use base qw(Tie::StdScalar);   sub STORE { my $self = shift; my $val = int shift; croak 'out of bounds' if $val < 1 or $val > 10; $$self = $val; };   package main; tie my $t, 'One_To_Ten'; $t = 3; # ok $t = 5.2; # ok, silently coerced to in...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Set_lang
Set lang
set ! 32 set ! 32 set ! 46 set ! 45 set ! 126 set ! 34 set ! 34 set ! 126 set ! 45 set ! 46 set ! 10 set ! 46 set ! 39 set ! 40 set ! 95 set ! 41 set ! 32 set ! 32 set ! 32 set ! 32 set ! 32 set ! 39 set ! 46 set ! 10 set ! 124 set ! 61 set ! 61 set ! 61 set ! 61 set ! 61 set ! 61 set ! 61 set ! 61 set ! 61 set ! 61 se...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Sidef
Sidef
func hitf(sph, x, y) { x -= sph[0] y -= sph[1]   var z = (sph[3]**2 - (x**2 + y**2))   z < 0 && return nil   z.sqrt! [sph[2] - z, sph[2] + z] }   func normalize(v) { v / v.abs }   func dot(x, y) { max(0, x*y) }   var pos = [120, 120, 0, 120] var neg = [-77, -33, -100, 190] var light = no...
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 ...
#Arc
Arc
  (= day-names '(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)) (= get-weekday-num (fn (year month day) (= helper '(0 3 2 5 0 3 5 1 4 6 2 4)) (if (< month 3) (= year (- year 1))) (mod (+ year (helper (- month 1)) day (apply + (map [trunc (/ year _)] '(4 -100 400)))) 7))) (= get-weekday-n...
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 ...
#Arturo
Arturo
print select 2008..2121 'year [ "Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day ]
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...
#11l
11l
F cut_it(=h, =w) V dirs = [(1, 0), (-1, 0), (0, -1), (0, 1)] I h % 2 != 0 swap(&h, &w) I h % 2 != 0 R 0 I w == 1 R 1 V count = 0   V next = [w + 1, -w - 1, -1, 1] V blen = (h + 1) * (w + 1) - 1 V grid = [0B] * (blen + 1)   F walk(Int y, x, =count) -> Int I y == 0 | y =...
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 ...
#Factor
Factor
USING: accessors formatting grouping io kernel lists lists.lazy math math.functions math.primes prettyprint sequences tools.memory.private tools.time ;       ! ==========={[ Cyclops data type and operations ]}=============   TUPLE: cyclops left right n max ;   : <cyclops> ( -- cyclops ) 1 1 1 9 cyclops boa ;   : >cyclo...
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 ...
#Go
Go
package main   import ( "fmt" "rcu" "strconv" "strings" )   func findFirst(list []int) (int, int) { for i, n := range list { if n > 1e7 { return n, i } } return -1, -1 }   func reverse(s string) string { chars := []rune(s) for i, j := 0, len(chars)-1; i < ...
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.
#Ada
Ada
with Ada.Calendar; with Ada.Calendar.Formatting; with Ada.Calendar.Time_Zones; with Ada.Integer_Text_IO; with Ada.Text_IO;   procedure Date_Manipulation is   type Month_Name_T is (January, February, March, April, May, June, July, August, September, October, November, December);   type Time_Zone_Name_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...
#J
J
deck=: ,/ 'A23456789TJQK' ,"0/ 7 u: '♣♦♥♠'   srnd=: 3 :'SEED=:{.y,11982' srnd '' seed=: do bind 'SEED' rnd=: (2^16) <.@%~ (2^31) srnd@| 2531011 + 214013 * seed   pairs=: <@<@~.@(<: , (| rnd))@>:@i.@-@# NB. indices to swap, for shuffle swaps=: [: > C.&.>/@|.@; NB. implement the specified shuffle deal=: ...
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...
#Java
Java
  import java.util.Arrays;   public class Shuffler {   private int seed;   private String[] deck = { "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", ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#Wren
Wren
import "/fmt" for Fmt import "/str" for Str   var deBruijn = "" for (n in 0..99) { var a = Fmt.rjust(2, n, "0") var a1 = a[0].bytes[0] var a2 = a[1].bytes[0] if (a2 >= a1) { deBruijn = deBruijn + ((a1 == a2) ? String.fromByte(a1): a) var m = n + 1 while (m <= 99) { va...
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.
#Phix
Phix
type iten(integer i) return i>=1 and i<=10 end type
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.
#PicoLisp
PicoLisp
(class +BoundedInt) # value lower upper   (dm T (Low Up) (=: lower (min Low Up)) (=: upper (max Low Up)) )   (de "checkBounds" (Val) (if (>= (: upper) Val (: lower)) Val (throw 'boundedIntOutOfBounds (pack "value " Val " is out of bounds [" (: lower) "," (: upper) "...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Tcl
Tcl
package require Tcl 8.5   proc normalize vec { upvar 1 $vec v lassign $v x y z set len [expr {sqrt($x**2 + $y**2 + $z**2)}] set v [list [expr {$x/$len}] [expr {$y/$len}] [expr {$z/$len}]] return }   proc dot {a b} { lassign $a ax ay az lassign $b bx by bz return [expr {-($ax*$bx + $ay*$b...
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 ...
#AutoHotkey
AutoHotkey
year = 2008 stop = 2121   While year <= stop { FormatTime, day,% year 1225, dddd If day = Sunday out .= year "`n" year++ } MsgBox,% out
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 ...
#AutoIt
AutoIt
#include <date.au3> Const $iSunday = 1 For $iYear = 2008 To 2121 Step 1 If $iSunday = _DateToDayOfWeek($iYear, 12, 25) Then ConsoleWrite(StringFormat($iYear & "\n")) EndIf Next
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...
#C
C
#include <stdio.h> #include <stdlib.h> #include <string.h>   typedef unsigned char byte; byte *grid = 0;   int w, h, len; unsigned long long cnt;   static int next[4], dir[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; void walk(int y, int x) { int i, t;   if (!y || y == h || !x || x == w) { cnt += 2; return; }   ...
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 ...
#Haskell
Haskell
import Control.Monad (replicateM) import Data.Numbers.Primes (isPrime)   --------------------- CYCLOPS NUMBERS --------------------   cyclops :: [Integer] cyclops = [0 ..] >>= flankingDigits where flankingDigits 0 = [0] flankingDigits n = fmap (\s -> read s :: Integer) ( (fmap ((<>) . (<...
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.
#AppleScript
AppleScript
set x to "March 7 2009 7:30pm EST" return (date x) + 12 * hours
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.
#Arturo
Arturo
; a tiny helper, so that we aren't too repetitive formatDate: function [dt][ to :string .format: "MMMM d yyyy h:mmtt" dt ]   initial: "March 7 2009 7:30pm EST"   ; chop timezone off initial: join.with:" " chop split.words initial initial: to :date .format: "MMMM d yyyy h:mmtt" initial   print ["initial:" ...
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...
#JavaScript
JavaScript
"use strict"; /* * Microsoft C Run-time-Library-compatible Random Number Generator * Copyright by Shlomi Fish, 2011. * Released under the MIT/X11 License * ( http://en.wikipedia.org/wiki/MIT_License ). * */ /* This uses Joose 2.x-or-above, an object system for JavaScript - http://code.google.com/p/joose-js/ . */  ...
http://rosettacode.org/wiki/De_Bruijn_sequences
de Bruijn sequences
The sequences are named after the Dutch mathematician   Nicolaas Govert de Bruijn. A note on Dutch capitalization:   Nicolaas' last name is   de Bruijn,   the   de   isn't normally capitalized unless it's the first word in a sentence.   Rosetta Code (more or less by default or by fiat) requires the first word in the...
#zkl
zkl
dbSeq:=Data(); // a byte/character buffer foreach n in (100){ a,a01,a11 := "%02d".fmt(n), a[0,1], a[1,1]; if(a11<a01) continue; dbSeq.append( if(a01==a11) a01 else a ); foreach m in ([n+1 .. 99]){ if("%02d".fmt(m)[1,1] <= a01) continue; dbSeq.append("%s%02d".fmt(a,m)); } } dbSeq.append("000")...
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.
#PowerShell
PowerShell
  [Int][ValidateRange(1,10)]$n = 3 # $n can only accept integers between 1 and 10  
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.
#PureBasic
PureBasic
If OpenConsole() Structure Persona nombre.s{15} apellido.s{30} edad.w List amigos$() EndStructure   Dim MyFriends.Persona(100)   ; Aquí la posición '1' del array MyFriends() ; contendrá una persona y su propia información MyFriends(1)\nombre = "Carlos" MyFriends(1)\apellido = "Gzlez." ...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Wren
Wren
import "dome" for Window import "graphics" for Canvas, Color, ImageData import "math" for Vector   var Normalize = Fn.new{ |vec| var invLen = 1 / vec.dot(vec).sqrt vec.x = vec.x * invLen vec.y = vec.y * invLen vec.z = vec.z * invLen }   class Sphere { construct new(cx, cy, cz, r) { _cx = cx ...
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 ...
#AWK
AWK
  # syntax: GAWK -f DAY_OF_THE_WEEK.AWK # runtime does not support years > 2037 on my 32-bit Windows XP O/S BEGIN { for (i=2008; i<=2121; i++) { x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i))) if (x ~ /Sun/) { print(x) } } }  
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
#11l
11l
print(Time().format(‘YYYY-MM-DD’)) print(Time().strftime(‘%A, %B %e, %Y’))
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.
#11l
11l
V matrix = [ [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,...
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...
#C.2B.2B
C++
#include <array> #include <iostream> #include <stack> #include <vector>   const std::array<std::pair<int, int>, 4> DIRS = { std::make_pair(0, -1), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(1, 0), };   void printResult(const std::vector<std::vector<int>> &v) { for (auto &row : v)...
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 ...
#jq
jq
  ## Generic helper functions   def count(s): reduce s as $x (0; .+1);   # counting from 0 def enumerate(s): foreach s as $x (-1; .+1; [., $x]);   def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;   ## Prime numbers def is_prime: if . == 2 then true else 2 < . and . % 2 == 1 and (...
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 ...
#Julia
Julia
  print5x10(a, w = 8) = for i in 0:4, j in 1:10 print(lpad(a[10i + j], w), j == 10 ? "\n" : "") end   function iscyclops(n) d = digits(n) l = length(d) return isodd(l) && d[l ÷ 2 + 1] == 0 && count(x -> x == 0, d) == 1 end   function isblindprimecyclops(n) d = digits(n) l = length(d) m = l ÷ 2 +...
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.
#AutoHotkey
AutoHotkey
DateString := "March 7 2009 7:30pm EST"   ; split the given string with RegExMatch Needle := "^(?P<mm>\S*) (?P<d>\S*) (?P<y>\S*) (?P<t>\S*) (?P<tz>\S*)$" RegExMatch(DateString, Needle, $)   ; split the time with RegExMatch Needle := "^(?P<h>\d+):(?P<min>\d+)(?P<xm>[amp]+)$" RegExMatch($t, Needle, $)   ; convert am/pm 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...
#Julia
Julia
const rank = split("A23456789TJQK", "") const suit = split("♣♦♥♠", "") const deck = Vector{String}()   const mslcg = [0] rng() = (mslcg[1] = ((mslcg[1] * 214013 + 2531011) & 0x7fffffff)) >> 16   initdeck() = for r in rank, s in suit push!(deck, "$r$s") end   function deal(num = rand(UInt,1)[1] % 32000 + 1) initd...
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...
#Kotlin
Kotlin
// version 1.1.3   class Lcg(val a: Long, val c: Long, val m: Long, val d: Long, val s: Long) { private var state = s   fun nextInt(): Long { state = (a * state + c) % m return state / d } }   const val CARDS = "A23456789TJQK" const val SUITS = "♣♦♥♠"   fun deal(): Array<String?> { val...
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.
#Python
Python
>>> class num(int): def __init__(self, b): if 1 <= b <= 10: return int.__init__(self+0) else: raise ValueError,"Value %s should be >=0 and <= 10" % b     >>> x = num(3) >>> x = num(11)   Traceback (most recent call last): File "<pyshell#394>", line 1, in <module> x = nu...
http://rosettacode.org/wiki/Death_Star
Death Star
Task Display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) Related tasks draw a sphere draw a cuboid draw a rotating cube write language name in 3D ASCII
#Yabasic
Yabasic
open window 100,100 window origin "cc" backcolor 0,0,0 clear window   tonos = 100 interv = int(255 / tonos) dim shades(tonos)   shades(1) = 255 for i = 2 to tonos shades(i) = shades(i-1) - interv next i   dim light(3)   light(0) = 30 light(1) = 30 light(2) = -50     sub normalize(v()) local long   long = sqrt(...
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 ...
#BASIC
BASIC
Declare Function modulo(x As Double, y As Double) As Double Declare Function wd(m As Double, d As Double, y As Double) As Integer   Cls Dim yr As Double For yr = 2008 To 2121 If wd(12,25,yr) = 1 Then Print "Dec " & 25 & ", " & yr EndIf Next Sleep   Function modulo(x As Double, y As Double) As Double If y = 0 Then ...
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 ...
#Batch_File
Batch File
:: Day of the Week task from Rosetta Code :: Batch File Implementation :: Question: In what years between 2008 and 2121 will the 25th of December be a Sunday? :: Method: Zeller's Rule   @echo off rem set month code for December set mon=33 rem set day number set day=25   for /L %%y in (2008,1,2121) do ( setlocal enab...
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
#68000_Assembly
68000 Assembly
JSR SYS_READ_CALENDAR ;outputs calendar date to BIOS RAM   MOVE.B #'2',D0 ;a character in single or double quotes refers to its ascii equivalent. JSR PrintChar MOVE.B #'0',D0 JSR PrintChar   LEA BIOS_YEAR,A1 MOVE.B (A1)+,D0 ;stores last 2 digits of year into D0, in binary coded decimal...
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.
#8080_Assembly
8080 Assembly
org 100h jmp demo ;;; Given an 0-terminated ASCII string containing digits in [DE], ;;; see if it matches its check digit. Returns with zero flag set ;;; if the string matches. damm: mvi c,0 ; Interim digit in C, starts off at 0. ldax d ; Get current byte from string inx d ; Advance the pointer ana a ; Is the ...
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.
#8086_Assembly
8086 Assembly
cpu 8086 bits 16 section .text org 100h jmp demo ;;; Given a 0-terminated ASCII string containing digits in ;;; [DS:SI], see if the check digit matches. Returns with zero flag ;;; set if it matches. damm: xor cl,cl ; Interim digit starts out at 0 mov bx,.tab ; Index for table lookup .dgt: lodsb ; Get next stri...
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...
#Arturo
Arturo
curzon?: function [n,base]-> zero? (inc base^n) % inc base*n   first50: function [b][ result: new [] i: 1 while [50 > size result][ if curzon? i b -> 'result ++ i i: i + 1 ] return result ]   oneThousandth: function [b][ cnt: 0 i: 1 while [cnt < 1000][ if cur...
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...
#Common_Lisp
Common Lisp
(defun cut-it (w h &optional (recur t)) (if (oddp (* w h)) (return-from cut-it 0)) (if (oddp h) (rotatef w h)) (if (= w 1) (return-from cut-it 1))   (let ((cnt 0) (m (make-array (list (1+ h) (1+ w)) :element-type 'bit :initial-element 0)) (cy (truncate h 2)) (cx (truncate w 2)))   (setf...
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 ...
#Ksh
Ksh
  #!/bin/ksh   # Cyclops numbers (odd number of digits that has a zero in the center) # - first 50 cyclops numbers # - first 50 prime cyclops numbers # - first 50 blind prime cyclops numbers # - first 50 palindromic prime cyclops numbers   # # Variables: # integer MAXN=50   # # Functions: #   # # Function _isprime(n) r...
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 ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
a = Flatten[Table[FromDigits[{i, 0, j}], {i, 9}, {j, 9}], 1]; b = Flatten@Table[FromDigits@{i, j}, {i, 9}, {j, 9}]; c = Flatten@Table[FromDigits@{i, j, k}, {i, 9}, {j, 9}, {k, 9}];   blindPrimeQ[n_] := Block[{digits = IntegerDigits@n, m}, m = Floor[Length[digits]/2]; PrimeQ[FromDigits@Join[digits[[;; m]], digits[[...
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.
#AWK
AWK
  # syntax: GAWK -f DATE_MANIPULATION.AWK BEGIN { fmt = "%a %Y-%m-%d %H:%M:%S %Z" # DAY YYYY-MM-DD HH:MM:SS TZ split("March 7 2009 7:30pm EST",arr," ") M = (index("JanFebMarAprMayJunJulAugSepOctNovDec",substr(arr[1],1,3)) + 2) / 3 D = arr[2] Y = arr[3] hhmm = arr[4] hh = substr(hhmm,1,index(...
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...
#Logo
Logo
; Linear congruential random number generator make "_lcg_state 0   to seed_lcg :seed make "_lcg_state :seed end   to sample_lcg make "_lcg_state modulo sum product 214013 :_lcg_state 2531011 2147483648 output int quotient :_lcg_state 65536 end   ; FreeCell to card_from_number :number output word item sum 1 int ...
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...
#Lua
Lua
deck = {} rank = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"} suit = {"C", "D", "H", "S"} two31, state = bit32.lshift(1, 31), 0   function rng() state = (214013 * state + 2531011) % two31 return bit32.rshift(state, 16) end   function initdeck() for i, r in ipairs(rank) do for j,...
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.
#QBasic
QBasic
  TYPE TipoUsuario nombre AS STRING * 15 apellido AS STRING * 30 edad AS INTEGER END TYPE   DIM usuario(1 TO 20) AS TipoUsuario   usuario(1).nombre = "Juan" usuario(1).apellido = "Hdez." usuario(1).edad = 49   PRINT usuario(1).nombre, usuario(1).apellido, usuario(1).edad  
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 ...
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"DATELIB"   FOR year% = 2008 TO 2121 IF FN_dow(FN_mjd(25, 12, year%)) = 0 THEN PRINT "Christmas Day is a Sunday in "; year% ENDIF NEXT
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 ...
#bc
bc
scale = 0   /* * Returns day of week (0 to 6) for year, month m, day d in proleptic * Gregorian calendar. Sunday is 0. Assumes y >= 1, scale = 0. */ define w(y, m, d) { auto a   /* Calculate Zeller's congruence. */ a = (14 - m) / 12 m += 12 * a y -= a return ((d + (13 * m + 8) / 5 + \ y + y / 4 - y / 100 ...
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...
#11l
11l
F cusip_check(=cusip) I cusip.len != 9 X ValueError(‘CUSIP must be 9 characters’)   cusip = cusip.uppercase() V total = 0 L(i) 8 V v = 0 V c = cusip[i] I c.is_digit() v = Int(c) E I c.is_alpha() V p = c.code - ‘A’.code + 1 v = p + 9 E I 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
#8th
8th
  d:new "%Y-%M-%D" over d:format . cr "%W, %N %D, %Y" over d:format . cr bye  
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
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program dateFormat64.s */     /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstante...
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.
#Action.21
Action!
BYTE FUNC Damm(CHAR ARRAY a) BYTE ARRAY 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] BYTE i,x,c   x=0 FOR i=...
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.
#Ada
Ada
with Ada.Text_IO;   procedure Damm_Algorithm is   function Damm (Input : in String) return Boolean is subtype Digit is Character range '0' .. '9';   Table : constant array (Digit, Digit) of Digit := (('0', '3', '1', '7', '5', '9', '8', '6', '4', '2'), ('7', '0', '9', '2', '1', '5', '4...
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...
#C.2B.2B
C++
#include <iomanip> #include <iostream> #include <vector>   #include <gmpxx.h>   bool is_curzon(int n, int k) { mpz_class p; mpz_ui_pow_ui(p.get_mpz_t(), k, n); return (p + 1) % (k * n + 1) == 0; }   int main() { for (int k = 2; k <= 10; k += 2) { std::cout << "Curzon numbers with base " << 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...
#Factor
Factor
USING: grouping interpolate io kernel make math math.functions prettyprint ranges sequences ;   : curzon? ( k n -- ? ) [ ^ 1 + ] 2keep * 1 + divisor? ;   : next ( k n -- k n' ) [ 2dup curzon? ] [ 1 + ] do until ;   : curzon ( k -- seq ) 1 [ 50 [ dup , next ] times ] { } make 2nip ;   : curzon. ( k -- ) dup [I C...
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...
#FreeBASIC
FreeBASIC
' limit: k * n +1 must be smaller then 2^32-1   Function pow_mod(b As ULongInt, power As ULongInt, modulus As ULongInt) As ULongInt ' returns b ^ power mod modulus Dim As ULongInt x = 1   While power > 0 If (power And 1) = 1 Then x = (x * b) Mod modulus End If b = (b * b)...
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...
#D
D
import core.stdc.stdio, core.stdc.stdlib, core.stdc.string, std.typecons;   enum int[2][4] dir = [[0, -1], [-1, 0], [0, 1], [1, 0]];   __gshared ubyte[] grid; __gshared uint w, h, len; __gshared ulong cnt; __gshared uint[4] next;   void walk(in uint y, in uint x) nothrow @nogc { if (!y || y == h || !x || x == w) { ...
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 ...
#Nim
Nim
import strutils, times   const Ranges = [0..0, 101..909, 11011..99099, 1110111..9990999, 111101111..999909999]     func isCyclops(d: string): bool = d[d.len shr 1] == '0' and d.count('0') == 1   func isPrime(n: Natural): bool = if n < 2: return if n mod 2 == 0: return n == 2 if n mod 3 == 0: return n == 3 var...
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 ...
#Pascal
Pascal
program cyclops; {$IFDEF FPC} {$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$CodeAlign proc=32,loop=1} {$ENDIF} //extra https://oeis.org/A136098/b136098.txt take ~37 s( TIO.RUN ) uses sysutils; const BIGLIMIT = 10*1000*1000;   type //number in base 9 tnumdgts = array[0..10] of byte; tpnumdgts = pByte; tnum9 ...
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.
#Batch_File
Batch File
  @echo off   call:Date_Manipulation "March 7 2009 7:30pm EST" call:Date_Manipulation "February 28 2009 2:28pm EST" call:Date_Manipulation "February 29 2000 9:52pm EST" pause>nul exit /b   :Date_Manipulation setlocal enabledelayedexpansion :: These are the arrays we'll be using set daysinmonth=31 28 31 30 31 30 31 31...