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... | #Klingphix | Klingphix | include ..\Utilitys.tlhy
%n 100 !n
0 $n repeat
$n [dup sqrt int dup * over
== ( [1 swap set] [drop] ) if] for
$n [ ( "The door " over " is " ) lprint get ( ["OPEN"] ["closed"] ) if print nl] for
( "Time elapsed: " msec " seconds" ) lprint nl
pstack
" " input |
http://rosettacode.org/wiki/Write_to_Windows_event_log | Write to Windows event log | Task
Write script status to the Windows Event Log
| #Scala | Scala | object RegisterWinLogEvent extends App {
import sys.process._
def eventCreate= Seq("EVENTCREATE", "/T", "SUCCESS", "/id", "123", "/l", "APPLICATION", "/so", "Scala RegisterWinLogEvent", "/d", "Rosetta Code Example" ).!!
println(eventCreate)
println(s"\nSuccessfully completed without errors. [total ${sc... |
http://rosettacode.org/wiki/Write_to_Windows_event_log | Write to Windows event log | Task
Write script status to the Windows Event Log
| #Standard_ML | Standard ML |
OS.Process.system "logger \"Log event\" " ;
|
http://rosettacode.org/wiki/Write_to_Windows_event_log | Write to Windows event log | Task
Write script status to the Windows Event Log
| #Tcl | Tcl | package require twapi
# This command handles everything; use “-type error” to write an error message
twapi::eventlog_log "My Test Event" -type info |
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.
| #AutoHotkey | AutoHotkey | file := FileOpen("test.txt", "w")
file.Write("this is a test string")
file.Close() |
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.
| #AWK | AWK |
# syntax: GAWK -f WRITE_ENTIRE_FILE.AWK
BEGIN {
dev = "FILENAME.TXT"
print("(Over)write a file so that it contains a string.") >dev
close(dev)
exit(0)
}
|
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,... | #Red | Red | arr1: [] ;create empty array
arr2: ["apple" "orange" 1 2 3] ;create an array with data
>> insert arr1 "blue"
>> arr1
== ["blue"]
append append arr1 "black" "green"
>> arr1
== ["blue" "black" "green"]
>> arr1/2
== "black"
>> second arr1
== "black"
>> pick arr1 2
== "black" |
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... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
procedure Write_Float_Array is
type Float_Array is array (1..4) of Float;
procedure Write_Columns
( ... |
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... | #Klong | Klong |
flip::{,/{(1-*x),1_x}'x:#y}
i::0;(100{i::i+1;flip(i;x)}:*100:^0)?1
|
http://rosettacode.org/wiki/Write_to_Windows_event_log | Write to Windows event log | Task
Write script status to the Windows Event Log
| #VBScript | VBScript |
Sub write_event(event_type,msg)
Set objShell = CreateObject("WScript.Shell")
Select Case event_type
Case "SUCCESS"
n = 0
Case "ERROR"
n = 1
Case "WARNING"
n = 2
Case "INFORMATION"
n = 4
Case "AUDIT_SUCCESS"
n = 8
Case "AUDIT_FAILURE"
n = 16
End Select
objShell.LogEvent n, msg
Set ob... |
http://rosettacode.org/wiki/Write_to_Windows_event_log | Write to Windows event log | Task
Write script status to the Windows Event Log
| #Wren | Wren | /* write_to_windows_event_log.wren */
class Windows {
foreign static eventCreate(args)
}
var args = [
"/T", "INFORMATION", "/ID", "123", "/L", "APPLICATION",
"/SO", "Wren", "/D", "\"Rosetta Code Example\""
].join(" ")
Windows.eventCreate(args) |
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.
| #BaCon | BaCon | SAVE s$ TO filename$ |
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.
| #BASIC | BASIC | f = freefile
open f, "output.txt"
write f, "This string is to be written to the file"
close f |
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.
| #BBC_BASIC | BBC BASIC | file% = OPENOUT filename$
PRINT#file%, text$
CLOSE#file% |
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,... | #ReScript | ReScript | let arr = [1, 2, 3]
let _ = Js.Array2.push(arr, 4)
arr[3] = 5
Js.log(Js.Int.toString(arr[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... | #ALGOL_68 | ALGOL 68 | PROC writedat = (STRING filename, []REAL x, y, INT x width, y width)VOID: (
FILE f;
INT errno = open(f, filename, stand out channel);
IF errno NE 0 THEN stop FI;
FOR i TO UPB x DO
# FORMAT := IF the absolute exponent is small enough, THEN use fixed ELSE use float FI; #
FORMAT repr x := ( ABS log(x[i])<x... |
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... | #Kotlin | Kotlin | fun oneHundredDoors(): List<Int> {
val doors = BooleanArray(100, { false })
for (i in 0..99) {
for (j in i..99 step (i + 1)) {
doors[j] = !doors[j]
}
}
return doors
.mapIndexed { i, b -> i to b }
.filter { it.second }
.map { it.first + 1 }
} |
http://rosettacode.org/wiki/Write_to_Windows_event_log | Write to Windows event log | Task
Write script status to the Windows Event Log
| #zkl | zkl | zkl: System.cmd(0'|eventcreate "/T" "INFORMATION" "/ID" "123" "/D" "Rosetta Code example"|) |
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>
| #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program createXml64.s */
/* install package libxml++2.6-dev */
/* link with gcc option -I/usr/include/libxml2 -lxml2 */
/*******************************************/
/* Constantes file */
/*******************************************/
/*... |
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.
| #Bracmat | Bracmat | put$("(Over)write a file so that it contains a string.",file,NEW) |
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.
| #C | C | /*
* Write Entire File -- RossetaCode -- dirty hackish solution
*/
#define _CRT_SECURE_NO_WARNINGS // turn off MS Visual Studio restrictions
#include <stdio.h>
int main(void)
{
return 0 >= fputs("ANY STRING TO WRITE TO A FILE AT ONCE.",
freopen("sample.txt","wb",stdout));
}
|
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.
| #C.23 | C# | System.IO.File.WriteAllText("filename.txt", "This file contains a string."); |
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,... | #Retro | Retro |
needs array'
( Create an array with four elements )
^array'new{ 1 2 3 4 } constant a
( Add 10 to each element in an array and update the array with the results )
a [ 10 + ] ^array'map
( Apply a quote to each element in an array; leaves the contents alone )
a [ 10 + putn cr ] ^array'apply
( Display an array )
... |
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... | #Amazing_Hopper | Amazing Hopper |
#include <flow.h>
DEF-MAIN(argv,argc)
VOID( x ), MSET( y, f )
MEM(1,2,3,1.0e11), APND-LST(x), SET( y, x )
SET-ROUND(5), SQRT(y), MOVE-TO(y)
UNSET-ROUND
CAT-COLS( f, y, x )
TOK-SEP( TAB ), SAVE-MAT(f, "filename.txt" )
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... | #AWK | AWK | $ awk 'BEGIN{split("1 2 3 1e11",x);
> split("1 1.4142135623730951 1.7320508075688772 316227.76601683791",y);
> for(i in x)printf("%6g %.5g\n",x[i],y[i])}'
1e+11 3.1623e+05
1 1
2 1.4142
3 1.7321 |
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... | #KQL | KQL | range InitialDoor from 1 to 100 step 1
| extend DoorsVisited=range(InitialDoor, 100, InitialDoor)
| mvexpand DoorVisited=DoorsVisited to typeof(int)
| summarize VisitCount=count() by DoorVisited
| project Door=DoorVisited, IsOpen=(VisitCount % 2) == 1 |
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>
| #ABAP | ABAP |
DATA: xml_string TYPE string.
DATA(xml) = cl_ixml=>create( ).
DATA(doc) = xml->create_document( ).
DATA(root) = doc->create_simple_element( name = 'root'
parent = doc ).
doc->create_simple_element( name = 'element'
parent = root
... |
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.
| #C.2B.2B | C++ | #include <fstream>
using namespace std;
int main()
{
ofstream file("new.txt");
file << "this is a string";
file.close();
return 0;
} |
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.
| #Clojure | Clojure | (spit "file.txt" "this is a 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.
| #COBOL | COBOL |
IDENTIFICATION DIVISION.
PROGRAM-ID. Overwrite.
AUTHOR. Bill Gunshannon.
INSTALLATION. Home.
DATE-WRITTEN. 31 December 2021.
************************************************************
** Program Abstract:
** Simple COBOL task. Open file for output. Write
... |
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,... | #REXX | REXX | /*REXX program demonstrates a simple array usage. */
a.='not found' /*value for all a.xxx (so far).*/
do j=1 to 100 /*start at 1, define 100 elements*/
a.j=-j*1000 /*define as negative J thousand. */
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... | #BASIC256 | BASIC256 | x$ = "1 2 3 1e11"
x$ = explode(x$, " ")
f = freefile
open f, "filename.txt"
for i = 0 to x$[?]-1
writeline f, int(x$[i]) + chr(9) + round(sqrt(x$[i]),4)
next i
close f |
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... | #BBC_BASIC | BBC BASIC | DIM x(3), y(3)
x() = 1, 2, 3, 1E11
FOR i% = 0 TO 3
y(i%) = SQR(x(i%))
NEXT
xprecision = 3
yprecision = 5
outfile% = OPENOUT("filename.txt")
IF outfile%=0 ERROR 100, "Could not create file"
FOR i% = 0 TO 3
@% = &1000000 + (xprecision << 8)
... |
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... | #LabVIEW | LabVIEW | var .doors = arr 100, false
for .i of .doors {
for .j = .i; .j <= len(.doors); .j += .i {
.doors[.j] = not .doors[.j]
}
}
writeln wherekeys .doors |
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>
| #Ada | Ada | with Ada.Text_IO.Text_Streams;
with DOM.Core.Documents;
with DOM.Core.Nodes;
procedure Serialization is
My_Implementation : DOM.Core.DOM_Implementation;
My_Document : DOM.Core.Document;
My_Root_Node : DOM.Core.Element;
My_Element_Node : DOM.Core.Element;
My_Text_Node : DOM.Core.Text;
... |
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>
| #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program createXml.s */
/* install package libxml++2.6-dev */
/* link with gcc option -lxml2 */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*********************************/
/* I... |
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.
| #Common_Lisp | Common Lisp | (with-open-file (str "filename.txt"
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format str "File content...~%")) |
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.
| #D | D | import std.stdio;
void main() {
auto file = File("new.txt", "wb");
file.writeln("Hello World!");
} |
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,... | #Ring | Ring | # create an array with one string in it
a = ['foo']
# add items
a + 1 # ["foo", 1]
# set the value at a specific index in the array
a[1] = 2 # [2, 1]
# retrieve an element
see a[1] |
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... | #C | C | #include <stdio.h>
#include <math.h>
int main(int argc, char **argv) {
float x[4] = {1,2,3,1e11}, y[4];
int i = 0;
FILE *filePtr;
filePtr = fopen("floatArray","w");
for (i = 0; i < 4; i++) {
y[i] = sqrt(x[i]);
fprintf(filePtr, "%.3g\t%.5g\n", x[i], y[i]);
}
return 0;
} |
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... | #langur | langur | var .doors = arr 100, false
for .i of .doors {
for .j = .i; .j <= len(.doors); .j += .i {
.doors[.j] = not .doors[.j]
}
}
writeln wherekeys .doors |
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>
| #AutoHotkey | AutoHotkey | version = "1.0"
xmlheader := "<?xml version=" . version . "?>" . "<" . root . ">"
element("root", "child")
element("root", "element", "more text here")
element("root_child", "kid", "yak yak")
MsgBox % xmlheader . serialize("root")
Return
element(parent, name, text="")
{
Global
%parent%_children .= name . "`n"
... |
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.
| #Delphi | Delphi |
program Write_entire_file;
{$APPTYPE CONSOLE}
uses
System.IoUtils;
begin
TFile.WriteAllText('filename.txt', 'This file contains a string.');
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.
| #Elena | Elena | import system'io;
public program()
{
File.assign("filename.txt").saveContent("This file contains a 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.
| #Elixir | Elixir | File.write("file.txt", string) |
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,... | #RLaB | RLaB |
// 1-D (row- or column-vectors)
// Static:
// row-vector
x = [1:3];
x = zeros(1,3); x[1]=1; x[2]=2; x[3]=3;
// column-vector
x = [1:3]'; // or
x = [1;2;3]; // or
x = zeros(3,1); x[1]=1; x[2]=2; x[3]=3;
// Dynamic:
x = []; // create an empty array
x = [x; 1, 2]; // add a row to 'x' containing [1, 2], o... |
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... | #C.23 | C# | using System.IO;
class Program
{
static void Main(string[] args)
{
var x = new double[] { 1, 2, 3, 1e11 };
var y = new double[] { 1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791 };
int xprecision = 3;
int yprecision = 5;
string formatString = "{0:G" + ... |
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... | #lambdatalk | lambdatalk |
1) unoptimized version
{def doors
{A.new
{S.map {lambda {} false} {S.serie 1 100}}}}
-> doors
{def toggle
{lambda {:i :a}
{let { {_ {A.set! :i {not {A.get :i :a}} :a} }}}}}
-> toggle
{S.map {lambda {:b}
{S.map {lambda {:i} {toggle :i {doors}}}
{S.serie :b 99 {+ :b 1}}}}
{S.serie 0 99}}
->
{S.re... |
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>
| #Bracmat | Bracmat | ( ("?"."xml version=\"1.0\" ")
\n
(root.,"\n " (element.,"
Some text here
") \n)
: ?xml
& out$(toML$!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>
| #C | C | #include <libxml/parser.h>
#include <libxml/tree.h>
int main()
{
xmlDoc *doc = xmlNewDoc("1.0");
xmlNode *root = xmlNewNode(NULL, BAD_CAST "root");
xmlDocSetRootElement(doc, root);
xmlNode *node = xmlNewNode(NULL, BAD_CAST "element");
xmlAddChild(node, xmlNewText(BAD_CAST "some text here"));
xmlAddChild... |
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.
| #F.23 | F# | System.IO.File.WriteAllText("filename.txt", "This file contains a 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.
| #Factor | Factor | USING: io.encodings.utf8 io.files ;
"this is a string" "file.txt" utf8 set-file-contents |
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.
| #Fortran | Fortran | OPEN (F,FILE="SomeFileName.txt",STATUS="REPLACE")
WRITE (F,*) "Whatever you like."
WRITE (F) BIGARRAY |
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,... | #Robotic | Robotic |
set "index" to 0
. "Assign random values to array"
: "loop"
set "array&index&" to random 0 to 99
inc "index" by 1
if "index" < 100 then "loop"
* "Value of index 50 is ('array('50')')."
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... | #C.2B.2B | C++ | template<class InputIterator, class InputIterator2>
void writedat(const char* filename,
InputIterator xbegin, InputIterator xend,
InputIterator2 ybegin, InputIterator2 yend,
int xprecision=3, int yprecision=5)
{
std::ofstream f;
f.exceptions(std::ofstream::failbit | std::of... |
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... | #Lasso | Lasso | loop(100) => {^
local(root = math_sqrt(loop_count))
local(state = (#root == math_ceil(#root) ? '<strong>open</strong>' | 'closed'))
#state != 'closed' ? 'Door ' + loop_count + ': ' + #state + '<br>'
^} |
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>
| #C.23 | C# | using System.Xml;
using System.Xml.Serialization;
[XmlRoot("root")]
public class ExampleXML
{
[XmlElement("element")]
public string element = "Some text here";
static void Main(string[] args)
{
var xmlnamespace = new XmlSerializerNamespaces();
xmlnamespace.Add("", ""); //used to stop def... |
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>
| #C.2B.2B | C++ |
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <utility>
#include <vector>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlerror.h>
#include <libxml/xmlsave.h>
#include <libxml/xmlstring.h>
#include <libxml/xmlversion.h>
#ifndef LIBXML_TREE_ENABLED
... |
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.
| #Free_Pascal | Free Pascal | program overwriteFile(input, output, stdErr);
{$mode objFPC} // for exception treatment
uses
sysUtils; // for applicationName, getTempDir, getTempFileName
// also: importing sysUtils converts all run-time errors to exceptions
resourcestring
hooray = 'Hello world!';
var
FD: text;
begin
// on a Debian GNU/Linux dist... |
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.
| #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Open "output.txt" For Output As #1
Print #1, "This is a string"
Close #1 |
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,... | #RPG | RPG |
//-Static array
//--def of 10 el array of integers, initialised to zeros
D array...
D s 10i 0 dim(10)
D inz
//--def an el
D el_1...
D s 10i 0 inz
/free
//-assign fi... |
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... | #COBOL | COBOL |
identification division.
program-id. wr-float.
environment division.
input-output section.
file-control.
select report-file assign "float.txt"
organization sequential.
data division.
file section.
fd report-file
report is flo... |
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... | #Latitude | Latitude | use 'format importAllSigils.
doors := Object clone.
doors missing := { False. }.
doors check := {
self slot ($1 ordinal).
}.
doors toggle := {
self slot ($1 ordinal) = self slot ($1 ordinal) not.
}.
1 upto 101 do {
takes '[i].
local 'j = i.
while { j <= 100. } do {
doors toggle (j).
j = j + i.
}.
... |
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>
| #Cach.C3.A9_ObjectScript | Caché ObjectScript | USER>set writer=##class(%XML.Writer).%New()
USER>set writer.Charset="UTF-8"
USER>Set writer.Indent=1
USER>Set writer.IndentChars=" "
USER>set sc=writer.OutputToString()
USER>set sc=writer.RootElement("root")
USER>set sc=writer.Element("element")
USER>set sc=writer.WriteChars("Some text here")
USER>set sc=writer.EndE... |
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>
| #Clojure | Clojure |
(require '[clojure.data.xml :as xml])
(def xml-example (xml/element :root {} (xml/element :element {} "Some text here")))
(with-open [out-file (java.io.OutputStreamWriter.
(java.io.FileOutputStream. "/tmp/output.xml") "UTF-8")]
(xml/emit xml-example out-file))
|
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.
| #Frink | Frink |
w = new Writer["test.txt"]
w.print["I am the captain now."]
w.close[]
|
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.
| #Gambas | Gambas | Public Sub Main()
File.Save(User.home &/ "test.txt", "(Over)write a file so that it contains a string.")
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.
| #Go | Go | import "io/ioutil"
func main() {
ioutil.WriteFile("path/to/your.file", []byte("data"), 0644)
} |
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,... | #Ruby | Ruby | # create an array with one object in it
a = ['foo']
# the Array#new method allows several additional ways to create arrays
# push objects into the array
a << 1 # ["foo", 1]
a.push(3,4,5) # ["foo", 1, 3, 4, 5]
# set the value at a specific index in the array
a[0] = 2 # [2, 1, 3, 4, 5]
# a couple o... |
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... | #Common_Lisp | Common Lisp | (with-open-file (stream (make-pathname :name "filename") :direction :output)
(let* ((x (make-array 4 :initial-contents '(1 2 3 1e11)))
(y (map 'vector 'sqrt x))
(xprecision 3)
(yprecision 5)
(fmt (format nil "~~,1,~d,,G~~12t~~,~dG~~%" xprecision yprecision)))
... |
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... | #Lhogho | Lhogho | to doors
;Problem 100 Doors
;Lhogho
for "p [1 100]
[
make :p "false
]
for "a [1 100 1]
[
for "b [:a 100 :a]
[
if :b < 101
[
make :b not thing :b
]
]
]
for "c [1 100]
[
if thing :c
[
(print "door :c "is "open)
]
]
end
doors |
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>
| #Common_Lisp | Common Lisp | (let* ((doc (dom:create-document 'rune-dom:implementation nil nil nil))
(root (dom:create-element doc "root"))
(element (dom:create-element doc "element"))
(text (dom:create-text-node doc "Some text here")))
(dom:append-child element text)
(dom:append-child root element)
(dom:append-child 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>
| #D | D | module xmltest ;
import std.stdio ;
import std.xml ;
void main() {
auto doc = new Document("root") ;
//doc.prolog = q"/<?xml version="1.0"?>/" ; // default
doc ~= new Element("element", "Some text here") ;
writefln(doc) ;
// output: <?xml version="1.0"?><root><element>Some text here</element></root>
} |
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.
| #Groovy | Groovy | new File("myFile.txt").text = """a big string
that can be
splitted over lines
"""
|
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.
| #Haskell | Haskell | main :: IO ( )
main = do
putStrLn "Enter a string!"
str <- getLine
putStrLn "Where do you want to store this string ?"
myFile <- getLine
appendFile myFile 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.
| #J | J | characters fwrite filename |
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" /... | #8th | 8th |
\ Load the XML text into the var 'x':
quote *
<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 T... |
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,... | #Run_BASIC | Run BASIC | print "Enter array 1 greater than 0"; : input a1
print "Enter array 2 greater than 0"; : input a2
dim chrArray$(max(a1,1),max(a2,1))
dim numArray(max(a1,1),max(a2,1))
chrArray$(1,1) = "Hello"
numArray(1,1) = 987.2
print chrArray$(1,1);" ";numArray(1,1) |
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... | #D | D | import std.file, std.conv, std.string;
void main() {
auto x = [1.0, 2, 3, 1e11];
auto y = [1.0, 1.4142135623730951,
1.7320508075688772, 316227.76601683791];
int xPrecision = 3,
yPrecision = 5;
string tmp;
foreach (i, fx; x)
tmp ~= format("%." ~ text(xPrecision) ~ "g... |
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... | #Liberty_BASIC | Liberty BASIC | dim doors(100)
for pass = 1 to 100
for door = pass to 100 step pass
doors(door) = not(doors(door))
next door
next pass
print "open doors ";
for door = 1 to 100
if doors(door) then print door;" ";
next 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>
| #E | E | def document := <unsafe:javax.xml.parsers.makeDocumentBuilderFactory> \
.newInstance() \
.newDocumentBuilder() \
.getDOMImplementation() \
.createDocument(null, "root", null)
def root := document.getDocumentElement()
root.appendChild(
def element... |
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>
| #F.23 | F# | open System.Xml
[<EntryPoint>]
let main argv =
let xd = new XmlDocument()
// Create the required nodes:
xd.AppendChild (xd.CreateXmlDeclaration("1.0", null, null)) |> ignore
let root = xd.AppendChild (xd.CreateNode("element", "root", ""))
let element = root.AppendChild (xd.CreateElement("element",... |
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.
| #Java | Java | import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
try (BufferedWriter bw = new BufferedWriter(new FileWriter("test.txt"))) {
bw.write("abc");
}
}
} |
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.
| #Julia | Julia | function writeFile(filename, data)
f = open(filename, "w")
write(f, data)
close(f)
end
writeFile("test.txt", "Hi there.") |
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" /... | #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program inputXml64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM... |
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,... | #Rust | Rust | let a = [1, 2, 3]; // immutable array
let mut m = [1, 2, 3]; // mutable array
let zeroes = [0; 200]; // creates an array of 200 zeroes |
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... | #11l | 11l | V games = [‘12’, ‘13’, ‘14’, ‘23’, ‘24’, ‘34’]
V results = ‘000000’
F numberToBase(=n, b)
I n == 0
R ‘0’
V digits = ‘’
L n != 0
digits ‘’= String(Int(n % b))
n I/= b
R reversed(digits)
F nextResult()
I :results == ‘222222’
R 0B
V res = Int(:results, radix' 3) + 1
:result... |
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... | #Delphi | Delphi |
program Write_float_arrays_to_a_text_file;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.IoUtils;
function ToString(v: TArray<Double>): TArray<string>;
var
fmt: TFormatSettings;
begin
fmt := TFormatSettings.Create('en-US');
SetLength(Result, length(v));
for var i := 0 to High(v) do
Result[i]... |
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... | #Lily | Lily | var doors = List.fill(100, false)
for i in 0...99:
for j in i...99 by i + 1:
doors[j] = !doors[j]
# The type must be specified since the list starts off empty.
var open_doors: List[Integer] = []
doors.each_index{|i|
if doors[i]:
open_doors.push(i + 1)
}
print($"Open doors: ^(open_doors)"... |
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>
| #Factor | Factor | USING: xml.syntax xml.writer ;
<XML <root><element>Some text here</element></root> XML>
pprint-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>
| #Fantom | Fantom |
using xml
class XmlDom
{
public static Void main ()
{
doc := XDoc()
root := XElem("root")
doc.add (root)
child := XElem("element")
child.add(XText("Some text here"))
root.add (child)
doc.write(Env.cur.out)
}
}
|
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.
| #Kotlin | Kotlin | // version 1.1.2
import java.io.File
fun main(args: Array<String>) {
val text = "empty vessels make most noise"
File("output.txt").writeText(text)
} |
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.
| #Lingo | Lingo | ----------------------------------------
-- Saves string as file
-- @param {string} tFile
-- @param {string} tString
-- @return {bool} success
----------------------------------------
on writeFile (tFile, tString)
fp = xtra("fileIO").new()
fp.openFile(tFile, 2)
err = fp.status()
if not (err) then fp.delete()
... |
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.
| #LiveCode | LiveCode |
put "this is a string" into URL "file:~/Desktop/TestFile.txt"
|
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 ... | #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program outputXml64.s */
/* use special library libxml2 */
/* special link gcc with options -I/usr/include/libxml2 -lxml2 */
/*******************************************/
/* Constantes file */
/*******************************************/
/*... |
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" /... | #ActionScript | ActionScript | package
{
import flash.display.Sprite;
public class XMLReading extends Sprite
{
public function XMLReading()
{
var xml:XML = <Students>
<Student Name="April" />
<Student Name="Bob" />
<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,... | #Sather | Sather | -- a is an array of INTs
a :ARRAY{INT};
-- create an array of five "void" elements
a := #ARRAY{INT}(5);
-- static creation of an array with three elements
b :ARRAY{FLT} := |1.2, 1.3, 1.4|;
-- accessing an array element
c ::= b[0]; -- syntactic sugar for b.aget(0)
-- set an array element
b[1] := c; -- syntactic sugar fo... |
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 | C | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// to supply to qsort
int compare(const void *a, const void *b) {
int int_a = *((int *)a);
int int_b = *((int *)b);
return (int_a > int_b) - (int_a < int_b);
}
char results[7];
bool next_result() {
char *ptr = results + ... |
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... | #Elixir | Elixir | defmodule Write_float_arrays do
def task(xs, ys, fname, precision\\[]) do
xprecision = Keyword.get(precision, :x, 2)
yprecision = Keyword.get(precision, :y, 3)
format = "~.#{xprecision}g\t~.#{yprecision}g~n"
File.open!(fname, [:write], fn file ->
Enum.zip(xs, ys)
|> Enum.each(fn {x, 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... | #Erlang | Erlang |
-module( write_float_arrays ).
-export( [task/0, to_a_text_file/3, to_a_text_file/4] ).
task() ->
File = "afile",
Xs = [1.0, 2.0, 3.0, 1.0e11],
Ys = [1.0, 1.4142135623730951, 1.7320508075688772, 316227.76601683791],
Options = [{xprecision, 3}, {yprecision, 5}],
to_a_text_file( File, Xs, Ys, Options ),
{ok, ... |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.