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/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... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | МГ П2 -> МГ П1 -> МГ sin П0
6 /-/ П3
ИП3 1 5 * ИП1 ИП2 - - П4
tg ИП0 * arctg ИП4 ИП3 С/П
ИП3 1 + П3 7 - x=0 12
Сx С/П |
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... | #Modula-2 | Modula-2 |
MODULE SunDial;
FROM STextIO IMPORT
WriteString, WriteLn, SkipLine;
FROM SRealIO IMPORT
ReadReal, WriteFixed, WriteFloat;
FROM SWholeIO IMPORT
WriteInt;
FROM RealMath IMPORT
sin, pi, arctan, tan;
VAR
Lat, Slat, Lng, Ref: REAL;
Hour: INTEGER;
HourAngle, HourLineAngle: REAL;
BEGIN
WriteString("Enter... |
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... | #Picat | Picat | go =>
huffman("this is an example for huffman encoding").
huffman(LA) :-
LS=sort(LA),
packList(LS,PL),
PLS=sort(PL).remove_dups(),
build_tree(PLS, A),
coding(A, [], C),
SC=sort(C).remove_dups(),
println("Symbol\tWeight\tCode"),
foreach(SS in SC) print_code(SS) end.
build_tree([[V1|R1], [V2... |
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
⋮
⋮
⋮
⋱
... | #Scala | Scala | def identityMatrix(n:Int)=Array.tabulate(n,n)((x,y) => if(x==y) 1 else 0)
def printMatrix[T](m:Array[Array[T]])=m map (_.mkString("[", ", ", "]")) mkString "\n"
printMatrix(identityMatrix(5)) |
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 |... | #SAS | SAS | /* Showing operators and their fortran-like equivalents. Note that ~= and ^= both mean "different" */
data _null_;
input a b;
put a= b=;
if a = b then put "a = b";
if a ^= b then put "a ^= b";
if a ~= b then put "a ~= b";
if a < b then put "a < b";
if a > b then put "a > b";
if a <= b then put "a <= b";
if a >= b then ... |
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.
| #Groovy | Groovy |
new URL("http://www.rosettacode.org").eachLine { println it }
|
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... | #JavaScript | JavaScript | var hofst_10k = function(n) {
var memo = [1, 1];
var a = function(n) {
var result = memo[n-1];
if (typeof result !== 'number') {
result = a(a(n-1))+a(n-a(n-1));
memo[n-1] = result;
}
return result;
}
return a;
}();
var maxima_between_twos = function(exp) {
var current_max = 0;
for(var i = Math... |
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 ... | #E | E | stderr.println("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 ... | #Elixir | Elixir | IO.puts :stderr, "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 ... | #Emacs_Lisp | Emacs Lisp | (message "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 ... | #Erlang | Erlang | io:put_chars(standard_error, "Goodbye, World!\n"). |
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... | #Elixir | Elixir | defmodule Hofstadter do
defp flip(v2, v1) when v1 > v2, do: 1
defp flip(_v2, _v1), do: 0
defp list_terms(max, n, acc), do: Enum.map_join(n..max, ", ", &acc[&1])
defp hofstadter(n, n, acc, flips) do
IO.puts "The first ten terms are: #{list_terms(10, 1, acc)}"
IO.puts "The 1000'th term is #{acc[1000]}... |
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... | #PL.2FI | PL/I | Hickerson: procedure options (main); /* 12 January 2014 */
declare s float (18), (i, n) fixed binary;
declare is fixed decimal (30);
declare f fixed decimal (4,3);
do n = 1 to 16; /* 17 exceeds hardware precision */
s = 0.5Q0 / 0.693147180559945309417232121458;
do i = 1 to n;
s = (s *... |
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
| #8080_Assembly | 8080 Assembly | ; This is Hello World, written in 8080 assembly to run under CP/M
; As you can see, it is similar to the 8086, and CP/M is very
; similar to DOS in the way it is called.
org 100h ; CP/M .COM entry point is 100h - like DOS
mvi c,9 ; C holds the syscall, 9 = print string - like DOS
lxi d,msg ; DE holds a pointer to... |
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... | #Elixir | Elixir | defmodule Heronian do
def triangle?(a,b,c) when a+b <= c, do: false
def triangle?(a,b,c) do
area = area(a,b,c)
area == round(area) and primitive?(a,b,c)
end
def area(a,b,c) do
s = (a + b + c) / 2
:math.sqrt(s * (s-a) * (s-b) * (s-c))
end
defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1
... |
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... | #ERRE | ERRE |
PROGRAM HERON
DIM LISTA%[600,4]
PROCEDURE GCD(J%,K%->MCD%)
WHILE J%<>K% DO
IF J%>K% THEN
J%=J%-K%
ELSE
K%=K%-J%
END IF
END WHILE
MCD%=J%
END PROCEDURE
BEGIN
PRINT(CHR$(12);) !CLS
FOR C%=1 TO 200 DO
FOR B%=1 TO C% DO
FOR A%=1 TO B% DO
... |
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
| #BQN | BQN | Uniq ← ⍷
•Show uniq {𝕎𝕩} 5‿6‿7‿5 |
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... | #Genie | Genie | /**
* Based on https://wiki.gnome.org/Projects/Genie/GIONetworkingSample
* Based on an example of Jezra Lickter http://hoof.jezra.net/snip/nV
*
* valac --pkg gio-2.0 --pkg gee-0.8 webserver.gs
* ./webserver
*/
[indent=8]
uses
GLib
Gee
init
var ws = new WebServer()
ws.run()
str... |
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 ... | #Lambdatalk | Lambdatalk |
1) defining a variable:
{def myVar 123}
2) defining some text:
Here is some
multi-line string. And here is
the value of "myVar": '{myVar}
That's all.
3) displays :
Here is some
multi-line string. And here is
the value of "myVar": 123
That's all.
|
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 ... | #langur | langur | val .s = q:block END
We put our text here.
Here we are, Doc.
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 ... | #Lingo | Lingo | str = "This is the first line.\
This is the second line.\
This ""E&"line""E&" contains quotes."
put str |
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 ... | #Lua | Lua |
print([[
This is a long paragraph of text
it is the simplest while using it
with lua, however it will have the
same line breaks and spacing as
you set in this block.
]])
print([=[by using equals signs, ]] may be embedded.]=])
local msg = [[this is a message that spans
multiple lines and will have the next li... |
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... | #Racket | Racket |
#lang racket
(require rackunit)
(struct hvar (current history) #:mutable)
(define (make-hvar v) (hvar v empty))
(define (hvar-set! hv new)
(match-define (hvar cur hist) hv)
(set-hvar-history! hv (cons cur hist))
(set-hvar-current! hv new))
(define (hvar-undo! hv)
(match-define (hvar cur (cons old hi... |
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... | #Raku | Raku | class HistoryVar {
has @.history;
has $!var handles <Str gist FETCH Numeric>;
method STORE($val) is rw {
push @.history, [now, $!var];
$!var = $val;
}
}
my \foo = HistoryVar.new;
foo = 1;
foo = 2;
foo += 3;
foo = 42;
.say for foo.history;
say "Current value: {foo}"; |
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... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | The instructions call for two functions.
Because S[n] is generated while computing R[n], one would normally avoid redundancy by combining
R and S into a single function that returns both sequences.
|
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... | #MATLAB_.2F_Octave | MATLAB / Octave | function [R,S] = ffr_ffs(N)
t = [1,0];
T = 1;
n = 1;
%while T<=1000,
while n<=N,
R = find(t,n);
S = find(~t,n);
T = R(n)+S(n);
% pre-allocate memory, this improves performance
if T > length(t), t = [t,zeros(size(t))]; end;
t(T) = 1;
n = n ... |
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... | #MATLAB | MATLAB | function accumulator = hornersRule(x,coefficients)
accumulator = 0;
for i = (numel(coefficients):-1:1)
accumulator = (accumulator * x) + coefficients(i);
end
end |
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... | #Maxima | Maxima | /* Function horner already exists in Maxima, though it operates on expressions, not lists of coefficients */
horner(5*x^3+2*x+1);
x*(5*x^2+2)+1
/* Here is an implementation */
horner2(p, x) := block([n, y, i],
n: length(p),
y: p[n],
for i: n - 1 step -1 thru 1 do y: y*x + p[i],
y
)$
horner2([-19, 7, -4,... |
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.
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Graphics@HilbertCurve[4] |
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.
| #Nim | Nim | const
Level = 4
Side = (1 shl Level) * 2 - 2
type Direction = enum E, N, W, S
const
# Strings to use according to direction.
Drawings1: array[Direction, string] = ["──", " │", "──", " │"]
# Strings to use according to old and current direction.
Drawings2: array[Direction, array[Direction, string]] =... |
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... | #Wren | Wren | import "graphics" for Canvas, Color
import "dome" for Window, Process
import "math" for Math
import "font" for Font
import "input" for Mouse, Keyboard
import "random" for Random
import "./polygon" for Polygon
var Rand = Random.new()
class Hexagon is Polygon {
static baseColor { Color.yellow }
static selecte... |
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
... | #Julia | Julia | # v0.6
using Dates
function easter(year::Int)::Date
a = rem(year, 19)
b, c = divrem(year, 100)
d = rem(19a + b - div(b, 4) - div(b - div(b + 8, 25) + 1, 3) + 15, 30)
e = rem(32 + 2 * rem(b, 4) + 2 * div(c, 4) - d - rem(c, 4), 7)
f = d + e - 7 * div(a + 11d + 22e, 451) + 114
month, day = divr... |
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... | #newLISP | newLISP | (define pi 3.141592654)
(define (radians degrees) (mul degrees (div pi 180)))
(define (degrees radians) (mul radians (div 180 pi)))
(print "Enter latitude => ")
(set 'lat (float (read-line)))
(print "Enter longitude => ")
(set 'lng (float (read-line)))
(print "Enter legal meridian => ")
(set 'rf (float... |
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... | #PicoLisp | PicoLisp | (de prio (Idx)
(while (cadr Idx) (setq Idx @))
(car Idx) )
(let (A NIL P NIL L NIL)
(for C (chop "this is an example for huffman encoding")
(accu 'A C 1) ) # Count characters
(for X A # Build index tree as priority queue
(idx 'P (cons (cdr X) (car ... |
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
⋮
⋮
⋮
⋱
... | #Scheme | Scheme |
(define (identity n)
(letrec
((uvec
(lambda (m i acc)
(if (= i n)
acc
(uvec m (+ i 1)
(cons (if (= i m) 1 0) acc)))))
(idgen
(lambda (i acc)
(if (= i n)
acc
(idgen (+ i 1)
(cons (uvec i 0 '()) acc))))))
(idgen 0 '())))
|
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 |... | #Scala | Scala | object IntCompare {
def main(args: Array[String]): Unit = {
val a=Console.readInt
val b=Console.readInt
if (a < b)
printf("%d is less than %d\n", a, b)
if (a == b)
printf("%d is equal to %d\n", a, b)
if (a > b)
printf("%d is greater than %d\n", 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 |... | #Scheme | Scheme | (define (my-compare a b)
(cond ((< a b) "A is less than B")
((> a b) "A is greater than B")
((= a b) "A equals B")))
(my-compare (read) (read)) |
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.
| #GUISS | GUISS | Start,Programs,Applications,Mozilla Firefox,Inputbox:address bar>www.rosettacode.org,Button:Go,
Click:Area:browser window,Type:[Control A],[Control C],Start,Programs,Accessories,Notepad,
Menu:Edit,Paste |
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... | #jq | jq | def hcSequence($limit):
reduce range(3; $limit) as $n ([0,1,1];
.[$n-1] as $p
| .[$n] = .[$p] + .[$n-$p]);
def task($limit):
hcSequence($limit) as $a
| " Range Maximum",
"---------------- --------",
(foreach range(2; $limit) as $n ( {max: $a[1], pow2: 1, p:1 };
($a[$n] / $n... |
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... | #Julia | Julia | # v0.6
# Task 1
function hofstadterconway(n::Integer)::Vector{Int}
rst = fill(1, n)
for i in 3:n
rst[i] = rst[rst[i - 1]] + rst[i - rst[i - 1]]
end
return rst
end
function hcfraction(n::Integer)::Vector{Float64}
rst = Array{Float64}(n)
for (i, a) in enumerate(hofstadterconway(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 ... | #Euphoria | Euphoria | puts(2,"Goodbye, world!\n") -- 2 means output to 'standard error' |
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 ... | #F.23 | F# | eprintfn "%s" "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 ... | #Factor | Factor | error-stream get [ "Goodbye, World! bbl, crashing" print flush ] with-output-stream* |
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... | #Erlang | Erlang | %% @author Jan Willem Luiten <jwl@secondmove.com>
%% Hofstadter Q Sequence for Rosetta Code
-module(hofstadter).
-export([main/0]).
-define(MAX, 100000).
flip(V2, V1) when V1 > V2 -> 1;
flip(_V2, _V1) -> 0.
list_terms(N, N, Acc) ->
io:format("~w~n", [array:get(N, Acc)]);
list_terms(Max, N, Acc) ->
io:format("~w... |
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... | #Python | Python | from decimal import Decimal
import math
def h(n):
'Simple, reduced precision calculation'
return math.factorial(n) / (2 * math.log(2) ** (n + 1))
def h2(n):
'Extended precision Hickerson function'
return Decimal(math.factorial(n)) / (2 * Decimal(2).ln() ** (n + 1))
for n in range(18):
x = h2(n... |
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... | #Racket | Racket | #lang racket
(require math/bigfloat)
(define (hickerson n)
(bf/ (bffactorial n)
2.bf
(bfexpt (bflog 2.bf) (bf (+ n 1)))))
(for ([n (in-range 18)])
(define hickerson-n (hickerson n))
(define first-decimal
(bigfloat->integer (bftruncate (bf* 10.bf (bffrac hickerson-n)))))
(define almost-intege... |
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
| #8086_Assembly | 8086 Assembly | DOSSEG
.MODEL TINY
.DATA
TXT DB "Hello world!$"
.CODE
START:
MOV ax, @DATA
MOV ds, ax
MOV ah, 09h ; prepare output function
MOV dx, OFFSET TXT ; set offset
INT 21h ; output string TXT
MOV AX, 4C00h ; go back to DOS
INT 21h
END START |
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... | #Factor | Factor | USING: accessors assocs backtrack combinators.extras
combinators.short-circuit formatting io kernel locals math
math.functions math.order math.parser math.ranges mirrors qw
sequences sorting.slots ;
IN: rosetta-code.heronian-triangles
TUPLE: triangle a b c area perimeter ;
:: area ( a b c -- x )
a b + c + 2 / :... |
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
| #Bracmat | Bracmat | ( (plus=a b.!arg:(?a.?b)&!a+!b)
& ( print
= text a b func
. !arg:(?a.?b.(=?func).?text)
& out$(str$(!text "(" !a "," !b ")=" func$(!a.!b)))
)
& print$(3.7.'$plus.add)
& print
$ ( 3
. 7
. (=a b.!arg:(?a.?b)&!a*!b)
. multiply
)
); |
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... | #Go | Go | package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Goodbye, World!")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
|
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... | #Haskell | Haskell | {-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Char8 ()
import Data.Conduit ( ($$), yield )
import Data.Conduit.Network ( ServerSettings(..), runTCPServer )
main :: IO ()
main = runTCPServer (ServerSettings 8080 "127.0.0.1") $ const (yield response $$)
where response = "HTTP/1.0 200 OK\nContent-Length:... |
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 ... | #M2000_Interpreter | M2000 Interpreter |
Module Checkit {
a$={This is the first line
This is the second line
End bracket position declare indentation fortext (except for first line)
}
Report a$ ' print all lines, without space at the left
}
CheckIt
|
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 ... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Print["Mathematica
is an
interesing
language,
with its
strings
being
multiline
by\
default
when not
back\
s\\ashed!"]; |
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 ... | #MATLAB | MATLAB | sprintf('%s\n',...
'line1 text',...
' line2 text',...
' line3 text',...
' line4 text')
sprintf('%s\n',...
'Usage: thingy [OPTIONS]',...
' -h Display this usage message',...
' -H hostname Hostname to connect to') |
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 ... | #NewLISP | NewLISP | ; here-document.lsp
; oofoe 2012-01-19
; http://rosettacode.org/wiki/Here_document
(print (format [text]
Blast it %s! I'm a %s,
not a %s!
--- %s
[/text] "James" "magician" "doctor" "L. McCoy"))
(exit) |
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... | #REXX | REXX | /*REXX program demonstrates a method to track history of assignments to a REXX variable.*/
varSet!.=0 /*initialize the all of the VARSET!'s. */
call varSet 'fluid',min(0,-5/2,-1) ; say 'fluid=' fluid
call varSet 'fluid',3.14159 ; say 'fluid=' fluid
call varSet ... |
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... | #Ruby | Ruby | foo_hist = []
trace_var(:$foo){|v| foo_hist.unshift(v)}
$foo = "apple"
$foo = "pear"
$foo = "banana"
p foo_hist # => ["banana", "pear", "apple"]
|
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... | #Nim | Nim | var cr = @[1]
var cs = @[2]
proc extendRS =
let x = cr[cr.high] + cs[cr.high]
cr.add x
for y in cs[cs.high] + 1 ..< x: cs.add y
cs.add x + 1
proc ffr(n: int): int =
assert n > 0
while n > cr.len: extendRS()
cr[n - 1]
proc ffs(n: int): int =
assert n > 0
while n > cs.len: extendRS()
cs[n - 1]
... |
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... | #Oforth | Oforth | tvar: R
ListBuffer new 1 over add R put
tvar: S
ListBuffer new 2 over add S put
: buildnext
| r s current i |
R at ->r
S at ->s
r last r size s at + dup ->current r add
s last 1+ current 1- for: i [ i s add ]
current 1+ s add ;
: ffr(n)
while ( R at size n < ) [ buildnext ]
n R at at ... |
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... | #Mercury | Mercury |
:- module horner.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, list, string.
main(!IO) :-
io.format("%i\n", [i(horner(3, [-19, 7, -4, 6]))], !IO).
:- func horner(int, list(int)) = int.
horner(X, Cs) = list.foldr((func(C, Acc) = Acc * X + C)... |
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... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | ИП0 1 + П0
ИПE ИПD * КИП0 + ПE
ИП0 1 - x=0 04
ИПE С/П |
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.
| #Perl | Perl | use SVG;
use List::Util qw(max min);
use constant pi => 2 * atan2(1, 0);
# Compute the curve with a Lindemayer-system
%rules = (
A => '-BF+AFA+FB-',
B => '+AF-BFB-FA+'
);
$hilbert = 'A';
$hilbert =~ s/([AB])/$rules{$1}/eg for 1..6;
# Draw the curve in SVG
($x, $y) = (0, 0);
$theta = pi/2;
$r = 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... | #XPL0 | XPL0 | include c:\cxpl\stdlib; \(color definitions, etc.)
proc DrawHexagon(X0, Y0, Side, Color); \Draw a filled hexagon centered at X0,Y0
int X0, Y0, Side, Color;
int X, Y;
for Y:= -Side*19/22 to +Side*19/22 do \19/22 aprox = sqrt(3.0)/2.0
for X:= -Side to +Side do
if abs(X) + abs(Y)... |
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
... | #Kotlin | Kotlin | // version 1.1.2
import java.util.Calendar
import java.util.GregorianCalendar
val holidayOffsets = listOf(
"Easter" to 0,
"Ascension" to 39,
"Pentecost" to 49,
"Trinity" to 56,
"C/Christi" to 60
)
fun String.padCenter(n: Int): String {
val len = this.length
if (n <= len) return this... |
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... | #Nim | Nim | import rdstdin, strutils, math, strformat
let lat = parseFloat readLineFromStdin "Enter latitude => "
let lng = parseFloat readLineFromStdin "Enter longitude => "
let med = parseFloat readLineFromStdin "Enter legal meridian => "
echo ""
let slat = sin lat.degToRad
echo &" sine of latitude: {slat:.3f... |
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... | #Objeck | Objeck |
class Sundial {
function : Main(args : String[]) ~ Nil {
"Enter latitude: "->Print();
lat := System.IO.Console->ReadString()->ToFloat();
"Enter longitude: "->Print();
lng := System.IO.Console->ReadString()->ToFloat();
"Enter legal meridian: "->Print();
ref := System.IO.Console->ReadStrin... |
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... | #PL.2FI | PL/I | *process source attributes xref or(!);
hencode: Proc Options(main);
/*--------------------------------------------------------------------
* 28.12.013 Walter Pachl translated from REXX
*-------------------------------------------------------------------*/
Dcl debug Bit(1) Init('0'b);
Dcl (i,j,k) Bin Fixed(15);
... |
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
⋮
⋮
⋮
⋱
... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const type: matrix is array array integer;
const func matrix: identity (in integer: size) is func
result
var matrix: identity is matrix.value;
local
var integer: index is 0;
begin
identity := size times size times 0;
for index range 1 to size do
identity[index][... |
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 |... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
local
var integer: a is 0;
var integer: b is 0;
begin
readln(a);
readln(b);
if a < b then
writeln(a <& " is less than " <& b);
end if;
if a = b then
writeln(a <& " is equal to " <& b);
end if;
if a > b then
... |
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 |... | #SenseTalk | SenseTalk | Ask "Provide Any Number"
Put It into A
Ask " Provide Another Number"
Put it into B
if A is less than B
Put A&" Is less than " &B
end if
if A is greater than B
Put A& " is Greater than " &B
end if
If A is Equal to B
Put A& " is Equal to " &B
End 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.
| #Halon | Halon | echo http("http://www.rosettacode.org"); |
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.
| #Haskell | Haskell |
import Network.Browser
import Network.HTTP
import Network.URI
main = do
rsp <- Network.Browser.browse $ do
setAllowRedirects True
setOutHandler $ const (return ())
request $ getRequest "http://www.rosettacode.org/"
putStrLn $ rspBody $ snd rsp
|
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... | #Kotlin | Kotlin | // version 1.1.2
fun main(args: Array<String>) {
val limit = (1 shl 20) + 1
val a = IntArray(limit)
a[1] = 1
a[2] = 1
for (n in 3 until limit) {
val p = a[n - 1]
a[n] = a[p] + a[n - p]
}
println(" Range Maximum")
println("---------------- --------")
... |
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 ... | #Fantom | Fantom |
class Main
{
public static Void main ()
{
Env.cur.err.printLine ("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 ... | #Forth | Forth | outfile-id
stderr to outfile-id
." Goodbye, World!" cr
to outfile-id |
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 ... | #Fortran | Fortran | program StdErr
! Fortran 2003
use iso_fortran_env
! in case there's no module iso_fortran_env ...
!integer, parameter :: ERROR_UNIT = 0
write (ERROR_UNIT, *) "Goodbye, World!"
end program StdErr |
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 ... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Open Err As #1
Print #1, "Goodbye World!"
Close #1
Sleep |
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... | #ERRE | ERRE |
PROGRAM HOFSTADER_Q
!
! for rosettacode.org
!
DIM Q%[10000]
PROCEDURE QSEQUENCE(Q,FLAG%->SEQ$)
! if FLAG% is true accumulate sequence in SEQ$
! (attention to string var lenght=255)
! otherwise calculate values in Q%[] only
LOCAL N
Q%[1]=1
Q%[2]=1
SEQ$="1 1"
IF NOT FLAG% THEN Q=NUM END IF
FOR N=3 T... |
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... | #F.23 | F# |
// Populate an array with values of Hofstadter Q sequence. Nigel Galloway: August 26th., 2020
let fQ N=let g=Array.length N in N.[0]<-1; N.[1]<-1;(for g in 2..g-1 do N.[g]<-N.[g-N.[g-1]]+N.[g-N.[g-2]])
|
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... | #Raku | Raku | constant ln2 = [+] (1/2.FatRat, */2 ... *) Z/ 1 .. 100;
constant h = [\*] 1/2, |(1..*) X/ ln2;
use Test;
plan *;
for h[1..17] {
ok m/'.'<[09]>/, .round(0.001)
} |
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... | #REXX | REXX | /* REXX ---------------------------------------------------------------
* 04.01.2014 Walter Pachl - using a rather aged ln function of mine
* with probably unreasonably high precision
* 05.01.2014 added n=18
*--------------------------------------------------------------------*/
Numeric Digits... |
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
| #8th | 8th | "Hello world!\n" . bye |
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... | #Fortran | Fortran |
MODULE GREEK MATHEMATICIANS !Two millenia back and more.
CONTAINS
INTEGER FUNCTION GCD(I,J) !Greatest common divisor.
INTEGER I,J !Of these two integers.
INTEGER N,M,R !Workers.
N = MAX(I,J) !Since I don't want to damage I or J,
M = MIN(I,J) !These copies mig... |
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
| #Brat | Brat | add = { a, b | a + b }
doit = { f, a, b | f a, b }
p doit ->add 1 2 #prints 3 |
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... | #Io | Io |
WebRequest := Object clone do(
handleSocket := method(aSocket,
aSocket streamWrite("Goodbye, World!")
aSocket close
)
)
WebServer := Server clone do(
setPort(8080)
handleSocket := method(aSocket,
WebRequest clone asyncSend(handleSocket(aSocket))
)
)
WebServer start
|
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... | #J | J | 'Goodbye, World!' |
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 ... | #Nim | Nim | echo """Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
""" |
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 ... | #NMAKE.EXE | NMAKE.EXE | target0: dependent0
command0 <<
temporary, discarded inline file
...
<<
target1: dependent1
command1 <<
temporary, but preserved inline file
...
<<KEEP
target2: dependent2
command2 <<filename2
named, but discarded inline file
...
<<NOKEEP
target3: dependent3
command3 <<filename3
named and preserve... |
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 ... | #OCaml | OCaml |
print_string {whatever|
'hahah', `this`
<is>
\a\
"Heredoc" ${example}
in OCaml
|whatever}
;;
|
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 ... | #OxygenBasic | OxygenBasic |
s=quote
""""
She said "He said 'I said `There is a rumour
going around.` ' "
""""
print s
|
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... | #Rust | Rust | #[derive(Clone, Debug)]
struct HVar<T> {
history: Vec<T>,
current: T,
}
impl<T> HVar<T> {
fn new(val: T) -> Self {
HVar {
history: Vec::new(),
current: val,
}
}
fn get(&self) -> &T {
&self.current
}
fn set(&mut self, val: T) {
sel... |
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... | #Scala | Scala | class HVar[A](initialValue: A) extends Proxy {
override def self = !this
override def toString = "HVar(" + !this + ")"
def history = _history
private var _history = List(initialValue)
def unary_! = _history.head
def :=(newValue: A): Unit = {
_history = newValue :: _history
}
def modify(f: A => A... |
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... | #Perl | Perl | #!perl
use strict;
use warnings;
my @r = ( undef, 1 );
my @s = ( undef, 2 );
sub ffsr {
my $n = shift;
while( $#r < $n ) {
push @r, $s[$#r]+$r[-1];
push @s, grep { $s[-1]<$_ } $s[-1]+1..$r[-1]-1, $r[-1]+1;
}
return $n;
}
sub ffr { $r[ffsr shift] }
sub ffs { $s[ffsr shift] }
printf " i: R(i) S(i... |
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... | #Modula-2 | Modula-2 | MODULE Horner;
FROM RealStr IMPORT RealToStr;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
PROCEDURE Horner(coeff : ARRAY OF REAL; x : REAL) : REAL;
VAR
ans : REAL;
i : CARDINAL;
BEGIN
ans := 0.0;
FOR i:=HIGH(coeff) TO 0 BY -1 DO
ans := (ans * x) + coeff[i];
END;
RETURN ans
END H... |
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... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols nobinary
c = [-19, 7, -4, 6] -- # list coefficients of all x^0..x^n in order
n=3
x=3
r=0
loop i=n to 0 by -1
r=r*x+c[i]
End
Say r
Say 6*x**3-4*x**2+7*x-19 |
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.
| #Phix | Phix | --
-- demo\rosetta\hilbert_curve.exw
-- ==============================
--
-- Draws a hilbert curve.
--
with javascript_semantics
include pGUI.e
constant title = "Hilbert Curve"
Ihandle dlg, canvas
cdCanvas cddbuffer, cdcanvas
constant width = 64
sequence points = {}
procedure hilbert(integer x, y, lg, i1, i2)
... |
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
... | #Lua | Lua | local Time = require("time")
function div (x, y) return math.floor(x / y) end
function easter (year)
local G = year % 19
local C = div(year, 100)
local H = (C - div(C, 4) - div((8 * C + 13), 25) + 19 * G + 15) % 30
local I = H - div(H, 28) * (1 - div(29, H + 1)) * (div(21 - G, 11))
local J = (ye... |
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... | #OCaml | OCaml | let () =
let pi = 4. *. atan 1. in
print_endline "Enter latitude => ";
let lat = read_float () in
print_endline "Enter longitude => ";
let lng = read_float () in
print_endline "Enter legal meridian => ";
let ref = read_float () in
print_newline ();
let slat = sin (lat *. 2. *. pi /. 360.) in
Prin... |
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... | #PowerShell | PowerShell |
function Get-HuffmanEncodingTable ( $String )
{
# Create leaf nodes
$ID = 0
$Nodes = [char[]]$String |
Group-Object |
ForEach { $ID++; $_ } |
Select @{ Label = 'Symbol' ; Expression = { $_.Name } },
@{ Label = 'Count' ; Expression = { $_.Count } },
... |
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
⋮
⋮
⋮
⋱
... | #SenseTalk | SenseTalk |
set matrix to buildIdentityMatrix(3)
repeat for each item in matrix
put it
end repeat
set matrix to buildIdentityMatrix(17)
repeat for each item in matrix
put it
end repeat
function buildIdentityMatrix matrixSize
set matrixList to ()
repeat matrixSize times
set rowMatrixIndex to the counter
set rowMat... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.