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/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
host=HOST ()
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #UNIX_Shell | UNIX Shell | hostname |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Ursa | Ursa | out (ursa.net.localhost.name) endl console |
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
⋮
⋮
⋮
⋱
... | #Ruby | Ruby | def identity(size)
Array.new(size){|i| Array.new(size){|j| i==j ? 1 : 0}}
end
[4,5,6].each do |size|
puts size, identity(size).map {|r| r.to_s}, ""
end |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #XLISP | XLISP | (DEFUN INCREMENT-STRING (X)
(NUMBER->STRING (+ (STRING->NUMBER X) 1))) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #XPL0 | XPL0 | string 0; \use zero-terminated string convention
code Text=12;
func StrLen(A); \Return number of characters in an ASCIIZ string
char A;
int I;
for I:= 0 to -1>>1-1 do
if A(I) = 0 then return I;
proc IncStr(S); \Increment a numeric string
char S;
int I;
[for I:= StrLen(S)-1 do... |
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 |... | #Rockstar | Rockstar |
(Get two numbers from user)
Listen to Number One
Listen to Number Two
(Check if n1 > n2)
If Number One is greater than Number Two
Say "The first is greater than the second"
(Check if n1 = n2)
If Number One is Number Two
Say "The Numbers are equal"
(Check if n1 < n2)
If Number One is less than Number Two
Say "The ... |
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 |... | #RPG | RPG |
h dftactgrp(*no)
d pi
d integer1 10i 0
d integer2 10i 0
d message s 50a
if integer1 < integer2;
message = 'Integer 1 is less than integer 2';
endif;
if integer1 > integer2;
... |
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.
| #friendly_interactive_shell | friendly interactive shell | curl -s -L http://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.
| #Frink | Frink |
print[read["http://frinklang.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... | #Icon_and_Unicon | Icon and Unicon | procedure main(args)
m := integer(!args) | 20
nextNum := create put(A := [], 1 | 1 | |A[A[*A]]+A[-A[*A]])[*A]
p2 := 2 ^ (p := 1)
maxv := 0
every n := 1 to (2^m) do {
if maxv <:= (x := @nextNum / real(n)) then maxm := n
if x >= 0.55 then mallows := n # Want *this* n, 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 ... | #COBOL | COBOL | program-id. ehello.
procedure division.
display "Goodbye, world!" upon syserr.
stop run. |
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 ... | #CoffeeScript | CoffeeScript | console.warn "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 ... | #Common_Lisp | Common Lisp | (format *error-output* "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... | #Dart | Dart | int Q(int n) => n>2 ? Q(n-Q(n-1))+Q(n-Q(n-2)) : 1;
main() {
for(int i=1;i<=10;i++) {
print("Q($i)=${Q(i)}");
}
print("Q(1000)=${Q(1000)}");
} |
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... | #Draco | Draco | proc nonrec make_Q([*] word q) void:
word n;
q[1] := 1;
q[2] := 1;
for n from 3 upto dim(q,1)-1 do
q[n] := q[n-q[n-1]] + q[n-q[n-2]]
od
corp
proc nonrec main() void:
word MAX = 1000;
word i;
[MAX+1] word q;
make_Q(q);
write("The first 10 terms are:");
for i from ... |
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... | #Nim | Nim | import strformat
import bignum
let ln2 = newInt("693147180559945309417232121458") / newInt("1000000000000000000000000000000")
iterator hickerson(): tuple[n: int; val: Rat] =
## Yield the hickerson series values as rational numbers.
var
n = 1
num = 1
denom = 2 * ln2 * ln2
while true:
yield (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... | #PARI.2FGP | PARI/GP | h(n)=n!/2/log(2)^(n+1)
almost(x)=abs(x-round(x))<.1
select(n->almost(h(n)),[1..17])
|
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
| #4DOS_Batch | 4DOS Batch | echo 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... | #D | D | import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons;
double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc {
immutable s = (a + b + c) / 2.0;
immutable a2 = s * (s - a) * (s - b) * (s - c);
return (a2 > 0) ? a2.sqrt : 0.0;
}
bool isHeronian(in uint... |
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
| #ATS | ATS |
#include
"share/atspre_staload.hats"
fun app_to_0 (f: (int) -> int): int = f (0)
implement
main0 () =
{
//
val () = assertloc (app_to_0(lam(x) => x+1) = 1)
val () = assertloc (app_to_0(lam(x) => 10*(x+1)) = 10)
//
} (* end of [main0] *)
|
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... | #Fantom | Fantom | using web
using wisp
const class HelloMod : WebMod // provides the content
{
override Void onGet ()
{
res.headers["Content-Type"] = "text/plain; charset=utf-8"
res.out.print ("Goodbye, World!")
}
}
class HelloWeb
{
Void main ()
{
WispService // creates the web service
{
port = 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... | #Fortran | Fortran |
program http_example
implicit none
character (len=:), allocatable :: code
character (len=:), allocatable :: command
logical :: waitForProcess
! Execute a Node.js code
code = "const http = require('http'); http.createServer((req, res) => &
{res.end('Hello World from a Node.js server started from... |
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 ... | #Frink | Frink |
lyrics = """Oh, Danny Boy,
The pipes, the pipes are calling
From glen to glen and down the mountainside"""
|
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 ... | #Genie | Genie | [indent=4]
/*
Here documents, as template and verbatim strings in Genie
valac heredoc.gs
*/
init
test:string = "Genie string"
var multilineString = """
this is a $test
"""
var templateString = @"
this is a $test template
with math for six times seven = $(6 * 7)
"
stdout.printf("%s", multilineS... |
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 ... | #Go | Go | var m = ` leading spaces
and blank lines` |
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 ... | #Groovy | Groovy | println '''
Time's a strange fellow;
more he gives than takes
(and he takes all) nor any marvel finds
quite disappearance but some keener makes
losing, gaining
--love! if a world ends
''' |
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... | #Phix | Phix | without js -- (desktop/Phix only)
sequence history = {}
type hvt(object o)
history = append(history,o)
return true
end type
hvt test = 1
test = 2
test = 3
?{"current",test}
?{"history",history}
|
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... | #PicoLisp | PicoLisp | (de setH ("Var" Val)
(when (val "Var")
(with "Var"
(=: history (cons @ (: history))) ) )
(set "Var" Val) )
(de restoreH ("Var")
(set "Var" (pop (prop "Var" 'history))) ) |
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... | #JavaScript | JavaScript | var R = [null, 1];
var S = [null, 2];
var extend_sequences = function (n) {
var current = Math.max(R[R.length-1],S[S.length-1]);
var i;
while (R.length <= n || S.length <= n) {
i = Math.min(R.length, S.length) - 1;
current += 1;
if (current === R[i] + S[i]) {
R.push(current);
} else {
S.push(current)... |
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... | #Lambdatalk | Lambdatalk |
{def horner
{def horner.r
{lambda {:p :x :r}
{if {A.empty? :p}
then :r
else {horner.r {A.rest :p} :x {+ {A.first :p} {* :x :r}}}}}}
{lambda {:p :x}
{horner.r {A.reverse :p} :x 0}}}
{horner {A.new -19 7 -4 6} 3}
-> 128
{def φ {/ {+ 1 {sqrt 5}} 2}} = 1.618033988749895
{horner {A.new -1 -1 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... | #Liberty_BASIC | Liberty BASIC | src$ = "Hello"
coefficients$ = "-19 7 -4 6" ' list coefficients of all x^0..x^n in order
x = 3
print horner(coefficients$, x) '128
print horner("4 3 2 1", 10) '1234
print horner("1 1 0 0 1", 2) '19
end
function horner(coefficients$, x)
accumulator = 0
'getting length of a list requires 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.
| #Kotlin | Kotlin | // Version 1.2.40
data class Point(var x: Int, var y: Int)
fun d2pt(n: Int, d: Int): Point {
var x = 0
var y = 0
var t = d
var s = 1
while (s < n) {
val rx = 1 and (t / 2)
val ry = 1 and (t xor rx)
val p = Point(x, y)
rot(s, p, rx, ry)
x = p.x + s * rx
... |
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... | #Scala | Scala | import java.awt.{BasicStroke, BorderLayout, Color, Dimension,
Font, FontMetrics, Graphics, Graphics2D, Point, Polygon, RenderingHints}
import java.awt.event.{KeyAdapter, KeyEvent, MouseAdapter, MouseEvent}
import javax.swing.{JFrame, JPanel}
import scala.math.{Pi, cos, sin}
object Honeycombs extends App {
pri... |
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
... | #J | J | jed=:3 :0
pfm=. 21 + 30 | _4 + 19 * 1 + 19|y
sn=. 6 - 7 | 4 + <.@*&1.25 y
dys=. 1 40 50 50 +/~sn (] + 7 | 4 + -) pfm
y,"0 1(+/\0 0 0 31 30 31 30) (I.,"0]-<:@I.{[) dys
) |
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... | #Lua | Lua | io.write("Enter latitude => ")
lat = tonumber(io.read())
io.write("Enter longitude => ")
lng = tonumber(io.read())
io.write("Enter legal meridian => ")
ref = tonumber(io.read())
print()
slat = math.sin(math.rad(lat))
print(string.format(" sine of latitude: %.3f", slat))
print(string.format(" ... |
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... | #Phix | Phix | with javascript_semantics
function store_nodes(object key, object data, integer nodes)
setd({data,key},0,nodes)
return 1
end function
function build_freqtable(string data)
integer freq = new_dict(),
nodes = new_dict()
for i=1 to length(data) do
integer di = data[i]
setd(di,... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Ursala | Ursala | #import cli
hostname = ~&hmh+ (ask bash)/<>+ <'hostname'>! |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #VBScript | VBScript |
Set objNetwork = CreateObject("WScript.Network")
WScript.Echo objNetwork.ComputerName
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Vim_Script | Vim Script | echo hostname() |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Visual_Basic | Visual Basic | Option Explicit
Private Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameW" _
(ByVal lpBuffer As Long, ByRef nSize As Long) As Long
Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
Private Const NO_ERR As Long = 0
Private Function Hostname() As String
Dim i As Long, l As Long, s As St... |
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
⋮
⋮
⋮
⋱
... | #Run_BASIC | Run BASIC | ' formats array im() of size ims
for ims = 4 to 6
print :print "--- Size: ";ims;" ---"
Dim im(ims,ims)
For i = 1 To ims
im(i,i) = 1
next
For row = 1 To ims
print "[";
cma$ = ""
For col = 1 To ims
print cma$;im(row, col);
cma$ = ", "
next
print "]"
next
next ims |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #zkl | zkl | fcn numStringPlusOne(s){1+s}
numStringPlusOne("123") //-->124 |
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 |... | #Ruby | Ruby | a = (print "enter a value for a: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i
puts "#{a} is less than #{b}" if a < b
puts "#{a} is greater than #{b}" if a > b
puts "#{a} is equal to #{b}" if a == b |
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.
| #Gastona | Gastona | #listix#
<main>
LOOP, TEXT FILE, http://www.rosettacode.org
, BODY, @<value>
|
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... | #J | J | hc10k =: , ] +/@:{~ (,&<: -.)@{: NB. Actual sequence a(n)
AnN =: % 1+i.@:# NB. a(n)/n
MxAnN =: >./;.1~ 2 (=<.)@:^. 1+i.@# NB. Maxima of a(n)/n between successive powers of 2 |
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 ... | #D | D | import std.stdio;
void main () {
stderr.writeln("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 ... | #Dart | Dart | import 'dart:io';
void main() {
stderr.writeln('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... | #EchoLisp | EchoLisp |
(define RECURSE_BUMP 500) ;; minimum of chrome:500 safari:1000 firefox:2000
;; count flips
(define (flips N)
(for/sum ((n (in-range 2 (1+ N))))
#:when (< (Q n) (Q (1- n))) 1))
(cache-size 120000)
(define (Q n)
;; prevent browser stack overflow at low-cost
(when (zero? (modulo n RECURSE_BUMP)) (for ((i (in-ra... |
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... | #Perl | Perl | use strict;
use warnings;
use Math::BigFloat;
my $iln2 = 1 / Math::BigFloat->new(2)->blog;
my $h = $iln2 / 2;
for my $n ( 1 .. 17 ) {
$h *= $iln2;
$h *= $n;
my $s = $h->copy->bfround(-3)->bstr;
printf "h(%2d) = %22s is%s almost an integer.\n",
$n, $s, ($s =~ /\.[09]/ ? "" : " NOT");
}
|
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
| #6502_Assembly | 6502 Assembly | ; goodbyeworld.s for C= 8-bit machines, ca65 assembler format.
; String printing limited to strings of 256 characters or less.
a_cr = $0d ; Carriage return.
bsout = $ffd2 ; C64 KERNEL ROM, output a character to current device.
; use $fded for Apple 2, $ffe3 (ascii) or $ffee (raw) for BBC.
.code
ldx #0 ; Sta... |
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... | #Delphi | Delphi |
;; returns quintuple (A s a b c)
;; or #f if not hero
(define (hero a b c (s 0) (A 0))
(when
(= 1 (gcd a b c))
(set! s (// (+ a b c) 2))
(set! A (* s (- s a)(- s b)(- s c)))
(when (square? A)
(list (sqrt A) (* s 2) c b a))))
;; all heroes a,b,c < sidemax
;; sorted by A|s|c & a <=b <= c
(define (heroes (sid... |
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
| #AutoHotkey | AutoHotkey |
f(x) {
return "This " . x
}
g(x) {
return "That " . x
}
show(fun) {
msgbox % %fun%("works")
}
show(Func("f")) ; either create a Func object
show("g") ; or just name the function
return
|
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... | #Free_Pascal | Free Pascal | program HelloWorldServer;
{$mode objfpc}{$H+}
uses
Classes, fphttpserver;
Type
TTestHTTPServer = Class(TFPHTTPServer)
public
procedure HandleRequest(Var ARequest: TFPHTTPConnectionRequest;
Var AResponse : TFPHTTPConnectionResponse); override;
end;
Var
Serv : TTestHTTPServer... |
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 ... | #Haskell | Haskell |
main :: IO ()
main = do
-- multiline String
putStrLn "Hello\
\ World!\n"
-- more haskell-ish way
putStrLn $ unwords ["This", "is", "an", "example", "text!\n"]
-- now with multiple lines
putStrLn $ unlines [
unwords ["This", "is", "the", "first" , "line."]
, unwords ["... |
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 ... | #J | J | here=:0 :0
0 :0 will be replaced by the text on the following lines.
This is three tokens: two instances of the number 0 and
one instance of the explicit definition token ':'.
Any indentation in the here document will be retained in the result.
There must be a space to the left of : or it will combine with th... |
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... | #PL.2FI | PL/I |
declare t float controlled;
do i = 1 to 5; /* a loop to read in and save five values. */
allocate t; get (t);
end;
do while (allocation(t) > 0); /* a loop to retrieve the values. */
put (t); free t;
end;
|
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... | #PureBasic | PureBasic | ; integer history variable
Structure historyint
List value.i()
EndStructure
Procedure SetInt (*var.historyint, val.i)
AddElement(*var\value())
If (ListSize(*var\value()) = 1)
*var\value() = 0
AddElement(*var\value())
EndIf
*var\value() = val
EndProcedure
Procedure ShowH... |
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... | #jq | jq | def init: {r: [0, 1], s: [0, 2] };
# input: {r,s}
# output: {r,s,emit} where .emit is either null or the next R and where either .r or .s on output has been extended.
# .emit is provided in case an unbounded stream of R values is desired.
def extend_ff:
(.r|length) as $rn
| if .s[$rn - 1]
then .emit = .r[$rn ... |
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... | #Julia | Julia |
type FigureFigure{T<:Integer}
r::Array{T,1}
rnmax::T
snmax::T
snext::T
end
function grow!{T<:Integer}(ff::FigureFigure{T}, rnmax::T=100)
ff.rnmax < rnmax || return nothing
append!(ff.r, zeros(T, (rnmax-ff.rnmax)))
snext = ff.snext
for i in (ff.rnmax+1):rnmax
ff.r[i] = ff.r[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... | #Logo | Logo | to horner :x :coeffs
if empty? :coeffs [output 0]
output (first :coeffs) + (:x * horner :x bf :coeffs)
end
show horner 3 [-19 7 -4 6] ; 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... | #Lua | Lua | function horners_rule( coeff, x )
local res = 0
for i = #coeff, 1, -1 do
res = res * x + coeff[i]
end
return res
end
x = 3
coefficients = { -19, 7, -4, 6 }
print( horners_rule( coefficients, x ) ) |
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.
| #Lambdatalk | Lambdatalk |
1) two twinned recursive functions
{def left {lambda {:d :n}
{if {< :n 1}
then
else T90 {right :d {- :n 1}}
M:d T-90 {left :d {- :n 1}}
M:d {left :d {- :n 1}}
T-90 M:d {right :d {- :n 1}}
T90}}}
{def right {lambda {:d :n}
{if {< :n 1}
then
else T-90 {le... |
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... | #Sidef | Sidef | require('Tk')
class Honeycombs(
Number size = 36,
Array letters = @('A' .. 'Z').shuffle.first(20),
) {
define tk = %S<Tk>
has changed = Hash()
func altitude(n) {
sqrt(3/4) * n
}
method polygon_coordinates(x, y, size) {
var alt = altitude(size)
return (x - ... |
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
... | #Java | Java | import java.text.DateFormatSymbols;
import java.util.*;
public class EasterRelatedHolidays {
final static Map<String, Integer> holidayOffsets;
static {
holidayOffsets = new LinkedHashMap<>();
holidayOffsets.put("Easter", 0);
holidayOffsets.put("Ascension", 39);
holidayOffse... |
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... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | lat = Input["latitude", -4.95];
lng = Input["longitude", -150.5];
ref = Input["legal meridian", -150];
slat = Sin[lat Degree];
Table[
hra = 15 h;
hra -= lng - ref;
hla = N@ArcTan[slat Tan[hra Degree]]/Degree;
{h, hra, hla}
,
{h, -6, 6}
] // Prepend[{"Hour", "Sun hour angle",
"Dial hour line ... |
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... | #Microsoft_Small_Basic | Microsoft Small Basic |
TextWindow.Write("Enter latitude => ")
lat = TextWindow.ReadNumber()
TextWindow.Write("Enter longitude => ")
lng = TextWindow.ReadNumber()
TextWindow.Write("Enter legal meridian => ")
ref = TextWindow.ReadNumber()
sLat = Math.Sin(Math.GetRadians(lat))
TextWindow.WriteLine("")
TextWindow.Write(" sine of ... |
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... | #PHP | PHP | <?php
function encode($symb2freq) {
$heap = new SplPriorityQueue;
$heap->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
foreach ($symb2freq as $sym => $wt)
$heap->insert(array($sym => ''), -$wt);
while ($heap->count() > 1) {
$lo = $heap->extract();
$hi = $heap->extract();
... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Wren | Wren | /* hostname.wren */
class Host {
foreign static name() // the code for this is provided by Go
}
System.print(Host.name()) |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #zkl | zkl | System.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
⋮
⋮
⋮
⋱
... | #Rust | Rust |
extern crate num;
struct Matrix<T> {
data: Vec<T>,
size: usize,
}
impl<T> Matrix<T>
where
T: num::Num + Clone + Copy,
{
fn new(size: usize) -> Self {
Self {
data: vec![T::zero(); size * size],
size: size,
}
}
fn get(&mut self, x: usize, y: usize) -> T ... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Zoea | Zoea |
program: increment_a_numerical_string
case: 1
input: '1234'
output: '1235'
case: 2
input: '19'
output: '20'
|
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 |... | #Run_BASIC | Run BASIC | input "1st number:"; n1
input "2nd number:"; n2
if n1 < n2 then print "1st number ";n1;" is less than 2nd number";n2
if n1 > n2 then print "1st number ";n1;" is greater than 2nd number";n2
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2 |
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 |... | #Rust | Rust | use std::io::{self, BufRead};
fn main() {
let mut reader = io::stdin();
let mut buffer = String::new();
let mut lines = reader.lock().lines().take(2);
let nums: Vec<i32>= lines.map(|string|
string.unwrap().trim().parse().unwrap()
).collect();
let a: i32 = nums[0];
let b: i32 = ... |
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.
| #GML | GML | get = http_get("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.
| #Go | Go |
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
r, err := http.Get("http://rosettacode.org/robots.txt")
if err != nil {
log.Fatalln(err)
}
io.Copy(os.Stdout, r.Body)
}
|
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... | #Java | Java |
// Title: Hofstadter-Conway $10,000 sequence
public class HofstadterConwaySequence {
private static int MAX = (int) Math.pow(2, 20) + 1;
private static int[] HCS = new int[MAX];
static {
HCS[1] = 1;
HCS[2] = 1;
for ( int n = 3 ; n < MAX ; n++ ) {
int nm1 = HCS[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 ... | #Delphi | Delphi | program Project1;
{$APPTYPE CONSOLE}
begin
WriteLn(ErrOutput, 'Goodbye, World!');
end. |
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 ... | #Dylan.NET | Dylan.NET | Console::get_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 ... | #D.C3.A9j.C3.A0_Vu | Déjà Vu | !write-fragment!stderr !encode!utf-8 "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... | #Eiffel | Eiffel |
class
APPLICATION
create
make
feature
make
-- Test output of the feature hofstadter_q_sequence.
local
count, i: INTEGER
test: ARRAY [INTEGER]
do
io.put_string ("%NFirst ten numbers: %N")
test := hofstadter_q_sequence (10)
across
test as ar
loop
io.put_string (ar.item.out + "%... |
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... | #Phix | Phix | without javascript_semantics -- (no mpfr_log() for pwa/p2js)
requires("1.0.0") -- (mpfr_set_default_prec[ision] renamed)
include mpfr.e
mpfr_set_default_precision(-23) -- (found by trial/error)
mpfr ln2 = mpfr_init(2),
hn = mpfr_init(0.5)
mpfr_log(ln2,ln2)
mpfr_div(hn,hn,ln2)
for n=1 to 17 do
mpfr_mul_si(hn,hn... |
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... | #PicoLisp | PicoLisp |
(load "@lib/misc.l")
(scl 25)
(setq LN2 0.69314718055994530941723212)
(de almost-int? (N)
(bool (member (% (/ N 0.1) 10) (0 9))))
(de fmt4 (N)
(format (/ N 0.0001) 4))
(de h (N)
(*/ (factorial N) `(* 1.0 1.0) (* 2 (s** LN2 (inc N)))))
(de s** (A N) # scaled integer exponentiation
(let R 1.0
... |
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
| #6800_Assembly | 6800 Assembly | .cr 6800
.tf gbye6800.obj,AP1
.lf gbye6800
;=====================================================;
; Hello world! for the Motorola 6800 ;
; by barrym 2013-03-17 ;
;-----------------------------------------------------;
; Prints the message "Hello w... |
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... | #EchoLisp | EchoLisp |
;; returns quintuple (A s a b c)
;; or #f if not hero
(define (hero a b c (s 0) (A 0))
(when
(= 1 (gcd a b c))
(set! s (// (+ a b c) 2))
(set! A (* s (- s a)(- s b)(- s c)))
(when (square? A)
(list (sqrt A) (* s 2) c b a))))
;; all heroes a,b,c < sidemax
;; sorted by A|s|c & a <=b <= c
(define (heroes (sid... |
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
| #BBC_BASIC | BBC BASIC | REM Test passing a function to a function:
PRINT FNtwo(FNone(), 10, 11)
END
REM Function to be passed:
DEF FNone(x, y) = (x + y) ^ 2
REM Function taking a function as an argument:
DEF FNtwo(RETURN f%, x, y) = FN(^f%)(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... | #FunL | FunL | native java.io.PrintWriter
native java.net.ServerSocket
val port = 8080
val listener = ServerSocket( port )
printf( 'Listening at port %1$d\n', port )
forever
socket = listener.accept()
PrintWriter( socket.getOutputStream(), true ).println( 'hello world' )
socket.shutdownOutput()
socket.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... | #Gastona | Gastona | #javaj#
<frames> oConsole
#listix#
<main>
MICOHTTP, START, myServer, 8080
<GET />
//<html><body>
// Goodbye world!
//</body></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 ... | #JavaScript | JavaScript | const myVar = 123;
const tempLit = `Here is some
multi-line string. And here is
the value of "myVar": ${myVar}
That's all.`;
console.log(tempLit)
|
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 ... | #jq | jq |
def s:
"x
y
z";
s |
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 ... | #Julia | Julia | print("""\
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 ... | #Kotlin | Kotlin | // version 1.1.0
fun main(args: Array<String>) {
val ev = "embed variables"
val here = """
This is a raw string literal
which does not treat escaped characters
(\t, \b, \n, \r, \', \", \\, \$ and \u)
specially and can contain new lines,
... |
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... | #Python | Python | import sys
HIST = {}
def trace(frame, event, arg):
for name,val in frame.f_locals.items():
if name not in HIST:
HIST[name] = []
else:
if HIST[name][-1] is val:
continue
HIST[name].append(val)
return trace
def undo(name):
HIST[name].pop(-1... |
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... | #Quackery | Quackery | /O> [ stack ] is x
... 3 x put
... 4 x put
... 5 x put
... x behead drop echo cr
... x take echo cr
... x take echo cr
... x take echo cr
...
[ 3 4 5 ]
5
4
3
|
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... | #Kotlin | Kotlin | fun ffr(n: Int) = get(n, 0)[n - 1]
fun ffs(n: Int) = get(0, n)[n - 1]
internal fun get(rSize: Int, sSize: Int): List<Int> {
val rlist = arrayListOf(1, 3, 7)
val slist = arrayListOf(2, 4, 5, 6)
val list = if (rSize > 0) rlist else slist
val targetSize = if (rSize > 0) rSize else sSize
while (li... |
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... | #Maple | Maple |
applyhorner:=(L::list,x)->foldl((s,t)->s*x+t,op(ListTools:-Reverse(L))):
applyhorner([-19,7,-4,6],x);
applyhorner([-19,7,-4,6],3);
|
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... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Horner[l_List, x_] := Fold[x #1 + #2 &, 0, l]
Horner[{6, -4, 7, -19}, x]
-> -19 + x (7 + x (-4 + 6 x))
-19 + x (7 + x (-4 + 6 x)) /. x -> 3
-> 128 |
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.
| #Lua | Lua | -- any version from LuaJIT 2.0/5.1, Lua 5.2, Lua 5.3 to LuaJIT 2.1.0-beta3-readline
local bit=bit32 or bit -- Lua 5.2/5.3 compatibilty
-- Hilbert curve implemented by Lindenmayer system
function string.hilbert(s, n)
for i=1,n do
s=s:gsub("[AB]",function(c)
if c=="A" then
c="-BF+AFA+FB-"
else
c="+AF-BF... |
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... | #Tcl | Tcl | package require Tcl 8.5
package require Tk
# How to make a honeycomb
proc honeycomb {w letterpattern} {
canvas $w -width 500 -height 470
set basey 10
foreach row $letterpattern {
set basex 10
set majoroffsety 0
foreach letter $row {
set x [expr {$basex + 60}]
set y [expr {$basey + 50 + $major... |
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
... | #JavaScript | JavaScript | const Пасха = год => {
let дата = (год % 19 * 19 + 15) % 30;
дата += (год % 4 * 2 + год % 7 * 4 + 6 * дата + 6) % 7;
if (год >= 1918) дата += (год / 100 | 0) - (год / 400 | 0) - 2;
return new Date(год, 2, 22 + дата);
};
for (let год = 400; год <= 2100; год += год < 2000 ? 100 : год >= 2020 ? 80 : год < 2010 ? 10 ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.