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/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Euphoria | Euphoria | include EuWinGUI.ew
Window("EuWinGUI - Simple windowed application",100,100,360,100)
constant Button1 = Control(Button,"Click me",250,20,80,25)
constant Label1 = Control(Label,"There have been no clicks yet",10,25,200,18)
integer clicks
clicks = 0
-- Event loop
while 1 do
WaitEvent()
if EventOwner = Butto... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #PicoLisp | PicoLisp | (mapc println '(a "cde" (X Y Z) 999)) |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #PL.2FI | PL/I | *process source attributes xref or(!);
/*********************************************************************
* 25.10.2013 Walter Pachl
* 'set dd:in=d:\sll.txt,recsize(80)'
* 'sll'
*********************************************************************/
sll: Proc Options(main);
Dcl in Record Input;
Dcl sysp... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #REXX | REXX | /*REXX program demonstrates how to create and show a single-linked list.*/
@.=0 /*define a null linked list. */
call set@ 3 /*linked list: 12 Proth primes. */
call set@ 5
call set@ 13
call set@ 17
call set@ 41
call set@ 97
call set@ 113
call set@ 193
cal... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #IDL | IDL |
read,i,prompt='Input sleep time in seconds: '
print,'Sleeping...'
wait,i ; in seconds, but accepts floats(/fractional) as input
print,'Awake!'
|
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #J | J | sleep =: 6!:3
sleeping=: monad define
smoutput 'Sleeping...'
sleep y
smoutput 'Awake!'
) |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #zkl | zkl | fcn bubbleSort(list){
itemCount := list.len();
do{
hasChanged := False;
foreach index in (itemCount -= 1){
if (list[index] > list[index + 1]){
list.swap(index,index + 1);
hasChanged = True;
}
}
}while(hasChanged);
list
} |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #11l | 11l | F sierpinski_square(fname, size, length, order)
V x = (size - length) / 2
V y = Float(length)
V angle = 0.0
V outfile = File(fname, ‘w’)
outfile.write(‘<svg xmlns='http://www.w3.org/2000/svg' width='’size‘' height='’size"'>\n")
outfile.write("<rect width='100%' height='100%' fill='white'/>\n")
ou... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #F.23 | F# | open System.Windows.Forms
let mutable clickCount = 0
let form = new Form()
let label = new Label(Text = "There have been no clicks yet.", Dock = DockStyle.Top)
form.Controls.Add(label)
let button = new Button(Text = "Click me", Dock = DockStyle.Bottom)
button.Click.Add(fun _ ->
clickCount <- clickCount+1
... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #PureBasic | PureBasic | Procedure traverse(*node.MyData)
While *node
;access data, i.e. PrintN(Str(*node\Value))
*node = *node\next
Wend
EndProcedure
;called using
traverse(*firstnode.MyData) |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Python | Python | for node in lst:
print node.value |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Ruby | Ruby | class ListNode
def insert_after(search_value, new_value)
if search_value == value
self.succ = self.class.new(new_value, succ)
elsif self.succ.nil?
raise StandardError, "value #{search_value} not found in list"
else
self.succ.insert_after(search_value, new_value)
end
end
end
list ... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Rust | Rust | impl<T> List<T> {
pub fn new() -> Self {
List { head: None }
}
pub fn push(&mut self, elem: T) {
let new_node = Box::new(Node {
elem: elem,
next: self.head.take(),
});
self.head = Some(new_node);
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Java | Java |
import java.util.InputMismatchException;
import java.util.Scanner;
public class Sleep {
public static void main(final String[] args) throws InterruptedException {
try {
int ms = new Scanner(System.in).nextInt(); //Java's sleep method accepts milliseconds
System.out.println("Sleep... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #JavaScript | JavaScript | <script>
setTimeout(function () {
document.write('Awake!')
}, prompt("Number of milliseconds to sleep"));
document.write('Sleeping... ');
</script> |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 5000 CLS
5002 LET a$="": FOR f=1 TO 64: LET a$=a$+CHR$ (32+INT (RND*96)): NEXT f
5004 PRINT a$; AT 10,0;"ZigZag BubbleSORT"
5010 LET la=LEN a$
5011 LET i=1: LET u=0
5020 LET d=0: LET p=(u=0)-(u=1)
5021 LET l=(i AND u=0)+(la-i+u AND u=1)
5030 IF u=0 THEN IF a$(l+1)>=a$(l) THEN GO TO 5050
5031 IF u=1 THEN IF a$(l-1)<... |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #C.2B.2B | C++ | // See https://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve#Representation_as_Lindenmayer_system
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
class sierpinski_square {
public:
void write(std::ostream& out, int size, int length, int order);
private:
static std::string rewrite(const ... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Factor | Factor | USING: accessors arrays kernel math math.parser namespaces
sequences ui ui.gadgets ui.gadgets.borders ui.gadgets.buttons
ui.gadgets.grids ui.gadgets.labels ui.gadgets.worlds ;
IN: rosetta-code.simple-windowed-application
SYMBOL: n
CONSTANT: on-btn-press [
parents second n get number>string <label> { 0 1 }
g... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Fantom | Fantom |
using fwt
using gfx
class SimpleApplication
{
public static Void main ()
{
Window
{
title = "Simple Window Application"
size = Size(350, 50)
clicked := 0
label := Label
{
text = "There have been no clicks yet"
}
Button
{
text = "Click me"
... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Racket | Racket |
#lang racket
(define l (list 1 2 3))
;; scan the list and collect a list of function results
(map add1 l)
;; scan the list and run some function on each element for its side-effect
(for-each displayln l)
;; scan a list and sum up its elements
(foldl + 0 l)
;; same as the above three, using a more modern syn... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Raku | Raku | my $list = 1 => 2 => 3 => 4 => 5 => 6 => Mu;
loop (my $l = $list; $l; $l.=value) {
say $l.key;
} |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Scala | Scala |
/*
Here is a basic list definition
sealed trait List[+A]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
case object Nil extends List[Nothing]
*/
object List {
def add[A](as: List[A], a: A): List[A] = Cons(a, as)
}
|
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Scheme | Scheme | (define (insert-after a b lst)
(if (null? lst)
lst ; This should be an error, but we will just return the list untouched
(let ((c (car lst))
(cs (cdr lst)))
(if (equal? a c)
(cons a (cons b cs))
(cons c (insert-after a b cs)))))) |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Jsish | Jsish | /*
Sleep, in Jsish
*/
printf('Sleep time (in milliseconds)? ');
var ms = parseInt(console.input());
puts('Sleeping...');
sleep(ms);
puts('Awake!'); |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Julia | Julia |
print("Please enter sleep duration in seconds: ")
input = int(readline(STDIN))
println("Sleeping...")
sleep(input)
println("Awake!")
|
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Factor | Factor | USING: accessors kernel L-system sequences ui ;
: square-curve ( L-system -- L-system )
L-parser-dialect >>commands
[ 90 >>angle ] >>turtle-values
"F+XF+F+XF" >>axiom
{
{ "X" "XF-F+F-XF+F+XF-F+F-X" }
} >>rules ;
[
<L-system> square-curve
"Sierpinski square curve" open-window
] wi... |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Go | Go | package main
import (
"github.com/fogleman/gg"
"github.com/trubitsyn/go-lindenmayer"
"log"
"math"
)
const twoPi = 2 * math.Pi
var (
width = 770.0
height = 770.0
dc = gg.NewContext(int(width), int(height))
)
var cx, cy, h, theta float64
func main() {
dc.SetRGB(0, 0, 1) // b... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Forth | Forth | also minos
text-label ptr click-label
Variable click# click# off
: click-win ( -- ) screen self window new window with
X" There have been no clicks yet" text-label new
dup F bind click-label
^ S[ 1 click# +!
click# @ 0 <# #S s" Number of clicks: " holds #>
click-label assign ]S X" Click... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #FreeBASIC | FreeBASIC |
#Include "windows.bi"
Dim As HWND Window_Main, Static_Text, Button_Click
Dim As MSG msg
Dim As Integer Num_Click
Dim As String Text
'Create a window with a static text control and a button:
Window_Main = CreateWindow("#32770", "Simple Windowed Application", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 350, 200, 0... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Retro | Retro | : traverse ( l- ) repeat @ 0; again ; |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #REXX | REXX | /* REXX ********************************************************************
* 25.10.2013 Walter Pachl
*********************************************************************/
in='d:\sll.txt'
Do i=1 By 1 while lines(in)>0
rec=linein(in)
elem.i.val=rec
elem.i.next=0
ip=i-1
elem.ip.next=i
End;
c=1
Do While c<>0... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Sidef | Sidef | func insert_after(a,b) {
b{:next} = a{:next};
a{:next} = b;
}
var B = Hash.new(
data => 3,
next => nil, # not a circular list
);
var A = Hash.new(
data => 1,
next => B,
);
var C = Hash.new(
data => 2,
);
insert_after(A, C); |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Stata | Stata |
proc insertIntoList {existingList predecessor newElement} {
upvar $existingList exList
set exList [linsert $exList [expr [lsearch -exact $exList $predecessor] + 1] $newElement]
}
set list {A B}
insertIntoList list A C
puts $list
|
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
print("Enter number of milliseconds to sleep: ")
val ms = readLine()!!.toLong()
println("Sleeping...")
Thread.sleep(ms)
println("Awake!")
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #LabVIEW | LabVIEW | stdoutnl('Sleeping...')
sleep(5000) // Sleep 5 seconds
stdoutnl('Awake!') |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Java | Java | import java.io.*;
public class SierpinskiSquareCurve {
public static void main(final String[] args) {
try (Writer writer = new BufferedWriter(new FileWriter("sierpinski_square.svg"))) {
SierpinskiSquareCurve s = new SierpinskiSquareCurve(writer);
int size = 635, length = 5;
... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #FutureBasic | FutureBasic | _window = 1
begin enum 1
_label
_clickMeBtn
end enum
void local fn BuildWindow
window _window, @"Simple Windowed Application", (0,0,366,59)
textlabel _label, @"There have been no clicks yet", (18,23,250,16)
button _clickMeBtn,,, @"Click Me", (267,13,86,32)
end fn
void local fn ButtonClicked
static... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Gambas | Gambas | iCount As Integer 'Counter of clicks!
hLabel As Label 'We need a Label
Public Sub Form_Open()
Dim hButton As Button 'We need a Button
With Me ... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Ruby | Ruby | head = ListNode.new("a", ListNode.new("b", ListNode.new("c")))
head.insertAfter("b", "b+")
# then:
head.each {|node| print node.value, ","}
puts
# or
current = head
begin
print current.value, ","
end while current = current.succ
puts |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Run_BASIC | Run BASIC | list$ = "now is the time for all good men"
for lnk = 1 to 8
print lnk;"->";word$(list$,lnk)
next lnk |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Tcl | Tcl |
proc insertIntoList {existingList predecessor newElement} {
upvar $existingList exList
set exList [linsert $exList [expr [lsearch -exact $exList $predecessor] + 1] $newElement]
}
set list {A B}
insertIntoList list A C
puts $list
|
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Wren | Wren | import "/llist" for LinkedList
var ll = LinkedList.new(["A", "B"])
ll.insertAfter("A", "C")
System.print(ll) |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Lasso | Lasso | stdoutnl('Sleeping...')
sleep(5000) // Sleep 5 seconds
stdoutnl('Awake!') |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Lhogho | Lhogho | make "Void "V0
make "Long "U4
make "kernel32_handle libload "kernel32.dll
to Sleep :dwMilliseconds
end
external "Sleep [ Void Sleep Long] :kernel32_handle
to millisleep :n
print [Sleeping...]
Sleep :n ; units: 1/1000th of a second
print [Awake.]
end |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #jq | jq | include "simple-turtle" {search: "."};
def rules: {"X": "XF-F+F-XF+F+XF-F+F-X"};
def sierpinski($count):
rules as $rules
| def p($count):
if $count <= 0 then .
else gsub("X"; $rules["X"]) | p($count-1)
end;
"F+XF+F+XF" | p($count) ;
def interpret($x):
if $x == "+" then turtleRotate(90)... |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Julia | Julia | using Lindenmayer # https://github.com/cormullion/Lindenmayer.jl
scurve = LSystem(Dict("X" => "XF-F+F-XF+F+XF-F+F-X"), "F+XF+F+XF")
drawLSystem(scurve,
forward = 3,
turn = 90,
startingy = -400,
iterations = 6,
filename = "sierpinski_square_curve.png",
showpreview = true
)
|
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Graphics[SierpinskiCurve[3]] |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Nim | Nim | import math
type
SierpinskiCurve = object
x, y: float
angle: float
length: int
file: File
proc line(sc: var SierpinskiCurve) =
let theta = degToRad(sc.angle)
sc.x += sc.length.toFloat * cos(theta)
sc.y += sc.length.toFloat * sin(theta)
sc.file.write " L", sc.x, ',', sc.y
proc execu... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Gastona | Gastona | #javaj#
<frames> main, Simple click counter
<layout of main>
PANEL, X
bClick me, lClicks
#data#
<NN> 0
<lClicks> //There have been no clicks yet
#listix#
<-- bClick me>
NUM=, NN, NN+1
-->, lClicks data!,, //@<NN> clicks so far
|
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Go | Go | package main
import (
"fmt"
"github.com/mattn/go-gtk/gtk"
)
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("Click me")
label := gtk.NewLabel("There have been no clicks yet")
var clicks int
button := gtk.NewButtonWithLabel("click me")
butt... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Rust | Rust | //
//
// Iteration by value (simply empties the list as the caller now owns all values)
//
//
pub struct IntoIter<T>(List<T>);
impl<T> Iterator for IntoIter<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
self.0.head.take().map(|node| {
let node = *node;
self.0... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Scala | Scala |
/*
Here is a basic list definition
sealed trait List[+A]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
case object Nil extends List[Nothing]
*/
def traverse[A](as: List[A]): Unit = as match {
case Nil => print("End")
case Cons(h, t) => {
print(h + " ")
traverse(t)
}
}
|
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #X86_Assembly | X86 Assembly |
; x86_64 Linux NASM
; Linked_List_Insert.asm
%ifndef INSERT
%define INSERT
%include "Linked_List_Definition.asm" ; see LL def task
%include "Heap_Alloc.asm" ; see memory allocation task
section .text
; rdi - link to insert after
; rsi - value that the new link will hold
Insert_After:
push rdi
push rsi
m... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #XPL0 | XPL0 | def \Node\ Link, Data; \linked list element definition
def IntSize = 4; \number of bytes in an integer
proc Insert(List, Node); \Insert Node into List
int List, Node;
[Node(Link):= List(Link);
List(Link):= Node;
];
int MyNode, MyList;
int A, B, C;
[A:= Reserve(2*IntSize);
B:= Reser... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Yabasic | Yabasic | // Rosetta Code problem: http://rosettacode.org/wiki/Singly-linked_list/Element_insertion
// by Galileo, 02/2022
FIL = 1 : DATO = 2 : LINK = 3
countNodes = 0 : Nodes = 10
dim list(Nodes, 3)
sub searchNode(node)
local i, prevNode
for i = 1 to countNodes
if i = node break
prevNode = list... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Liberty_BASIC | Liberty BASIC | Input "Please input the number of milliseconds you would like to sleep. "; sleeptime
Print "Sleeping..."
CallDLL #kernel32, "Sleep", sleeptime As long, ret As void
Print "Awake!"
|
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Lingo | Lingo | on doSleep (ms)
put "Sleeping..."
sleep(ms)
put "Awake!"
end |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Perl | Perl | use strict;
use warnings;
use SVG;
use List::Util qw(max min);
use constant pi => 2 * atan2(1, 0);
my $rule = 'XF-F+F-XF+F+XF-F+F-X';
my $S = 'F+F+XF+F+XF';
$S =~ s/X/$rule/g for 1..5;
my (@X, @Y);
my ($x, $y) = (0, 0);
my $theta = pi/4;
my $r = 6;
for (split //, $S) {
if (/F/) {
push @X, spri... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Groovy | Groovy | import groovy.swing.SwingBuilder
count = 0
new SwingBuilder().edt {
frame(title:'Click frame', pack: true, show: true) {
vbox {
countLabel = label("There have been no clicks yet.")
button('Click Me', actionPerformed: {count++; countLabel.text = "Clicked ${count} time(s)."})
}
}
} |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Scheme | Scheme | (define (traverse seq func)
(if (null? seq)
'()
(begin
(func (car seq))
(traverse (cdr seq) func)))) |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Sidef | Sidef | var list = 'a':'b':'c':nil;
#var list = ['a', ['b', ['c']]];
#var list = Pair.new('a', Pair.new('b', Pair.new('c', nil)));
for (var l = list; l != nil; l = l[1]) {
say l[0];
} |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #zkl | zkl | L("a","b","c").insert(1,"foo") //-->L("a","foo","b","c")
a:=L("a","b","c"); a.insert(a.find("b"),"foo") //-->L("a","foo","b","c") |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Zig | Zig |
const std = @import("std");
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const allocator = arena.allocator();
pub fn LinkedList(comptime Value: type) type {
return struct {
const This = @This();
const Node = struct {
value: Value,
next: ?*Node,... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Logo | Logo |
to sleep :n
print [Sleeping...]
wait :n ; units: 1/60th of a second
print [Awake.]
end
|
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Logtalk | Logtalk |
:- object(sleep).
:- public(how_long/1).
how_long(Seconds) :-
write('Sleeping ...'), nl,
thread_sleep(Seconds),
write('... awake!'), nl.
:- end_object.
|
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Phix | Phix | --
-- demo\rosetta\Sierpinski_square_curve.exw
-- ========================================
--
-- My second atempt at a Lindenmayer system. The first
-- is now saved in demo\rosetta\Penrose_tiling.exw
--
with javascript_semantics
include pGUI.e
Ihandle dlg, canvas
cdCanvas cddbuffer, cdcanvas
function redraw_cb(Ihan... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Haskell | Haskell | import Graphics.UI.Gtk
import Data.IORef
main :: IO ()
main = do
initGUI
window <- windowNew
window `onDestroy` mainQuit
windowSetTitle window "Simple Windowed App"
set window [ containerBorderWidth := 10 ]
hbox <- hBoxNew True 5
set window [ containerChild := hbox ]
lab <- labelNew (Just "There... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #SSEM | SSEM | 11101000000000100000000000000000 0. -23 to c
10011000000000010000000000000000 1. Sub. 25
10010000000001100000000000000000 2. c to 9
10101000000000010000000000000000 3. Sub. 21
11010000000001100000000000000000 4. c to 11
10010000000000100000000000000000 5. -9 to c
10010000000001100000000000000000 6. c to 9... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Stata | Stata | oo::define List {
method for {varName script} {
upvar 1 $varName var
set elem [self]
while {$elem ne ""} {
set var [$elem value]
uplevel 1 $script
set elem [$elem next]
}
}
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Lua | Lua | local socket = require("socket")
io.write("Input a number of seconds to sleep: ")
local input = io.read("*number")
print("Sleeping")
socket.sleep(input)
print("Awake!") |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
Input "Input a number of milliseconds to sleep:", N
Print "Sleeping..."
Wait N
Print "Awake"
}
CheckIt
|
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Python | Python | import matplotlib.pyplot as plt
import math
def nextPoint(x, y, angle):
a = math.pi * angle / 180
x2 = (int)(round(x + (1 * math.cos(a))))
y2 = (int)(round(y + (1 * math.sin(a))))
return x2, y2
def expand(axiom, rules, level):
for l in range(0, level):
a2 = ""
for c in axiom:... |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Quackery | Quackery | [ $ "turtleduck.qky" loadfile ] now!
[ stack ] is switch.arg ( --> [ )
[ switch.arg put ] is switch ( x --> )
[ switch.arg release ] is otherwise ( --> )
[ switch.arg share
!= iff ]else[ done
otherwise ]'[ do ]done[ ] is case ( ... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #HicEst | HicEst | CHARACTER label="There have been no clicks yet"
DO count = 1, 1E100 ! "forever"
DLG(Button="Click me", Width=3, TItle=label) ! Width=3 to display full length label
label = "Clicked " // count // "time(s)"
ENDDO
END |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Tcl | Tcl | oo::define List {
method for {varName script} {
upvar 1 $varName var
set elem [self]
while {$elem ne ""} {
set var [$elem value]
uplevel 1 $script
set elem [$elem next]
}
}
} |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Trith | Trith | [1 2 3 4 5] [print] each |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Maple | Maple | sleep := proc(secs)
print("Sleeping...");
Threads:-Sleep(secs);
print("Awake!");
end proc: |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Sleep[seconds_] := (Print["Sleeping..."]; Pause[seconds]; Print["Awake!"];) |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Raku | Raku | use SVG;
role Lindenmayer {
has %.rules;
method succ {
self.comb.map( { %!rules{$^c} // $c } ).join but Lindenmayer(%!rules)
}
}
my $sierpinski = 'X' but Lindenmayer( { X => 'XF-F+F-XF+F+XF-F+F-X' } );
$sierpinski++ xx 5;
my $dim = 600;
my $scale = 6;
my @points = (-80, 298);
for $sierpi... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Icon_and_Unicon | Icon and Unicon | import gui
$include "guih.icn"
procedure main()
SimpleWindow().show_modal()
end
class SimpleWindow : Dialog(label, button, count)
method component_setup()
self.set_attribs("size=222,139")
label := Label()
label.set_pos("24", "24")
label.set_internal_alignment("l")
label.set_label... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Visual_Basic_.NET | Visual Basic .NET | Private Sub Iterate(ByVal list As LinkedList(Of Integer))
Dim node = list.First
Do Until node Is Nothing
node = node.Next
Loop
End Sub |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Wart | Wart | each x '(1 2 3)
prn x |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #MATLAB_.2F_Octave | MATLAB / Octave | function sleep()
time = input('How many seconds would you like me to sleep for? ');
assert(time > .01);
disp('Sleeping...');
pause(time);
disp('Awake!');
end |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #min | min | "Enter number of milliseconds to sleep" ask int
"Sleeping..." puts!
sleep
"Awake!" puts! |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Rust | Rust | // [dependencies]
// svg = "0.8.0"
use svg::node::element::path::Data;
use svg::node::element::Path;
struct SierpinskiSquareCurve {
current_x: f64,
current_y: f64,
current_angle: i32,
line_length: f64,
}
impl SierpinskiSquareCurve {
fn new(x: f64, y: f64, length: f64, angle: i32) -> Sierpinski... |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Sidef | Sidef | var rules = Hash(
x => 'xF-F+F-xF+F+xF-F+F-x',
)
var lsys = LSystem(
width: 510,
height: 510,
xoff: -505,
yoff: -254,
len: 4,
angle: 90,
color: 'dark green',
)
lsys.execute('F+xF+F+xF', 5, "sierpiński_square_curve.png", rules) |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #Wren | Wren | import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
import "./lsystem" for LSystem, Rule
var TwoPi = Num.pi * 2
class SierpinskiSquareCurve {
construct new(width, height, back, fore) {
Window.title = "Sierpinski Square Curve"
Window.resize(width, height)
C... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #IDL | IDL | pro counter, ev
widget_control, ev.top, get_uvalue=tst
tst[1] = tst[1]+1
widget_control, tst[0], set_value="Number of clicks: "+string(tst[1],format='(i0)')
widget_control, ev.top, set_uvalue=tst
end
id = widget_base(title = 'Window Title',column=1)
ld = widget_label(id, value = 'There have been no clicks yet... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Wren | Wren | import "/llist" for LinkedList
import "/fmt" for Fmt
//create a new linked list and add the first 50 positive integers to it
var ll = LinkedList.new(1..50)
// traverse the linked list
for (i in ll) {
Fmt.write("$4d ", i)
if (i % 10 == 0) System.print()
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Nanoquery | Nanoquery | time = int(input("time to sleep (ms): "))
println "Sleeping..."
sleep(time)
println "Awake!" |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Nemerle | Nemerle | using System;
using System.Console;
using System.Threading.Thread; // this is where the Sleep() method comes from
module Zzzz
{
Main() : void
{
def nap_time = Int32.Parse(ReadLine());
WriteLine("Sleeping...");
Sleep(nap_time); // parameter is time in milliseconds
WriteLine("Awa... |
http://rosettacode.org/wiki/Sierpinski_square_curve | Sierpinski square curve |
Task
Produce a graphical or ASCII-art representation of a Sierpinski square curve of at least order 3.
| #zkl | zkl | sierpinskiSquareCurve(4) : turtle(_);
fcn sierpinskiSquareCurve(n){ // Lindenmayer system --> Data of As
var [const] A="AF-F+F-AF+F+AF-F+F-A", B=""; // Production rules
var [const] Axiom="F+AF+F+AF";
buf1,buf2 := Data(Void,Axiom).howza(3), Data().howza(3); // characters
do(n){
buf1.pump(buf2.clear... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #J | J | SIMPLEAPP=: noun define
pc simpleApp;
cc inc button;cn "Click me";
cc shownText static;cn "There have been no clicks yet.";
)
simpleApp_run=: verb define
wd SIMPLEAPP
simpleApp_accum=: 0 NB. initialize accumulator
wd 'pshow;'
)
simpleApp_inc_button=: verb define
wd 'set shownText text ','Button-use count:... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #XPL0 | XPL0 | def \Node\ Link, Data; \linked list element definition
int Node, List;
[Node:= List; \traverse the linked list
while Node # 0 do
Node:= Node(Link); \move to next node
] |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Yabasic | Yabasic | // Rosetta Code problem: http://rosettacode.org/wiki/Singly-linked_list/Element_insertion & removal & traverse
// by Galileo, 02/2022
FIL = 1 : DATO = 2 : LINK = 3
countNodes = 0 : Nodes = 10
dim list(Nodes, 3)
sub searchNode(node)
local i, prevNode
for i = 1 to countNodes
if i = node break
... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method sleep(secs) public static binary
ms = (secs * 1000).format(null, 0) -- milliseconds, rounded to nearest integer
say 'Sleeping... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Java | Java | import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class Clicks extends JFrame{
private long clicks = 0;
public C... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #Zig | Zig | const std = @import("std");
pub fn main() anyerror!void {
var l1 = LinkedList(i32).init();
try l1.add(1);
try l1.add(2);
try l1.add(4);
try l1.add(3);
var h = l1.head;
while (h) |head| : (h = head.next) {
std.log.info("> {}", .{ head.value });
}
} |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Definition, Usage
Set
Singly-linked ... | #zkl | zkl | foreach n in (List(1,2,3) {...}
List(1,2,3).pump(...) // traverse and munge elements, generalized apply/map
List(1,2,3).filter(...)
List(1,2,3).filter22(...) // partition list
List(1,2,3).reduce(...)
List(1,2,3).apply(...)
List(1,2,3).sum()
List(1,2,3).run() // treat each element as f, perform f()
List(1,2,3).enumerat... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #NewLISP | NewLISP | (println "Sleeping..." )
(sleep 2000) ; Wait for 2 seconds
(println "Awake!") |
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.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic data retrieval without meaningful analysis or patterns.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic filtering that shows what data looks like but doesn't provide meaningful analysis or patterns.
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.