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/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.
... | #Nim | Nim | import os, strutils
echo "Enter how long I should sleep (in milliseconds):"
var timed = stdin.readLine.parseInt()
echo "Sleeping..."
sleep timed
echo "Awake!" |
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.
| #JavaFX_Script | JavaFX Script | import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
Stage {
scene: Scene {
width: 300 height: 200
content: VBox {
var clicks: Integer;
spacing: 10
content: [
Label {
def varText = bind if (cli... |
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.
| #JavaScript | JavaScript |
<html>
<head>
<title>Simple Window Application</title>
</head>
<body>
<br>        
<script type="text/javascript">
var box = document.createElement('input')
box.style.position = 'absolute'; // position it
box.style.left = '10px';
box.style.top = '6... |
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.
... | #NS-HUBASIC | NS-HUBASIC | 10 PRINT "I'LL TELL YOU WHEN I BECOME AWAKE AGAIN..."
20 PAUSE 100
30 PRINT "NOW I'M AWAKE AGAIN." |
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.
... | #Objeck | Objeck |
bundle Default {
class Test {
function : Main(args : System.String[]) ~ Nil {
if(args->Size() = 1) {
"Sleeping..."->PrintLine();
Thread->Sleep(args[0]->ToInt());
"Awake!"->PrintLine();
};
}
}
}
|
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.
| #Julia | Julia | using Gtk.ShortNames
function clickwindow()
clicks = 0
win = Window("Click Counter", 300, 100) |> (Frame() |> (vbox = Box(:v)))
lab = Label("There have been no clicks yet.")
but = Button("click me")
push!(vbox, lab)
push!(vbox, but)
set_gtk_property!(vbox, :expand, lab, true)
set_gtk_p... |
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.
| #Kotlin | Kotlin | // version 1.0.6
import java.awt.BorderLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.*
class Clicks : JFrame(), ActionListener {
private var clicks = 0
private val label: JLabel
private val clicker: JButton
private var text: String
init {
... |
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.
... | #Objective-C | Objective-C | #import <Foundation/Foundation.h>
int main()
{
@autoreleasepool {
NSTimeInterval sleeptime;
printf("wait time in seconds: ");
scanf("%f", &sleeptime);
NSLog(@"sleeping...");
[NSThread sleepForTimeInterval: sleeptime];
NSLog(@"awakening...");
}
return 0;
} |
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.
... | #OCaml | OCaml | #load "unix.cma";;
let seconds = read_int ();;
print_endline "Sleeping...";;
Unix.sleep seconds;; (* number is integer in seconds *)
print_endline "Awake!";; |
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.
| #Lambdatalk | Lambdatalk |
1) the label: {div {@ id="label"} There have been no clicks yet }
2) the button: {input {@ type="button" value="click me" onclick="CLICKAPP.inc()" }}
3) the script: {script °° code °°} where code is a single function:
var CLICKAPP = (function() {
var counter = 0;
var inc = function() {
counter++;
ge... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #11l | 11l | V sqrt3_2 = sqrt(3) / 2
F sierpinski_arrowhead_next(points)
V result = [(0.0, 0.0)] * (3 * (points.len - 1) + 1)
V j = 0
L(i) 0 .< points.len - 1
V (x0, y0) = points[i]
V (x1, y1) = points[i + 1]
V dx = x1 - x0
result[j] = (x0, y0)
I y0 == y1
V d = abs(dx * :sqrt3_2 / 2... |
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.
... | #Oforth | Oforth | : sleepMilli(n) "Sleeping..." . n sleep "Awake!" println ; |
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.
... | #ooRexx | ooRexx | Say time()
Call sysSleep 10 -- wait 10 seconds
Say time() |
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.
| #Liberty_BASIC | Liberty BASIC | nomainwin
button #demo.btn, "Click Me", [btnClick], UL, 20, 50
statictext #demo.num, "There have been no clicks yet.", 20, 100, 240, 30
open "Rosetta Task: Simple windowed application" for window as #demo
#demo "trapclose [quit]"
nClicks = 0
wait
[quit]
close #demo
end
[btnClick]
nClicks... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Ada | Ada | with Ada.Command_Line;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with PDF_Out;
procedure Arrowhead_Curve is
package Real_Math is
new Ada.Numerics.Generic_Elementary_Functions (PDF_Out.Real);
use Real_Math, PDF_Out, Ada.Command_Line, Ada.Text_IO;
subtype Angle_Deg is Real;
... |
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.
... | #Oz | Oz | declare
class TextFile from Open.file Open.text end
StdIn = {New TextFile init(name:stdin)}
WaitTime = {String.toInt {StdIn getS($)}}
in
{System.showInfo "Sleeping..."}
{Delay WaitTime} %% in milliseconds
{System.showInfo "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.
... | #PARI.2FGP | PARI/GP | sleep(ms)={
print("Sleeping...");
while((ms-=gettime()) > 0,);
print("Awake!")
};
sleep(input()) |
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.
| #Lingo | Lingo | on startMovie
-- window settings
_movie.stage.title = "Hello World!"
_movie.stage.titlebarOptions.visible = TRUE
_movie.stage.rect = rect(0,0,320, 240)
_movie.centerStage = 1
-- create a label (called "field" in Director)
m = new(#field)
m.name = "label"
m.rect = rect(0,0,320,0)
m.text = "There ... |
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.
| #LiveCode | LiveCode | global count
on openCard
put empty into count
put "There have been no clicks yet" into field "clicks"
end openCard
on mouseUp
add 1 to count
put count into field "clicks"
end mouseUp |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #ALGOL_W | ALGOL W | begin % draw sierpinski arrowhead curves using ascii art %
integer CANVAS_WIDTH;
CANVAS_WIDTH := 200;
begin
% the ascii art canvas and related items %
string(1) array canvas ( 1 :: CANVAS_WIDTH, 1 :: CANVAS_WIDTH );
integer heading, asciiX, asciiY, width, maxX, maxY, minX, mi... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #AutoHotkey | AutoHotkey | order := 7
theta := 0
curve := []
curve.curveW := 1000
curve.curveH := 1000
curve.iy := 1
curve.cx := curve.curveW/2
curve.cy := curve.curveH
curve.ch := curve.cx/2
arrowhead(order, curve, theta, Arr :=[])
xmin := xmax := ymin := ymax := 0
for i, point in Arr
{
xmin := A_Index = 1 ? point.x : xmin < point.x ? xmin... |
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.
... | #Pascal | Pascal | <@ SAYLIT>Number of seconds: </@><@ GETVAR>secs</@>
<@ SAYLIT>Sleeping</@>
<@ ACTPAUVAR>secs</@>
<@ SAYLIT>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.
... | #Peloton | Peloton | <@ SAYLIT>Number of seconds: </@><@ GETVAR>secs</@>
<@ SAYLIT>Sleeping</@>
<@ ACTPAUVAR>secs</@>
<@ SAYLIT>Awake</@> |
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.
| #Logo | Logo | to clickwindow
windowCreate "root "clickWin [Click that button!!!] 0 0 100 100 []
Make "i 0
staticCreate "clickWin "clickSt [There have been no clicks yet] 0 0 100 20
buttonCreate "clickWin "clickBtn [click me] 10 20 80 20 ~
[Make "i :i+1 ~
ifelse :i=1 [staticUpdate "clickSt (list "clicked :i "time)] ~
[... |
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.
| #Lua | Lua | require"iuplua"
l = iup.label{title="There have been no clicks yet."}
b = iup.button{title="Click me!"}
clicks = 0
function b:button_cb()
clicks = clicks + 1
l.title = "There have been " .. clicks/2 .. " clicks so far." --yes, this is correct.
end
dlg = iup.dialog{iup.vbox{l, b}, title="Simple Windowed Application"... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #C | C | // See https://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve#Arrowhead_curve
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
// Structure to keep track of current position and orientation
typedef struct cursor_tag {
double x;
double y;
int angle;
} cursor_t;
void turn(cursor_t* cursor, int angle)... |
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.
... | #Perl | Perl | $seconds = <>;
print "Sleeping...\n";
sleep $seconds; # number is in seconds
print "Awake!\n"; |
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.
... | #Phix | Phix | without js -- (prompt_number, sleep)
atom a = prompt_number("wait for duration (in seconds, 0..20):", {0,20})
puts(1,"Sleeping...\n")
sleep(a)
puts(1,"Awake!\n")
|
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.
| #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
Declare Form1 Form
Declare Label1 Button Form Form1
Declare Button1 Button Form Form1
Method Label1,"move", 2000, 2000, 4000, 600
Method Button1,"move", 2000, 3000, 4000, 600
With Label1, "Caption" as caption$, "Locked", true, "Caption" as cap
With Button1, ... |
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.
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | DynamicModule[{n = 0},
CreateDialog[{Dynamic@
TextCell@If[n == 0, "There have been no clicks yet", n],
Button["click me", n++]}]] |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #C.2B.2B | C++ | #include <fstream>
#include <iostream>
#include <vector>
constexpr double sqrt3_2 = 0.86602540378444; // sqrt(3)/2
struct point {
double x;
double y;
};
std::vector<point> sierpinski_arrowhead_next(const std::vector<point>& points) {
size_t size = points.size();
std::vector<point> output(3*(size -... |
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.
... | #PHP | PHP | $seconds = 42;
echo "Sleeping...\n";
sleep($seconds); # number is integer in seconds
echo "Awake!\n"; |
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.
... | #PicoLisp | PicoLisp | (prinl "Sleeping..." )
(wait 2000) # Wait for 2 seconds
(prinl "Awake!") |
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.
| #MAXScript | MAXScript | rollout buttonClick "Button Click"
(
label l "There have been no clicks yet"
button clickMe "Click me"
local clickCount = 0
on clickMe pressed do
(
clickCount += 1
l.text = ("Number of clicks: " + clickCount as string)
)
)
createDialog buttonClick |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Factor | Factor | USING: accessors L-system ui ;
: arrowhead ( L-system -- L-system )
L-parser-dialect >>commands
[ 60 >>angle ] >>turtle-values
"XF" >>axiom
{
{ "X" "YF+XF+Y" }
{ "Y" "XF-YF-X" }
} >>rules ;
[ <L-system> arrowhead "Arrowhead" open-window ] with-ui |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Forth | Forth | ( ASCII output with use of ANSI terminal control )
: draw-line ( direction -- )
case
0 of .\" _" endof ( horizontal right: _ )
1 of .\" \e[B\\" endof ( down right: CUD \ )
2 of .\" \e[D\e[B/\e[D" endof ( down left: CUB CUD / CUB )
3... |
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.
... | #Pike | Pike | int main() {
int seconds = (int)Stdio.stdin->gets();
write("Sleeping...\n");
sleep(seconds);
write("Awake!\n");
return 0;
} |
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.
... | #Pixilang | Pixilang | fputs("Sleeping...\n")
sleep(1000)
fputs("Awake!\n") |
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.
| #Modula-3 | Modula-3 | MODULE Click EXPORTS Main;
IMPORT Fmt, TextVBT, ButtonVBT, VBT, Axis, HVSplit, TrestleComm, Trestle;
VAR label := TextVBT.New("There have been no clicks yet.");
button := ButtonVBT.New(TextVBT.New("Click me!"), Clicked);
main := HVSplit.Cons(Axis.T.Ver, label, button, adjustable := FALSE);
count := 0;
... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Go | Go | package main
import (
"github.com/fogleman/gg"
"math"
)
var (
width = 770.0
height = 770.0
dc = gg.NewContext(int(width), int(height))
iy = 1.0
theta = 0
)
var cx, cy, h float64
func arrowhead(order int, length float64) {
// if order is even, we can just draw the curve
... |
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.
... | #PL.2FI | PL/I |
put ('sleeping');
delay (2000); /* wait for 2 seconds (=2000 milliseconds). */
put ('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.
... | #Plain_English | Plain English | To run:
Start up.
Demonstrate waiting.
Wait for the escape key.
Shut down.
To demonstrate waiting:
Write "How many milliseconds should I wait? " to the console without advancing.
Read some milliseconds from the console.
Write "Sleeping..." to the console.
Wait for the milliseconds.
Write "Awake!" to the console. |
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.
| #Nanoquery | Nanoquery | import Nanoquery.Util.Windows
// define the necessary objects
$w = new("Window")
$b = new("Button")
$l = new("Label")
$b.setParent($w)
$l.setParent($w)
// define the amount of clicks
$clicks = 0
// a function to update the label
def updateLabel($caller, $event)
global $clicks
global $l
... |
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.
| #Nim | Nim | import gtk2
nim_init()
var
win = windowNew WINDOW_TOPLEVEL
button = buttonNew "Click me"
label = labelNew "There have been no clicks yet"
vbox = vboxNew(true, 1)
counter = 0
proc clickedMe(o: var PButton, l: PLabel) =
inc counter
l.setText "You clicked me " & $counter & " times"
win.setTitle "Cli... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #jq | jq | include "turtle" {search: "."};
# Compute the curve using a Lindenmayer system of rules
def rules:
{X: "Yf+Xf+Y", Y: "Xf-Yf-X", "": "X"};
def sierpinski($count):
rules as $rules
| def repeat($count):
if $count == 0 then .
else ascii_downcase | gsub("x"; $rules["X"]) | gsub("y"; $rules["Y"])
... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Julia | Julia | using Lindenmayer # https://github.com/cormullion/Lindenmayer.jl
scurve = LSystem(Dict("F" => "G+F+Gt", "G"=>"F-G-F"), "G")
drawLSystem(scurve,
forward = 3,
turn = 60,
startingy = -350,
iterations = 8,
startingorientation = π/3,
filename = "sierpinski_arrowhead_curve.png",
showpreview = ... |
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.
... | #PowerShell | PowerShell | $d = [int] (Read-Host Duration in seconds)
Write-Host Sleeping ...
Start-Sleep $d
Write-Host 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.
... | #Prolog | Prolog | rosetta_sleep(Time) :-
writeln('Sleeping...'),
sleep(Time),
writeln('Awake!').
|
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.
| #Objective-C | Objective-C | #include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
@interface ClickMe : NSWindow
{
NSButton *_button;
NSTextField *_text;
int _counter;
}
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification;
- (... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #11l | 11l | F sierpinski(n)
V d = [String(‘*’)]
L(i) 0 .< n
V sp = ‘ ’ * (2 ^ i)
d = d.map(x -> @sp‘’x‘’@sp) [+] d.map(x -> x‘ ’x)
R d
print(sierpinski(4).join("\n")) |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Lambdatalk | Lambdatalk |
{def sierp
{def sierp.r
{lambda {:order :length :angle}
{if {= :order 0}
then M:length
else {sierp.r {- :order 1} {/ :length 2} {- :angle}}
T:angle
{sierp.r {- :order 1} {/ :length 2} :angle}
T:angle
{sierp.r {- :order 1} {/ :length 2} {- :angle}}
}}}
{lambda {:orde... |
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.
... | #PureBasic | PureBasic | If OpenConsole()
Print("Enter a time(milliseconds) to sleep: ")
x.i = Val(Input())
PrintN("Sleeping...")
Delay(x) ;in milliseconds
PrintN("Awake!")
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf |
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.
... | #Python | Python | import time
seconds = float(raw_input())
print "Sleeping..."
time.sleep(seconds) # number is in seconds ... but accepts fractions
print "Awake!" |
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.
| #OCaml | OCaml | #directory "+labltk"
#load "labltk.cma"
let () =
let top = Tk.openTk() in
Wm.title_set top "Tk-OCaml Example";
let label = Label.create ~text:"There have been no clicks yet" top in
let b =
Button.create
~text:"click me"
~command:(fun () -> Tk.closeTk (); exit 0)
top
in
Tk.pack ... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #8080_Assembly | 8080 Assembly | argmt: equ 5Dh ; Command line argument
puts: equ 9 ; CP/M syscall to print a string
putch: equ 2 ; CP/M syscall to print a character
org 100h
mvi b,4 ; Default order is 4
mvi e,' ' ; Keep space in E since we're saving it anyway
lda argmt ; Argument given?
cmp e ; If not, use default
jz start
sui '0' ; Make sure ... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | ClearAll[DoStep]
DoStep[Line[{x_, y_}]] := Module[{diff, perp, pts},
diff = y - x;
perp = Cross[diff] Sqrt[3]/2;
pts = {x, x + diff/4 + perp/2, x + 3 diff/4 + perp/2, y};
{Line[pts[[{2, 1}]]], Line[pts[[{2, 3}]]], Line[pts[[{4, 3}]]]}
]
lns = {Line[{{0.0, 0.0}, {1.0, 0.0}}]};
lns = Nest[Catenate[DoStep /@ #] ... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Nim | Nim | import math
const Sqrt3_2 = sqrt(3.0) / 2.0
type Point = tuple[x, y: float]
func sierpinskiArrowheadNext(points: seq[Point]): seq[Point] =
result.setLen(3 * (points.len - 1) + 1)
var j = 0
for i in 0..<points.high:
let (x0, y0) = points[i]
let (x1, y1) = points[i + 1]
let dx = x1 - x0
resu... |
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.
... | #R | R |
sleep <- function(time=1)
{
message("Sleeping...")
flush.console()
Sys.sleep(time)
message("Awake!")
}
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.
... | #Racket | Racket |
#lang racket
(displayln "Enter a time (in seconds): ")
(define time (read))
(when (number? time)
(displayln "Sleeping...")
(sleep time)
(displayln "Awake!"))
|
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.
| #ooRexx | ooRexx | /* REXX ***************************************************************************************
* 18.06.2014 Walter Pachl shortened from Rony Flatscher's bsf4oorexx (see sourceforge) samples
* Look there for ShowCount.rxj
* bsf4oorexx lets the ooRexx program use Java classes
********************************************... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #8086_Assembly | 8086 Assembly | putch: equ 2 ; MS-DOS syscall to print character
puts: equ 9 ; MS-DOS syscall to print string
argmt: equ 5Dh ; MS-DOS still has FCB in same place as CP/M
cpu 8086
org 100h
section .text
mov cx,4 ; Default order is 4
mov al,[argmt]
sub al,'3' ; Argument is there and makes sense? (3 - 7)
cmp al,7-3
ja start ... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead 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 %rules = (
X => 'YF+XF+Y',
Y => 'XF-YF-X'
);
my $S = 'Y';
$S =~ s/([XY])/$rules{$1}/eg for 1..7;
my (@X, @Y);
my ($x, $y) = (0, 0);
my $theta = 0;
my $r = 6;
for (split //, $S) {
if (/F/) {
... |
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.
... | #Raku | Raku | my $sec = prompt("Sleep for how many microfortnights? ") * 1.2096;
say "Sleeping...";
sleep $sec;
say "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.
... | #RapidQ | RapidQ |
input "Enter the number of seconds to sleep: ";s
sleep s
print "I'm awake I think..."
input "Press enter to quit";a$
|
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.
| #Oz | Oz | functor
import
Application
QTk at 'x-oz://system/wp/QTk.ozf'
define
Count = {NewCell 0}
Label
GUI = td(action:proc {$} {Application.exit 0} end %% exit on close
label(text:"There have been no clicks yet." handle:Label)
button(text:"Click Me"
action:proc {$}
Count := @Count + 1
... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #ACL2 | ACL2 | (defun pascal-row (prev)
(if (endp (rest prev))
(list 1)
(cons (+ (first prev) (second prev))
(pascal-row (rest prev)))))
(defun pascal-triangle-r (rows prev)
(if (zp rows)
nil
(let ((curr (cons 1 (pascal-row prev))))
(cons curr (pascal-triangle-r (1- rows) cur... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Phix | Phix | --
-- demo\rosetta\Sierpinski_arrowhead_curve.exw
-- ===========================================
--
-- Draws curves lo to hi (simultaneously), initially {6,6}, max {10,10}, min {1,1}
-- Press +/- to change hi, shift +/- to change lo.
-- ("=_" are also mapped to "+-", for the non-numpad +/-)
--
with javascript_semant... |
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.
... | #REBOL | REBOL | rebol [
Title: "Sleep Main Thread"
URL: http://rosettacode.org/wiki/Sleep_the_Main_Thread
]
naptime: to-integer ask "Please enter sleep time in seconds: "
print "Sleeping..."
wait naptime
print "Awake!" |
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.
| #Pascal | Pascal | Program SimpleWindowApplication;
uses
SysUtils,
glib2,
Gtk2;
const
clickme = 'Click Me';
MAXLEN = 64;
var
counter: integer = 0;
procedure clickedme(o: PGtkButton; d: pointer); cdecl;
var
nt: Pchar;
l: PGtkLabel;
begin
l := Gtk_LABEL(d);
inc(counter);
nt := Pchar('You clicked ... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Action.21 | Action! | PROC Main()
BYTE x,y,size=[16]
Graphics(0)
PutE() PutE()
y=size-1
DO
FOR x=1 TO y+2
DO Put(' ) OD
FOR x=0 TO size-y-1
DO
IF (x&y)=0 THEN
Print("* ")
ELSE
Print(" ")
FI
OD
PutE()
IF y=0 THEN
EXIT
FI
y==-1
OD |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #8086_Assembly | 8086 Assembly | ;;; Display a Sierpinski triangle on a CGA screen
;;; (order 7 is the maximum that fits in 200 lines)
mode: equ 0Fh ; INT 10H call to get current video mode
puts: equ 9h ; MS-DOS call to print string
cgaseg: equ 0B800h ; Location of CGA video memory
cpu 8086
bits 16
org 100h
section .text
cmp [80h],byte 2 ; Argum... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Processing | Processing | final PVector t = new PVector(20, 30, 60);
void setup() {
size(450, 400);
noLoop();
background(0, 0, 200);
stroke(-1);
sc(7, 400, -60, t);
}
PVector sc(int o, float l, final int a, final PVector s) {
if (o > 0) {
sc(--o, l *= .5, -a, s).z += a;
sc(o, l, a, s).z += a;
sc(o, l, -a, s);
} els... |
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.
... | #Red | Red |
str-time: to integer! ask "Enter wait time " ;get user input , convert to integer
print "waiting"
wait str-time ;Seconds
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.
... | #Retro | Retro | : sleep ( n- )
[ time [ time over - 1 > ] until drop ] times ;
: test
"\nTime to sleep (in seconds): " puts getToken toNumber
"\nSleeping..." sleep
"\nAwake!\n" ; |
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.
| #Perl | Perl | use Tk;
$main = MainWindow->new;
$l = $main->Label('-text' => 'There have been no clicks yet.')->pack;
$count = 0;
$main->Button(
-text => ' Click Me ',
-command => sub { $l->configure(-text => 'Number of clicks: '.(++$count).'.'); },
)->pack;
MainLoop(); |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Ada | Ada | with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
procedure Sieteri_Triangles is
subtype Practical_Order is Unsigned_32 range 0..4;
function Pow(X : Unsigned_32; N : Unsigned_32) return Unsigned_32 is
begin
if N = 0 then
return 1;
else
... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Action.21 | Action! | PROC Draw(INT x0 BYTE y0,depth)
BYTE i,x,y,size
size=1 LSH depth
FOR y=0 TO size-1
DO
FOR x=0 TO size-1
DO
IF (x&y)=0 THEN
Plot(x0+x,y0+y)
FI
OD
OD
RETURN
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
Graphics(8+16)
Color=1
COLOR1=$0C
COLOR2=$02
Draw... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #ActionScript | ActionScript |
package {
import flash.display.GraphicsPathCommand;
import flash.display.Sprite;
/**
* A Sierpinski triangle.
*/
public class SierpinskiTriangle extends Sprite {
/**
* Creates a new SierpinskiTriangle object.
*
* @param n The order of the Sierpinski ... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead 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 axio... |
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.
... | #REXX | REXX | /*REXX program sleeps X seconds (the number of seconds is supplied via the argument).*/
parse arg secs . /*obtain optional argument from the CL.*/
if secs=='' | secs=="," then secs=0 /*Not specified? Then assume 0 (zero).*/
say 'Sleeping' secs "seconds." ... |
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.
... | #Ring | Ring |
load "guilib.ring"
for n = 1 to 10
Sleep(3)
see "" + n + " "
next
see nl
func Sleep x
nTime = x * 1000
oTest = new qTest
oTest.qsleep(nTime)
|
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.
| #Phix | Phix | -- demo\rosetta\Simple_window.exw
with javascript_semantics
include pGUI.e
Ihandle dlg, lbl, btn, vbox
integer clicks = 0
function click_cb(Ihandle /*btn*/)
clicks += 1
IupSetStrAttribute(lbl,"TITLE","clicked %d times",{clicks})
return IUP_DEFAULT;
end function
IupOpen()
lbl = IupLabel("There have bee... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #ALGOL_68 | ALGOL 68 | PROC sierpinski = (INT n)[]STRING: (
FLEX[0]STRING d := "*";
FOR i TO n DO
[UPB d * 2]STRING next;
STRING sp := " " * (2 ** (i-1));
FOR x TO UPB d DO
STRING dx = d[x];
next[x] := sp+dx+sp;
next[UPB d+x] := dx+" "+dx
OD;
d := next
OD;
... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Asymptote | Asymptote | path subtriangle(path p, real node) {
return
point(p, node) --
point(p, node + 1/2) --
point(p, node - 1/2) --
cycle;
}
void sierpinski(path p, int order) {
if (order == 0)
fill(p);
else {
sierpinski(subtriangle(p, 0), order - 1);
sierpinski(subtrian... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead curve of at least order 3.
| #Prolog | Prolog | main:-
write_sierpinski_arrowhead('sierpinski_arrowhead.svg', 600, 8).
write_sierpinski_arrowhead(File, Size, Order):-
open(File, write, Stream),
format(Stream,
"<svg xmlns='http://www.w3.org/2000/svg' width='~d' height='~d'>\n",
[Size, Size]),
write(Stream, "<rect width='100%' h... |
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.
... | #Ruby | Ruby | seconds = gets.to_f
puts "Sleeping..."
sleep(seconds) # number is in seconds ... but accepts fractions
# Minimum resolution is system dependent.
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.
... | #Rust | Rust | use std::{io, time, thread};
fn main() {
println!("How long should we sleep in milliseconds?");
let mut sleep_string = String::new();
io::stdin().read_line(&mut sleep_string)
.expect("Failed to read line");
let sleep_timer: u64 = sleep_string.trim()
... |
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.
| #PicoLisp | PicoLisp | #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
(zero *Count)
(de start ()
(app)
(action
(html 0 "Clicks" NIL NIL
(form NIL
(gui '(+Init +TextField) "There have been no clicks yet")
(----)
(gui '(+JS +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.
| #Pike | Pike | GTK2.Widget mainwindow,clickcnt,clicker;
int clicks;
void click()
{
clickcnt->set_text("Clicks: "+(++clicks));
}
int main()
{
GTK2.setup_gtk();
mainwindow=GTK2.Window(GTK2.WindowToplevel);
mainwindow->set_title("Click counter");
mainwindow->add(GTK2.Vbox(0,10)
... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #ALGOL_W | ALGOL W | begin
integer SIZE;
SIZE := 16;
for y := SIZE - 1 step - 1 until 0 do begin
integer x;
for i := 0 until y - 1 do writeon( " " );
x := 0;
while x + y < SIZE do begin
writeon( if number( bitstring( x ) and bitstring( y ) ) not = 0 then " " else "* " );
... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #ATS | ATS | // patscc -O2 -flto -D_GNU_SOURCE -DATS_MEMALLOC_LIBC sierpinski.dats -o sierpinski -latslib -lSDL2
#include "share/atspre_staload.hats"
typedef point = (int, int)
extern fun midpoint(A: point, B: point): point = "mac#"
extern fun sierpinski_draw(n: int, A: point, B: point, C: point): void = "mac#"
extern fun t... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #AutoHotkey | AutoHotkey | #NoEnv
#SingleInstance, Force
SetBatchLines, -1
; Parameters
Width := 512, Height := Width/2*3**0.5, n := 8 ; iterations = 8
; Uncomment if Gdip.ahk is not in your standard library
#Include ..\lib\Gdip.ahkl
If !pToken := Gdip_Startup() ; Start gdi+
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please en... |
http://rosettacode.org/wiki/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead 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/Sierpinski_arrowhead_curve | Sierpinski arrowhead curve | Task
Produce a graphical or ASCII-art representation of a Sierpinski arrowhead 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 $arrow = 'X' but Lindenmayer( { X => 'YF+XF+Y', Y => 'XF-YF-X' } );
$arrow++ xx 7;
my $w = 800;
my $h = ($w * 3**.5 / 2).round(1);
my $scale = 6;
my @points =... |
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.
... | #Scala | Scala | object Sleeper extends App {
print("Enter sleep time in milli sec: ")
val ms = scala.io.StdIn.readInt()
println("Sleeping...")
val sleepStarted = scala.compat.Platform.currentTime
Thread.sleep(ms)
println(s"Awaked after [${scala.compat.Platform.currentTime - sleepStarted} ms]1")
} |
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.
... | #Scheme | Scheme |
(use format)
(use srfi-18)
(format #t "Enter a time (in seconds): ")
(let ((time (read))) ; converts input to a number, if possible
(if (number? time)
(begin
(format #t "Sleeping...~&")
(thread-sleep! time)
(format #t "Awake!~&"))
(format #t "You must enter a number~&")))
|
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.
| #PowerShell | PowerShell |
$Label1 = [System.Windows.Forms.Label]@{
Text = 'There have been no clicks yet'
Size = '200, 20' }
$Button1 = [System.Windows.Forms.Button]@{
Text = 'Click me'
Location = '0, 20' }
$Button1.Add_Click(
{
$Script:Clicks++
If ( $Clicks -eq 1 ) { $Label1.Text... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #AppleScript | AppleScript | ------------------- SIERPINKSI TRIANGLE ------------------
-- sierpinski :: Int -> [String]
on sierpinski(n)
if n > 0 then
set previous to sierpinski(n - 1)
set padding to replicate(2 ^ (n - 1), space)
script alignedCentre
on |λ|(s)
concat(padding & s & paddin... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #BASIC | BASIC |
SCREEN 9
H=.5
P=300
FOR I=1 TO 9^6
N=RND
IF N > 2/3 THEN
X=H+X*H:Y=Y*H
ELSEIF N > 1/3 THEN
X=H^2+X*H:Y=H+Y*H
ELSE
X=X*H:Y=Y*H
END IF
PSET(P-X*P,P-Y*P)
NEXT
|
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #C | C | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
long long x, y, dx, dy, scale, clen, cscale;
typedef struct { double r, g, b; } rgb;
rgb ** pix;
void sc_up()
{
scale *= 2; x *= 2; y *= 2;
cscale *= 3;
}
void h_rgb(long long x, long long y)
{
rgb *p = &pix[y][x];
# define SAT 1
d... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.