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/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#xTalk
xTalk
  on mouseUp repeat with tStep = 1 to 100 repeat with tDoor = tStep to 100 step tStep put not tDoors[tDoor] into tDoors[tDoor] end repeat if tDoors[tStep] then put "Door " & tStep & " is open" & cr after tList end repeat set the text of field "Doors" to tList end mouseUp  
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Forth
Forth
include ffl/dom.fs   \ Create a dom variable 'doc' in the dictionary   dom-create doc   \ Add the document root with its version attribute   dom.document doc dom-append-node   s" version" s" 1.0" dom.attribute doc dom-append-node   \ Add root and element   doc dom-parent 2drop   s" root" dom.element doc dom-append-n...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Go
Go
package main   import ( "fmt" dom "gitlab.com/stone.code/xmldom-go.git" )   func main() { d, err := dom.ParseStringXml(` <?xml version="1.0" ?> <root> <element> Some text here </element> </root>`) if err != nil { fmt.Println(err) return } fmt.Println(string(d.ToXm...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Lua
Lua
function writeFile (filename, data) local f = io.open(filename, 'w') f:write(data) f:close() end   writeFile("stringFile.txt", "Mmm... stringy.")
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Maple
Maple
Export("directory/filename.txt", string);
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Export["filename.txt","contents string"]
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#Action.21
Action!
DEFINE PTR="CARD" DEFINE CHARACTER_SIZE="4" TYPE Character=[PTR name,remark]   PTR FUNC GetCharacterPointer(BYTE ARRAY d INT index) RETURN (d+index*CHARACTER_SIZE)   PROC SetCharacter(BYTE ARRAY d INT index CHAR ARRAY n,r) Character POINTER ch   ch=GetCharacterPointer(d,index) ch.name=n ch.remark=r RETURN   PRO...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Ada
Ada
with Sax.Readers; with Input_Sources.Strings; with Unicode.CES.Utf8; with My_Reader;   procedure Extract_Students is Sample_String : String := "<Students>" & "<Student Name=""April"" Gender=""F"" DateOfBirth=""1989-01-02"" />" & "<Student Name=""Bob"" Gender=""M"" DateOfBirth=""1990-03-04"" />" & "<Student ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Scala
Scala
// Create a new integer array with capacity 10 val a = new Array[Int](10)   // Create a new array containing specified items val b = Array("foo", "bar", "baz")   // Assign a value to element zero a(0) = 42   // Retrieve item at element 2 val c = b(2)
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#C.2B.2B
C++
#include <algorithm> #include <array> #include <iomanip> #include <iostream> #include <sstream>   std::array<std::string, 6> games{ "12", "13", "14", "23", "24", "34" }; std::string results = "000000";   int fromBase3(std::string num) { int out = 0; for (auto c : num) { int d = c - '0'; out = 3 ...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#Euphoria
Euphoria
constant x = {1, 2, 3, 1e11}, y = {1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}   integer fn   fn = open("filename","w") for n = 1 to length(x) do printf(fn,"%.3g\t%.5g\n",{x[n],y[n]}) end for close(fn)
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Logo
Logo
to doors ;Problem 100 Doors ;FMSLogo ;lrcvs 2010   make "door (vector 100 1) for [p 1 100][setitem :p :door 0]   for [a 1 100 1][for [b :a 100 :a][make "x item :b :door ifelse :x = 0 [setitem :b :door 1][setitem :b :door 0] ] ]   for [c 1 100][make "y item :c :door ifelse :y = 0...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Groovy
Groovy
import groovy.xml.MarkupBuilder def writer = new StringWriter() << '<?xml version="1.0" ?>\n' def xml = new MarkupBuilder(writer) xml.root() { element('Some text here' ) } println writer
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Haskell
Haskell
import Data.List import Text.XML.Light   xmlDOM :: String -> String xmlDOM txt = showTopElement $ Element (unqual "root") [] [ Elem $ Element (unqual "element") [] [Text $ CData CDataText txt Nothing] Nothing ] Nothing
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#11l
11l
V s = |‘ XX X X X X X XXXXX’   V lines = s.split("\n") V width = max(lines.map(l -> l.len))   L(line) lines print((‘ ’ * (lines.len - L.index - 1))‘’(line.ljust(width).replace(‘ ’, ‘ ’).replace(‘X’, ‘__/’) * 3))
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Nanoquery
Nanoquery
import Nanoquery.IO   new(File, fname).create().write(string)
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Nim
Nim
  writeFile("filename.txt", "An arbitrary string")  
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Objeck
Objeck
use System.IO.File;   class WriteFile { function : Main(args : String[]) ~ Nil { writer ← FileWriter→New("test.txt"); leaving { writer→Close(); }; writer→WriteString("this is a test string"); } }
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm
Xiaolin Wu's line algorithm
Task Implement the   Xiaolin Wu's line algorithm   described in Wikipedia. This algorithm draws anti-aliased lines. Related task   See   Bresenham's line algorithm   for aliased lines.
#Action.21
Action!
INCLUDE "H6:REALMATH.ACT"   REAL one   PROC PutBigPixel(INT x,y,col) IF x>=0 AND x<=79 AND y>=0 AND y<=47 THEN y==LSH 2 IF col<0 THEN col=0 ELSEIF col>15 THEN col=15 FI Color=col Plot(x,y) DrawTo(x,y+3) FI RETURN   INT FUNC Abs(INT x) IF x<0 THEN RETURN (-x) FI RETURN (x)   PROC Swap(INT P...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#Ada
Ada
with Ada.Strings.Unbounded; with Ada.Text_IO.Text_Streams; with DOM.Core.Documents; with DOM.Core.Elements; with DOM.Core.Nodes;   procedure Character_Remarks is package DC renames DOM.Core; package IO renames Ada.Text_IO; package US renames Ada.Strings.Unbounded; type Remarks is record Name : US.Unbo...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Aikido
Aikido
  import xml   var s = openin ("t.xml") var tree = XML.parseStream (s)   foreach node tree { if (node.name == "Students") { foreach studentnode node { if (studentnode.name == "Student") { println (studentnode.getAttribute ("Name")) } } } }    
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Scheme
Scheme
(let ((array #(1 2 3 4 5)) ; vector literal (array2 (make-vector 5)) ; default is unspecified (array3 (make-vector 5 0))) ; default 0 (vector-set! array 0 3) (vector-ref array 0)) ; 3
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Linq.Enumerable;   namespace WorldCupGroupStage { public static class WorldCupGroupStage { static int[][] _histogram;   static WorldCupGroupStage() { ...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#F.23
F#
[<EntryPoint>] let main argv = let x = [ 1.; 2.; 3.; 1e11 ] let y = List.map System.Math.Sqrt x   let xprecision = 3 let yprecision = 5   use file = System.IO.File.CreateText("float.dat") let line = sprintf "%.*g\t%.*g" List.iter2 (fun x y -> file.WriteLine (line xprecision x yprecision y)) ...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#Forth
Forth
create x 1e f, 2e f, 3e f, 1e11 f, create y 1e f, 2e fsqrt f, 3e fsqrt f, 1e11 fsqrt f,   : main s" sqrt.txt" w/o open-file throw to outfile-id   4 0 do 4 set-precision x i floats + f@ f. 6 set-precision y i floats + f@ f. cr loop   outfile-id stdout to outfile-id close-f...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#LOLCODE
LOLCODE
HAI 1.3   I HAS A doors ITZ A BUKKIT IM IN YR hallway UPPIN YR door TIL BOTH SAEM door AN 100 doors HAS A SRS door ITZ FAIL BTW, INISHULIZE ALL TEH DOORZ AS CLOZD IM OUTTA YR hallway   IM IN YR hallway UPPIN YR pass TIL BOTH SAEM pass AN 100 I HAS A door ITZ pass IM IN YR passer doors'Z SRS door R N...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#J
J
serialize=: ('<?xml version="1.0" ?>',LF),;@serialize1&'' serialize1=:4 :0 if.L.x do. start=. y,'<',(0{::x),'>',LF middle=. ;;(}.x) serialize1&.> <' ',y end=. y,'</',(0{::x),'>',LF <start,middle,end else. <y,x,LF end. )
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Java
Java
  import java.io.StringWriter;   import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; ...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#360_Assembly
360 Assembly
THREED CSECT STM 14,12,12(13) BALR 12,0 USING *,12 XPRNT =CL23'0 ####. #. ###.',23 XPRNT =CL24'1 #. #. #. #.',24 XPRNT =CL24'1 ##. # ##. #. #.',24 XPRNT =CL24'1 #. #. #. #. #.',24 XPRNT =CL23'1 ####. ###. ...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#OCaml
OCaml
let write_file filename s = let oc = open_out filename in output_string oc s; close_out oc; ;;   let () = let filename = "test.txt" in let s = String.init 26 (fun i -> char_of_int (i + int_of_char 'A')) in write_file filename s
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Pascal
Pascal
{$ifDef FPC}{$mode ISO}{$endIf} program overwriteFile(FD); begin writeLn(FD, 'Whasup?'); close(FD); end.
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Perl
Perl
use File::Slurper 'write_text'; write_text($filename, $data);
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm
Xiaolin Wu's line algorithm
Task Implement the   Xiaolin Wu's line algorithm   described in Wikipedia. This algorithm draws anti-aliased lines. Related task   See   Bresenham's line algorithm   for aliased lines.
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program xiaolin1.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess displayerror see at end oh this program the instruction include */   /* REMARK 2 : display use a FrameBuffe...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#ALGOL_68
ALGOL 68
# returns a translation of str suitable for attribute values and content in an XML document # OP TOXMLSTRING = ( STRING str )STRING: BEGIN STRING result := ""; FOR pos FROM LWB str TO UPB str DO CHAR c = str[ pos ]; result +:= IF c = "<" THEN "&lt;" ...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program inputXml.s */   /* Constantes */ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall .equ XML_ELEMENT_NODE, 1 .equ XML_ATTRIBUTE_NODE, 2 .equ XML_TEXT_NODE, 3 .equ XML_CDATA_SEC...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Scratch
Scratch
$ include "seed7_05.s7i";   const type: charArray is array [char] string; # Define an array type for arrays with char index. const type: twoDim is array array char; # Define an array type for a two dimensional array.   const proc: main is func local var array integer: array1 is 10 times 0; # A...
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#Common_Lisp
Common Lisp
(defun histo () (let ((scoring (vector 0 1 3)) (histo (list (vector 0 0 0 0 0 0 0 0 0 0) (vector 0 0 0 0 0 0 0 0 0 0) (vector 0 0 0 0 0 0 0 0 0 0) (vector 0 0 0 0 0 0 0 0 0 0))) (team-combs (vector '(0 1) '(0 2) '(0 3) '(1 2) '(1 3) '(2 3))) (single-tupel) ...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#Fortran
Fortran
program writefloats implicit none   real, dimension(10) :: a, sqrta integer :: i integer, parameter :: unit = 40   a = (/ (i, i=1,10) /) sqrta = sqrt(a)   open(unit, file="xydata.txt", status="new", action="write") call writexy(unit, a, sqrta) close(unit)   contains   subroutine writexy(u, x, y) ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Lua
Lua
local is_open = {}   for pass = 1,100 do for door = pass,100,pass do is_open[door] = not is_open[door] end end   for i,v in next,is_open do print ('Door '..i..':',v and 'open' or 'close') end
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#JavaScript
JavaScript
var doc = document.implementation.createDocument( null, 'root', null ); var root = doc.documentElement; var element = doc.createElement( 'element' ); root.appendChild( element ); element.appendChild( document.createTextNode('Some text here') ); var xmlString = new XMLSerializer().serializeToString( doc );
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Julia
Julia
using LightXML   # Modified from the documentation for LightXML.jl. The underlying library requires an encoding string be printed.   # create an empty XML document xdoc = XMLDocument()   # create & attach a root node xroot = create_root(xdoc, "root")   # create the first child xs1 = new_child(xroot, "element")   # add ...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#Action.21
Action!
BYTE ARRAY data = [ $00 $00 $00 $00 $4E $4E $4E $00 $00 $00 $00 $00 $00 $00 $00 $00 $4E $00 $00 $00 $00 $4E $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $4E $00 $00 $00 $00 $00 $00 $46 $47 $00 $00 $47 $00 $00 $00 $00 $00 $00 $00 $42 $47 $47 $00 $00 $42 $47 $47 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Phix
Phix
without js -- (file i/o) integer res = write_lines("file.txt",{"line 1\nline 2"}) if res=-1 then crash("error") end if
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#PHP
PHP
file_put_contents($filename, $data)
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm
Xiaolin Wu's line algorithm
Task Implement the   Xiaolin Wu's line algorithm   described in Wikipedia. This algorithm draws anti-aliased lines. Related task   See   Bresenham's line algorithm   for aliased lines.
#AutoHotkey
AutoHotkey
#SingleInstance, Force #NoEnv SetBatchLines, -1   pToken := Gdip_Startup() global pBitmap := Gdip_CreateBitmap(500, 500) drawLine(100,50,400,400) Gdip_SaveBitmapToFile(pBitmap, A_ScriptDir "\linetest.png") Gdip_DisposeImage(pBitmap) Gdip_Shutdown(pToken) Run, % A_ScriptDir "\linetest.png" ExitApp   plot(x, y, c) { ...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program outputXml.s */   /* Constantes */ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall     /*********************************/ /* Initialized data */ /*********************************/ .data szMe...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Arturo
Arturo
data: { <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08"> <Pet Type="dog" Name="Rover" /> ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Seed7
Seed7
$ include "seed7_05.s7i";   const type: charArray is array [char] string; # Define an array type for arrays with char index. const type: twoDim is array array char; # Define an array type for a two dimensional array.   const proc: main is func local var array integer: array1 is 10 times 0; # A...
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#D
D
void main() { import std.stdio, std.range, std.array, std.algorithm, combinations3;   immutable scoring = [0, 1, 3]; /*immutable*/ auto r3 = [0, 1, 2]; immutable combs = 4.iota.array.combinations(2).array; uint[10][4] histo;   foreach (immutable results; cartesianProduct(r3, r3, r3, r3, r3, r3))...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Dim x(0 To 3) As Double = {1, 2, 3, 1e11} Dim y(0 To 3) As Double = {1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}   Open "output.txt" For Output As #1 For i As Integer = 0 To 2 Print #1, Using "#"; x(i); Print #1, Spc(7); Using "#.####"; y(i) Next Print #1, Using "#^^^^"; x(3)...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#M2000_Interpreter
M2000 Interpreter
  Module Doors100 { Dim Doors(1 to 100) For i=1 to 100 For j=i to 100 step i Doors(j)~ Next j Next i DispAll() ' optimization Dim Doors(1 to 100)=False For i=1 to 10 Doors(i**2)=True Next i Print DispAll() ...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Kotlin
Kotlin
// version 1.1.3   import javax.xml.parsers.DocumentBuilderFactory import javax.xml.transform.dom.DOMSource import java.io.StringWriter import javax.xml.transform.stream.StreamResult import javax.xml.transform.TransformerFactory   fun main(args: Array<String>) { val dbFactory = DocumentBuilderFactory.newInstance() ...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Fixed; use Ada.Strings.Fixed; procedure AsciiArt is art : constant array(1..27) of String(1..14) := (1=>" /\\\\\\ ", 2=>" /\\\", 3|6|9=>" ", 4|12=>" /\\\\\\\\\\ ", 5|8|11=>" \/\\\", 7|17|21=>" /\\\//////\\\", ...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#PicoLisp
PicoLisp
(out "file.txt" (prinl "My string") )
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Pike
Pike
Stdio.write_file("file.txt", "My string");
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#PowerShell
PowerShell
  Get-Process | Out-File -FilePath .\ProcessList.txt  
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm
Xiaolin Wu's line algorithm
Task Implement the   Xiaolin Wu's line algorithm   described in Wikipedia. This algorithm draws anti-aliased lines. Related task   See   Bresenham's line algorithm   for aliased lines.
#BBC_BASIC
BBC BASIC
PROCdrawAntiAliasedLine(100, 100, 600, 400, 0, 0, 0) END   DEF PROCdrawAntiAliasedLine(x1, y1, x2, y2, r%, g%, b%) LOCAL dx, dy, xend, yend, grad, yf, xgap, ix1%, iy1%, ix2%, iy2%, x%   dx = x2 - x1 dy = y2 - y1 IF ABS(dx) < ABS(dy) THEN SWAP x1, y1 SWAP x2, y2 ...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#AutoHotkey
AutoHotkey
gosub constants names := xmlescape(names) remarks := xmlescape(remarks)   stringsplit, remarks, remarks, `n xml = "<CharacterRemarks>"   loop, parse, names, `n xml .= "<Character name=" . A_LoopField . ">" . remarks%A_Index% . "</Character>`n"   xml .= "</CharacterRemarks>"   msgbox % xml return   xmlescape(string)...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#AutoHotkey
AutoHotkey
students = ( <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08"> <Pet Type="dog" Name="Rover" /> </Studen...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Self
Self
vector copySize: 100
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#Elena
Elena
import system'routines; import extensions;   public singleton program { static games := new string[]{"12", "13", "14", "23", "24", "34"};   static results := "000000";   nextResult() { var s := results;   if (results=="222222") { ^ false };   results := (results.toInt(3) + 1).toS...
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#Elixir
Elixir
defmodule World_Cup do def group_stage do results = [[3,0],[1,1],[0,3]] teams = [0,1,2,3] allresults = combos(2,teams) |> combinations(results) allpoints = for list <- allresults, do: (for {l1,l2} <- list, do: Enum.zip(l1,l2)) |> List.flatten totalpoints = for list <- allpoints, do: (for t <- team...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#Go
Go
package main   import ( "fmt" "os" )   var ( x = []float64{1, 2, 3, 1e11} y = []float64{1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}   xprecision = 3 yprecision = 5 )   func main() { if len(x) != len(y) { fmt.Println("x, y different length") return } ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#M4
M4
define(`_set', `define(`$1[$2]', `$3')')dnl define(`_get', `defn(`$1[$2]')')dnl define(`for',`ifelse($#,0,``$0'',`ifelse(eval($2<=$3),1, `pushdef(`$1',$2)$5`'popdef(`$1')$0(`$1',eval($2+$4),$3,$4,`$5')')')')dnl define(`opposite',`_set(`door',$1,ifelse(_get(`door',$1),`closed',`open',`closed'))')dnl define(`upper',`100'...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Lasso
Lasso
  content_type( 'text/xml' );// set MIME type if serving   xml( '<?xml version="1.0" ?><root><element>Some text here</element></root>' );    
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Lingo
Lingo
-- create an XML document doc = newObject("XML", "<?xml version='1.0' ?>")   root = doc.createElement("root") doc.appendChild(root)   element = doc.createElement("element") root.appendChild(element)   textNode = doc.createTextNode("Some text here") element.appendChild(textNode)   put doc.toString() -- "<?xml version=...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#Arturo
Arturo
print {: ______ __ /\ _ \ /\ \__ \ \ \L\ \ _ __\ \ ,_\ __ __ _ __ ___ \ \ __ \/\`'__\ \ \/ /\ \/\ \/\`'__\/ __`\ \ \ \/\ \ \ \/ \ \ \_\ \ \_\ \ \ \//\ \L\ \ \ \_\ \_\ \_\ \ \__\\ \____/\ \_\\ \____/ \/_/\/_/\/_/ \/__/ \/___/ \/...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#PureBasic
PureBasic
  EnableExplicit   Define fOutput$ = "output.txt" ; enter path of file to create or overwrite Define str$ = "This string is to be written to the file"   If OpenConsole() If CreateFile(0, fOutput$) WriteString(0, str$) CloseFile(0) Else PrintN("Error creating or opening output file") EndIf PrintN...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Python
Python
with open(filename, 'w') as f: f.write(data)
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Racket
Racket
#lang racket/base (with-output-to-file "/tmp/out-file.txt" #:exists 'replace (lambda () (display "characters")))
http://rosettacode.org/wiki/Wordiff
Wordiff
Wordiff is an original game in which contestants take turns spelling new dictionary words of three or more characters that only differ from the last by a change in one letter. The change can be either: a deletion of one letter; addition of one letter; or change in one letter. Note: All words must be in the...
#11l
11l
V dict_fname = ‘unixdict.txt’   F load_dictionary(String fname = dict_fname) ‘Return appropriate words from a dictionary file’ R Set(File(fname).read().split("\n").filter(word -> re:‘[a-z]{3,}’.match(word)))   F get_players() V names = input(‘Space separated list of contestants: ’) R names.trim(‘ ’).split(‘...
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm
Xiaolin Wu's line algorithm
Task Implement the   Xiaolin Wu's line algorithm   described in Wikipedia. This algorithm draws anti-aliased lines. Related task   See   Bresenham's line algorithm   for aliased lines.
#C
C
void draw_line_antialias( image img, unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, color_component r, color_component g, color_component b );
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#BASIC
BASIC
100 Q$ = CHR$(34) 110 DE$(0) = "April" 120 RE$(0) = "Bubbly: I'm > Tam and <= Emily" 130 DE$(1) = "Tam O'Shanter" 140 RE$(1) = "Burns: " + Q$ + "When chapman billies leave the street ..." + Q$ 150 DE$(2) = "Emily" 160 RE$(2) = "Short & shrift"   200 Print "<CharacterRemarks>" 210 For I = 0 to 2 220 Print " <Chara...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#AWK
AWK
function parse_buf() { if ( match(buffer, /<Student[ \t]+[^>]*Name[ \t]*=[ \t]*"([^"]*)"/, mt) != 0 ) { students[mt[1]] = 1 } buffer = "" }   BEGIN { FS="" mode = 0 buffer = "" li = 1 }   mode==1 { for(i=1; i <= NF; i++) { buffer = buffer $i if ( $i == ">" ) { mode = 0; b...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#SenseTalk
SenseTalk
// Initial creation of an array set a to (1, 2, 3)   // pushing a value to the array // Both approaches are valid insert 4 after a push 5 into a   put a -- (1, 2, 3, 4, 5)   // Treating the array as a stack, using `push` and `pop` pop a into v1   put a -- (1, 2, 3, 4) put v1-- 5   // Treating the array as a queue, usin...
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#Erlang
Erlang
  -module(world_cup).   -export([group_stage/0]).   group_stage() -> Results = [[3,0],[1,1],[0,3]], Teams = [1,2,3,4], Matches = combos(2,Teams), AllResults = combinations(Matches,Results), AllPoints = [lists:flatten([lists:zip(L1,L2) || {L1,L2} <- L]) || L <- AllResults], TotalPoints = [ [ {T,lists:sum(...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#Haskell
Haskell
import System.IO import Text.Printf import Control.Monad   writeDat filename x y xprec yprec = withFile filename WriteMode $ \h -> -- Haskell's printf doesn't support a precision given as an argument for some reason, so we insert it into the format manually: let writeLine = hPrintf h $ "%." ++ show xprec ++...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#HicEst
HicEst
REAL :: n=4, x(n), y(n) CHARACTER :: outP = "Test.txt"   OPEN(FIle = outP) x = (1, 2, 3, 1E11) y = x ^ 0.5 DO i = 1, n WRITE(FIle=outP, Format='F5, F10.3') x(i), y(i) ENDDO
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#MAD
MAD
NORMAL MODE IS INTEGER DIMENSION OPEN(100) PRINT COMMENT $ $   R MAKE SURE ALL DOORS ARE CLOSED AT BEGINNING THROUGH CLOSE, FOR DOOR=1, 1, DOOR.G.100 CLOSE OPEN(DOOR) = 0   R MAKE 100 PASSES THROUGH TOGGLE, FOR PASS=1, 1, PASS.G.100 ...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Lua
Lua
require("LuaXML") local dom = xml.new("root") local element = xml.new("element") table.insert(element, "Some text here") dom:append(element) dom:save("dom.xml")
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
DOM = XMLObject["Document"][{XMLObject["Declaration"]["Version" -> "1.0","Encoding" -> "utf-8"]}, XMLElement["root", {}, {XMLElement["element", {}, {"Some text here"}]}], {}]; ExportString[DOM, "XML", "AttributeQuoting" -> "\""]
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#AutoHotkey
AutoHotkey
AutoTrim, Off draw = ( ______ __ __ __ __ /\ __ \/\ \_\ \/\ \/ / \ \ __ \ \ __ \ \ _"-. \ \_\ \_\ \_\ \_\ \_\ \_\ \/_/\/_/\/_/\/_/\/_/\/_/ ) Gui, +ToolWindow Gui, Color, 1A1A1A, 1A1A1A Gui, Font, s8 cLime w800, Courier New Gui, Add, text, x4 y0 , % " " draw Gui, Show, w192 h82, AHK in 3D return ...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Raku
Raku
spurt 'path/to/file', $file-data;
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#RATFOR
RATFOR
    # Program to overwrite an existing file   open(11,FILE="file.txt") 101 format(A) write(11,101) "Hello World" close(11)   end  
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#REXX
REXX
  /*REXX*/   of='file.txt' 'erase' of s=copies('1234567890',10000) Call charout of,s Call lineout of Say chars(of) length(s)
http://rosettacode.org/wiki/Wordiff
Wordiff
Wordiff is an original game in which contestants take turns spelling new dictionary words of three or more characters that only differ from the last by a change in one letter. The change can be either: a deletion of one letter; addition of one letter; or change in one letter. Note: All words must be in the...
#Arturo
Arturo
wordset: map read.lines relative "unixdict.txt" => strip   validAnswer?: function [answer][ if not? contains? wordset answer [ prints "\tNot a valid dictionary word." return false ] if contains? pastWords answer [ prints "\tWord already used." return false ] if 1 <> l...
http://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm
Xiaolin Wu's line algorithm
Task Implement the   Xiaolin Wu's line algorithm   described in Wikipedia. This algorithm draws anti-aliased lines. Related task   See   Bresenham's line algorithm   for aliased lines.
#C.2B.2B
C++
  #include <functional> #include <algorithm> #include <utility>   void WuDrawLine(float x0, float y0, float x1, float y1, const std::function<void(int x, int y, float brightess)>& plot) { auto ipart = [](float x) -> int {return int(std::floor(x));}; auto round = [](float x) -> float {return std:...
http://rosettacode.org/wiki/XML/Output
XML/Output
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks. All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element. As an example, calling ...
#Bracmat
Bracmat
( ( 2XML = PCDATAentities attributeValueEntities doAll doAttributes , xml . ( attributeValueEntities = a c . @( !arg  :  ?a (("<"|"&"|\"):?c)  ?arg ) &  !a "&" ...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"XMLLIB" xmlfile$ = "C:\students.xml" PROC_initXML(xmlobj{}, xmlfile$)   level% = FN_skipTo(xmlobj{}, "Students", 0) IF level%=0 ERROR 100, "Students not found"   REPEAT IF FN_isTag(xmlobj{}) THEN tag$ = FN_nextToken(xmlobj{}) IF LEFT$(tag$, ...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Sidef
Sidef
# create an empty array var arr = [];   # push objects into the array arr << "a"; #: ['a'] arr.append(1,2,3); #: ['a', 1, 2, 3]   # change an element inside the array arr[2] = "b"; #: ['a', 1, 'b', 3]   # set the value at a specific index in the array (with autovivification) arr[5] = "end"; #...
http://rosettacode.org/wiki/World_Cup_group_stage
World Cup group stage
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years.   Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other internat...
#Go
Go
package main   import ( "fmt" "sort" "strconv" )   var games = [6]string{"12", "13", "14", "23", "24", "34"} var results = "000000"   func nextResult() bool { if results == "222222" { return false } res, _ := strconv.ParseUint(results, 3, 32) results = fmt.Sprintf("%06s", strconv.For...
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#Icon_and_Unicon
Icon and Unicon
link printf   procedure main() every put(x := [], (1 to 3) | 1e11) every put(y := [], sqrt(!x)) every fprintf(open("filename","w"),"%10.2e %10.4e\n", x[i := 1 to *x], y[i]) end
http://rosettacode.org/wiki/Write_float_arrays_to_a_text_file
Write float arrays to a text file
Task Write two equal-sized numerical arrays 'x' and 'y' to a two-column text file named 'filename'. The first column of the file contains values from an 'x'-array with a given 'xprecision', the second -- values from 'y'-array with 'yprecision'. For example, considering: x = {1, 2, 3, 1e11}; y = {1, 1.41421356...
#IDL
IDL
; the data: x = [1,2,3,1e11] y=sqrt(x) xprecision=3 yprecision=5 ; NOT how one would do things in IDL, but in the spirit of the task - the output format: form = string(xprecision,yprecision,format='("(G0.",I0.0,",1x,G0.",I0.0,")")') ; file I/O: openw,unit,"datafile.txt",/get for i = 1L, n_elements(x) do printf, u...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Maple
Maple
  NDoors := proc( N :: posint ) # Initialise, using 0 to represent "closed" local pass, door, doors := Array( 1 .. N, 'datatype' = 'integer'[ 1 ] ); # Now do N passes for pass from 1 to N do for door from pass by pass while door <= N do doors[ door...
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#MATLAB
MATLAB
docNode = com.mathworks.xml.XMLUtils.createDocument('root'); docRootNode = docNode.getDocumentElement; thisElement = docNode.createElement('element'); thisElement.appendChild(docNode.createTextNode('Some text here')); docRootNode.appendChild(thisElement);  
http://rosettacode.org/wiki/XML/DOM_serialization
XML/DOM serialization
Create a simple DOM and having it serialize to: <?xml version="1.0" ?> <root> <element> Some text here </element> </root>
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   import java.io.StringWriter import javax.xml. import org.w3c.dom.   class RDOMSerialization public   properties private domDoc = Document   method main(args = String[]) public static   lcl = RDOMSerialization() lcl.buildDOMDocument() ...
http://rosettacode.org/wiki/Write_language_name_in_3D_ASCII
Write language name in 3D ASCII
Task Write/display a language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.) Related tasks draw a sphere draw a cuboid draw a rotating cube draw a Deathstar
#AWK
AWK
  # syntax: GAWK -f WRITE_LANGUAGE_NAME_IN_3D_ASCII.AWK BEGIN { arr[1] = " xxxx x x x x" arr[2] = "x x x x x x" arr[3] = "x x x x x x" arr[4] = "xxxxxx x x xx" arr[5] = "x x x xx x xx" arr[6] = "x x xx xx x x" arr[7] = "x x xx xx x...
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Ring
Ring
  write("myfile.txt","Hello, World!")  
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Ruby
Ruby
open(fname, 'w'){|f| f.write(str) }
http://rosettacode.org/wiki/Write_entire_file
Write entire file
Task (Over)write a file so that it contains a string. The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.
#Rust
Rust
use std::fs::File; use std::io::Write;   fn main() -> std::io::Result<()> { let data = "Sample text."; let mut file = File::create("filename.txt")?; write!(file, "{}", data)?; Ok(()) }