task_url stringlengths 30 116 | task_name stringlengths 2 86 | task_description stringlengths 0 14.4k | language_url stringlengths 2 53 | language_name stringlengths 1 52 | code stringlengths 0 61.9k |
|---|---|---|---|---|---|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #MATLAB | MATLAB | [failed,hostname] = system('hostname') |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #mIRC_Scripting_Language | mIRC Scripting Language | echo -ag $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
⋮
⋮
⋮
⋱
... | #Pascal | Pascal | program IdentityMatrix(input, output);
var
matrix: array of array of integer;
n, i, j: integer;
begin
write('Size of matrix: ');
readln(n);
setlength(matrix, n, n);
for i := 0 to n - 1 do
matrix[i,i] := 1;
for i := 0 to n - 1 do
begin
for j := 0 to n - 1 do
write (matrix[i,j], ' ')... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Rust | Rust | fn next_string(input: &str) -> String {
(input.parse::<i64>().unwrap() + 1).to_string()
}
fn main() {
let s = "-1";
let s2 = next_string(s);
println!("{:?}", s2);
} |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Scala | Scala | implicit def toSucc(s: String) = new { def succ = BigDecimal(s) + 1 toString } |
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 |... | #Pascal | Pascal | program compare(input, output);
var
a, b: integer;
begin
write('Input an integer number: ');
readln(a);
write('Input another integer number: ');
readln(b);
if (a < b) then writeln(a, ' is less than ', b);
if (a = b) then writeln(a, ' is equal to ', b);
if (a > b) then writeln(a, ' is greater than ', ... |
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... | #Scala | Scala | import scala.io.Source
object HttpsTest extends App {
System.setProperty("http.agent", "*")
Source.fromURL("https://sourceforge.net").getLines.foreach(println)
} |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "gethttps.s7i";
include "utf8.s7i";
const proc: main is func
begin
writeln(STD_UTF8_OUT, getHttps("sourceforge.net"));
end func; |
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... | #Sidef | Sidef | var lwp = require('LWP::UserAgent'); # LWP::Protocol::https is needed
var url = 'https://rosettacode.org';
var ua = lwp.new(
agent => 'Mozilla/5.0',
ssl_opts => Hash.new(verify_hostname => 1),
);
var resp = ua.get(url);
resp.is_success || die "Failed to GET #{url.dump}: #{resp.status_line}";
print res... |
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.2B.2B | C++ |
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
int main() {
WSADATA wsaData;
WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
addrinfo *result = NULL;
addrinfo hints;
ZeroMemory( &hints, sizeof( hints ) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROT... |
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... | #BASIC | BASIC | arraybase 1
pow2 = 2
p2 = 2 ^ pow2
peak = .5
dim a(2 ^ 20)
a[1] = 1
a[2] = 1
for n = 3 to 2 ^ 20
a[n] = a[a[n-1]] + a[n-a[n-1]]
r = a[n] / n
if r >= .55 then mallows = n
if r > peak then peak = r : peakpos = n
if n = p2 then
print "Maximum between 2 ^ "; rjust((pow2 - 1),2); " and 2 ^ "; r... |
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... | #Bracmat | Bracmat | ( ( a
=
. !arg:(1|2)&1
| (as..find)$!arg:(?.?arg)&!arg
| (as..insert)
$ ( !arg
. a$(a$(!arg+-1))+a$(!arg+-1*a$(!arg+-1)):?arg
)
& !arg
)
& new$hash:?as
& 0:?n:?maxan/n
& 1:?pow
& whl
' ( 1+!n:?n
& !pow:~>20
& ( 2^!pow:~!n
| out... |
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_W | ALGOL W | begin % find elements of the Hofstader Q sequence Q(1) = Q(2) = 1 %
% Q(n) = Q( n - Q( n - 1 ) ) + Q( n - Q( n - 2 ) ) for n > 2 %
integer MAX_Q;
max_Q := 100000;
begin
integer array Q ( 1 :: MAX_Q );
integer array xQ ( 1 :: 10 );
integer ltCount;
... |
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... | #APL | APL | ∇ Q_sequence;seq;size
size←100000
seq←{⍵,+/⍵[(1+⍴⍵)-¯2↑⍵]}⍣(size-2)⊢1 1
⎕←'The first 10 terms are:', seq[⍳10]
⎕←'The 1000th term is:', seq[1000]
⎕←(+/ 2>/seq),'terms were preceded by a larger term.'
∇ |
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... | #ALGOL_68 | ALGOL 68 | # determine whether the first few Hickerson numbers really are "near integers" #
# The Hickerson number n is defined by: h(n) = n! / ( 2 * ( (ln 2)^(n+1) ) ) #
# so: h(1) = 1 / ( 2 * ( ( ln 2 ) ^ 2 ) #
# and: h(n) = ( n / ln 2 ) * h(n-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... | #C.23 | C# | using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace History
{
class Program
{
static void Main(string[] args)
{
var h = new HistoryObject();
h.Value = 5;
h.Value = "foo";
h.Value += "bar";
... |
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... | #AutoHotkey | AutoHotkey | R(n){
if n=1
return 1
return R(n-1) + S(n-1)
}
S(n){
static ObjR:=[]
if n=1
return 2
ObjS:=[]
loop, % n
ObjR[R(A_Index)] := true
loop, % n-1
ObjS[S(A_Index)] := true
Loop
if !(ObjR[A_Index]||ObjS[A_Index])
return A_index
} |
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... | #E | E | def makeHornerPolynomial(coefficients :List) {
def indexing := (0..!coefficients.size()).descending()
return def hornerPolynomial(x) {
var acc := 0
for i in indexing {
acc := acc * x + coefficients[i]
}
return acc
}
} |
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.
| #ALGOL_68 | ALGOL 68 | BEGIN
INT level = 4; # <-- change this #
INT side = 2**level * 2 - 2;
[-side:1, 0:side]STRING grid;
INT x := 0, y := 0, dir := 0;
INT old dir := -1;
INT e=0, n=1, w=2, s=3;
FOR i FROM 1 LWB grid TO 1 UPB grid DO
FOR j FROM 2 LWB grid TO 2 UPB grid DO grid[i,j] := " "
OD OD;
PROC left = ... |
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.23 | C# | using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
////////////////////////////////////////////////////////////////////////////////////////////////////
// namespace... |
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
... | #Befunge | Befunge | 037*>1- : 9`#v_2*4+>1-:3`#v_v
^\+*"(2":< ^\*"d":< >$ v
v"Pentcst"9"Trinity"9"Corpus"+550<
>9"nsnecsA"9"retsaE"9"raeY">:#,_$v
MarAprMayJun
v-/4::/"d"\*/2"&"%/2"&"::,9.:_@#:<
>\:8+55*/-1+3/-35*++65*%00p::"d"v,
v:%7+*84+*2%4/"d"\-g00-%4\*2/4:%<+
>10p","2/*00g56+*+\"&"2/%+19"2"*v5
v \+55\7\4\0+/2","-\+g... |
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... | #EasyLang | EasyLang | func getn s$ . v .
write s$
v = number input
print v
.
call getn "Enter latitude: " lat
call getn "Enter longitude: " lng
call getn "Enter legal meridian: " merid
slat = sin lat
diff = lng - merid
print ""
print " sine of latitude: " & slat
print " diff longitude: " & diff
print ""
print "Hour\tSun hour ang... |
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... | #ERRE | ERRE | PROGRAM SUN_DIAL
FUNCTION RAD(X)
RAD=X*π/180
END FUNCTION
FUNCTION DEG(X)
DEG=X*180/π
END FUNCTION
BEGIN
INPUT("Enter latitude (degrees) : ",latitude)
INPUT("Enter longitude (degrees) : ",longitude)
INPUT("Enter legal meridian (degrees): ",meridian)
PRINT
PRINT("... |
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... | #Icon_and_Unicon | Icon and Unicon | record huffnode(l,r,n,c) # internal and leaf nodes
record huffcode(c,n,b,i) # encoding table char, freq, bitstring, bits (int)
procedure main()
s := "this is an example for huffman encoding"
Count := huffcount(s) # frequency count
Tree := ... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #PicoLisp | PicoLisp | (in (cmd) # Inspect ELF header
(rd 4) # Skip "7F" and 'E', 'L' and 'F'
(prinl
(case (rd 1) # Get EI_CLASS byte
(1 "32 bits")
(2 "64 bits")
(T "Bad EI_CLASS") ) )
(prinl
(case (rd 1) ... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #PL.2FI | PL/I |
details: procedure options (main); /* 6 July 2012 */
declare x float, i fixed binary initial (1);
put skip list ('word size=', length(unspec(x)));
if unspec(i) = '0000000000000001'b then
put skip list ('Big endian');
else
put skip list ('Little endian');
end details;
|
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #PowerShell | PowerShell | Write-Host Word Size: ((Get-WMIObject Win32_Processor).DataWidth)
Write-Host -NoNewLine "Endianness: "
if ([BitConverter]::IsLittleEndian) {
Write-Host Little-Endian
} else {
Write-Host Big-Endian
} |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Modula-3 | Modula-3 | MODULE Hostname EXPORTS Main;
IMPORT IO, OSConfig;
BEGIN
IO.Put(OSConfig.HostName() & "\n");
END Hostname. |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #MUMPS | MUMPS | Write $Piece($System,":") |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols binary
say InetAddress.getLocalHost.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
⋮
⋮
⋮
⋱
... | #Perl | Perl | use strict;
use warnings;
use feature 'say';
sub identity_matrix {
my($n) = shift() - 1;
map { [ (0) x $_, 1, (0) x ($n - $_) ] } 0..$n
}
for (<4 5 6>) {
say "\n$_:";
say join ' ', @$_ for identity_matrix $_;
} |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Scheme | Scheme | (number->string (+ 1 (string->number "1234"))) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Sed | Sed | s/^.*$/&:/
:bubble
s/^:/1/
/.:/ {
h
s/^.*\(.\):.*$/\1/
y/0123456789/123456789:/
s/:/:0/
G
s/\(.*\)\n\(.*\).:\(.*\)$/\2\1\3/
b bubble
} |
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 |... | #Perl | Perl | sub test_num {
my $f = shift;
my $s = shift;
if ($f < $s){
return -1; # returns -1 if $f is less than $s
} elsif ($f > $s) {
return 1; # returns 1 if $f is greater than $s
} elsif ($f == $s) {
# = operator is an assignment
# == operator is a numeric comparison
return 0; # retu... |
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... | #Swift | Swift | import Foundation
// With https
let request = NSURLRequest(URL: NSURL(string: "https://sourceforge.net")!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue()) {res, data, err in // callback
// data is binary
if (data != nil) {
let string = NSString(data: data!, encoding: NS... |
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... | #Tcl | Tcl |
package require http
package require tls
# Tell the http package what to do with “https:” URLs.
#
# First argument is the protocol name, second the default port, and
# third the connection builder command
http::register "https" 443 ::tls::socket
# Make a secure connection, which is almost identical to normal
# co... |
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... | #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
SET DATEN = REQUEST ("https://sourceforge.net")
*{daten}
|
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.
| #Cach.C3.A9_ObjectScript | Caché ObjectScript | USER>Set HttpRequest=##class(%Net.HttpRequest).%New()
USER>Set HttpRequest.Server="checkip.dyndns.org"
USER>Do HttpRequest.Get("/")
USER>Do HttpRequest.HttpResponse.Data.OutputToDevice()
|
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... | #C | C | #include <stdio.h>
#include <stdlib.h>
int a_list[1<<20 + 1];
int doSqnc( int m)
{
int max_df = 0;
int p2_max = 2;
int v, n;
int k1 = 2;
int lg2 = 1;
double amax = 0;
a_list[0] = -50000;
a_list[1] = a_list[2] = 1;
v = a_list[2];
for (n=3; n <= m; n++) {
v = a_list[... |
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... | #ARM_Assembly | ARM Assembly | .text
.global _start
_start: ldr r6,=qs @ R6 = base register for Q array
@@@ Write first 2 elements
mov r0,#1 @ Q(1) and Q(2) are 1
strh r0,[r6,#4]
strh r0,[r6,#8]
@@@ Generate 100 thousand elements
mov r1,#0x86A0
movt r1,#1 @ 0x186A0 = 100.000
mov r0,#3 @ Starting at element 3
1: sub r2,r0,#1 @ r2 ... |
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... | #Arturo | Arturo | q: new [1 1]
n: 2
while [n<1001][
'q ++ (get q n-q\[n-1]) + get q n-q\[n-2]
n: n+1
]
print ["First ten items:" first.n: 10 q]
print ["1000th item:" q\[999]] |
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... | #AWK | AWK |
# syntax: GAWK -M -f HICKERSON_SERIES_OF_ALMOST_INTEGERS.AWK
# using GNU Awk 4.1.0, API: 1.0 (GNU MPFR 3.1.2, GNU MP 5.1.2)
BEGIN {
PREC = 100
for (i=1; i<=17; i++) {
h = sprintf("%25.5f",factorial(i) / (2 * log(2) ^ (i + 1)))
msg = (h ~ /\.[09]/) ? "true" : "false"
printf("%2d %s almost int... |
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... | #Bracmat | Bracmat | ( 0:?n
& 1:?fac
& whl
' ( 1+!n:~>17:?n
& !n*!fac:?fac
& -1:?k
& 0:?L2
& 0:?oldN
& whl
' ( 1+!k:?k
& ((2*!k+1)*9^!k)^-1+!L2:?L2
& !fac*1/2*(2/3*!L2)^(-1*(!n+1)):?N
& div$(1000*!N+1/2.1):?newN
& !newN:~!oldN:?oldN
)
& out
$ ( str$("h(" !n... |
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... | #Clojure | Clojure |
(def a (ref 0))
(def a-history (atom [@a])) ; define a history vector to act as a stack for changes on variable a
(add-watch a :hist (fn [key ref old new] (swap! a-history conj new)))
|
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... | #Common_Lisp | Common Lisp | (defmacro make-hvar (value)
`(list ,value))
(defmacro get-hvar (hvar)
`(car ,hvar))
(defmacro set-hvar (hvar value)
`(push ,value ,hvar))
;; Make sure that setf macro can be used
(defsetf get-hvar set-hvar)
(defmacro undo-hvar (hvar)
`(pop ,hvar))
(let ((v (make-hvar 1)))
(format t "Initial value =... |
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... | #AWK | AWK | # Hofstadter Figure-Figure sequences
#
# R(1) = 1; S(1) = 2;
# R(n) = R(n-1) + S(n-1), n > 1
# S(n) is the values not in R(n)
BEGIN {
# start with the first two values of R and S to simplify finding S[n]:
R[ 1 ] = 1;
R[ 2 ] = 3;
S[ 1 ] = 2;
S[ 2 ] = 4;
# maximum n we currently have ... |
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... | #EchoLisp | EchoLisp |
(define (horner x poly)
(foldr (lambda (coeff acc) (+ coeff (* acc x))) 0 poly))
(horner 3 '(-19 7 -4 6)) → 128
|
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #EDSAC_order_code | EDSAC order code |
[Copyright <2021> <ERIK SARGSYAN>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, s... |
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.
| #AutoHotkey | AutoHotkey | gdip1()
HilbertX := A_ScreenWidth/2 - 100, HilbertY := A_ScreenHeight/2 - 100
Hilbert(HilbertX, HilbertY, 2**5, 5, 5, Arr:=[])
xmin := xmax := ymin := ymax := 0
for i, point in Arr
{
xmin := A_Index = 1 ? point.x : xmin < point.x ? xmin : point.x
xmax := point.x > xmax ? point.x : xmax
ymin := A_Index = 1 ? point.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... | #C.2B.2B | C++ | //
// honeycombwidget.h
//
#ifndef HONEYCOMBWIDGET_H
#define HONEYCOMBWIDGET_H
#include <QWidget>
#include <vector>
class HoneycombWidget : public QWidget {
Q_OBJECT
public:
HoneycombWidget(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event) override;
void mouseReleaseEvent(QM... |
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
... | #C | C | #include <stdio.h>
typedef int year_t, month_t, week_t, day_t;
typedef struct{
year_t year; /* day_t year_day, */
month_t month; day_t month_day;/*
week_t week, */ day_t week_day; } date_t;
const char *mon_fmt[] = {0, "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", ... |
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... | #Euphoria | Euphoria |
include std/console.e
include std/mathcons.e
atom lat = prompt_number("Enter Latitude: ",{})
atom lng = prompt_number("Enter Longitude: ",{})
atom lm = prompt_number("Enter Legal Meridian: ",{})
puts(1,'\n')
atom ha, hla
function D2R(atom degrees)
return degrees * PI / 180
end function
function R2D(atom radi... |
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... | #J | J | hc=: 4 : 0
if. 1=#x do. y
else. ((i{x),+/j{x) hc (i{y),<j{y [ i=. (i.#x) -. j=. 2{./:x end.
)
hcodes=: 4 : 0
assert. x -:&$ y NB. weights and words have same shape
assert. (0<:x) *. 1=#$x NB. weights are non-negative
assert. 1 >: L.y NB. words are boxed not more than once
w=. ,&.> y ... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #PureBasic | PureBasic | Enumeration
#LittleEndian
#BigEndian
EndEnumeration
ProcedureDLL EndianTest()
Protected Endian = #LittleEndian
Protected dummy.l= 'ABCD'
If "A"=Chr(PeekA(@dummy))
Endian=#BigEndian
EndIf
ProcedureReturn Endian
EndProcedure
;- *** Start of test code
If OpenConsole()
PrintN("Your word size is... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Python | Python | >>> import platform, sys, socket
>>> platform.architecture()
('64bit', 'ELF')
>>> platform.machine()
'x86_64'
>>> platform.node()
'yourhostname'
>>> platform.system()
'Linux'
>>> sys.byteorder
little
>>> socket.gethostname()
'yourhostname'
>>> |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #NewLISP | NewLISP | (! "hostname") |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Nim | Nim | import nativesockets
echo getHostName() |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Oberon-2 | Oberon-2 |
MODULE HostName;
IMPORT
OS:ProcessParameters,
Out;
BEGIN
Out.Object("Host: " + ProcessParameters.GetEnv("HOSTNAME"));Out.Ln
END 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
⋮
⋮
⋮
⋱
... | #Phix | Phix | function identity(integer n)
sequence res = repeat(repeat(0,n),n)
for i=1 to n do
res[i][i] = 1
end for
return res
end function
ppOpt({pp_Nest,1})
pp(identity(3))
pp(identity(5))
pp(identity(7))
pp(identity(9))
|
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Seed7 | Seed7 | var string: s is "12345";
s := str(succ(integer parse s)); |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #SenseTalk | SenseTalk |
put "123" + 1 // 124
|
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Phix | Phix | atom a = prompt_number("first number:",{}),
b = prompt_number("second number:",{})
printf(1,"%g is ",a)
if a < b then
puts(1,"less than")
elsif a = b then
puts(1,"equal to")
elsif a > b then
puts(1,"greater than")
end if
printf(1," %g",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... | #UNIX_Shell | UNIX Shell |
curl -k -s -L 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... | #VBScript | VBScript |
Option Explicit
Const sURL="https://sourceforge.net/"
Dim oHTTP
Set oHTTP = CreateObject("Microsoft.XmlHTTP")
On Error Resume Next
oHTTP.Open "GET", sURL, False
oHTTP.Send ""
If Err.Number = 0 Then
WScript.Echo oHTTP.responseText
Else
Wscript.Echo "error " & Err.Number & ": " & Err.Description
End If
... |
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... | #Visual_Basic | Visual Basic | Sub Main()
Dim HttpReq As WinHttp.WinHttpRequest
' in the "references" dialog of the IDE, check
' "Microsoft WinHTTP Services, version 5.1" (winhttp.dll)
Const HTTPREQUEST_PROXYSETTING_PROXY As Long = 2
Const WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 As Long = &H80&
Const WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 As L... |
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.
| #Clojure | Clojure |
(defn get-http [url]
(let [sc (java.util.Scanner.
(.openStream (java.net.URL. url)))]
(while (.hasNext sc)
(println (.nextLine sc)))))
(get-http "http://www.rosettacode.org")
|
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #C.23 | C# |
using System;
using System.Linq;
namespace HofstadterConway
{
class Program
{
static int[] GenHofstadterConway(int max)
{
int[] result = new int[max];
result[0]=result[1]=1;
for (int ix = 2; ix < max; ix++)
result[ix] = result[result[ix - 1... |
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... | #AutoHotkey | AutoHotkey | SetBatchLines, -1
Q := HofsQSeq(100000)
Loop, 10
Out .= Q[A_Index] ", "
MsgBox, % "First ten:`t" Out "`n"
. "1000th:`t`t" Q[1000] "`n"
. "Flips:`t`t" Q.flips
HofsQSeq(n) {
Q := {1: 1, 2: 1, "flips": 0}
Loop, % n - 2 {
i := A_Index + 2
, Q[i] := Q[i - Q[i - 1]] + Q[i - Q[A_Index]]
if (Q[i] < Q[i - 1])
... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #C | C | #include <stdio.h>
#include <mpfr.h>
void h(int n)
{
MPFR_DECL_INIT(a, 200);
MPFR_DECL_INIT(b, 200);
mpfr_fac_ui(a, n, MPFR_RNDD); // a = n!
mpfr_set_ui(b, 2, MPFR_RNDD); // b = 2
mpfr_log(b, b, MPFR_RNDD); // b = log(b)
mpfr_pow_ui(b, b, n + 1, MPFR_RNDD); // b = b^(n+1)
mpfr_div(a, a, b, MPFR_RNDD);... |
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... | #D | D | import std.stdio, std.array, std.string, std.datetime, std.traits;
/// A history variable.
struct HistoryVariable(T) {
/// A value in a point in time.
static struct HistoryValue {
SysTime time;
T value;
// Alternative to the more common toString.
//void toString(scope void de... |
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... | #BBC_BASIC | BBC BASIC | PRINT "First 10 values of R:"
FOR i% = 1 TO 10 : PRINT ;FNffr(i%) " "; : NEXT : PRINT
PRINT "First 10 values of S:"
FOR i% = 1 TO 10 : PRINT ;FNffs(i%) " "; : NEXT : PRINT
PRINT "Checking for first 1000 integers:"
r% = 1 : s% = 1
ffr% = FNffr(r%)
ffs% = FNffs(s%)
FO... |
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 | C | #include <stdio.h>
#include <stdlib.h>
// simple extensible array stuff
typedef unsigned long long xint;
typedef struct {
size_t len, alloc;
xint *buf;
} xarray;
xarray rs, ss;
void setsize(xarray *a, size_t size)
{
size_t n = a->alloc;
if (!n) n = 1;
while (n < size) n <<= 1;
if (a->alloc < n) {
a->b... |
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... | #Elena | Elena | import extensions;
import system'routines;
horner(coefficients,variable)
{
^ coefficients.clone().sequenceReverse().accumulate(new Real(),(accumulator,coefficient => accumulator * variable + coefficient))
}
public program()
{
console.printLine(horner(new real[]{-19.0r, 7.0r, -4.0r, 6.0r}, 3.0r))
} |
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... | #Elixir | Elixir | horner = fn(list, x)-> List.foldr(list, 0, fn(c,acc)-> x*acc+c end) end
IO.puts 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 | C | #include <stdio.h>
#define N 32
#define K 3
#define MAX N * K
typedef struct { int x; int y; } point;
void rot(int n, point *p, int rx, int ry) {
int t;
if (!ry) {
if (rx == 1) {
p->x = n - 1 - p->x;
p->y = n - 1 - p->y;
}
t = p->x;
p->x = p->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... | #Go | Go | package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
"math"
"strings"
)
type hexagon struct {
x, y float32
letter rune
selected bool
}
func (h hexagon) points(r float32) []rl.Vector2 {
res := make([]rl.Vector2, 7)
for i := 0; i < 7; i++ {
fi := float64(i)
... |
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
... | #C.23 | C# | using System;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
internal class Program
{
private static readonly OrderedDictionary _holidayOffsets = new OrderedDictionary
{
... |
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... | #F.23 | F# | // Learn more about F# at http://fsharp.net
open System
//(degree measure)*Degrees => Radian measure
//(radian measure)/Degrees => Degree measure
let Degrees = Math.PI / 180.0
Console.Write("Enter latitude: ")
let latitude = Console.ReadLine() |> Double.Parse
Console.Write("Enter longitude: ")
let longitude = C... |
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... | #Java | Java | import java.util.*;
abstract class HuffmanTree implements Comparable<HuffmanTree> {
public final int frequency; // the frequency of this tree
public HuffmanTree(int freq) { frequency = freq; }
// compares on the frequency
public int compareTo(HuffmanTree tree) {
return frequency - tree.frequ... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #R | R | 8 * .Machine$sizeof.long # e.g. 32 |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Racket | Racket |
#lang racket/base
(printf "Word size: ~a\n" (system-type 'word))
(printf "Endianness: ~a\n" (if (system-big-endian?) 'big 'little))
|
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Raku | Raku | use NativeCall;
say $*VM.config<ptr_size>;
my $bytes = nativecast(CArray[uint8], CArray[uint16].new(1));
say $bytes[0] ?? "little-endian" !! "big-endian"; |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Objeck | Objeck |
use Net;
bundle Default {
class Hello {
function : Main(args : String[]) ~ Nil {
TCPSocket->HostName()->PrintLine();
}
}
}
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Objective-C | Objective-C |
NSLog(@"%@", [[NSProcessInfo processInfo] hostName]);
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #OCaml | OCaml | Unix.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
⋮
⋮
⋮
⋱
... | #PHP | PHP |
function identity($length) {
return array_map(function($key, $value) {$value[$key] = 1; return $value;}, range(0, $length-1),
array_fill(0, $length, array_fill(0,$length, 0)));
}
function print_identity($identity) {
echo implode(PHP_EOL, array_map(function ($value) {return implode(' ', $value);}, $identity));
}
pr... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #SequenceL | SequenceL | import <Utilities/Conversion.sl>;
increment(input(1)) := intToString(stringToInt(input) + 1); |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Sidef | Sidef | say '1234'.inc; #=> '1235'
say '99'.inc; #=> '100' |
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 |... | #PHL | PHL | module intergertest;
extern printf;
extern scanf;
@Integer main [
var a = 0;
var b = 0;
scanf("%i %i", ref (a), ref (b));
if (a < b)
printf("%i is less than %i\n", a::get, b::get);
if (a == b)
printf("%i is equal to %i\n", a::get, b::get);
if (a > b)
printf("%i is greater than %i\n", a::get, b::ge... |
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 |... | #PHP | PHP | <?php
echo "Enter an integer [int1]: ";
fscanf(STDIN, "%d\n", $int1);
if(!is_numeric($int1)) {
echo "Invalid input; terminating.\n";
exit(1); // return w/ general error
}
echo "Enter an integer [int2]: ";
fscanf(STDIN, "%d\n", $int2);
if(!is_numeric($int2)) {
echo "Invalid input; terminating.\n";
exit(... |
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... | #Visual_Basic_.NET | Visual Basic .NET |
Imports System.Net
Dim client As WebClient = New WebClient()
Dim content As String = client.DownloadString("https://sourceforge.net")
Console.WriteLine(content)
|
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... | #Wren | Wren | /* https.wren */
var CURLOPT_URL = 10002
var CURLOPT_FOLLOWLOCATION = 52
var CURLOPT_ERRORBUFFER = 10010
foreign class Curl {
construct easyInit() {}
foreign easySetOpt(opt, param)
foreign easyPerform()
foreign easyCleanup()
}
var curl = Curl.easyInit()
if (curl == 0) {
System.print("Err... |
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.
| #COBOL | COBOL | COBOL >>SOURCE FORMAT IS FIXED
identification division.
program-id. curl-rosetta.
environment division.
configuration section.
repository.
function read-url
function all intrinsic.
data division.
working-storage section.
copy "gccurlsy... |
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... | #C.2B.2B | C++ |
#include <deque>
#include <iostream>
int hcseq(int n)
{
static std::deque<int> seq(2, 1);
while (seq.size() < n)
{
int x = seq.back();
seq.push_back(seq[x-1] + seq[seq.size()-x]);
}
return seq[n-1];
}
int main()
{
int pow2 = 1;
for (int i = 0; i < 20; ++i)
{
int pow2next = 2*pow2;
... |
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... | #AWK | AWK | #!/usr/bin/awk -f
BEGIN {
N = 100000
print "Q-sequence(1..10) : " Qsequence(10)
Qsequence(N,Q)
print "1000th number of Q sequence : " Q[1000]
for (n=2; n<=N; n++) {
if (Q[n]<Q[n-1]) NN++
}
print "number of Q(n)<Q(n+1) for n<=100000 : " NN
}
function Qsequence(N,Q) {
Q[1] = 1
Q[2] = 1
seq = "1 ... |
http://rosettacode.org/wiki/Hickerson_series_of_almost_integers | Hickerson series of almost integers | The following function, due to D. Hickerson, is said to generate "Almost integers" by the
"Almost Integer" page of Wolfram MathWorld, (December 31 2013). (See formula numbered 51.)
The function is:
h
(
n
)
=
n
!
2
(
ln
2
)
n
+
1
{\displaystyle h(n)={\operatorname {n} ! \ove... | #C.2B.2B | C++ | #include <iostream>
#include <iomanip>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/math/constants/constants.hpp>
typedef boost::multiprecision::cpp_dec_float_50 decfloat;
int main()
{
const decfloat ln_two = boost::math::constants::ln_two<decfloat>();
decfloat numerator = 1, denominator ... |
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
| #11l | 11l | F first(function)
R function()
F second()
R ‘second’
V result = first(second)
print(result) |
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... | #Delphi | Delphi |
program History_variables;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
THistoryVarType = record
value: variant;
timestamp: TDateTime;
function ToString: string;
end;
THistoryVar = record
Fvalue: variant;
FHistory: TArray<THistoryVarType>;
private
procedure SetValue(const Va... |
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.23 | C# | using System;
using System.Collections.Generic;
using System.Linq;
namespace HofstadterFigureFigure
{
class HofstadterFigureFigure
{
readonly List<int> _r = new List<int>() {1};
readonly List<int> _s = new List<int>();
public IEnumerable<int> R()
{
int iR = 0;
while (true)
{
if (iR >= _r.Coun... |
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... | #Emacs_Lisp | Emacs Lisp | (require 'cl-lib)
(defun horner (coeffs x)
(cl-reduce #'(lambda (coef acc) (+ (* acc x) coef))
coeffs :from-end t :initial-value 0))
(horner '(-19 7 -4 6) 3) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.