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/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #Red | Red | Red[]
identity-matrix: function [size][
matrix: copy []
repeat i size [
append/only matrix append/dup copy [] 0 size
matrix/:i/:i: 1
]
matrix
]
probe identity-matrix 5 |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #VBA | VBA |
Public Function incr(astring As String) As String
'simple function to increment a number string
incr = CStr(CLng(astring) + 1)
End Function
|
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Vedit_macro_language | Vedit macro language | itoa(atoi(10)+1, 10) |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #ReScript | ReScript | let my_compare = (a, b) => {
if a < b { "A is less than B" } else
if a > b { "A is greater than B" } else
if a == b { "A equals B" }
else { "cannot compare NANs" }
}
let a = int_of_string(Sys.argv[2])
let b = int_of_string(Sys.argv[3])
Js.log(my_compare(a, b)) |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Retro | Retro | :example (ab-)
dup-pair gt? [ 'A>B s:put nl ] if
dup-pair lt? [ 'A<B s:put nl ] if
eq? [ 'A=B s:put nl ] if ; |
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #F.23 | F# |
let wget (url : string) =
use c = new System.Net.WebClient()
c.DownloadString(url)
printfn "%s" (wget "http://www.rosettacode.org/")
|
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #F.C5.8Drmul.C3.A6 | Fōrmulæ | window 1
// Set width of tab
def tab 9
dim as long Mallows, n, pow2, p2, pPos, uprLim
dim as double p
print
// Adjust array elements depending on size of sequence
_maxArrayElements = 1200000
input "Enter upper limit between 1 and 20 (Enter 20 gives 2^20): "; uprLim
dim as double r
dim as long a( _maxArrayElem... |
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #FutureBasic | FutureBasic | window 1
// Set width of tab
def tab 9
dim as long Mallows, n, pow2, p2, pPos, uprLim
dim as double p
print
// Adjust array elements depending on size of sequence
_maxArrayElements = 1200000
input "Enter upper limit between 1 and 20 (Enter 20 gives 2^20): "; uprLim
dim as double r
dim as long a( _maxArrayElem... |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #BBC_BASIC | BBC BASIC | STD_ERROR_HANDLE = -12
SYS "GetStdHandle", STD_ERROR_HANDLE TO @hfile%(1)
PRINT #13, "Goodbye, World!"
QUIT |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #Blade | Blade | import io
io.stderr.write('Goodbye, World!') |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #C | C | #include <stdio.h>
int main()
{
fprintf(stderr, "Goodbye, ");
fputs("World!\n", stderr);
return 0;
} |
http://rosettacode.org/wiki/Hofstadter_Q_sequence | Hofstadter Q sequence | Hofstadter Q sequence
Q
(
1
)
=
Q
(
2
)
=
1
,
Q
(
n
)
=
Q
(
n
−
Q
(
n
−
1
)
)
+
Q
(
n
−
Q
(
n
−
2
)
)
,
n
>
2.
{\displaystyle {\begin{aligned}Q(1)&=Q(2)=1,\\Q(n)&=Q{\big (}n-Q(n-1){\big )}+Q{\big (}n-Q(n-2){\big )},\quad n>2.\end{aligned}}}
It is defined like the Fibonacc... | #Common_Lisp | Common Lisp | (defparameter *mm* (make-hash-table :test #'equal))
;;; generic memoization macro
(defmacro defun-memoize (f (&rest args) &body body)
(defmacro hash () `(gethash (cons ',f (list ,@args)) *mm*))
(let ((h (gensym)))
`(defun ,f (,@args)
(let ((,h (hash)))
(if ,h ,h
(setf (hash) (progn ,@body)))))))
... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #jq | jq | def hickerson:
. as $n
| (2|log) as $log2
| reduce range(1;$n+1) as $i ( 0.5/$log2; . * $i / $log2) ;
def precise:
(. - 0.05) as $x | . != ($x + 0.1) ;
def almost_an_integer:
tostring
| index(".") as $ix
| if $ix == null then true
else .[$ix+1:$ix+2] | (. == "9" or . == "0")
end ;
range(... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #Julia | Julia |
function makehickerson{T<:Real}(x::T)
n = 0
h = one(T)/2x
function hickerson()
n += 1
h *= n/x
end
end
function reporthickerson{T<:Real,U<:Integer}(a::T, nmax::U)
h = makehickerson(a)
hgm = makehickerson(prevfloat(a))
hgp = makehickerson(nextfloat(a))
println()
... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #0815 | 0815 |
<:48:x<:65:=<:6C:$=$=$$~<:03:+
$~<:ffffffffffffffb1:+$<:77:~$
~<:fffffffffffff8:x+$~<:03:+$~
<:06:x-$x<:0e:x-$=x<:43:x-$
|
http://rosettacode.org/wiki/Heronian_triangles | Heronian triangles | Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by:
A
=
s
(
s
−
a
)
(
s
−
b
)
(
s
−
c
)
,
{\displaystyle A={\sqrt {s(s-a)(s-b)(s-c)}},}
where s is half the perimeter of the triangle; that is,
s
=
a
+
b
+
c
2
.
{\displaystyle s... | #C.23 | C# | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b;... |
http://rosettacode.org/wiki/Higher-order_functions | Higher-order functions | Task
Pass a function as an argument to another function.
Related task
First-class functions
| #AntLang | AntLang | twice:{x[x[y]]}
echo twice "Hello!" |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #Crystal | Crystal |
require "http/server"
server = HTTP::Server.new do |context|
context.response.print "Goodbye World"
end
server.listen(8080)
|
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #D | D | import std.socket, std.array;
ushort port = 8080;
void main() {
Socket listener = new TcpSocket;
listener.bind(new InternetAddress(port));
listener.listen(10);
Socket currSock;
while (null !is (currSock = listener.accept())) {
currSock.sendTo(replace(q"EOF
HTTP/1.1 200 OK
Content-Type: text/html; ... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #EchoLisp | EchoLisp | (string-delimiter "")
(writeln
#<<
A noir, E blanc, I rouge, U vert, O bleu : voyelles,
Je dirai quelque jour vos naissances latentes :
A, noir corset velu des mouches éclatantes
Qui bombinent autour des puanteurs cruelles,
Golfes d'ombre ; E, candeur des vapeurs et des tentes,
Lances des glaciers fiers, rois blancs, ... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Elixir | Elixir | IO.puts """
привет
мир
""" |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Erlang | Erlang |
2> S = " ad
2> 123
2> the end".
3> io:fwrite( S ).
ad
123
the end
|
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #F.23 | F# | [[ |
http://rosettacode.org/wiki/History_variables | History variables | Storing the history of objects in a program is a common task.
Maintaining the history of an object in a program has traditionally required programmers either to write specific code for handling the historical data, or to use a library which supports history logging.
History variables are variables in a programming la... | #OCaml | OCaml |
open Stack
(* The following line is only for convenience when typing code *)
module H = Stack
let show_entry e =
Printf.printf "History entry: %5d\n" e
let () =
let hs = H.create() in
H.push 111 hs ;
H.push 4 hs ;
H.push 42 hs ;
H.iter show_entry hs;
hs |> H.pop |> Printf.printf "%d\n";
hs |> H... |
http://rosettacode.org/wiki/History_variables | History variables | Storing the history of objects in a program is a common task.
Maintaining the history of an object in a program has traditionally required programmers either to write specific code for handling the historical data, or to use a library which supports history logging.
History variables are variables in a programming la... | #OxygenBasic | OxygenBasic |
'============
class History
'============
indexbase 0
string buf
sys ii,ld,pb
method constructor(sys n=1000, l=sizeof sys) {buf=nuls n*l : pb=strptr buf : ld=l : ii=0}
method destructor () {clear}
'
method setup(sys n=1000, l=sizeof sys) {buf=nuls n*l : pb=strptr buf : ld=l : ii=0}
method clear() ... |
http://rosettacode.org/wiki/Hofstadter_Figure-Figure_sequences | Hofstadter Figure-Figure sequences | These two sequences of positive integers are defined as:
R
(
1
)
=
1
;
S
(
1
)
=
2
R
(
n
)
=
R
(
n
−
1
)
+
S
(
n
−
1
)
,
n
>
1.
{\displaystyle {\begin{aligned}R(1)&=1\ ;\ S(1)=2\\R(n)&=R(n-1)+S(n-1),\quad n>1.\end{aligned}}}
The sequence
S
(
n
)
{\displaystyle S(n)}
is further... | #Haskell | Haskell | import Data.List (delete, sort)
-- Functions by Reinhard Zumkeller
ffr :: Int -> Int
ffr n = rl !! (n - 1)
where
rl = 1 : fig 1 [2 ..]
fig n (x:xs) = n_ : fig n_ (delete n_ xs)
where
n_ = n + x
ffs :: Int -> Int
ffs n = rl !! n
where
rl = 2 : figDiff 1 [2 ..]
figDiff n (x:xs) = x :... |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #Java | Java | import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Horner {
public static void main(String[] args){
List<Double> coeffs = new ArrayList<Double>();
coeffs.add(-19.0);
coeffs.add(7.0);
coeffs.add(-4.0);
coeffs.add(6.0);
Syste... |
http://rosettacode.org/wiki/Hilbert_curve | Hilbert curve |
Task
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.
| #Java | Java | // Translation from https://en.wikipedia.org/wiki/Hilbert_curve
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class HilbertCurve {
public static class Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
... |
http://rosettacode.org/wiki/Honeycombs | Honeycombs | The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position... | #PureBasic | PureBasic | Structure hexGadget
text.s
Status.i ;nonselected = 0, selected = 1
center.POINT ;location of hex's center
List shape.POINT()
EndStructure
Structure honeycomb
gadgetID.i
margins.POINT
unusedLetters.s
chosen.s
maxLength.i
Array hexGadgets.hexGadget(0)
textY.i
EndStructure
Prototype hexEvent_... |
http://rosettacode.org/wiki/Holidays_related_to_Easter | Holidays related to Easter | Task
Calculate the dates of:
Easter
Ascension Thursday
Pentecost
Trinity Sunday
Corpus Christi feast (for Catholic)
All Saints' Sunday (for Orthodox)
As an example, calculate for the first year of each century from;
years 400 to 2100 CE and for
years 2010 to 2020 CE.
Note
... | #F.C5.8Drmul.C3.A6 | Fōrmulæ | package main
import (
"fmt"
"time"
)
type holiday struct {
time.Time
}
func easter(y int) holiday {
c := y / 100
n := mod(y, 19)
i := mod(c-c/4-(c-(c-17)/25)/3+19*n+15, 30)
i -= (i / 28) * (1 - (i/28)*(29/(i+1))*((21-n)/11))
l := i - mod(y+y/4+i+2-c+c/4, 7)
m := 3 + (l+40)/44
... |
http://rosettacode.org/wiki/Horizontal_sundial_calculations | Horizontal sundial calculations | Task
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), wit... | #Julia | Julia |
print("Enter latitude => ")
lat = parse(Float64, readline(STDIN))
print("Enter longitude => ")
lng = parse(Float64, readline(STDIN))
print("Enter legal meridian => ")
ref = parse(Float64, readline(STDIN))
println()
slat = sin(deg2rad(lat))
@printf " sine of latitude: %.3f\n" slat
@printf " diff l... |
http://rosettacode.org/wiki/Horizontal_sundial_calculations | Horizontal sundial calculations | Task
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), wit... | #Kotlin | Kotlin | import java.lang.Math.atan2
import java.lang.Math.cos
import java.lang.Math.sin
import java.lang.Math.toDegrees
import java.lang.Math.toRadians
// version 1.1.4
fun main(args: Array<String>) {
println("Please enter the following in degrees:")
print(" Latitude : ")
val lat = readLine()!!.toDouble(... |
http://rosettacode.org/wiki/Huffman_coding | Huffman coding | Huffman encoding is a way to assign binary codes to symbols that reduces the overall number of bits used to encode a typical string of those symbols.
For example, if you use letters as symbols and have details of the frequency of occurrence of those letters in typical strings, then you could just encode each letter wi... | #OCaml | OCaml | type 'a huffman_tree =
| Leaf of 'a
| Node of 'a huffman_tree * 'a huffman_tree
module HSet = Set.Make
(struct
type t = int * char huffman_tree (* pair of frequency and the tree *)
let compare = compare
(* We can use the built-in compare function to order this: it will order
first by ... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #SNOBOL4 | SNOBOL4 |
output = host(4,"HOSTNAME")
end |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #SQL | SQL |
SELECT host_name FROM v$instance;
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #SQL_PL | SQL PL |
SELECT HOST_NAME FROM SYSIBMADM.ENV_SYS_INFO
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Standard_ML | Standard ML | NetHostDB.getHostName () |
http://rosettacode.org/wiki/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #REXX | REXX | /*REXX program creates and displays any sized identity matrix (centered, with title).*/
do k=3 to 6 /* [↓] build and display a sq. matrix.*/
call ident_mat k /*build & display a KxK square matrix. */
end /*k*/ ... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Visual_Basic_.NET | Visual Basic .NET | Dim s As String = "123"
s = CStr(CInt("123") + 1)
' or
s = (CInt("123") + 1).ToString |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Vlang | Vlang | // Increment a numerical string in V
module main
// V int conversion will give 0 for nonnumeric strings
pub fn main() {
mut numstr := "-5"
print("numstr: ${numstr:-5} ")
numstr = (numstr.int()+1).str()
println("numstr: $numstr")
// Run a few tests
for testrun in ["0", "100", "00110", "abc", ... |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #REXX | REXX | /*REXX program prompts for two integers, compares them, and displays the results.*/
numeric digits 2000 /*for the users that really go ka─razy.*/
@=copies('─', 20) /*eyeball catcher for the user's eyen. */
a=getInt(@ 'Please enter your 1st integer:') ... |
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #Factor | Factor | USE: http.client
"http://www.rosettacode.org" http-get nip print
|
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #Forth | Forth |
include unix/socket.fs
s" localhost" 80 open-socket
dup s\" GET / HTTP/1.0\n\n" rot write-socket
dup pad 8092 read-socket type
close-socket
|
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #Go | Go | package main
import (
"fmt"
)
func main() {
a := []int{0, 1, 1} // ignore 0 element. work 1 based.
x := 1 // last number in list
n := 2 // index of last number in list = len(a)-1
mallow := 0
for p := 1; p < 20; p++ {
max := 0.
for nextPot := n*2; n < nextPot; {
... |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #C.23 | C# | static class StdErr
{
static void Main(string[] args)
{
Console.Error.WriteLine("Goodbye, World!");
}
} |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #C.2B.2B | C++ | #include <iostream>
int main() {
std::cerr << "Goodbye, World!\n";
} |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #Clojure | Clojure | (binding [*out* *err*]
(println "Goodbye, world!")) |
http://rosettacode.org/wiki/Hofstadter_Q_sequence | Hofstadter Q sequence | Hofstadter Q sequence
Q
(
1
)
=
Q
(
2
)
=
1
,
Q
(
n
)
=
Q
(
n
−
Q
(
n
−
1
)
)
+
Q
(
n
−
Q
(
n
−
2
)
)
,
n
>
2.
{\displaystyle {\begin{aligned}Q(1)&=Q(2)=1,\\Q(n)&=Q{\big (}n-Q(n-1){\big )}+Q{\big (}n-Q(n-2){\big )},\quad n>2.\end{aligned}}}
It is defined like the Fibonacc... | #Cowgol | Cowgol | include "cowgol.coh";
# Generate 1000 terms of the Q sequence
var Q: uint16[1001];
Q[1] := 1;
Q[2] := 1;
var n: @indexof Q := 3;
while n <= 1000 loop
Q[n] := Q[n-Q[n-1]] + Q[n-Q[n-2]];
n := n + 1;
end loop;
# Print first 10 terms
print("The first 10 terms are: ");
n := 1;
while n <= 10 loop
print_i16(... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #Kotlin | Kotlin | // version 1.1.4
import java.math.BigDecimal
import java.math.BigInteger
import java.math.MathContext
object Hickerson {
private const val LN2 = "0.693147180559945309417232121458"
fun almostInteger(n: Int): Boolean {
val a = BigDecimal(LN2).pow(n + 1) * BigDecimal(2)
var nn = n
var... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | h[n_] = n!/(2 (Log[2])^(n + 1));
firstdecimal[x_] := Floor[10 x] - 10 Floor[x];
almostIntegerQ[x_] := firstdecimal[x] == 0 || firstdecimal[x] == 9;
Table[{i, AccountingForm[N[h[i], 50], {Infinity, 5}], almostIntegerQ[N[h[i], 50]]}, {i, 1, 17}] // TableForm |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #11l | 11l | print(‘Hello world!’) |
http://rosettacode.org/wiki/Heronian_triangles | Heronian triangles | Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by:
A
=
s
(
s
−
a
)
(
s
−
b
)
(
s
−
c
)
,
{\displaystyle A={\sqrt {s(s-a)(s-b)(s-c)}},}
where s is half the perimeter of the triangle; that is,
s
=
a
+
b
+
c
2
.
{\displaystyle s... | #C.2B.2B | C++ | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;... |
http://rosettacode.org/wiki/Higher-order_functions | Higher-order functions | Task
Pass a function as an argument to another function.
Related task
First-class functions
| #AppleScript | AppleScript | -- This handler takes a script object (singer)
-- with another handler (call).
on sing about topic by singer
call of singer for "Of " & topic & " I sing"
end sing
-- Define a handler in a script object,
-- then pass the script object.
script cellos
on call for what
say what using "Cellos"
end call... |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #Dart | Dart | import 'dart:io';
main() async {
var server = await HttpServer.bind('127.0.0.1', 8080);
await for (HttpRequest request in server) {
request.response
..write('Hello, world')
..close();
}
} |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #Delphi | Delphi | program HelloWorldWebServer;
{$APPTYPE CONSOLE}
uses SysUtils, IdContext, IdCustomHTTPServer, IdHTTPServer;
type
TWebServer = class
private
FHTTPServer: TIdHTTPServer;
public
constructor Create;
destructor Destroy; override;
procedure HTTPServerCommandGet(AContext: TIdContext;
ARequest... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Factor | Factor | [[ |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Forth | Forth | \ GForth specific words:
\ under+ ( a b c -- a+c b) , latest ( -- nt ) , name>string ( nt -- ca u )
\ Should not be a problem to modify it to work with other Forth implementation:
: $! ( ca u -- a )
dup >R dup , here swap move R> allot ;
: $@ ( a -- ca u )
dup @ 1 cells under+ ;
: c!+ ( c ca - ca+1 )
tuck... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Fortran | Fortran |
INTEGER I !A stepper.
CHARACTER*666 I AM !Sufficient space.
I AM = "<col72
C 111111111122222222223333333333444444444455555555556666666666
C 123456789012345678901234567890123456789012345678901234567890123456789
... |
http://rosettacode.org/wiki/History_variables | History variables | Storing the history of objects in a program is a common task.
Maintaining the history of an object in a program has traditionally required programmers either to write specific code for handling the historical data, or to use a library which supports history logging.
History variables are variables in a programming la... | #PARI.2FGP | PARI/GP | default(histsize, 1000) \\ or some other positive number to suit
1+7
sin(Pi)
2^100
\a1 \\ display history item #1, etc.
% \\ alternate syntax
%1 \\ alternate syntax
\a2
\a3
[%1, %2, %3] \\ or any other command using these values |
http://rosettacode.org/wiki/History_variables | History variables | Storing the history of objects in a program is a common task.
Maintaining the history of an object in a program has traditionally required programmers either to write specific code for handling the historical data, or to use a library which supports history logging.
History variables are variables in a programming la... | #Peloton | Peloton | Turn history on <@ DEFHST>__on</@>
Notify Protium we are interested in the variable mv
<@ DEFHST>mv</@>
Assign a value: <@ LETVARLIT>mv|first value</@><@ SAYVAR>mv</@>
Reassign the value: <@ LETVARLIT>mv|second value</@><@ SAYVAR>mv</@>
Reassign the value: <@ LETVARLIT>mv|third value</@><@ SAYVAR>mv</@>
Dump hist... |
http://rosettacode.org/wiki/Hofstadter_Figure-Figure_sequences | Hofstadter Figure-Figure sequences | These two sequences of positive integers are defined as:
R
(
1
)
=
1
;
S
(
1
)
=
2
R
(
n
)
=
R
(
n
−
1
)
+
S
(
n
−
1
)
,
n
>
1.
{\displaystyle {\begin{aligned}R(1)&=1\ ;\ S(1)=2\\R(n)&=R(n-1)+S(n-1),\quad n>1.\end{aligned}}}
The sequence
S
(
n
)
{\displaystyle S(n)}
is further... | #Icon_and_Unicon | Icon and Unicon | link printf,ximage
procedure main()
printf("Hofstader ff sequences R(n:= 1 to %d)\n",N := 10)
every printf("R(%d)=%d\n",n := 1 to N,ffr(n))
L := list(N := 1000,0)
zero := dup := oob := 0
every n := 1 to (RN := 40) do
if not L[ffr(n)] +:= 1 then # count R occurrence
oob +:= 1 ... |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #JavaScript | JavaScript | function horner(coeffs, x) {
return coeffs.reduceRight( function(acc, coeff) { return(acc * x + coeff) }, 0);
}
console.log(horner([-19,7,-4,6],3)); // ==> 128
|
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #Julia | Julia | function horner(coefs, x)
s = coefs[end] * one(x)
for k in length(coefs)-1:-1:1
s = coefs[k] + x * s
end
return s
end
@show horner([-19, 7, -4, 6], 3) |
http://rosettacode.org/wiki/Hilbert_curve | Hilbert curve |
Task
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.
| #JavaScript | JavaScript | const hilbert = (width, spacing, points) => (x, y, lg, i1, i2, f) => {
if (lg === 1) {
const px = (width - x) * spacing;
const py = (width - y) * spacing;
points.push(px, py);
return;
}
lg >>= 1;
f(x + i1 * lg, y + i1 * lg, lg, i1, 1 - i2, f);
f(x + i2 * lg, y + (1 - ... |
http://rosettacode.org/wiki/Honeycombs | Honeycombs | The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position... | #Python | Python | #lang racket
(struct Hex (x y letter clicked?) #:mutable #:transparent)
(define hexes
(let* ([A (char->integer #\A)]
[letters (take (shuffle (map (compose string integer->char)
(range A (+ A 26))))
20)])
(for*/list ([row 4] [column 5])
... |
http://rosettacode.org/wiki/Honeycombs | Honeycombs | The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position... | #Racket | Racket | #lang racket
(struct Hex (x y letter clicked?) #:mutable #:transparent)
(define hexes
(let* ([A (char->integer #\A)]
[letters (take (shuffle (map (compose string integer->char)
(range A (+ A 26))))
20)])
(for*/list ([row 4] [column 5])
... |
http://rosettacode.org/wiki/Holidays_related_to_Easter | Holidays related to Easter | Task
Calculate the dates of:
Easter
Ascension Thursday
Pentecost
Trinity Sunday
Corpus Christi feast (for Catholic)
All Saints' Sunday (for Orthodox)
As an example, calculate for the first year of each century from;
years 400 to 2100 CE and for
years 2010 to 2020 CE.
Note
... | #Go | Go | package main
import (
"fmt"
"time"
)
type holiday struct {
time.Time
}
func easter(y int) holiday {
c := y / 100
n := mod(y, 19)
i := mod(c-c/4-(c-(c-17)/25)/3+19*n+15, 30)
i -= (i / 28) * (1 - (i/28)*(29/(i+1))*((21-n)/11))
l := i - mod(y+y/4+i+2-c+c/4, 7)
m := 3 + (l+40)/44
... |
http://rosettacode.org/wiki/Horizontal_sundial_calculations | Horizontal sundial calculations | Task
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), wit... | #Liberty_BASIC | Liberty BASIC | global pi
pi = 3.14159265
input "Enter latitude (degrees) : "; latitude ' -4.95
input "Enter longitude (degrees) : "; longitude ' -150.5
input "Enter legal meridian (degrees): "; meridian ' -150.0
print
print "Time Sun hour angle Dial hour line angle"
for hour = 6 TO 18
hra = ... |
http://rosettacode.org/wiki/Huffman_coding | Huffman coding | Huffman encoding is a way to assign binary codes to symbols that reduces the overall number of bits used to encode a typical string of those symbols.
For example, if you use letters as symbols and have details of the frequency of occurrence of those letters in typical strings, then you could just encode each letter wi... | #Ol | Ol |
(define phrase "this is an example for huffman encoding")
; prepare initial probabilities table
(define table (ff->list
(fold (lambda (ff x)
(put ff x (+ (ff x 0) 1)))
{}
(string->runes phrase))))
; just sorter...
(define (resort l)
(sort (lambda (x y) (< (cdr x) (cdr y))) l))
; ...t... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Swift | Swift | print(ProcessInfo.processInfo.hostName) |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Tcl | Tcl | set hname [info hostname] |
http://rosettacode.org/wiki/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #Ring | Ring |
size = 5
im = newlist(size, size)
identityMatrix(size, im)
for r = 1 to size
for c = 1 to size
see im[r][c]
next
see nl
next
func identityMatrix s, m
m = newlist(s, s)
for i = 1 to s
m[i][i] = 1
next
return m
func newlist x, y
if isstring(x) x=0+x ok
if ... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Wren | Wren | var ns = "41"
var n = Num.fromString(ns) + 1
var ns2 = "%(n)"
System.print("%(ns) + 1 = %(ns2)") |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Ring | Ring |
Func Compare a,b
if a < b
See "A is less than B"
but a > b
See "A is more than B"
else
See "A equals B"
ok
|
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #FreeBASIC | FreeBASIC | Dim As String urlfile
urlfile="start http://rosettacode.org/wiki/Main_Page"
Print urlfile
Shell(urlfile)
Print !"\n--- pulsa RETURN para continuar ---"
Sleep |
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #Haskell | Haskell | import Data.List
import Data.Ord
import Data.Array
import Text.Printf
hc :: Int -> Array Int Int
hc n = arr
where arr = listArray (1, n) $ 1 : 1 : map (f (arr!)) [3 .. n]
f a i = a (a $ i - 1) + a (i - a (i - 1))
printMaxima :: (Int, (Int, Double)) -> IO ()
printMaxima (n, (pos, m)) =
printf "Max betw... |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #CLU | CLU | start_up = proc ()
stream$putl(stream$error_output(), "Goodbye, World!")
end start_up |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #CMake | CMake | message("Goodbye, World!") |
http://rosettacode.org/wiki/Hofstadter_Q_sequence | Hofstadter Q sequence | Hofstadter Q sequence
Q
(
1
)
=
Q
(
2
)
=
1
,
Q
(
n
)
=
Q
(
n
−
Q
(
n
−
1
)
)
+
Q
(
n
−
Q
(
n
−
2
)
)
,
n
>
2.
{\displaystyle {\begin{aligned}Q(1)&=Q(2)=1,\\Q(n)&=Q{\big (}n-Q(n-1){\big )}+Q{\big (}n-Q(n-2){\big )},\quad n>2.\end{aligned}}}
It is defined like the Fibonacc... | #D | D | import std.stdio, std.algorithm, std.functional, std.range;
int Q(in int n) nothrow
in {
assert(n > 0);
} body {
alias mQ = memoize!Q;
if (n == 1 || n == 2)
return 1;
else
return mQ(n - mQ(n - 1)) + mQ(n - mQ(n - 2));
}
void main() {
writeln("Q(n) for n = [1..10] is: ", iota(1, 1... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #ML | ML | local
fun log (n, k, last = sum, sum) = sum
| (n, k, last, sum) = log (n, k + 1, sum, sum + ( 1 / (k * n ^ k)))
| n = log (n, 1, 1, 0);
val ln2 = log 2
in
fun hickerson n = (fold (opt *,1) ` iota n) / (2 * ln2 ^ (n+1));
... |
http://rosettacode.org/wiki/Hello_world/Text | Hello world/Text | Hello world/Text is part of Short Circuit's Console Program Basics selection.
Task
Display the string Hello world! on a text console.
Related tasks
Hello world/Graphical
Hello world/Line Printer
Hello world/Newbie
Hello world/Newline omission
Hello world/Standard error
Hello world/Web server
| #360_Assembly | 360 Assembly |
HELLO CSECT
USING HELLO,15
LA 1,MSGAREA Point Register 1 to message area
SVC 35 Invoke SVC 35 (Write to Operator)
BR 14 Return
MSGAREA EQU * Message Area
DC AL2(19) Total area length = 19 (Prefix length:4 + Dat... |
http://rosettacode.org/wiki/Heronian_triangles | Heronian triangles | Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by:
A
=
s
(
s
−
a
)
(
s
−
b
)
(
s
−
c
)
,
{\displaystyle A={\sqrt {s(s-a)(s-b)(s-c)}},}
where s is half the perimeter of the triangle; that is,
s
=
a
+
b
+
c
2
.
{\displaystyle s... | #CoffeeScript | CoffeeScript | heronArea = (a, b, c) ->
s = (a + b + c) / 2
Math.sqrt s * (s - a) * (s - b) * (s - c)
isHeron = (h) -> h % 1 == 0 and h > 0
gcd = (a, b) ->
leftover = 1
dividend = if a > b then a else b
divisor = if a > b then b else a
until leftover == 0
leftover = dividend % divisor
if le... |
http://rosettacode.org/wiki/Higher-order_functions | Higher-order functions | Task
Pass a function as an argument to another function.
Related task
First-class functions
| #Arturo | Arturo | doSthWith: function [x y f][
f x y
]
print [ "add:" doSthWith 2 3 $[x y][x+y] ]
print [ "multiply:" doSthWith 2 3 $[x y][x*y] ] |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #Dylan.NET | Dylan.NET |
//compile with dylan.NET 11.5.1.2 or later!!
#refstdasm "mscorlib.dll"
#refstdasm "System.dll"
import System.Text
import System.Net.Sockets
import System.Net
assembly helloweb exe
ver 1.1.0.0
namespace WebServer
class public GoodByeWorld
method public static void main(var args as string[])
... |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #Erlang | Erlang |
-module( hello_world_web_server ).
-export( [do/1, httpd_start/2, httpd_stop/1, task/0] ).
do( _Data ) ->
{proceed, [{response,{200,"Goodbye, World!"}}]}.
httpd_start( Port, Module ) ->
Arguments = [{bind_address, "localhost"}, {port, Port}, {ipfamily, inet},
{modules, [Module]},
{server_name,erlang... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Free_Pascal | Free Pascal |
Dim As String text1 = " " & Chr(10) & _
"<<'FOO' " & Chr(10) & _
" 'jaja', `esto`" & Chr(10) & _
" <simula>" & Chr(10) & _
" \un\" & Chr(10) & _
!" ${ejemplo} de \"heredoc\"" & Chr(10) & _
" en FreeBASIC."
Dim As String text2 = "Esta es la primera linea." & Chr(10) & _
"Esta es la segunda linea." & Chr(10) & _... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #FreeBASIC | FreeBASIC |
Dim As String text1 = " " & Chr(10) & _
"<<'FOO' " & Chr(10) & _
" 'jaja', `esto`" & Chr(10) & _
" <simula>" & Chr(10) & _
" \un\" & Chr(10) & _
!" ${ejemplo} de \"heredoc\"" & Chr(10) & _
" en FreeBASIC."
Dim As String text2 = "Esta es la primera linea." & Chr(10) & _
"Esta es la segunda linea." & Chr(10) & _... |
http://rosettacode.org/wiki/History_variables | History variables | Storing the history of objects in a program is a common task.
Maintaining the history of an object in a program has traditionally required programmers either to write specific code for handling the historical data, or to use a library which supports history logging.
History variables are variables in a programming la... | #Perl | Perl | package History;
sub TIESCALAR {
my $cls = shift;
my $cur_val = shift;
return bless [];
}
sub FETCH {
return shift->[-1]
}
sub STORE {
my ($var, $val) = @_;
push @$var, $val;
return $val;
}
sub get(\$) { @{tied ${+shift}} }
sub on(\$) { tie ${+shift}, __PACKAGE__ }
sub off(\$) { untie ${+shift} }
sub un... |
http://rosettacode.org/wiki/Hofstadter_Figure-Figure_sequences | Hofstadter Figure-Figure sequences | These two sequences of positive integers are defined as:
R
(
1
)
=
1
;
S
(
1
)
=
2
R
(
n
)
=
R
(
n
−
1
)
+
S
(
n
−
1
)
,
n
>
1.
{\displaystyle {\begin{aligned}R(1)&=1\ ;\ S(1)=2\\R(n)&=R(n-1)+S(n-1),\quad n>1.\end{aligned}}}
The sequence
S
(
n
)
{\displaystyle S(n)}
is further... | #J | J | R=: 1 1 3
S=: 0 2 4
FF=: 3 :0
while. +./y>:R,&#S do.
R=: R,({:R)+(<:#R){S
S=: (i.<:+/_2{.R)-.R
end.
R;S
)
ffr=: { 0 {:: FF@(>./@,)
ffs=: { 1 {:: FF@(0,>./@,) |
http://rosettacode.org/wiki/Hofstadter_Figure-Figure_sequences | Hofstadter Figure-Figure sequences | These two sequences of positive integers are defined as:
R
(
1
)
=
1
;
S
(
1
)
=
2
R
(
n
)
=
R
(
n
−
1
)
+
S
(
n
−
1
)
,
n
>
1.
{\displaystyle {\begin{aligned}R(1)&=1\ ;\ S(1)=2\\R(n)&=R(n-1)+S(n-1),\quad n>1.\end{aligned}}}
The sequence
S
(
n
)
{\displaystyle S(n)}
is further... | #Java | Java | import java.util.*;
class Hofstadter
{
private static List<Integer> getSequence(int rlistSize, int slistSize)
{
List<Integer> rlist = new ArrayList<Integer>();
List<Integer> slist = new ArrayList<Integer>();
Collections.addAll(rlist, 1, 3, 7);
Collections.addAll(slist, 2, 4, 5, 6);
List<Intege... |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #K | K |
horner:{y _sv|x}
horner[-19 7 -4 6;3]
128
|
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #Kotlin | Kotlin | // version 1.1.2
fun horner(coeffs: DoubleArray, x: Double): Double {
var sum = 0.0
for (i in coeffs.size - 1 downTo 0) sum = sum * x + coeffs[i]
return sum
}
fun main(args: Array<String>) {
val coeffs = doubleArrayOf(-19.0, 7.0, -4.0, 6.0)
println(horner(coeffs, 3.0))
} |
http://rosettacode.org/wiki/Hilbert_curve | Hilbert curve |
Task
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.
| #jq | jq | include "simple-turtle" {search: "."};
def rules:
{ A: "-BF+AFA+FB-",
B: "+AF-BFB-FA+" };
def hilbert($count):
rules as $rules
| def p($count):
if $count <= 0 then .
else gsub("A"; "a") | gsub("B"; $rules["B"]) | gsub("a"; $rules["A"])
| p($count-1)
end;
"A" | p($count) ;
def... |
http://rosettacode.org/wiki/Hilbert_curve | Hilbert curve |
Task
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.
| #Julia | Julia | using Gtk, Graphics, Colors
Base.isless(p1::Vec2, p2::Vec2) = (p1.x == p2.x ? p1.y < p2.y : p1.x < p2.x)
struct Line
p1::Point
p2::Point
end
dist(p1, p2) = sqrt((p2.y - p1.y)^2 + (p2.x - p1.x)^2)
length(ln::Line) = dist(ln.p1, ln.p2)
isvertical(line) = (line.p1.x == line.p2.x)
ishorizontal(line) = (line.p1.y ==... |
http://rosettacode.org/wiki/Honeycombs | Honeycombs | The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position... | #Ruby | Ruby | Shoes.app(title: "Honeycombs", height: 700, width: 700) do
C = Math::cos(Math::PI/3)
S = Math::sin(Math::PI/3)
Radius = 60.0
letters = [
%w[L A R N D 1 2],
%w[G U I Y T 3 4],
%w[P C F E B 5 6],
%w[V S O M K 7 8],
%w[Q X J Z H 9 0],
]
def highlight(hexagon)
hexagon.style(fill: ma... |
http://rosettacode.org/wiki/Holidays_related_to_Easter | Holidays related to Easter | Task
Calculate the dates of:
Easter
Ascension Thursday
Pentecost
Trinity Sunday
Corpus Christi feast (for Catholic)
All Saints' Sunday (for Orthodox)
As an example, calculate for the first year of each century from;
years 400 to 2100 CE and for
years 2010 to 2020 CE.
Note
... | #Icon_and_Unicon | Icon and Unicon | link printf
procedure main()
printf("Christian holidays, related to Easter, for each centennial from 400 to 2100 CE:\n")
every year := 400 to 2100 by 100 do
OutputHolidays(year)
printf("\nChristian holidays, related to Easter, for years from 2010 to 2020 CE:\n")
every year := 2010 to 2020 do
... |
http://rosettacode.org/wiki/Horizontal_sundial_calculations | Horizontal sundial calculations | Task
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), wit... | #LiveCode | LiveCode | on mouseUp
ask "Enter lng,lat,meridian"
if it is empty then exit mouseup
// -150.5, -4.95, -150.0
put item 1 of it into longitude
put item 2 of it into latitude
put item 3 of it into meridian
repeat with hour = 6 TO 18
put 15 *hour - longitude + meridian - 180 into hra
put ... |
http://rosettacode.org/wiki/Horizontal_sundial_calculations | Horizontal sundial calculations | Task
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), wit... | #Logo | Logo | type "|Enter latitude: |
make "lat readword
type "|Enter longitude: |
make "long readword
type "|Enter legal meridian: |
make "long :long - readword
print [Hour : HourAngle , DialAngle]
for [hour -6 6] [
make "hra 15 * :hour - :long
make "hla arctan product sin :lat quotient sin :hra cos :hra
print (sentence... |
http://rosettacode.org/wiki/Huffman_coding | Huffman coding | Huffman encoding is a way to assign binary codes to symbols that reduces the overall number of bits used to encode a typical string of those symbols.
For example, if you use letters as symbols and have details of the frequency of occurrence of those letters in typical strings, then you could just encode each letter wi... | #Perl | Perl | use 5.10.0;
use strict;
# produce encode and decode dictionary from a tree
sub walk {
my ($node, $code, $h, $rev_h) = @_;
my $c = $node->[0];
if (ref $c) { walk($c->[$_], $code.$_, $h, $rev_h) for 0,1 }
else { $h->{$c} = $code; $rev_h->{$code} = $c }
$h, $rev_h
}
# make a tree, and return resulting ... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Toka | Toka | 2 import gethostname
1024 chars is-array foo
foo 1024 gethostname
foo type |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.