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/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #MATLAB_.2F_Octave | MATLAB / Octave | function [endian]=endian()
fid=tmpfile();
fwrite(fid,1:8,'uint8');
fseek(fid,0,'bof');
t=fread(fid,8,'int8');
i8=sprintf('%02X',t);
fseek(fid,0,'bof');
t=fread(fid,4,'int16');
i16=sprintf('%04X',t);
fclose(fid);
if strcmp(i8,i16) endian='big';
else endian='little';
... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #K | K |
_h
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Kotlin | Kotlin | // version 1.1.4
import java.net.InetAddress
fun main(args: Array<String>) {
println(InetAddress.getLocalHost().hostName)
} |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Lasso | Lasso | [web_request->httpHost] |
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 REM REM Used the following as official standard:
20 REM REM http://www.cnb.cz/cs/platebni_styk/iban/download/EBS204.pdf
30 REM REM Pairs of ISO 3166 country code & expected IBAN length for this country
40 LET c$="AL28 AD24 AT20 AZ28 BE16 BH22 BA20 BR29 BG22 CR21 HR21 CY28 CZ24 DK18 DO28 EE20 "
50 LET c$=c$+"FO18 FI... |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Tcl | Tcl | import "graphics" for Canvas, Color, ImageData
import "dome" for Window, Process
import "math" for Math
var Hypot = Fn.new { |x, y| (x*x + y*y).sqrt }
class ArrayData {
construct new(width, height) {
_width = width
_height = height
_dataArray = List.filled(width * height, 0)
}
... |
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
⋮
⋮
⋮
⋱
... | #Ol | Ol |
(define (make-identity-matrix n)
(map (lambda (i)
(append (repeat 0 i) '(1) (repeat 0 (- n i 1))))
(iota n)))
(for-each print (make-identity-matrix 3))
(for-each print (make-identity-matrix 17)) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #REBOL | REBOL | rebol [
Title: "Increment Numerical String"
URL: http://rosettacode.org/wiki/Increment_numerical_string
]
; Note the use of unusual characters in function name. Also note that
; because REBOL collects terms from right to left, I convert the
; string argument (s) to integer first, then add that result to one.
s++:... |
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 |... | #Octave | Octave | printf("Enter a: ");
a = scanf("%d", "C");
printf("Enter b: ");
b = scanf("%d", "C");
if (a > b)
disp("a greater than b");
elseif (a == b)
disp("a equal to b");
elseif (a < b)
disp("a less than b");
endif |
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... | #PowerShell | PowerShell |
$wc = New-Object Net.WebClient
$wc.DownloadString('https://sourceforge.net')
|
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... | #Python | Python | import urllib.request
print(urllib.request.urlopen("https://sourceforge.net/").read()) |
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #BBC_BASIC | BBC BASIC | SYS "LoadLibrary", "URLMON.DLL" TO urlmon%
SYS "GetProcAddress", urlmon%, "URLDownloadToFileA" TO URLDownloadToFile
url$ = "http://www.bbcbasic.co.uk/aboutus.html"
file$ = @tmp$ + "rosetta.tmp"
SYS URLDownloadToFile, 0, url$, file$, 0, 0 TO fail%
IF fail% ERROR 100, "File download ... |
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... | #ALGOL_68 | ALGOL 68 | PROC do sqnc = (INT max)INT:
BEGIN
[max]INT a list;
INT k1 := 2,
lg2 := 1,
v := a list[1] := a list[2] := 1; # Concurrent declaration and assignment in declarations are allowed #
INT nmax;
LONG REAL amax := 0.0;
INT mallows number;
FOR n FROM 3 TO max DO
v := a list[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... | #Action.21 | Action! | PROC Main()
DEFINE MAX="1000"
INT ARRAY q(MAX+1)
INT i
q(1)=1 q(2)=1
FOR i=3 TO MAX
DO
q(i)=q(i-q(i-1))+q(i-q(i-2))
OD
FOR i=1 TO 10
DO
PrintF("%I: %I%E",i,q(i))
OD
PrintF("%I: %I%E",MAX,q(MAX))
RETURN |
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... | #C | C | #include <stdio.h>
double horner(double *coeffs, int s, double x)
{
int i;
double res = 0.0;
for(i=s-1; i >= 0; i--)
{
res = res * x + coeffs[i];
}
return res;
}
int main()
{
double coeffs[] = { -19.0, 7.0, -4.0, 6.0 };
printf("%5.1f\n", horner(coeffs, sizeof(coeffs)/sizeof(double), 3.0));... |
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... | #Ada | Ada | with Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Discrete_Random;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Surfaces;
with SDL.Video.Rectangles;
with SDL.TTFs.Makers;
with SDL.Events.Events;
with SDL.Events.Keyboards;
with SDL.Events.Mice;
procedure Honeycombs is
use... |
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
... | #Ada | Ada | with Ada.Calendar.Arithmetic;
with Ada.Calendar.Formatting;
with Ada.Text_IO;
procedure Main is
use Ada.Calendar;
use Arithmetic;
function Get_Easter (Year : Year_Number) return Time is
A : Integer := Year mod 19;
B : Integer := Year / 100;
C : Integer := Year mod 100;
D : Integer :... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Sidef | Sidef | for n in (2..20, 65) {
var steps = []
var orig = n
for (var f = n.factor; true; f = n.factor) {
steps << f
n = Num(f.join)
break if n.is_prime
}
say ("HP(#{orig}) = ", steps.map { .join('_') }.join(' -> '))
} |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Wren | Wren | import "/math" for Int
import "/big" for BigInt
var list = (2..20).toList
list.add(65)
for (i in list) {
if (Int.isPrime(i)) {
System.print("HP%(i) = %(i)")
continue
}
var n = 1
var j = BigInt.new(i)
var h = [j]
while (true) {
var k = BigInt.primeFactors(j).reduce("") {... |
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... | #COBOL | COBOL | PROGRAM-ID. horizontal-sundial-calc.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 latitude PIC S9(3)V9(5) COMP.
01 longitude PIC S9(3)V9(5) COMP.
01 legal-meridian PIC S9(3)V9(5) COMP.
01 lat-sine PIC S9(3)V9(5) COMP.
01 diff-longit... |
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... | #FreeBASIC | FreeBASIC | type block
freq as uinteger
chars as string
end type
type code
char as string*1
code as string
end type
sub bubble( lst() as block, n_l as uinteger )
for j as integer = n_l-1 to 0 step -1
if j>0 andalso lst(j).freq > lst(j-1).freq then
swap lst(j), lst(j-1)
endif
... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Modula-3 | Modula-3 | MODULE Host EXPORTS Main;
IMPORT IO, Fmt, Word, Swap;
BEGIN
IO.Put("Word Size: " & Fmt.Int(Word.Size) & "\n");
IF Swap.endian = Swap.Endian.Big THEN
IO.Put("Endianness: Big\n");
ELSE
IO.Put("Endianness: Little\n");
END;
END Host. |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Neko | Neko | /* Return wordsize to Neko */
/* From Rosetta Code, C entry, with Neko marshalling */
#include <stdio.h>
#include <stddef.h> /* for size_t */
#include <limits.h> /* for CHAR_BIT */
#include <neko.h>
value wordsize(void) {
/*
* Best bet: size_t typically is exactly one word.
*/
return alloc_int((in... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #LFE | LFE |
(net_adm:localhost)
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Liberty_BASIC | Liberty BASIC | lpBuffer$=Space$(128) + Chr$(0)
struct SIZE,sz As Long
SIZE.sz.struct=Len(lpBuffer$)
calldll #kernel32, "GetComputerNameA",lpBuffer$ as ptr, SIZE as struct, result as Long
CurrentComputerName$=Trim$(Left$(lpBuffer$, SIZE.sz.struct))
print CurrentComputerName$ |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Wren | Wren | import "graphics" for Canvas, Color, ImageData
import "dome" for Window, Process
import "math" for Math
var Hypot = Fn.new { |x, y| (x*x + y*y).sqrt }
class ArrayData {
construct new(width, height) {
_width = width
_height = height
_dataArray = List.filled(width * height, 0)
}
... |
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
⋮
⋮
⋮
⋱
... | #ooRexx | ooRexx |
say "a 3x3 identity matrix"
say
call printMatrix createIdentityMatrix(3)
say
say "a 5x5 identity matrix"
say
call printMatrix createIdentityMatrix(5)
::routine createIdentityMatrix
use arg size
matrix = .array~new(size, size)
loop i = 1 to size
loop j = 1 to size
if i == j then matrix[i, j] = ... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Retro | Retro | '123 s:to-number n:inc n:to-string |
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 |... | #Oforth | Oforth | import: console
: cmpInt
| a b |
doWhile: [ System.Console askln asInteger dup ->a isNull ]
doWhile: [ System.Console askln asInteger dup ->b isNull ]
a b < ifTrue: [ System.Out a << " is less than " << b << cr ]
a b == ifTrue: [ System.Out a << " is equal to " << b << cr ]
a b > ifTrue: [ System.O... |
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 |... | #Ol | Ol |
(define (compare a b)
(cond ((< a b) "A is less than B")
((> a b) "A is greater than B")
((= a b) "A equals B")))
(print (compare 1 2))
; ==> A is less than B
(print (compare 2 2))
; ==> A equals B
(print (compare 3 2))
; ==> A is greater than B
; manual user input:
(print (compare (read) (r... |
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... | #R | R | library(RCurl)
webpage <- getURL("https://sourceforge.net/", .opts=list(followlocation=TRUE, ssl.verifyhost=FALSE, ssl.verifypeer=FALSE)) |
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... | #Racket | Racket |
#lang racket
(require net/url)
(copy-port (get-pure-port (string->url "https://www.google.com")
#:redirections 100)
(current-output-port))
|
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... | #Raku | Raku | use WWW;
say get 'https://sourceforge.net/'; |
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.
| #Biferno | Biferno | $httpExt.ExecRemote("www.tabasoft.it") |
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #AppleScript | AppleScript | on HC10000(ceiling)
script o
property lst : {1, 1}
property maxima : {}
end script
set p to missing value
set max to 0
set maxPos to 0
set power to 0
set x to end of o's lst
repeat with n from 3 to ceiling
set x to (item x of o's lst) + (item -x of o's lst)
... |
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... | #Ada | Ada | with Ada.Text_IO;
procedure Hofstadter_Q_Sequence is
type Callback is access procedure(N: Positive);
procedure Q(First, Last: Positive; Q_Proc: Callback) is
-- calls Q_Proc(Q(First)); Q_Proc(Q(First+1)); ... Q_Proc(Q(Last));
-- precondition: Last > 2
Q_Store: array(1 .. Last) of Natural := (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... | #68000_Assembly | 68000 Assembly | HistoryVar equ $100200 ;assume this is work ram.
LEA HistoryVar+4,A0
MOVE.L #$11223344,D0
MOVE.L D0,-(A0) ;store the 32-bit value #$11223344 starting at $100200
MOVE.L #$55667788,D0
MOVE.L D0,-(A0) ;store the 32-bit value #$5566788 at $1001FC
MOVE.L #$AABBCCDD,D0
MOVE.L D0,-(A0) ;store the 32-bit value #$AABB... |
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... | #C.23 | C# | using System;
using System.Linq;
class Program
{
static double Horner(double[] coefficients, double variable)
{
return coefficients.Reverse().Aggregate(
(accumulator, coefficient) => accumulator * variable + coefficient);
}
static void Main()
{
Console.WriteLine(H... |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #C.2B.2B | C++ | #include <iostream>
#include <vector>
using namespace std;
double horner(vector<double> v, double x)
{
double s = 0;
for( vector<double>::const_reverse_iterator i = v.rbegin(); i != v.rend(); i++ )
s = s*x + *i;
return s;
}
int main()
{
double c[] = { -19, 7, -4, 6 };
vector<double> v(c, c + sizeo... |
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... | #AutoHotkey | AutoHotkey | Columns := 5 ; cater for a different number of columns
hexPerCol := 4 ; cater for a different number of hexagons
size := 40
w := sqrt(3) * size
h := 2 * size
Coord := [], Chosen := [], Seq:= ""
Letters := StrSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
x := A_ScreenWidth/2 - w*(Columns/2) + w/2
y := A_ScreenHeig... |
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
... | #ALGOL_68 | ALGOL 68 | MODE YEAR = INT, MONTH = INT, WEEK = INT, DAY = INT;
MODE DATE = STRUCT(
YEAR year, #DAY year day, #
MONTH month, DAY month day,#
WEEK week, #DAY week day);
FORMAT mon fmt = $c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")$,
FORMAT week day... |
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... | #D | D | import std.stdio, std.math, std.conv, std.string;
double radians(in double x) pure nothrow { return x * (PI / 180); }
double degrees(in double x) pure nothrow { return x / (PI / 180); }
T input(T)(in string msg) {
msg.write;
return readln.strip.to!T;
}
void main() {
immutable lat = input!double("Enter... |
http://rosettacode.org/wiki/Huffman_coding | Huffman coding | Huffman encoding is a way to assign binary codes to symbols that reduces the overall number of bits used to encode a typical string of those symbols.
For example, if you use letters as symbols and have details of the frequency of occurrence of those letters in typical strings, then you could just encode each letter wi... | #Go | Go | package main
import (
"container/heap"
"fmt"
)
type HuffmanTree interface {
Freq() int
}
type HuffmanLeaf struct {
freq int
value rune
}
type HuffmanNode struct {
freq int
left, right HuffmanTree
}
func (self HuffmanLeaf) Freq() int {
return self.freq
}
func (self Huf... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols nobinary
wordSize = System.getProperty('sun.arch.data.model')
endian = System.getProperty('sun.cpu.endian')
say ' word size:' wordSize
say 'endianness:' endian
|
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Nim | Nim | echo cpuEndian
echo sizeof(int) * 8 |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Objective-C | Objective-C | switch (NSHostByteOrder()) {
case NS_BigEndian:
NSLog(@"%@", @"Big Endian");
break;
case NS_LittleEndian:
NSLog(@"%@", @"Little Endian");
break;
case NS_UnknownByteOrder:
NSLog(@"%@", @"endianness unknown");
break;
} |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Limbo | Limbo | implement Hostname;
include "sys.m"; sys: Sys;
include "draw.m";
Hostname: module {
init: fn(nil: ref Draw->Context, nil: list of string);
};
init(nil: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
buf := array[Sys->ATOMICIO] of byte;
fd := sys->open("/dev/sysname", Sys->OREAD);
if(fd... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Lingo | Lingo |
sx = xtra("Shell").new()
if the platform contains "win" then
hostname = sx.shell_cmd("hostname", ["eol":RETURN]).line[1] -- win 7 or later
else
hostname = sx.shell_cmd("hostname", RETURN).line[1]
end if |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #LiveCode | LiveCode | answer the hostName |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #zkl | zkl | const WHITE=0xffFFff, X=0x010101;
fcn houghTransform(image,hx=460,hy=360){
if(hy.isOdd) hy-=1; // hy argument must be even
out:=PPM(hx,hy,WHITE);
rMax:=image.w.toFloat().hypot(image.h);
dr,dTh:=rMax/(hy/2), (0.0).pi/hx;
foreach y,x in (image.h,image.w){
if(image[x,y]==WHITE) continue;
forea... |
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
⋮
⋮
⋮
⋱
... | #OxygenBasic | OxygenBasic |
Class SquareMatrix
'=================
double *Cell
sys size
method SetIdentity()
indexbase 0
sys e,i,j
e=size*size
for i=0 to <size
cell(i*size+j)=1 : j++
next
end method
method constructor(sys n)
@cell=getmemory n*n*sizeof double
size=n
end method
method destructor()
free... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #REXX | REXX | /*REXX program demonstrates a method how to increment a numerical string*/
count = "3" /*REXX variables (and constants) are character strings.*/
count = 3 /*(identical to the above statement.) */
count = count+1 /*strings in a numerical context are treated as numbers*/
say 'sum=' count /*d... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Ring | Ring |
x = "1234" See 1+x # print 1235
|
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 |... | #Oz | Oz | functor
import
Application(exit)
Open(text file)
define
Txt = class from Open.file Open.text end
Stdout = {New Open.file init(name:stdout)}
Stdin = {New Txt init(name:stdin)}
proc{Print Msg}
{Stdout write(vs:Msg)}
end
fun{GetInt Prompt}
{Print Prompt}
{StringToInt {Stdin getS($)}}
end
Int1 = {GetI... |
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... | #REALbasic | REALbasic |
Dim sock As New HTTPSecureSocket
Print(sock.Get("https://sourceforge.net", 10)) //set the timeout period to 10 seconds.
|
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... | #Ring | Ring |
cStr= download("http://sourceforge.net/")
see cStr + nl
|
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... | #RLaB | RLaB |
require 'net/https'
require 'uri'
require 'pp'
uri = URI.parse('https://sourceforge.net')
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start do
content = http.get(uri)
p [content.code, content.message]
pp content.to_hash
puts content.body
en... |
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.
| #C | C |
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
int
main(void)
{
CURL *curl;
char buffer[CURL_ERROR_SIZE];
if ((curl = curl_easy_init()) != NULL) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.rosettacode.org/");
curl_easy_setopt(curl, CURLO... |
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... | #AutoHotkey | AutoHotkey | Progress, b2 w150 zh0 fs9, CreateLists ...
CreateLists(2 ** (Max:=20))
Progress,, Find Maxima ...
Loop, % Max - 1
msg .= "Maximum between 2^" A_Index " and 2^" A_Index + 1
. " is " GetMax(2 ** A_Index, 2 ** (A_Index + 1), n)
. " for n = " n "`n"
Progress,, Find Mallows Number ...
Loop, % 2 ** ... |
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... | #ALGOL_68 | ALGOL 68 | #!/usr/local/bin/a68g --script #
INT n = 100000;
main:
(
INT flip;
[n]INT q;
q[1] := q[2] := 1;
FOR i FROM 3 TO n DO
q[i] := q[i - q[i - 1]] + q[i - q[i - 2]] OD;
FOR i TO 10 DO
printf(($g(0)$, q[i], $b(l,x)$, i = 10)) OD;
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... | #Ada | Ada | private with Ada.Containers.Indefinite_Vectors;
generic
type Item_Type (<>) is private;
package History_Variables is
type Variable is tagged limited private;
-- set and get current value
procedure Set(V: in out Variable; Item: Item_Type);
function Get(V: Variable) return Item_Type;
-- number of ... |
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... | #ALGOL_W | ALGOL W | begin
% implements integer history variables %
% similar history types could be defined for other types of variable %
record HInteger ( integer iValue; reference(HInteger) iPrev );
% sets the latest value of hv to n %
procedure se... |
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... | #11l | 11l | V cR = [1]
V cS = [2]
F extend_RS()
V x = :cR[:cR.len-1] + :cS[:cR.len-1]
:cR [+]= (x)
:cS [+]= :cS.last+1 .< x
:cS [+]= (x + 1)
F ff_R(n)
assert(n > 0)
L n > :cR.len
extend_RS()
R :cR[n - 1]
F ff_S(n)
assert(n > 0)
L n > :cS.len
extend_RS()
R :cS[n - 1]
print((1..10).m... |
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... | #Clojure | Clojure | (defn horner [coeffs x]
(reduce #(-> %1 (* x) (+ %2)) (reverse coeffs)))
(println (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... | #CoffeeScript | CoffeeScript |
eval_poly = (x, coefficients) ->
# coefficients are for ascending powers
return 0 if coefficients.length == 0
ones_place = coefficients.shift()
x * eval_poly(x, coefficients) + ones_place
console.log eval_poly 3, [-19, 7, -4, 6] # 128
console.log eval_poly 10, [4, 3, 2, 1] # 1234
console.log eval_poly 2, [1... |
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.
| #11l | 11l | T Point
x = 0
y = 0
F rot(n, rx, ry)
I !ry
I rx
.x = (n - 1) - .x
.y = (n - 1) - .y
swap(&.x, &.y)
F calcD(n)
V d = 0
V s = n >> 1
L s > 0
V rx = ((.x [&] s) != 0)
V ry = ((.y [&] s) != 0)
d += s * s * ((I 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... | #BBC_BASIC | BBC BASIC | ALTERNATE = 1
VDU 23,22,252;252;8,16,16,128
*FONT Arial,24,B
Letters$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Letters% = !^Letters$
FOR i% = 0 TO 24
SWAP Letters%?i%, Letters%?(i%+RND(26-i%)-1)
NEXT
DIM xpos%(20), ypos%(20), hrgn%(20)
C% = 1
FOR Y% = 36 TO ... |
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
... | #BBC_BASIC | BBC BASIC | INSTALL @lib$+"DATELIB"
PRINT "Year Easter Ascension Pentecost Trinity Corpus"
FOR year% = 1800 TO 2100 STEP 100
e% = FNeaster(year%) : f$ = "dd MMM"
PRINT ;year%, FN_date$(e%,f$), FN_date$(e%+39,f$), \
\ FN_date$(e%+49,f$), FN_date$(e%+56,f$), FN_date$(e%+60,f$... |
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... | #Delphi | Delphi | procedure PrintSundial(lat, lng, lme : Float);
begin
PrintLn(Format('latitude: %7.2f', [lat]));
PrintLn(Format('longitude: %7.2f', [lng]));
PrintLn(Format('legal meridian: %7.2f', [lme]));
var slat := Sin(DegToRad(lat));
PrintLn(Format('sine of latitude: %.3f', [slat]));
PrintLn(Form... |
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... | #Groovy | Groovy |
import groovy.transform.*
@Canonical
@Sortable(includes = ['freq', 'letter'])
class Node {
String letter
int freq
Node left
Node right
boolean isLeaf() { left == null && right == null }
}
Map correspondance(Node n, Map corresp = [:], String prefix = '') {
if (n.isLeaf()) {
corr... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #OCaml | OCaml | Printf.printf "%d\n" Sys.word_size; (* Print word size *)
Printf.printf "%s\n" Sys.os_type; (* Print operating system *) |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Pascal | Pascal | program HostIntrospection(output);
begin
writeln('Pointer size: ', SizeOf(Pointer), ' byte, i.e. ', SizeOf(Pointer)*8, ' bit.');
{ NtoBE converts from native endianess to big endianess }
if 23453 = NtoBE(23453) then
writeln('This host is big endian.')
else
writeln('This host is little endian.');
end. |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Lua | Lua | socket = require "socket"
print( socket.dns.gethostname() ) |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #M2000_Interpreter | M2000 Interpreter |
Module Host {
\\ one way
Print computer$
\\ second way
Declare objNetwork "WScript.Network"
With objNetwork, "ComputerName" as cName$
Print cName$, cName$=Computer$
Declare objNetwork Nothing
}
Host
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Maple | Maple | Sockets:-GetHostName() |
http://rosettacode.org/wiki/Identity_matrix | Identity matrix | Task
Build an identity matrix of a size known at run-time.
An identity matrix is a square matrix of size n × n,
where the diagonal elements are all 1s (ones),
and all the other elements are all 0s (zeroes).
I
n
=
[
1
0
0
⋯
0
0
1
0
⋯
0
0
0
1
⋯
0
⋮
⋮
⋮
⋱
... | #PARI.2FGP | PARI/GP | matid(9) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Ruby | Ruby | '1234'.succ #=> '1235'
'99'.succ #=> '100' |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Run_BASIC | Run BASIC | string$ = "12345"
numeric = val(string$)
numeric = numeric + 1
string$ = str$(numeric)
print string$
|
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 |... | #PARI.2FGP | PARI/GP | a=input();
b=input();
if(a<b, print(a" < "b));
if(a==b, print(a" = "b));
if(a>b, print(a" > "b)); |
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... | #Ruby | Ruby |
require 'net/https'
require 'uri'
require 'pp'
uri = URI.parse('https://sourceforge.net')
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start do
content = http.get(uri)
p [content.code, content.message]
pp content.to_hash
puts content.body
en... |
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... | #Rust | Rust |
extern crate reqwest;
fn main() {
let response = match reqwest::blocking::get("https://sourceforge.net") {
Ok(response) => response,
Err(e) => panic!("error encountered while making request: {:?}", e),
};
println!("{}", response.text().unwrap());
}
|
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.
| #C.23 | C# |
using System;
using System.Text;
using System.Net;
class Program
{
static void Main(string[] args)
{
WebClient wc = new WebClient();
string content = wc.DownloadString("http://www.google.com");
Console.WriteLine(content);
}
}
|
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... | #AWK | AWK | #!/usr/bin/awk -f
BEGIN {
NN = 20;
iterativeHCsequence(2^NN+1,Q);
for (K=1; K<NN; K++) {
m = 0;
for (n=2^K+1; n<=2^(K+1); n++) {
v = Q[n]/n;
if (m < v) {nn=n; m = v};
}
printf "Maximum a(n)/n between 2^%i and 2^%i is %f at n=%i\n",K,K+1,m,nn;
}
print "number of Q(n)<Q(n+1) for 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... | #ALGOL-M | ALGOL-M | begin
integer array Q[1:1000];
integer n;
Q[1] := Q[2] := 1;
for n := 3 step 1 until 1000 do
Q[n] := Q[n-Q[n-1]] + Q[n-Q[n-2]];
write("The first 10 terms are:");
write("");
for n := 1 step 1 until 10 do writeon(Q[n]);
write("The 1000th term is:", Q[1000]);
end |
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... | #Ada | Ada | with Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Almost_Integers is
type Real is new Long_Long_Float;
package Real_IO is
new Ada.Text_IO.Float_IO (Real);
package Integer_IO is
new Ada.Text_IO.Integer_IO (Integer);
function Faculty (N : in Long_Long_Integer) ret... |
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... | #AspectJ | AspectJ | public class HistoryVariable
{
private Object value;
public HistoryVariable(Object v)
{
value = v;
}
public void update(Object v)
{
value = v;
}
public Object undo()
{
return value;
}
@Override
public String toString()
{
return ... |
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... | #AutoHotkey | AutoHotkey | HV := new HistoryVariable
HV.var := 1
HV.var := 2
HV.var := "Latest value"
Msgbox % HV.var "`n" HV[2] "`n" HV[3]
class HistoryVariable {
__Set(aName, aValue) {
this.Insert(1,aValue)
Return aValue
}
__Get(aName) {
Return this[1]
}
} |
http://rosettacode.org/wiki/Hofstadter_Figure-Figure_sequences | Hofstadter Figure-Figure sequences | These two sequences of positive integers are defined as:
R
(
1
)
=
1
;
S
(
1
)
=
2
R
(
n
)
=
R
(
n
−
1
)
+
S
(
n
−
1
)
,
n
>
1.
{\displaystyle {\begin{aligned}R(1)&=1\ ;\ S(1)=2\\R(n)&=R(n-1)+S(n-1),\quad n>1.\end{aligned}}}
The sequence
S
(
n
)
{\displaystyle S(n)}
is further... | #Ada | Ada | package Hofstadter_Figure_Figure is
function FFR(P: Positive) return Positive;
function FFS(P: Positive) return Positive;
end Hofstadter_Figure_Figure; |
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... | #APL | APL | :Class HFF
:Field Private Shared RBuf←,1
∇r←ffr n
:Access Public Shared
r←n⊃RBuf←(⊢,⊃∘⌽+≢⊃(⍳1+⌈/)~⊢)⍣(0⌈n-≢RBuf)⊢RBuf
∇
∇s←ffs n;S
:Access Public Shared
:Repeat
S←((⍳1+⌈/)~⊢)RBuf
:If n≤≢S ⋄ :Leave ⋄ :EndIf
S←ffr 1+≢RBuf
:En... |
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... | #Common_Lisp | Common Lisp | (defun horner (coeffs x)
(reduce #'(lambda (coef acc) (+ (* acc x) coef))
coeffs :from-end t :initial-value 0)) |
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... | #D | D | void main() {
void main() {
import std.stdio, std.math;
double x = 3.0;
static real[] pp = [-19,7,-4,6];
poly(x,pp).writeln;
}
} |
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.
| #Action.21 | Action! | DEFINE MAXSIZE="12"
INT ARRAY
dxStack(MAXSIZE),dyStack(MAXSIZE)
BYTE ARRAY
depthStack(MAXSIZE),stageStack(MAXSIZE)
BYTE stacksize=[0]
BYTE FUNC IsEmpty()
IF stacksize=0 THEN RETURN (1) FI
RETURN (0)
BYTE FUNC IsFull()
IF stacksize=MAXSIZE THEN RETURN (1) FI
RETURN (0)
PROC Push(INT dx,dy BYTE depth,stag... |
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.
| #Ada | Ada | with PDF_Out; use PDF_Out;
procedure Hilbert_Curve_PDF is
Length : constant := 500.0;
Corner : constant Point := (50.0, 300.0);
type Rule_Type is (A, B, C, D);
PDF : PDF_Out.Pdf_Out_File;
First : Boolean;
procedure Hilbert (Order : in Natural;
Rule : in Rule_Typ... |
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... | #C | C |
/* Program for gtk3 */
/* discovery: essential to use consistent documentation */
/* compilation on linux: */
/* $ a=./hexagon && make -k "CFLAGS=$( pkg-config --cflags gtk+-3.0 )" "LOADLIBES=$( pkg-config --libs gtk+-3.0 )" $a && $a --gtk-debug=all */
/* search for to do */
/* The keyboard and mouse callbacks inc... |
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
... | #bc | bc | scale = 0
/* Format d days after March 21. Assumes March, April, May or June. */
define format(d) {
if (d > 80) { print " Jun ", d - 71
} else if (d > 71) { print " Jun 0", d - 71
} else if (d > 49) { print " May ", d - 40
} else if (d > 40) { print " May 0", d - 40
} else if (d > 19) { print... |
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... | #DWScript | DWScript | procedure PrintSundial(lat, lng, lme : Float);
begin
PrintLn(Format('latitude: %7.2f', [lat]));
PrintLn(Format('longitude: %7.2f', [lng]));
PrintLn(Format('legal meridian: %7.2f', [lme]));
var slat := Sin(DegToRad(lat));
PrintLn(Format('sine of latitude: %.3f', [slat]));
PrintLn(Form... |
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... | #Haskell | Haskell | import Data.List (group, insertBy, sort, sortBy)
import Control.Arrow ((&&&), second)
import Data.Ord (comparing)
data HTree a
= Leaf a
| Branch (HTree a)
(HTree a)
deriving (Show, Eq, Ord)
test :: String -> IO ()
test =
mapM_ (\(a, b) -> putStrLn ('\'' : a : ("' : " ++ b))) .
serialize . huffm... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Perl | Perl | use Config;
print "UV size: $Config{uvsize}, byte order: $Config{byteorder}\n"; |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Phix | Phix | with javascript_semantics
function endianness()
if platform()=JS then
return "n/a (web browser)"
end if
atom m4 = allocate(4)
poke4(m4,#01020304)
integer b1 = peek1s(m4)
free(m4)
if b1=#01 then
return "big-endian"
elsif b1=#04 then
return "little-endian"
else
... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | $MachineName |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.