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/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... | #Erlang | Erlang |
horner(L,X) ->
lists:foldl(fun(C, Acc) -> X*Acc+C end,0, lists:reverse(L)).
t() ->
horner([-19,7,-4,6], 3).
|
http://rosettacode.org/wiki/Hilbert_curve | Hilbert curve |
Task
Produce a graphical or ASCII-art representation of a Hilbert curve of at least order 3.
| #C.23 | C# | using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace HilbertCurve {
class Program {
static void Swap<T>(ref T a, ref T b) {
var c = a;
a = b;
b = c;
}
struct Point {
public int x, y;
... |
http://rosettacode.org/wiki/Honeycombs | Honeycombs | The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position... | #Haskell | Haskell | import Data.Char (toUpper)
import Data.Function (on)
import Data.List (zipWith4)
import System.Exit
import System.Random
-- External libraries.
import Graphics.Gloss
import Graphics.Gloss.Data.Vector
import Graphics.Gloss.Geometry
import Graphics.Gloss.Interface.IO.Game
import System.Random.Shuffle
-- A record of a... |
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
... | #COBOL | COBOL |
identification division.
program-id. Easter.
environment division.
configuration section.
repository.
function date-of-integer intrinsic
function integer-of-date intrinsic
function mod intrinsic.
data division.
working-storage secti... |
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... | #Factor | Factor | USING: formatting io kernel locals math math.functions math.libm
math.parser math.ranges math.trig sequences ;
IN: rosetta-code.sundial
: get-num ( str -- x ) write flush readln string>number ;
: get-input ( -- lat lng ref )
"Enter latitude: " "Enter longitude: "
"Enter legal meridian: " [ get-num ] tri@ ;
... |
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... | #Forth | Forth | : faccept ( -- f )
pad 32 accept pad swap >float 0= throw ;
: >radians ( deg -- rad ) 180e f/ pi f* ;
: >degrees ( rad -- deg ) pi f/ 180e f* ;
: sundial
cr ." Enter latitude: "
faccept >radians fsin
cr ." Enter longitude: "
faccept
cr ." Enter legal meridian: "
faccept f- fnegate ( sin[latitude] -longi... |
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... | #JavaScript | JavaScript | function HuffmanEncoding(str) {
this.str = str;
var count_chars = {};
for (var i = 0; i < str.length; i++)
if (str[i] in count_chars)
count_chars[str[i]] ++;
else
count_chars[str[i]] = 1;
var pq = new BinaryHeap(function(x){return x[0];});
for (var ch i... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Retro | Retro | needs variations'
^variations'size |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #REXX | REXX | /*REXX program to examine which operating system that REXX is running under. */
parse source opSys howInvoked pathName
/*where opSys will indicate which operating system REXX is running under, and */
/*from that, one could make assumptions what the wordsize is, etc. */ |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Ruby | Ruby | # We assume that a Fixnum occupies one machine word.
# Fixnum#size returns bytes (1 byte = 8 bits).
word_size = 42.size * 8
puts "Word size: #{word_size} bits"
# Array#pack knows the native byte order. We pack 1 as a 16-bit integer,
# then unpack bytes: [0, 1] is big endian, [1, 0] is little endian.
bytes = [1].pack(... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Octave | Octave | uname().nodename |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #ooRexx | ooRexx | say .oleObject~new('WScript.Network')~computerName |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Oz | Oz | {System.showInfo {OS.getHostByName 'localhost'}.name} |
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
⋮
⋮
⋮
⋱
... | #PicoLisp | PicoLisp | (de identity (Size)
(let L (need Size (1) 0)
(make
(do Size
(link (copy (rot L))) ) ) ) ) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Slate | Slate | ((Integer readFrom: '123') + 1) printString |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Smalltalk | Smalltalk | ('123' asInteger + 1) printString |
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 |... | #PicoLisp | PicoLisp | (prin "Please enter two values: ")
(in NIL # Read from standard input
(let (A (read) B (read))
(prinl
"The first one is "
(cond
((> A B) "greater than")
((= A B) "equal to")
(T "less than") )
" the second." ) ) ) |
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 |... | #Pike | Pike | int main(int argc, array(int) argv){
if(argc != 3){
write("usage: `pike compare-two-ints.pike <x> <y>` where x and y are integers.\n");
return 0;
}
int a = argv[1];
int b = argv[2];
if(a > b) {
write(a + " is greater than " + b + "\n");
} else if (a < b) {
write(a + " is le... |
http://rosettacode.org/wiki/HTTPS | HTTPS | Task
Send a GET request to obtain the resource located at the URL "https://www.w3.org/", then print it to the console.
Checking the host certificate for validity is recommended.
Do not authenticate. That is the subject of other tasks.
Readers may wish to contrast with the HTTP Request task, and also the task on HTT... | #zkl | zkl | zkl: var ZC=Import("zklCurl")
zkl: var data=ZC().get("https://sourceforge.net")
L(Data(36,265),826,0) |
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.
| #ColdFusion | ColdFusion |
<cfhttp url="http://www.rosettacode.org" result="result">
<cfoutput>#result.FileContent#</cfoutput>
|
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.
| #Common_Lisp | Common Lisp |
(defun wget-clisp (url)
(ext:with-http-input (stream url)
(loop for line = (read-line stream nil nil)
while line
do (format t "~a~%" line))))
|
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... | #Clojure | Clojure | (ns rosettacode.hofstader-conway
(:use [clojure.math.numeric-tower :only [expt]]))
;; A literal transcription of the definition, with memoize doing the heavy lifting
(def conway
(memoize
(fn [x]
(if (< x 3)
1
(+ (-> x dec conway conway)
(->> x dec conway (- x) conway))))))
... |
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... | #BASIC256 | BASIC256 |
limite = 100000
dim Q[limite+1]
cont = 0
Q[1] = 1
Q[2] = 1
for i = 3 to limite
Q[i] = Q[i-Q[i-1]] + Q[i-Q[i-2]]
if Q[i] < Q[i-1] then cont += 1
next i
print "Primeros 10 términos: ";
for i = 1 to 10
print Q[i] + " ";
next i
print "Término número 1000: "; Q[1000]
print "Términos menores que los anteriores: "; ... |
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... | #BBC_BASIC | BBC BASIC | PRINT "First 10 terms of Q = " ;
FOR i% = 1 TO 10 : PRINT ;FNq(i%, c%) " "; : NEXT : PRINT
PRINT "1000th term = " ; FNq(1000, c%)
PRINT "100000th term = " ; FNq(100000, c%)
PRINT "Term is less than preceding term " ; c% " times"
END
DEF FNq(n%, RETURN c%)
LOCAL i%,q%()
... |
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... | #Clojure | Clojure | (defn hickerson
"Hickerson number, calculated with BigDecimals and manually-entered high-precision value for ln(2)."
[n]
(let [n! (apply *' (range 1M (inc n)))]
(.divide n! (*' 2 (.pow 0.693147180559945309417232121458M (inc n)))
30 BigDecimal/ROUND_HALF_UP)))
(defn almost-integer?
"Tests... |
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
| #6502_Assembly | 6502 Assembly | macro PrintOutput,input,addr
; input: desired function's input
; addr: function you wish to call
LDA #<\addr ;#< represents this number's low byte
STA z_L
LDA #>\addr ;#> represents this number's high byte
STA z_H
LDA \input
JSR doPrintOutput
endm |
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... | #Ada | Ada |
with AWS; use AWS;
with AWS.Response;
with AWS.Server;
with AWS.Status;
with Ada.Text_IO; use Ada.Text_IO;
procedure HelloHTTP is
function CB (Request : Status.Data) return Response.Data is
pragma Unreferenced (Request);
begin
return Response.Build ("text/html", "Hello world!");
end CB;
TheSer... |
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 ... | #11l | 11l | print(‘
here
doc
’) |
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... | #EchoLisp | EchoLisp |
(define-syntax-rule (make-h-var name) (define name (stack (gensym))))
(define-syntax-rule (h-get name) (stack-top name))
(define-syntax-rule (h-set name value) (push name value))
(define-syntax-rule (h-undo name)
(begin
(pop name)
(when ( stack-empty? name) (error "no more values" 'name))
(stack-top name)))
(d... |
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... | #Elena | Elena | import extensions;
import system'collections;
import system'routines;
import extensions'routines;
class HistoryVariable
{
Stack previous := new Stack();
object value;
Value
{
get() = value;
set(value)
{
if ((this value) != nil)
{
pre... |
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... | #C.2B.2B | C++ | #include <iomanip>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
unsigned hofstadter(unsigned rlistSize, unsigned slistSize)
{
auto n = rlistSize > slistSize ? rlistSize : slistSize;
auto rlist = new vector<unsigned> { 1, 3, 7 };
auto slist = new vector<unsigned> { 2, 4, 5, 6... |
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... | #ERRE | ERRE |
PROGRAM HORNER
! 2 3
! polynomial is -19+7x-4x +6x
!
DIM C[3]
PROCEDURE HORNER(C[],X->RES)
LOCAL I%,V
FOR I%=UBOUND(C,1) TO 0 STEP -1 DO
V=V*X+C[I%]
END FOR
RES=V
END PROCEDURE
BEGIN
C[]=(-19,7,-4,6)
HORNER(C[],3->RES)
PRINT(RES)
END PROGRAM
|
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... | #Euler_Math_Toolbox | Euler Math Toolbox |
>function horner (x,v) ...
$ n=cols(v); res=v{n};
$ loop 1 to n-1; res=res*x+v{n-#}; end;
$ return res
$endfunction
>v=[-19,7,-4,6]
[ -19 7 -4 6 ]
>horner(2,v) // test Horner
27
>evalpoly(2,v) // built-in Horner
27
>horner(I,v) // complex values
-15+1i
>horner(1±0.05,v) // interval values
~-10.9,-9.11~
>fu... |
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.
| #C.2B.2B | C++ | #include <algorithm>
#include <iostream>
#include <vector>
struct Point {
int x, y;
//rotate/flip a quadrant appropriately
void rot(int n, bool rx, bool ry) {
if (!ry) {
if (rx) {
x = (n - 1) - x;
y = (n - 1) - y;
}
std::swap(x,... |
http://rosettacode.org/wiki/Honeycombs | Honeycombs | The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position... | #Icon_and_Unicon | Icon and Unicon | link printf
procedure main(A)
h := (0 < integer(\A[1])) | 4 # cells high
w := (0 < integer(\A[2])) | 5 # cells wide
u := (10 < integer(\A[3])) | 30 # length of cell side
HoneyComb(h,w,u)
end
$define INACTIVE "light yellow"
$define ACTIVE "light purple... |
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
... | #Common_Lisp | Common Lisp | ; Easter sunday. Result is a list '(month day)
;
; See:
; Jean Meeus, "Astronomical Formulae for Calculators",
; 4th edition, Willmann-Bell, 1988, p.31
(defun easter (year)
(let (a b c d e f g h i k l m n p)
(setq a (rem year 19))
(multiple-value-setq (b c) (floor year 100))
(multiple-value-setq (d e) (... |
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... | #Fortran | Fortran | program SunDial
real :: lat, slat, lng, ref
real :: hra, hla
integer :: h
real, parameter :: pi = 3.14159265358979323846
print *, "Enter latitude"
read *, lat
print *, "Enter longitude"
read *, lng
print *, "Enter legal meridian"
read *, ref
print *
slat = sin(dr(lat))
write(*,... |
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... | #Julia | Julia |
abstract type HuffmanTree end
struct HuffmanLeaf <: HuffmanTree
ch::Char
freq::Int
end
struct HuffmanNode <: HuffmanTree
freq::Int
left::HuffmanTree
right::HuffmanTree
end
function makefreqdict(s::String)
d = Dict{Char, Int}()
for c in s
if !haskey(d, c)
d[c] = 1
... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Rust | Rust | #[derive(Copy, Clone, Debug)]
enum Endianness {
Big, Little,
}
impl Endianness {
fn target() -> Self {
#[cfg(target_endian = "big")]
{
Endianness::Big
}
#[cfg(not(target_endian = "big"))]
{
Endianness::Little
}
}
}
fn main() {
p... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Scala | Scala | import java.nio.ByteOrder
object ShowByteOrder extends App {
println(ByteOrder.nativeOrder())
println(s"Word size: ${System.getProperty("sun.arch.data.model")}")
println(s"Endianness: ${System.getProperty("sun.cpu.endian")}")
} |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Scheme | Scheme | (define host-info
(begin
(display "Endianness: ")
(display (machine-byte-order))
(newline)
(display "Word Size: ")
(display (if (fixnum? (expt 2 33)) 64 32))
(newline))) |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PARI.2FGP | PARI/GP | str = externstr("hostname")[1];
str = externstr("uname -n")[1]; |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Pascal | Pascal | Program HostName;
uses
unix;
begin
writeln('The name of this computer is: ', GetHostName);
end. |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Perl | Perl | use Sys::Hostname;
$name = 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
⋮
⋮
⋮
⋱
... | #PL.2FI | PL/I |
identity: procedure (A, n);
declare A(n,n) fixed controlled;
declare (i,n) fixed binary;
allocate A; A = 0;
do i = 1 to n; A(i,i) = 1; end;
end identity;
|
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
⋮
⋮
⋮
⋱
... | #PostScript | PostScript |
% n ident [identity-matrix]
% create an identity matrix of dimension n*n.
% Uses a local dictionary for its one parameter, perhaps overkill.
% Constructs arrays of arrays of integers using [], for loops, and stack manipulation.
/ident { 1 dict begin /n exch def
[
1 1 n { % [ i
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #SNOBOL4 | SNOBOL4 |
output = trim(input) + 1
output = "123" + 1
end |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Sparkling | Sparkling | function numStrIncmt(s) {
return fmtstr("%d", toint(s) + 1);
}
spn:1> numStrIncmt("12345")
= 12346 |
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 |... | #PL.2FI | PL/I |
declare (a, b) fixed binary;
get list (a, b);
if a = b then
put skip list ('The numbers are equal');
if a > b then
put skip list ('The first number is greater than the second');
if a < b then
put skip list ('The second number is greater than the first');
|
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 |... | #Plain_English | Plain English | To run:
Start up.
Write "Enter the first number: " to the console without advancing.
Read a first number from the console.
Write "Enter the second number: " to the console without advancing.
Read a second number from the console.
If the first number is less than the second number, write "Less than!" to the console.
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.
| #Crystal | Crystal |
require "http/client"
HTTP::Client.get("http://google.com")
|
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.
| #D | D |
void main() {
import std.stdio, std.net.curl;
writeln(get("http://google.com"));
}
|
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... | #Common_Lisp | Common Lisp | (defparameter *hof-con*
(make-array '(2) :initial-contents '(1 1) :adjustable t
:element-type 'integer :fill-pointer 2))
(defparameter *hof-con-ratios*
(make-array '(2) :initial-contents '(1.0 0.5) :adjustable t
:element-type 'single-float :fill-pointer 2))
(defun hof-con (n)
(let ((l (length *h... |
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 ... | #11l | 11l | :stderr.write("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... | #Bracmat | Bracmat | ( 0:?memocells
& tbl$(memo,!memocells+1) { allocate array }
& ( Q
=
. !arg:(1|2)&1
| !arg:>2
& ( !arg:>!memocells:?memocells { Array is too small. }
& tbl$(memo,!memocells+1) { Let array grow to needed size. }
| ... |
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... | #BCPL | BCPL | get "libhdr"
let start() be
$( let Q = vec 1000
Q!1 := 1
Q!2 := 1
for n = 3 to 1000 do
Q!n := Q!(n-Q!(n-1)) + Q!(n-Q!(n-2))
writes("The first 10 terms are:")
for n = 1 to 10 do writef(" %N", Q!n)
writef("*NThe 1000th term is: %N*N", Q!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... | #COBOL | COBOL | >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. hickerson-series.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION ALL INTRINSIC
.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 n PIC 99 COMP.
01 h PIC Z(19)9.9(10).... |
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... | #Crystal | Crystal | require "big"
LN2 = Math.log(2).to_big_f
FACTORIALS = Hash(Int32, Float64).new{|h,k| h[k] = k * h[k-1]}
FACTORIALS[0] = 1
def hickerson(n)
FACTORIALS[n] / (2 * LN2 ** (n+1))
end
def nearly_int?(n)
int = n.round
(int - 0.1..int + 0.1).includes? n
end
1.upto(17) do |n|
h = hickerson(n)
str = nearly_in... |
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
| #68000_Assembly | 68000 Assembly | LEA foo,A0
JSR bar
JMP * ;HALT
bar:
MOVE.L A0,-(SP)
RTS ;JMP foo
foo:
RTS ;do nothing and return. This rts retuns execution just after "JSR bar" but before "JMP *". |
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... | #Aime | Aime | void
serve(dispatch w, file s, list colors)
{
file i, o;
date d;
accept(i, o, s, 0);
f_(o, "HTTP/1.1 200 OK\n"
"Content-Type: text/html; charset=UTF-8\n\n"
"<!DOCTYPE html><html><head><title>Bye-bye baby bye-bye</title>"
"<style>body { background-color: #111 }"
"h1 { font-size:4cm; text-align: center;... |
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... | #Amazing_Hopper | Amazing Hopper |
// Hello world! mode Server
#include <hopper.h>
main:
fd=0,fdc=0,message=""
{"HTTP/1.1 200 OK\n","Content-Type: text/html; charset=UTF-8\n\n"}cat
{"<!DOCTYPE html><html><head><title>Bye-bye baby bye-bye</title>"},cat
{"<style>body { background-color: #111 },cat
{"h1 { font-size:4cm; text-align: cen... |
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 ... | #8th | 8th |
quote *
Hi
there
* .
|
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 ... | #Ada | Ada | with Ada.Containers.Indefinite_Vectors, Ada.Text_IO;
procedure Here_Doc is
package String_Vec is new Ada.Containers.Indefinite_Vectors
(Index_Type => Positive,
Element_Type => String);
use type String_Vec.Vector;
Document: String_Vec.Vector := String_Vec.Empty_Vector
& "This is a vecto... |
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 ... | #ALGOL_68 | ALGOL 68 | #!/usr/local/bin/a68g --script #
[]STRING help = (
"Usage: thingy [OPTIONS]",
" -h Display this usage message",
" -H hostname Hostname to connect to"
);
printf(($gl$,help,$l$));
printf(($gl$,
"The river was deep but I swam it, Janet.",
"The future is ours so let's plan... |
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... | #Erlang | Erlang | 1> V1 = "123".
"123"
2> V1 = V1 ++ "qwe".
** exception error: no match of right hand side value "123qwe"
3> V2 = V1 ++ "qwe".
"123qwe"
4> V3 = V2 ++ "ASD".
"123qweASD"
5> V1.
"123"
6> V2.
"123qwe"
7> V3.
"123qweASD"
|
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... | #Factor | Factor | USING: accessors combinators formatting kernel models.history ;
1 <history> {
[ add-history ]
[ value>> "Initial value: %u\n" printf ]
[ 2 >>value add-history ]
[ 3 swap value<< ]
[ value>> "Current value: %u\n" printf ]
[ go-back ]
[ go-back ]
[ value>> "Restored value: %u\n" printf ]... |
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... | #Forth | Forth | : history create here cell+ , 0 , -1 , ;
: h@ @ @ ;
: h! swap here >r , dup @ , r> swap ! ;
: .history @ begin dup cell+ @ -1 <> while dup ? cell+ @ repeat drop ;
: h-- dup @ cell+ @ dup -1 = if abort" End of history" then swap ! ; |
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... | #CLU | CLU | figfig = cluster is ffr, ffs
rep = null
ai = array[int]
own R: ai := ai$[1]
own S: ai := ai$[2]
% Extend R and S until R(n) is known
extend = proc (n: int)
while n > ai$high(R) do
next: int := ai$top(R) + S[ai$high(R)]
ai$addh(R, next)
while ai$top(S... |
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... | #CoffeeScript | CoffeeScript | R = [ null, 1 ]
S = [ null, 2 ]
extend_sequences = (n) ->
current = Math.max(R[R.length - 1], S[S.length - 1])
i = undefined
while R.length <= n or 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
ff = (X, ... |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #F.23 | F# |
let horner l x =
List.rev l |> List.fold ( fun acc c -> x*acc+c) 0
horner [-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... | #Factor | Factor | : horner ( coeff x -- res )
[ <reversed> 0 ] dip '[ [ _ * ] dip + ] reduce ; |
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.
| #D | D | import std.stdio;
void main() {
foreach (order; 1..6) {
int n = 1 << order;
auto points = getPointsForCurve(n);
writeln("Hilbert curve, order=", order);
auto lines = drawCurve(points, n);
foreach (line; lines) {
writeln(line);
}
writeln;
}
}
... |
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... | #J | J | require'ide/qt/gl2'
coinsert'jgl2'
NB. corners of a unit hexagon
ucorn=: +.^j.2p1*(%~i.)6
NB. center to center offset for columns and rows
uof=: %:2.3 3
shape=: 4 5
scale=: 50
scorn=: scale*ucorn
centers=: scale*(((%:0 0.75)*/~2|{:"1)+uof*"1 1:+|."1)shape#:i.shape
honeycomb=: {{)n
pc honeycomb nosize closeok;... |
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
... | #D | D | import std.stdio, std.datetime;
void printEasterRelatedHolidays(in int year) {
static struct Holyday {
string name;
int offs;
}
static immutable Holyday[] holidayOffsets = [{"Easter", 0},
{"Ascension", 39},
... |
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... | #FreeBASIC | FreeBASIC | ' version 04-11-2016
' compile with: fbc -s console
#Macro deg2rad (x)
(x) * Atn(1) / 45
#EndMacro
#Macro rad2deg (x)
(x) * 45 / Atn(1)
#EndMacro
' ------=< MAIN >=------
Dim As Double latitude, longitude, meridian, hra, hla
Dim As ULong h
Input " Enter latitude (degrees): ", latitude
Input " ... |
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... | #Kotlin | Kotlin | import java.util.*
abstract class HuffmanTree(var freq: Int) : Comparable<HuffmanTree> {
override fun compareTo(other: HuffmanTree) = freq - other.freq
}
class HuffmanLeaf(freq: Int, var value: Char) : HuffmanTree(freq)
class HuffmanNode(var left: HuffmanTree, var right: HuffmanTree) : HuffmanTree(left.freq +... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "cc_conf.s7i";
const proc: main is func
begin
writeln("Word size: " <& ccConf.POINTER_SIZE);
write("Endianness: ");
if ccConf.LITTLE_ENDIAN_INTTYPE then
writeln("Little endian");
else
writeln("Big endian");
end if;
end func; |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Slate | Slate | inform: 'Endianness: ' ; Platform current endianness.
inform: 'Word Size: ' ; (Platform current bytesPerWord * 8) printString. |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Tcl | Tcl | % parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine) = intel
tcl_platform(os) = Windows NT
tcl_platform(osVersion) = 5.1
tcl_platform(platform) = windows
tcl_platform(pointerSize) = 4
tcl_platform(threaded) = 1
tcl_platform(user) = glennj
tcl_platform(wordSize... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Phix | Phix | without js -- (system_exec, file i/o)
constant tmp = "hostname.txt",
cmd = iff(platform()=WINDOWS?"hostname":"uname -n")
{} = system_exec(sprintf("%s > %s",{cmd,tmp}),4)
string host = trim(get_text(tmp))
{} = delete_file("hostname.txt")
?host
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PHP | PHP | echo $_SERVER['HTTP_HOST']; |
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
⋮
⋮
⋮
⋱
... | #PowerShell | PowerShell |
function identity($n) {
0..($n-1) | foreach{$row = @(0) * $n; $row[$_] = 1; ,$row}
}
function show($a) { $a | foreach{ "$_"} }
$array = identity 4
show $array
|
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #SuperTalk | SuperTalk | put 0 into someVar
add 1 to someVar
-- without "into [field reference]" the value will appear
-- in the message box
put someVar -- into cd fld 1 |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Swift | Swift | let s = "1234"
if let x = Int(s) {
print("\(x + 1)")
} |
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 |... | #Pop11 | Pop11 | ;;; Comparison procedure
define compare_integers(x, y);
if x > y then
printf('x is greater than y\n');
elseif x < y then
printf('x is less than y\n');
elseif x = y then
printf('x equals y\n');
endif;
enddefine;
;;; Setup token reader
vars itemrep;
incharitem(charin) -> itemrep;
;;; Read numbers and call co... |
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.
| #Dart | Dart | import 'dart:io';
void main(){
var url = 'http://rosettacode.org';
var client = new HttpClient();
client.getUrl(Uri.parse(url))
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) => response.pipe(stdout));
} |
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... | #D | D | import std.stdio, std.algorithm;
void hofstadterConwaySequence(in int m) {
auto alist = new int[m + 1];
alist[0 .. 2] = 1;
auto v = alist[2];
int k1 = 2, lg2 = 1;
double amax = 0.0;
foreach (n; 2 .. m + 1) {
v = alist[n] = alist[v] + alist[n - v];
amax = max(amax, v * 1.0 / 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 ... | #4DOS_Batch | 4DOS Batch | echoerr 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 ... | #AArch64_Assembly | AArch64 Assembly | .equ STDERR, 2
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
.text
.global _start
_start:
stp x29, x30, [sp, -16]!
mov x0, #STDERR
ldr x1, =msg
mov x2, 15
mov x8, #SVC_WRITE
mov x29, sp
svc #0 // write(stderr, msg, 15);
ldp x29, x30, [sp], 16
mov x0, #0
mov x8, #SVC_EXIT
svc #0 // exit(0);
msg: .ascii "Goodbye ... |
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 ... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
procedure Goodbye_World is
begin
Put_Line (Standard_Error, "Goodbye, World!");
end 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... | #C | C | #include <stdio.h>
#include <stdlib.h>
#define N 100000
int main()
{
int i, flip, *q = (int*)malloc(sizeof(int) * N) - 1;
q[1] = q[2] = 1;
for (i = 3; i <= N; i++)
q[i] = q[i - q[i - 1]] + q[i - q[i - 2]];
for (i = 1; i <= 10; i++)
printf("%d%c", q[i], i == 10 ? '\n' : ' ');
printf("%d\n", q[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... | #D | D | void main() {
import std.stdio, std.algorithm, std.mathspecial;
foreach (immutable n; 1 .. 18) {
immutable x = gamma(n + 1) / (2 * LN2 ^^ (n + 1)),
tenths = cast(int)floor((x - x.floor) * 10);
writefln("H(%2d)=%22.2f is %snearly integer.", n, x,
tenths.among... |
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... | #Factor | Factor | USING: formatting kernel math math.factorials math.functions
math.ranges sequences ;
IN: rosetta-code.hickerson
: ln2 ( -- x )
99 [1,b] [ [ 2 swap ^ ] [ * ] bi recip ] map-sum ;
: hickerson ( n -- x ) [ n! ] [ 1 + ln2 swap ^ 2 * ] bi / ;
: almost-int? ( x -- ? ) 10 * truncate 10 mod { 0 9 } member? ;
: hick... |
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... | #11l | 11l | F gcd(=u, =v)
L v != 0
(u, v) = (v, u % v)
R abs(u)
F hero(a, b, c)
V s = (a + b + c) / 2
V a2 = s * (s - a) * (s - b) * (s - c)
R I a2 > 0 {sqrt(a2)} E 0
F is_heronian(a, b, c)
V x = hero(a, b, c)
R x > 0 & fract(x) == 0
F gcd3(x, y, z)
R gcd(gcd(x, y), z)
V MAXSIDE = 200
[(Int, I... |
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
| #8th | 8th |
: pass-me
"I was passed\n" . ;
: passer
w:exec ;
\ pass 'pass-me' to 'passer'
' pass-me passer
|
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... | #AntLang | AntLang | serv: httprun[8080; {"HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\nGoodbye, World!"}] |
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... | #Arturo | Arturo | serve.port:8080 [ GET "/" -> "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 ... | #APL | APL |
BODY←⎕INP 'END-OF-⎕INP'
First line
Second line
Third line
...
END-OF-⎕INP
|
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 ... | #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program heredoc.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
.equ BUFFERSIZE, 100
/* Initialized data */
.... |
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... | #Go | Go | package main
import (
"fmt"
"sort"
"sync"
"time"
)
// data type for history variable (its an int)
type history struct {
timestamp tsFunc
hs []hset
}
// data type for timestamp generator
type tsFunc func() time.Time
// data type for a "set" event
type hset struct {
int ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.