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/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
#Crystal
Crystal
require "time"   time = Time.local puts time.to_s("%Y-%m-%d") puts time.to_s("%A, %B %d, %Y")  
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
#D
D
module datetimedemo ;   import tango.time.Time ; import tango.text.locale.Locale ; import tango.time.chrono.Gregorian ;   import tango.io.Stdout ;   void main() { Gregorian g = new Gregorian ; Stdout.layout = new Locale; // enable Stdout to handle date/time format Time d = g.toTime(2007, 11, 10, 0, 0, 0, 0...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Arturo
Arturo
; data.csv ; ; C1,C2,C3,C4,C5 ; 1,5,9,13,17 ; 2,6,10,14,18 ; 3,7,11,15,19 ; 4,8,12,16,20   table: read.csv "data.csv" data: [] loop table 'row [ addable: ["SUM"] if row <> first table -> addable: @[to :string sum map row 'x [to :integer x]]   'data ++ @[row ++ addable] ]   loop data 'row [ loop...
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.
#FreeBASIC
FreeBASIC
' version 04-07-2018 ' compile with: fbc -s console   Function Damm(digit_str As String) As UInteger   Dim As UInteger 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 } , { 6, 1, 2, 3, 0, 4, 5, 9, 7, ...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Action.21
Action!
PROC Save(CHAR ARRAY text) BYTE dev=[1]   Close(dev) Open(dev,"C:",8,128) PrintE("Saving started...") PrintF("Saving text: ""%S""%E",text) PrintD(dev,text) Close(dev) PrintE("Saving finished.") RETURN   PROC Load() CHAR ARRAY result(255) BYTE dev=[1]   Close(dev) Open(dev,"C:",4,128) PrintE("L...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Applesoft_BASIC
Applesoft BASIC
SAVE
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Arturo
Arturo
write "TAPE.FILE" { This code should be able to write a file to magnetic tape }
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...
#F.23
F#
open System   let hamburgers = 4000000000000000M let hamburgerPrice = 5.50M let milkshakes = 2M let milkshakePrice = 2.86M let taxRate = 0.0765M   let total = hamburgers * hamburgerPrice + milkshakes * milkshakePrice let tax = total * taxRate let totalWithTax = total + tax   printfn "Total before tax:\t$%M" <| Math.Rou...
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...
#Factor
Factor
USING: combinators.smart io kernel math math.functions money ;   10 15 ^ 4 * 5+50/100 * ! hamburger subtotal 2 2+86/100 *  ! milkshake subtotal +  ! subtotal dup DECIMAL: 0.0765 *  ! tax [ + ] preserving  ! total   "Total before tax: " write [ money. ] 2dip "Tax: " write [ money. ] dip...
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...
#FreeBASIC
FreeBASIC
Dim As Longint hamburger_p = 550 Dim As Longint hamburger_q = 4000000000000000 Dim As Longint hamburger_v = hamburger_p * hamburger_q Dim As Longint milkshake_p = 286 Dim As Longint milkshake_q = 2 Dim As Longint milkshake_v = milkshake_p * milkshake_q Dim As Longint subtotal = hamburger_v + milkshake_v Dim As Longint ...
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...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "fmt" "math" )   func PowN(b float64) func(float64) float64 { return func(e float64) float64 { return math.Pow(b, e) } }   func PowE(e float64) func(float64) float64 { return func(b float64) float64 { return math.Pow(b, e) } }   type Foo int   func (f Foo) Method(...
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 |...
#Go
Go
package main   import( "fmt" "unsafe" "reflect" )   func pointer() { fmt.Printf("Pointer:\n")   // Create a *int and store the address of 'i' in it. To create a pointer to // an arbitrary memory location, use something like the following: // p := (*int)(unsafe.Pointer(uintptr(0x100))) // And replace '0x100' ...
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 |...
#J
J
  function unsafepointers() intspace = [42] address = pointer_from_objref(intspace) println("The address of intspace is $address") anotherint = unsafe_pointer_to_objref(address) println("intspace is $(intspace[1]), memory at $address, reference value $(anotherint[1])") intspace[1] = 123456 p...
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 |...
#Julia
Julia
  function unsafepointers() intspace = [42] address = pointer_from_objref(intspace) println("The address of intspace is $address") anotherint = unsafe_pointer_to_objref(address) println("intspace is $(intspace[1]), memory at $address, reference value $(anotherint[1])") intspace[1] = 123456 p...
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...
#Phix
Phix
-- demo\rosetta\Cyclotomic_Polynomial.exw with javascript_semantics function degree(sequence p) for i=length(p) to 1 by -1 do if p[i]!=0 then return i end if end for return -1 end function function poly_div(sequence n, d) while length(d)<length(n) do d &=0 end while integer dn = degree(n),...
http://rosettacode.org/wiki/Cut_a_rectangle
Cut a rectangle
A given rectangle is made from m × n squares. If m and n are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles...
#REXX
REXX
/*REXX program cuts rectangles into two symmetric pieces, the rectangles are cut along */ /*────────────────────────────────────────────────── unit dimensions and may be rotated.*/ numeric digits 20 /*be able to handle some big integers. */ parse arg N .; if N=='' | N=="," then N= 10...
http://rosettacode.org/wiki/Date_manipulation
Date manipulation
Task Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.
#JavaScript
JavaScript
function add12hours(dateString) {   // Get the parts of the date string var parts = dateString.split(/\s+/), date = parts[1], month = parts[0], year = parts[2], time = parts[3];   var hr = Number(time.split(':')[0]), min = Number(time.split(':')[1].replace(/\D/g,'')), a...
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...
#UNIX_Shell
UNIX Shell
test $# -gt 0 || set -- $((RANDOM % 32000)) for seed; do print Game $seed:   # Shuffle deck. deck=({A,{2..9},T,J,Q,K}{C,D,H,S}) for i in {52..1}; do ((seed = (214013 * seed + 2531011) & 0x7fffffff)) ((j = (seed >> 16) % i + 1)) t=$deck[$i] deck[$i]=$deck[$j] deck[$j]=$t done   # Deal cards. print -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 ...
#F.23
F#
open System   [ 2008 .. 2121 ] |> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None) |> printfn "%A"
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 ...
#Factor
Factor
USING: calendar math.ranges prettyprint sequences ; 2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .
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...
#Groovy
Groovy
class Cusip { private static Boolean isCusip(String s) { if (s.length() != 9) return false int sum = 0 for (int i = 0; i <= 7; i++) { char c = s.charAt(i)   int v if (c >= ('0' as char) && c <= ('9' as char)) { v = c - 48 } else...
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...
#AWK
AWK
  # syntax: GAWK -f STANDARD_DEVIATION.AWK BEGIN { n = split("2,4,4,4,5,5,7,9",arr,",") for (i=1; i<=n; i++) { temp[i] = arr[i] printf("%g %g\n",arr[i],stdev(temp)) } exit(0) } function stdev(arr, i,n,s1,s2,variance,x) { for (i in arr) { n++ x = arr[i] s1 += x ^ 2 ...
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
#Delphi
Delphi
ShowMessage(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));
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
#Diego
Diego
me_lang(en)_cal(gregorian); me_msg()_now()_format(yyyy-mm-dd); me_msg()_now()_format(eeee, mmmm dd, yyyy);
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#AutoHotkey
AutoHotkey
Loop, Read, Data.csv { i := A_Index Loop, Parse, A_LoopReadLine, CSV Output .= (i=A_Index && i!=1 ? A_LoopField**2 : A_LoopField) (A_Index=5 ? "`n" : ",") } FileAppend, %Output%, NewData.csv
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.
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import "fmt"   var table = [10][10]byte{ {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...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#C
C
  #include<stdio.h>   int main() { FILE* fp = fopen("TAPE.FILE","w");   fprintf(fp,"This code should be able to write a file to magnetic tape.\n"); fprintf(fp,"The Wikipedia page on Magnetic tape data storage shows that magnetic tapes are still in use.\n"); fprintf(fp,"In fact, the latest format, at the time of wri...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#C.2B.2B
C++
#include <iostream> #include <fstream>   #if defined(_WIN32) || defined(WIN32) constexpr auto FILENAME = "tape.file"; #else constexpr auto FILENAME = "/dev/tape"; #endif   int main() { std::filebuf fb; fb.open(FILENAME,std::ios::out); std::ostream os(&fb); os << "Hello World\n"; fb.close(); retu...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Clojure
Clojure
(spit "/dev/tape" "Hello, World!")
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...
#Frink
Frink
  st = 4000000000000000 * 5.50 dollars + 2 * 2.86 dollars tax = round[st * 7.65 percent, cent] total = st + tax println["Subtotal: " + format[st, "dollars", 2]] println["Tax: " + format[tax, "dollars", 2]] println["Total: " + format[total, "dollars", 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...
#Go
Go
package main   import ( "fmt" "log" "math/big" )   // DC for dollars and cents. Value is an integer number of cents. type DC int64   func (dc DC) String() string { d := dc / 100 if dc < 0 { dc = -dc } return fmt.Sprintf("%d.%02d", d, dc%100) }   // Extend returns extended price of a...
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...
#Go
Go
package main   import ( "fmt" "math" )   func PowN(b float64) func(float64) float64 { return func(e float64) float64 { return math.Pow(b, e) } }   func PowE(e float64) func(float64) float64 { return func(b float64) float64 { return math.Pow(b, e) } }   type Foo int   func (f Foo) Method(...
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 |...
#Kotlin
Kotlin
// Kotlin/Native Technology Preview   import kotlinx.cinterop.*   fun main(args: Array<String>) { val intVar = nativeHeap.alloc<IntVar>().apply { value = 42 } with(intVar) { println("Value is $value, address is $rawPtr") } intVar.value = 52 // create new value at this address with(intVar) { println("Va...
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 |...
#Lua
Lua
local a = {10} local b = a   print ("address a:"..tostring(a), "value a:"..a[1]) print ("address b:"..tostring(b), "value b:"..b[1])   b[1] = 42   print ("address a:"..tostring(a), "value a:"..a[1]) print ("address b:"..tostring(b), "value b:"..b[1])
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 |...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { structure alfa { val as long } Buffer Clear Beta as alfa*2 Print Beta(0) ' return address Return Beta, 0!val:=500 ' unsigned integer 32 bit Print Eval(Beta, 0!val)=500 Return Beta, 0!val:=0xFFFFFFFF Print Eval(Beta, 0!val)=4294967295 ...
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...
#Python
Python
from itertools import count, chain from collections import deque   def primes(_cache=[2, 3]): yield from _cache for n in count(_cache[-1]+2, 2): if isprime(n): _cache.append(n) yield n   def isprime(n): for p in primes(): if n%p == 0: return False ...
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...
#Ruby
Ruby
def cut_it(h, w) if h.odd? return 0 if w.odd? h, w = w, h end return 1 if w == 1   nxt = [[w+1, 1, 0], [-w-1, -1, 0], [-1, 0, -1], [1, 0, 1]] # [next,dy,dx] blen = (h + 1) * (w + 1) - 1 grid = [false] * (blen + 1)   walk = lambda do |y, x, count=0| return count+1 if y==0 or y==h or x==0 or...
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.
#jq
jq
"March 7 2009 7:30pm EST" | strptime("%B %d %Y %I:%M%p %Z") | .[3] += 12 | mktime | strftime("%B %d %Y %I:%M%p %Z")
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.
#Julia
Julia
using Dates   function main() dtstr = "March 7 2009 7:30pm" # Base.Dates doesn't handle "EST" cleandtstr = replace(dtstr, r"(am|pm)"i, "") dtformat = dateformat"U dd yyyy HH:MM" dtime = parse(DateTime, cleandtstr, dtformat) + Hour(12 * contains(dtstr, r"pm"i)) # add 12h for the pm println(Da...
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...
#Wren
Wren
class Lcg { construct new(a, c, m, d, s) { _a = a _c = c _m = m _d = d _s = s }   nextInt() { _s = (_a * _s + _c) % _m return _s / _d } }   var CARDS = "A23456789TJQK" var SUITS = "♣♦♥♠".toList   var deal = Fn.new { var cards = List.filled(52, ...
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 ...
#FBSL
FBSL
#APPTYPE CONSOLE   'In what years between 2008 and 2121 will the 25th of December be a Sunday? DIM date AS INTEGER, dayname AS STRING FOR DIM year = 2008 TO 2121 date = year * 10000 + 1225 dayname = dateconv(date,"dddd") IF dayname = "Sunday" THEN PRINT "Christmas Day is on a Sunday in ", year END IF NEXT PAUSE  
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...
#Haskell
Haskell
import Data.List(elemIndex)   data Result = Valid | BadCheck | TooLong | TooShort | InvalidContent deriving Show   -- convert a list of Maybe to a Maybe list. -- result is Nothing if any of values from the original list are Nothing allMaybe :: [Maybe a] -> Maybe [a] allMaybe = sequence   toValue :: Char -> Maybe Int to...
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...
#Axiom
Axiom
)abbrev package TESTD TestDomain TestDomain(T : Join(Field,RadicalCategory)): Exports == Implementation where R ==> Record(n : Integer, sum : T, ssq : T) Exports == AbelianMonoid with _+ : (%,T) -> % _+ : (T,%) -> % sd : % -> T Implementation == R add Rep := R -- similar representation and imple...
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
#EGL
EGL
  // 2012-09-26 SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd")); // Wednesday, September 26, 2012 SysLib.setLocale("en", "US"); SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, 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
#Elixir
Elixir
defmodule Date_format do def iso_date, do: Date.utc_today |> Date.to_iso8601   def iso_date(year, month, day), do: Date.from_erl!({year, month, day}) |> Date.to_iso8601   def long_date, do: Date.utc_today |> long_date   def long_date(year, month, day), do: Date.from_erl!({year, month, day}) |> long_date   @mo...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#AWK
AWK
#!/usr/bin/awk -f BEGIN { FS = OFS = "," } NR==1 { print $0, "SUM" next } { sum = 0 for (i=1; i<=NF; i++) { sum += $i } print $0, sum }
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.
#Go
Go
package main   import "fmt"   var table = [10][10]byte{ {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...
http://rosettacode.org/wiki/Cuban_primes
Cuban primes
The name   cuban   has nothing to do with   Cuba  (the country),   but has to do with the fact that cubes   (3rd powers)   play a role in its definition. Some definitions of cuban primes   primes which are the difference of two consecutive cubes.   primes of the form:   (n+1)3 - n3.   primes of the form:   n3 - ...
#ALGOL_68
ALGOL 68
BEGIN # find some cuban primes (using the definition: a prime p is a cuban prime if # # p = n^3 - ( n - 1 )^3 # # for some n > 0) #   # returns a string representation of n with commas...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#COBOL
COBOL
>>SOURCE FORMAT IS FREE IDENTIFICATION DIVISION. PROGRAM-ID. MAKE-TAPE-FILE.   ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TAPE-FILE ASSIGN "./TAPE.FILE" ORGANIZATION IS LINE SEQUENTIAL.   DATA DIVISION. FILE SECTION. FD TAPE-FILE. 01 TAPE-FILE-RECORD PIC X(51).   PROCEDU...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Crystal
Crystal
filename = {% if flag?(:win32) %} "TAPE.FILE" {% else %} "/dev/tape" {% end %} File.write filename, "howdy, planet!"
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#D
D
import std.stdio;   void main() { version(Windows) { File f = File("TAPE.FILE", "w"); } else { File f = File("/dev/tape", "w"); } f.writeln("Hello World!"); }
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Delphi
Delphi
  program Create_a_file_on_magnetic_tape;   {$APPTYPE CONSOLE}   const {$IFDEF WIN32} FileName = 'tape.file'; {$ELSE} FileName = '/dev/tape'; {$ENDIF}   var f: TextFile;   begin Assign(f, FileName); Rewrite(f); Writeln(f, 'Hello World'); close(f); end.  
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...
#Haskell
Haskell
import Data.Fixed import Text.Printf   type Percent = Centi type Dollars = Centi   tax :: Percent -> Dollars -> Dollars tax rate = MkFixed . round . (rate *)   printAmount :: String -> Dollars -> IO () printAmount name = printf "%-10s %20s\n" name . showFixed False   main :: IO () main = do let subtotal = 40000000000...
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...
#J
J
require 'format/printf'   Items=:  ;: 'Hamburger Milkshake' Quantities=: 4000000000000000 2 Prices=: x: 5.50 2.86 Tax_rate=: x: 0.0765   makeBill=: verb define 'items prices quantities'=. y values=. prices * quantities subtotal=. +/ values tax=. Tax_rate * subtotal total=. s...
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...
#Groovy
Groovy
def divide = { Number x, Number y -> x / y }   def partsOf120 = divide.curry(120)   println "120: half: ${partsOf120(2)}, third: ${partsOf120(3)}, quarter: ${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...
#Haskell
Haskell
\ ->
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 |...
#Nim
Nim
type MyObject = object x: int y: float   var mem = alloc(sizeof(MyObject)) objPtr = cast[ptr MyObject](mem) echo "object at ", cast[int](mem), ": ", objPtr[]   objPtr[] = MyObject(x: 42, y: 3.1415) echo "object at ", cast[int](mem), ": ", objPtr[]  
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 |...
#Pascal
Pascal
program test; type t8Byte = array[0..7] of byte; var I : integer; A : integer absolute I; K : t8Byte; L : Int64 absolute K; begin I := 0; A := 255; writeln(I); I := 4711;writeln(A);   For i in t8Byte do Begin K[i]:=i; write(i:3,' '); end; writeln(#8#32); writeln(L); end.
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 |...
#Perl
Perl
# 20210218 Perl programming solution   use strict; use warnings;   # create an integer object   print "Here is an integer  : ", my $target = 42, "\n";   # print the machine address of the object   print "And its reference is  : ", my $targetref = \$target, "\n";   # take the address of the object an...
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...
#Raku
Raku
use Math::Polynomial::Cyclotomic:from<Perl5> <cyclo_poly_iterate cyclo_poly>;   say 'First 30 cyclotomic polynomials:'; my $iterator = cyclo_poly_iterate(1); say "Φ($_) = " ~ super $iterator().Str for 1..30;   say "\nSmallest cyclotomic polynomial with |n| as a coefficient:"; say "Φ(1) has a coefficient magnitude: 1"; ...
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...
#Rust
Rust
  fn cwalk(mut vis: &mut Vec<Vec<bool>>, count: &mut isize, w: usize, h: usize, y: usize, x: usize, d: usize) { if x == 0 || y == 0 || x == w || y == h { *count += 1; return; }   vis[y][x] = true; vis[h - y][w - x] = true;   if x != 0 && ! vis[y][x - 1] { cwalk(&mut vis, coun...
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.
#Kotlin
Kotlin
// version 1.0.6   import java.text.SimpleDateFormat import java.util.*   fun main(args: Array<String>) { val dts = "March 7 2009 7:30pm EST" val sdf = SimpleDateFormat("MMMM d yyyy h:mma z") val dt = sdf.parse(dts) val cal = GregorianCalendar(TimeZone.getTimeZone("EST")) // stay with EST cal....
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.
#langur
langur
val .input = "March 7 2009 7:30pm -05:00" val .iformat = "January 2 2006 3:04pm -07:00" # input format val .format = "January 2 2006 3:04pm MST" # output format   val .d1 = toDateTime .input, .iformat val .d2 = .d1 + dt/PT12H/ val .d3 = toDateTime .d2, "US/Arizona" val .d4 = toDateTime .d2, ZLS val .d5 = toDate...
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...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations string 0; \use zero-terminated string convention int RandState;   func Rand; \Random number in range 0 to 32767 [RandState:= (214013*RandState + 2531011) & $7FFF_FFFF; return RandState >> 1...
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...
#zkl
zkl
var suits=T(0x1F0D1,0x1F0C1,0x1F0B1,0x1F0A1); //unicode 🃑,🃁,🂱,🂡   var seed=1; const RMAX32=(1).shiftLeft(31) - 1; fcn rnd{ (seed=((seed*214013 + 2531011).bitAnd(RMAX32))).shiftRight(16) }   fcn game(n){ seed=n; deck:=(0).pump(52,List,'wrap(n){ if(n>=44) n+=4; // I want JQK, not JCQ (suits[n%4] + n/4).t...
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 ...
#Forth
Forth
  \ Zeller's Congruence : weekday ( d m y -- wd) \ 1 mon..7 sun over 3 < if 1- swap 12 + swap then 100 /mod dup 4 / swap 2* - swap dup 4 / + + swap 1+ 13 5 */ + + ( in zeller 0=sat, so -2 to 0= mon, then mod, then 1+ for 1=mon) 2- 7 mod 1+ ;   : yuletide ." December 25 is Sunday in " 2122 2008 do ...
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 ...
#Fortran
Fortran
PROGRAM YULETIDE   IMPLICIT NONE   INTEGER :: day, year   WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" DO year = 2008, 2121 day = Day_of_week(25, 12, year) IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year END DO   CONTAINS   FUNCTION Day_of_week(d, m, y) INTEGER :: Day_of_week, j, k, mm, yy...
http://rosettacode.org/wiki/CUSIP
CUSIP
This page uses content from Wikipedia. The original article was at CUSIP. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) A   CUSIP   is a nine-character alphanumeric code that identifies a North A...
#Icon_and_Unicon
Icon and Unicon
# cusip.icn -- Committee on Uniform Security Identification Procedures   procedure main() local code, codes codes := ["037833100", "17275R102", "38259P508", "594918104", "68389X106", "68389X105"] while code := pop(codes) do { writes(code, " : ") if check_code(code) then write("...
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...
#BBC_BASIC
BBC BASIC
MAXITEMS = 100 FOR i% = 1 TO 8 READ n PRINT "Value = "; n ", running SD = " FNrunningsd(n) NEXT END   DATA 2,4,4,4,5,5,7,9   DEF FNrunningsd(n) PRIVATE list(), i% DIM list(MAXITEMS) i% += 1 list(i%) = n = SQR(MOD(list())^2/i% - (SUM(list(...
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
#Emacs_Lisp
Emacs Lisp
(format-time-string "%Y-%m-%d") (format-time-string "%F") ;; new in Emacs 24 ;; => "2015-11-08"   (format-time-string "%A, %B %e, %Y") ;; => "Sunday, November 8, 2015"
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
#Erlang
Erlang
-module(format_date). -export([iso_date/0, iso_date/1, iso_date/3, long_date/0, long_date/1, long_date/3]). -import(calendar,[day_of_the_week/1]). -import(io,[format/2]). -import(lists,[append/1]).   iso_date() -> iso_date(date()). iso_date(Year, Month, Day) -> iso_date({Year, Month, Day}). iso_date(Date) -> format("...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#BaCon
BaCon
OPTION COLLAPSE TRUE OPTION DELIM ","   csv$ = LOAD$("data.csv")   DOTIMES AMOUNT(csv$, NL$) line$ = TOKEN$(csv$, _, NL$)   IF _ = 1 THEN total$ = APPEND$(line$, 0, "SUM") ELSE line$ = CHANGE$(line$, _, STR$(_*10) ) total$ = APPEND$(total$, 0, line$, NL$) total$ = APPEND$(tot...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#BASIC
BASIC
OPEN "manip.csv" FOR INPUT AS #1 OPEN "manip2.csv" FOR OUTPUT AS #2   LINE INPUT #1, header$ PRINT #2, header$ + ",SUM"   WHILE NOT EOF(1) INPUT #1, c1, c2, c3, c4, c5 sum = c1 + c2 + c3 + c4 + c5 WRITE #2, c1, c2, c3, c4, c5, sum WEND   CLOSE #1, #2 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.
#Groovy
Groovy
class DammAlgorithm { private static final 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], [3, 6, 7, 4, 2, 0, 9, 5, 8, 1], [5, 8, ...
http://rosettacode.org/wiki/Cuban_primes
Cuban primes
The name   cuban   has nothing to do with   Cuba  (the country),   but has to do with the fact that cubes   (3rd powers)   play a role in its definition. Some definitions of cuban primes   primes which are the difference of two consecutive cubes.   primes of the form:   (n+1)3 - n3.   primes of the form:   n3 - ...
#Bracmat
Bracmat
( ( cubanprimes = .  !arg:(?N.?bigN) & :?cubans & (0.1.1):(?cube100k.?cube1.?count) & 0:?i & whl ' ( 1+!i:?i & !i+1:?j & !j^3:?cube2 & !cube2+-1*!cube1:?diff & ( !diff^1/2:~(!diff^?) | (  !count:~>!N & !d...
http://rosettacode.org/wiki/Cuban_primes
Cuban primes
The name   cuban   has nothing to do with   Cuba  (the country),   but has to do with the fact that cubes   (3rd powers)   play a role in its definition. Some definitions of cuban primes   primes which are the difference of two consecutive cubes.   primes of the form:   (n+1)3 - n3.   primes of the form:   n3 - ...
#C
C
#include <limits.h> #include <math.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h>   typedef long long llong_t; struct PrimeArray { llong_t *ptr; size_t size; size_t capacity; };   struct PrimeArray allocate() { struct PrimeArray primes;   primes.size = 0; primes.capacity = 10; ...
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#F.23
F#
  open System open System.IO   let env = Environment.OSVersion.Platform let msg = "Hello Rosetta!"   match env with | PlatformID.Win32NT | PlatformID.Win32S | PlatformID.Win32Windows | PlatformID.WinCE -> File.WriteAllText("TAPE.FILE", msg) | _ -> File.WriteAllText("/dev/tape", msg)  
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Factor
Factor
USING: io.encodings.ascii io.files kernel system ;   "Hello from Rosetta Code!" os windows? "tape.file" "/dev/tape" ? ascii set-file-contents
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Fortran
Fortran
Dim As Integer numarch = Freefile Open "tape.file" For Output As #numarch Print #numarch, "Soy un archivo de cinta ahora, o espero serlo pronto." Close #numarch
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#FreeBASIC
FreeBASIC
Dim As Integer numarch = Freefile Open "tape.file" For Output As #numarch Print #numarch, "Soy un archivo de cinta ahora, o espero serlo pronto." Close #numarch
http://rosettacode.org/wiki/Create_a_file_on_magnetic_tape
Create a file on magnetic tape
The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape.
#Go
Go
package main   import ( "archive/tar" "compress/gzip" "flag" "io" "log" "os" "time" )   func main() { filename := flag.String("file", "TAPE.FILE", "filename within TAR") data := flag.String("data", "", "data for file") outfile := flag.Strin...
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...
#Java
Java
import java.math.*; import java.util.*;   public class Currency { final static String taxrate = "7.65";   enum MenuItem {   Hamburger("5.50"), Milkshake("2.86");   private MenuItem(String p) { price = new BigDecimal(p); }   public final BigDecimal price; }   p...
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...
#Hy
Hy
(defn addN [n] (fn [x] (+ x n)))
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...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) add2 := addN(2) write("add2(7) = ",add2(7)) write("add2(1) = ",add2(1)) end   procedure addN(n) return makeProc{ repeat { (x := (x@&source)[1], x +:= n) } } end   procedure makeProc(A) return (@A[1], A[1]) end
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 |...
#Phix
Phix
poke(0x80,or_bits(peek(0x80),0x40)) #ilASM{ mov al,[0x80] or al,0x40 mov [0x80],al}
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 |...
#PicoLisp
PicoLisp
: (setq IntSpace 12345) # Integer -> 12345   : (setq Address (adr 'IntSpace)) # Encoded machine address -> -2969166782547   : (set (adr Address) 65535) # Set this address to a new value -> 65535   : IntSpace # Show the new value -> 65535
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 |...
#PureBasic
PureBasic
; Allocate a 1Mb memory area work within to avoid conflicts, ; this address could be any number but it may then fail on some systems. *a=AllocateMemory(1024*1024)   ; Write a int wit value "31415" at address +312, ; using pointer '*a' with a displacement. PokeI(*a+312, 31415)   ; Write a float with value Pi at address ...
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 |...
#Racket
Racket
  #lang racket (require ffi/unsafe)   (define x #"Foo") ;; Get the address of the `x' object (printf "The address of `x' is: ~s\n" (cast x _scheme _long)) (define address (cast x _bytes _long)) (printf "The address of the bytestring it holds: ~s\n" address) (define y (cast address _long _bytes)) (printf "Converting thi...
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...
#Sidef
Sidef
var Poly = require('Math::Polynomial') Poly.string_config(Hash(fold_sign => true, prefix => "", suffix => ""))   func poly_interpolation(v) { v.len.of {|n| v.len.of {|k| n**k } }.msolve(v) }   say "First 30 cyclotomic polynomials:" for k in (1..30) { var a = (k+1).of { cyclotomic(k, _) } var Φ = poly_interp...
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...
#Tcl
Tcl
package require Tcl 8.5   proc walk {y x} { global w ww h cnt grid len if {!$y || $y==$h || !$x || $x==$w} { incr cnt 2 return } set t [expr {$y*$ww + $x}] set m [expr {$len - $t}] lset grid $t [expr {[lindex $grid $t] + 1}] lset grid $m [expr {[lindex $grid $m] + 1}] if {![lindex $gri...
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.
#Lasso
Lasso
local(date) = date('March 7 2009 7:30PM EST',-format='MMMM d yyyy h:mma z') #date->add(-hour = 24) #date->timezone = 'GMT'
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.
#Lingo
Lingo
---------------------------------------- -- Returns string representation of given date object in YYYY-MM-DD hh:mm:ii format -- @param {date} dateObj -- @returns {string} ---------------------------------------- on dateToDateTimeString (dateObj) str = "" s = string(dateObj.year) if s.length<4 then put "0000".char...
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 ...
#F.C5.8Drmul.C3.A6
Fōrmulæ
for y = 2008 to 2121 if (parseDate["$y-12-25"] -> ### u ###) == "7" println[y]
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 ...
#Frink
Frink
for y = 2008 to 2121 if (parseDate["$y-12-25"] -> ### u ###) == "7" println[y]
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...
#J
J
ccd =. 10 | 10 - 10 | [: +/ [: , 10 (#.^:_1) (8 $ 1 2) * '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#' i. ] ccd '68389X10' 5
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...
#Java
Java
import java.util.List;   public class Cusip { private static Boolean isCusip(String s) { if (s.length() != 9) return false; int sum = 0; for (int i = 0; i <= 7; i++) { char c = s.charAt(i);   int v; if (c >= '0' && c <= '9') { v = c - 48; ...
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...
#C
C
#include <stdio.h> #include <stdlib.h> #include <math.h>   typedef enum Action { STDDEV, MEAN, VAR, COUNT } Action;   typedef struct stat_obj_struct { double sum, sum2; size_t num; Action action; } sStatObject, *StatObject;   StatObject NewStatObject( Action action ) { StatObject so;   so = malloc(sizeof(...
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
#Euphoria
Euphoria
constant days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"} constant months = {"January","February","March","April","May","June", "July","August","September","October","November","December"}   sequence now   now = date() now[1] += 1900   printf(1,"%d-%02d-%02d\n",now[1..3]) printf(1,"%s...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#BQN
BQN
    csvstr ← ⟨"C1,C2,C3,C4,C5", "1,5,9,13,17", "2,6,10,14,18", "3,7,11,15,19", "4,8,12,16,20"⟩   Split ← (⊢-˜¬×+`)∘=⟜','⊸⊔ strdata ← >Split¨csvstr intdata ← •BQN¨⌾(1⊸↓) strdata sums ← ⟨"SUMS"⟩ ∾+´˘ 1↓ intdata done ← sums ∾˜˘ intdata  
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#C
C
    #define TITLE "CSV data manipulation" #define URL "http://rosettacode.org/wiki/CSV_data_manipulation"   #define _GNU_SOURCE #define bool int #include <stdio.h> #include <stdlib.h> /* malloc...*/ #include <string.h> /* strtok...*/ #include <ctype.h> #include <errno.h>     /** * How to read a CSV file ? */     type...