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/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... | #Common_Lisp | Common Lisp | ;;; equally doable with a list
(flet ((seq (i) (make-array 1 :element-type 'integer
:initial-element i
:fill-pointer 1
:adjustable t)))
(let ((rr (seq 1)) (ss (seq 2)))
(labels ((extend-r ()
(let* ((l (1- (length rr)))
(r (+ (aref rr l) (aref ss l)))
(s (elt s... |
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... | #Forth | Forth | : fhorner ( coeffs len F: x -- F: val )
0e
floats bounds ?do
fover f* i f@ f+
1 floats +loop
fswap fdrop ;
create coeffs 6e f, -4e f, 7e f, -19e f,
coeffs 4 3e fhorner f. \ 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... | #Fortran | Fortran | program test_horner
implicit none
write (*, '(f5.1)') horner ([-19.0, 7.0, -4.0, 6.0], 3.0)
contains
function horner (coeffs, x) result (res)
implicit none
real, dimension (0:), intent (in) :: coeffs
real, intent (in) :: x
real :: res
integer :: i
res = coeffs(ubound(coeffs,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.
| #Factor | Factor | USING: accessors L-system ui ;
: hilbert ( L-system -- L-system )
L-parser-dialect >>commands
[ 90 >>angle ] >>turtle-values
"A" >>axiom
{
{ "A" "-BF+AFA+FB-" }
{ "B" "+AF-BFB-FA+" }
} >>rules ;
[ <L-system> hilbert "Hilbert curve" open-window ] with-ui |
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.
| #Forth | Forth | include lib/graphics.4th
64 constant /width \ hilbert curve order^2
9 constant /length \ length of a line
variable origin \ point of origin
aka r@ lg \ get parameters from return stack
aka r'@ i1 ... |
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... | #Java | Java | import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Honeycombs extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame f = new Honeycombs();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setV... |
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
... | #Delphi | Delphi |
program Holidays_related_to_Easter;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
THollyday = record
name: string;
offs: Integer;
end;
const
Holyday: array[0..4] of THollyday = ((
name: 'Easter';
offs: 0
), (
name: 'Ascension';
offs: 39
), (
name: 'Pentecost';
offs:... |
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... | #FutureBasic | FutureBasic | window 1
def fn rad2deg( theta as double ) as double = theta * 180 / pi
def fn deg2rad( theta as double ) as double = theta * pi / 180
local fn SolarHourAngle( latitude as double, longitude as double, meridian as double )
long hour
double hra, hla, t
CFStringRef ap
print "Latitude = "; latitu... |
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... | #Go | Go | package main
import (
"fmt"
"math"
"os"
)
func getnum(prompt string) (r float64) {
fmt.Print(prompt)
if _, err := fmt.Scan(&r); err != nil {
fmt.Println(err)
os.Exit(-1)
}
return
}
func main() {
lat := getnum("Enter latitude => ")
lng := getnum("Enter long... |
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... | #Lua | Lua | local build_freqtable = function (data)
local freq = { }
for i = 1, #data do
local cur = string.sub (data, i, i)
local count = freq [cur] or 0
freq [cur] = count + 1
end
local nodes = { }
for w, f in next, freq do
nodes [#nodes + 1] = { word = w, freq = f }
end
table.sort (nodes, fun... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #TI-89_BASIC | TI-89 BASIC | Disp "32-bit big-endian" |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #TXR | TXR | This is the TXR Lisp interactive listener of TXR 177.
Use the :quit command or type Ctrl-D on empty line to exit.
1> (sizeof (ptr char))
8
2> (sizeof int)
4 |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Wren | Wren | /* host_introspection.wren */
class C {
foreign static wordSize
foreign static endianness
}
System.print("word size = %(C.wordSize) bits")
System.print("endianness = %(C.endianness)") |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PicoLisp | PicoLisp | (call 'hostname) |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Pike | Pike | import System;
int main(){
write(gethostname() + "\n");
} |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PL.2FSQL | PL/SQL | SET serveroutput ON
BEGIN
DBMS_OUTPUT.PUT_LINE(UTL_INADDR.GET_HOST_NAME);
END; |
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
⋮
⋮
⋮
⋱
... | #Prolog | Prolog | %rotates one list clockwise by one integer
rotate(Int,List,Rotated) :-
integer(Int),
length(Suff,Int),
append(Pre,Suff,List),
append(Suff,Pre,Rotated).
%rotates a list of lists by a list of integers
rotate(LoInts,LoLists,Rotated) :-
is_list(LoInts),
maplist(rotate,LoInts,LoLists,Rotated).
%helper function
appen... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Tcl | Tcl | set str 1234
incr str |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #TI-83_BASIC | TI-83 BASIC | :"1"→Str1
:expr(Str1)+1→A
:{0,1}→L₁
:{0,A}→L₂
:LinReg(ax+b) Y₁
:Equ►String(Y₁,Str1)
:sub(Str1,1,length(Str1)-3)→Str1 |
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 |... | #PowerShell | PowerShell | $a = [int] (Read-Host a)
$b = [int] (Read-Host b)
if ($a -lt $b) {
Write-Host $a is less than $b`.
} elseif ($a -eq $b) {
Write-Host $a is equal to $b`.
} elseif ($a -gt $b) {
Write-Host $a is greater than $b`.
} |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PureBasic | PureBasic | If OpenConsole()
Print("Enter an integer: ")
x.i = Val(Input())
Print("Enter another integer: ")
y.i = Val(Input())
If x < y
Print( "The first integer is less than the second integer.")
ElseIf x = y
Print("The first integer is equal to the second integer.")
ElseIf x > y
Print("The first ... |
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.
| #Delphi | Delphi |
program HTTP;
{$APPTYPE CONSOLE}
{$DEFINE DEBUG}
uses
Classes,
httpsend; // Synapse httpsend class
var
Response: TStrings;
HTTPObj: THTTPSend;
begin
HTTPObj := THTTPSend.Create;
try
{ Stringlist object to capture HTML returned
from URL }
Response := TStringList.Create;
try
... |
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... | #EchoLisp | EchoLisp |
(decimals 4)
(cache-size 2000000)
(define (a n)
(+ (a (a (1- n))) (a (- n (a (1- n))))))
(remember 'a #(0 1 1)) ;; memoize
;; prints max a(n)/n in [2**i 2**i+1] intervals
;; return Mallows number checked up to 2**20
(define (task (maxv) (start 1) (end 2) (v) (mrange 0))
(for ((i (in-range 1 21)))
(set! max... |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #Agena | Agena | io.write( io.stderr, "Goodbye, World!\n" ) |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #Aime | Aime | v_text("Goodbye, World!\n"); |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #ALGOL_68 | ALGOL 68 | main:(
put(stand error, ("Goodbye, World!", new line))
) |
http://rosettacode.org/wiki/Hofstadter_Q_sequence | Hofstadter Q sequence | Hofstadter Q sequence
Q
(
1
)
=
Q
(
2
)
=
1
,
Q
(
n
)
=
Q
(
n
−
Q
(
n
−
1
)
)
+
Q
(
n
−
Q
(
n
−
2
)
)
,
n
>
2.
{\displaystyle {\begin{aligned}Q(1)&=Q(2)=1,\\Q(n)&=Q{\big (}n-Q(n-1){\big )}+Q{\big (}n-Q(n-2){\big )},\quad n>2.\end{aligned}}}
It is defined like the Fibonacc... | #C.23 | C# | using System;
using System.Collections.Generic;
namespace HofstadterQSequence
{
class Program
{
// Initialize the dictionary with the first two indices filled.
private static readonly Dictionary<int, int> QList = new Dictionary<int, 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... | #Forth | Forth | [UNDEFINED] ANS [IF]
include lib/fp1.4th \ Zen float version
include lib/zenfprox.4th \ for F~
include lib/zenround.4th \ for FROUND
include lib/zenfln.4th \ for FLN
include lib/zenfpow.4th \ for FPOW
[ELSE]
include lib/fp3.4th ... |
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... | #Fortran | Fortran | program hickerson
implicit none
integer, parameter :: q = selected_real_kind(30)
integer, parameter :: l = selected_int_kind(15)
real(q) :: s, l2
integer :: i, n, k
l2 = log(2.0_q)
do n = 1, 17
s = 0.5_q / l2
do i = 1, n
s = (s * i) / l2
end do
... |
http://rosettacode.org/wiki/Heronian_triangles | Heronian triangles | Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by:
A
=
s
(
s
−
a
)
(
s
−
b
)
(
s
−
c
)
,
{\displaystyle A={\sqrt {s(s-a)(s-b)(s-c)}},}
where s is half the perimeter of the triangle; that is,
s
=
a
+
b
+
c
2
.
{\displaystyle s... | #Ada | Ada | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
-- ----- Some math...
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
... |
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
| #ActionScript | ActionScript | package {
public class MyClass {
public function first(func:Function):String {
return func.call();
}
public function second():String {
return "second";
}
public static function main():void {
var result:String = first(second);
... |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #AutoIt | AutoIt |
TCPStartup()
$socket = TCPListen("0.0.0.0",8080)
$string = "Goodbye, World!"
While 1
Do
$newConnection = TCPAccept($socket)
Sleep(1)
Until $newConnection <> -1
$content = TCPRecv($newConnection, 2048)
If StringLen($content) > 0 Then
TCPSend($newConnection, Binary("HTTP/1.1 200 OK" & @CRLF))
TC... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Arturo | Arturo | print {:
The “Red Death” had long devastated the country.
No pestilence had ever been so fatal, or so hideous.
Blood was its Avator and its seal—
the redness and the horror of blood.
There were sharp pains,
and sudden dizziness,
and then profuse bleeding at the pores... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #AutoHotkey | AutoHotkey | MyVar = "This is the text inside MyVar"
MyVariable =
(
Note that whitespace is preserved
As well as newlines.
The LTrim option can be present to remove left whitespace.
Variable references such as %MyVar% are expanded.
)
MsgBox % MyVariable |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #AWK | AWK | •Out "dsdfsdfsad
""fsadf""sdf" |
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... | #Haskell | Haskell | import Data.IORef
newtype HVar a = HVar (IORef [a])
newHVar :: a -> IO (HVar a)
newHVar value = fmap HVar (newIORef [value])
readHVar :: HVar a -> IO a
readHVar (HVar ref) = fmap head (readIORef ref)
writeHVar :: a -> HVar a -> IO ()
writeHVar value (HVar ref) = modifyIORef ref (value:)
undoHVar :: HVar a -> ... |
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... | #J | J | varref_hist_=:'VAR','_hist_',~]
set_hist_=:4 :0
V=.varref x
if.0>nc<V do.(<V)=:''end.
(<V)=.V~,<y
y
)
getall_hist_=:3 :0
(varref y)~
)
length_hist_=: #@getall
get_hist_=: _1 {:: getall |
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... | #Cowgol | Cowgol | include "cowgol.coh";
include "strings.coh";
include "malloc.coh";
# An uint16 is big enough to deal with the figures from the task,
# but it is good practice to allow it to be easily redefined.
typedef N is uint16;
# There is no extensible vector type included in the standard library,
# so it is necessary to defin... |
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... | #D | D | int delegate(in int) nothrow ffr, ffs;
nothrow static this() {
auto r = [0, 1], s = [0, 2];
ffr = (in int n) nothrow {
while (r.length <= n) {
immutable int nrk = r.length - 1;
immutable int rNext = r[nrk] + s[nrk];
r ~= rNext;
foreach (immutable sn; r... |
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... | #FreeBASIC | FreeBASIC |
Function AlgoritmoHorner(coeffs() As Integer, x As Integer) As Integer
Dim As Integer i, acumulador = 0
For i = Ubound(coeffs, 1) To 0 Step -1
acumulador = (acumulador * x) + coeffs(i)
Next i
Return acumulador
End Function
Dim As Integer x = 3
Dim As Integer coeficientes(3) = {-19, 7, -4, 6... |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #FunL | FunL | import lists.foldr
def horner( poly, x ) = foldr( \a, b -> a + b*x, 0, poly )
println( 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.
| #FreeBASIC | FreeBASIC |
Dim Shared As Integer ancho = 64
Sub Hilbert(x As Integer, y As Integer, lg As Integer, i1 As Integer, i2 As Integer)
If lg = 1 Then
Line - ((ancho-x) * 10, (ancho-y) * 10)
Return
End If
lg = lg / 2
Hilbert(x+i1*lg, y+i1*lg, lg, i1, 1-i2)
Hilbert(x+i2*lg, y+(1-i2)*lg, lg, i1, i2)... |
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... | #Julia | Julia | using Gtk.ShortNames, GtkReactive, Graphics, Cairo, Colors, Random
mutable struct Hexagon
center::Point
radius::Int
letter::String
color::Colorant
end
const offset = 50
const hgt = 450
const wid = 400
const hcombdim = (rows = 5, cols = 4)
const randletters = reshape(string.(Char.(shuffle(UInt8('A'):... |
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... | #Kotlin | Kotlin | // version 1.1.4
import java.awt.BasicStroke
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Dimension
import java.awt.Font
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.Polygon
import java.awt.RenderingHints
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
impo... |
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
... | #Elixir | Elixir | defmodule Holiday do
@offsets [ Easter: 0, Ascension: 39, Pentecost: 49, Trinity: 56, Corpus: 60 ]
@mon { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
def easter_date(year) do
a = rem(year, 19)
b = div(year, 100)
c = rem(year, 100)
d = div(b, 4)
e = ... |
http://rosettacode.org/wiki/Horizontal_sundial_calculations | Horizontal sundial calculations | Task
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), wit... | #GW-BASIC | GW-BASIC |
10 ' Horizontal sundial calculations
20 PRINT "Enter latitude => ";
30 INPUT LAT
40 PRINT "Enter longitude => ";
50 INPUT LNG
60 PRINT "Enter legal meridian => ";
70 INPUT REF
80 PRINT
90 LET PI = 4 * ATN(1)
100 LET SLAT = SIN(LAT * PI / 180)
110 PRINT " sine of latitude: "; USING "#.##^^^^"; ... |
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... | #M2000_Interpreter | M2000 Interpreter |
Module Huffman {
comp=lambda (a, b) ->{
=array(a, 0)<array(b, 0)
}
module InsertPQ (a, n, &comp) {
if len(a)=0 then stack a {data n} : exit
if comp(n, stackitem(a)) then stack a {push n} : exit
stack a {
push n
t=2:... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic 'code' declarations
int A, B;
char C;
[IntOut(0, @B-@A); CrLf(0); \word size = integer size
A:= $1234;
C:= @A;
Text(0, if C(0)=$34 then "Little" else "Big");
Text(0, " endian
");
] |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Z80_Assembly | Z80 Assembly | EndianTest:
ld hl,&8000
ld (&C000),hl ;store &8000 into memory.
ld a,(&C000) ;loads the byte at &C000 into A. If the Z80 were big-endian, A would equal &80. But it equals zero.
or a ;still, we need to pretend we don't already know the result and compare A to zero.
jr z,LittleEndian ;handle the cas... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Pop11 | Pop11 | lvars host = sys_host_name(); |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PowerBASIC | PowerBASIC | HOST NAME TO hostname$ |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PowerShell | PowerShell | $Env:COMPUTERNAME |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #PureBasic | PureBasic | InitNetwork()
answer$=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
⋮
⋮
⋮
⋱
... | #PureBasic | PureBasic | >Procedure identityMatrix(Array i(2), size) ;valid only for size >= 0
;formats array i() as an identity matrix of size x size
Dim i(size - 1, size - 1)
Protected j
For j = 0 To size - 1
i(j, j) = 1
Next
EndProcedure
Procedure displayMatrix(Array a(2))
Protected rows = ArraySize(a(), 2), columns =... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #TI-89_BASIC | TI-89 BASIC | string(expr(str)+1) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Toka | Toka | " 100" >number drop 1 + >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 |... | #Python | Python | #!/usr/bin/env python
a = input('Enter value of a: ')
b = input('Enter value of b: ')
if a < b:
print 'a is less than b'
elif a > b:
print 'a is greater than b'
elif a == b:
print 'a is equal to b' |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Quackery | Quackery | $ "Please enter two numbers separated by a space; "
input quackery cr
say "The first number is "
[ 2dup > iff [ say "larger than" ] done
2dup = iff [ say "equal to" ] done
2dup < if [ say "smaller than" ] ]
2drop
say " the second number." cr |
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.
| #Dragon | Dragon | select "http"
select "std"
http("http://www.rosettacode.org", ::echo)
|
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.
| #E | E |
when (def t := <http://www.rosettacode.org> <- getText()) -> {
println(t)
}
|
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... | #Eiffel | Eiffel |
class
APPLICATION
create
make
feature
make
--Tests the feature sequence.
local
j, n, exp: INTEGER
max: REAL_64
do
exp := 15
n := (2 ^ exp).floor
sequence (n)
across
1 |..| (exp - 1) as c
loop
max := 0
from
j := (2 ^ c.item).floor
until
j > 2 ^ (c.item + 1... |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #Argile | Argile | use std
eprint "Goodbye, World!" |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program hellowordLP.s */
.data
szMessage: .asciz "Goodbye world. \n " @ error message
.equ LGMESSAGE, . - szMessage @ compute length of message
.text
.global main
main:
mov r0, #2 @ output error linux
ldr r1, iAdrMessage @ adresse of ... |
http://rosettacode.org/wiki/Hofstadter_Q_sequence | Hofstadter Q sequence | Hofstadter Q sequence
Q
(
1
)
=
Q
(
2
)
=
1
,
Q
(
n
)
=
Q
(
n
−
Q
(
n
−
1
)
)
+
Q
(
n
−
Q
(
n
−
2
)
)
,
n
>
2.
{\displaystyle {\begin{aligned}Q(1)&=Q(2)=1,\\Q(n)&=Q{\big (}n-Q(n-1){\big )}+Q{\big (}n-Q(n-2){\big )},\quad n>2.\end{aligned}}}
It is defined like the Fibonacc... | #C.2B.2B | C++ | #include <iostream>
int main() {
const int size = 100000;
int hofstadters[size] = { 1, 1 };
for (int i = 3 ; i < size; i++)
hofstadters[ i - 1 ] = hofstadters[ i - 1 - hofstadters[ i - 1 - 1 ]] +
hofstadters[ i - 1 - hofstadters[ i - 2 - 1 ]];
std::cout << "The first ... |
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... | #FreeBASIC | FreeBASIC | ' version 08-10-2016
' compile with: fbc -s gui
#Include Once "gmp.bi"
#Macro init_float_size (big_float ,size)
Dim As Mpf_ptr big_float = Allocate( Len( __mpf_struct))
Mpf_init2( big_float,size)
#EndMacro
#Macro mpf_remove(big_float)
Mpf_clear(big_float)
DeAllocate (big_float)
#EndMacro
Screen 20
ini... |
http://rosettacode.org/wiki/Heronian_triangles | Heronian triangles | Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by:
A
=
s
(
s
−
a
)
(
s
−
b
)
(
s
−
c
)
,
{\displaystyle A={\sqrt {s(s-a)(s-b)(s-c)}},}
where s is half the perimeter of the triangle; that is,
s
=
a
+
b
+
c
2
.
{\displaystyle s... | #ALGOL_68 | ALGOL 68 | # mode to hold details of a Heronian triangle #
MODE HERONIAN = STRUCT( INT a, b, c, area, perimeter );
# returns the details of the Heronian Triangle with sides a, b, c or nil if it isn't one #
PROC try ht = ( INT a, b, c )REF HERONIAN:
BEGIN
REF HERONIAN t := NIL;
REAL s = ( a + b +... |
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
| #Ada | Ada | with Ada.Text_Io; use Ada.Text_Io;
procedure Subprogram_As_Argument is
type Proc_Access is access procedure;
procedure Second is
begin
Put_Line("Second Procedure");
end Second;
procedure First(Proc : Proc_Access) is
begin
Proc.all;
end First;
begin
First(Second'Access);
end Sub... |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #AWK | AWK | #!/usr/bin/gawk -f
BEGIN {
RS = ORS = "\r\n"
HttpService = "/inet/tcp/8080/0/0"
Hello = "<HTML><HEAD>" \
"<TITLE>A Famous Greeting</TITLE></HEAD>" \
"<BODY><H1>Hello, world</H1></BODY></HTML>"
Len = length(Hello) + length(ORS)
print "HTTP/1.0 200 OK"... |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #BaCon | BaCon | ' Define HTTP constants
CONST New$ = CHR$(13) & NL$
CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$
CONST Msg$ = "<html><head>BaCon web greeting</head><body><h2>Goodbye, World!</h2></body></html>"
' Get our IP
Ip$ = "localhost"
PRINT "Connect from browser '", Ip$, ":8080'."
' Ignore child signals to avoid zombie proce... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #BQN | BQN | •Out "dsdfsdfsad
""fsadf""sdf" |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #Bracmat | Bracmat | ( {Multiline string:}
"
Second line
Third line
\"quoted\"
A backslash: \\
":?stringA
& out$("Multiline string:")
& out$(!stringA)
) |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #BaCon | BaCon |
'--- we dont have a print here doc built-in command in BaCon
'--- we can get the end result like this with the newline NL$
PRINT "To use Bacon your system must have either Korn Shell, or ZShell, or Bourne Again Shell (BASH) available." NL$ \
"If none of these shells are available on your platform, download and i... |
http://rosettacode.org/wiki/Here_document | Here document | A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text.
Depending on the language being used, a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string.
The text ... | #BASIC | BASIC |
text1$ = " " + CHR$(10) + "<<'FOO' " + CHR$(10) + " 'jaja', `esto`" + CHR$(10) + " <simula>" + CHR$(10) + " \un\" + CHR$(10) + " ${ejemplo} de 'heredoc'" + CHR$(10) + " en QBASIC."
text2$ = "Esta es la primera línea." + CHR$(10) + "Esta es la segunda línea." + CHR$(10) + "Esta 'línea' contiene comillas."
PRI... |
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... | #Java | Java | import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* A class for an "Integer with a history".
* <p>
* Note that it is not possible to create an empty Variable (so there is no "null") with this type. This is a design
* choice, because if "empty" variables were allowed, reading 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... | #Julia | Julia | mutable struct Historied
num::Number
history::Vector{Number}
Historied(n) = new(n, Vector{Number}())
end
assign(y::Historied, z) = (push!(y.history, y.num); y.num = z; y)
x = Historied(1)
assign(x, 3)
assign(x, 5)
assign(x, 4)
println("Past history of variable x: $(x.history). Current value is $(x.n... |
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... | #EchoLisp | EchoLisp | (define (FFR n)
(+ (FFR (1- n)) (FFS (1- n))))
(define (FFS n)
(define next (1+ (FFS (1- n))))
(for ((k (in-naturals next)))
#:break (not (vector-search* k (cache 'FFR))) => k
))
(remember 'FFR #(0 1)) ;; init cache
(remember 'FFS #(0 2))
|
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... | #Euler_Math_Toolbox | Euler Math Toolbox |
>function RSstep (r,s) ...
$ n=cols(r);
$ r=r|(r[n]+s[n]);
$ s=s|(max(s[n]+1,r[n]+1):r[n+1]-1);
$ return {r,s};
$ endfunction
>function RS (n) ...
$ if n==1 then return {[1],[2]}; endif;
$ if n==2 then return {[1,3],[2]}; endif;
$ r=[1,3]; s=[2,4];
$ loop 3 to n; {r,s}=RSstep(r,s); end;
$ return {r,s};
$ e... |
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... | #FutureBasic | FutureBasic | include "NSLog.incl"
local fn horner( coeffs as CFArrayRef, x as NSInteger ) as double
CFArrayRef reversedCoeffs
CFNumberRef num
double accumulator = 0.0
// Reverse coeffs array
reversedCoeffs = fn EnumeratorAllObjects( fn ArrayReverseObjectEnumerator( coeffs ) )
// Iterate over CFNumberRefs in reversed arr... |
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... | #GAP | GAP | # The idiomatic way to compute with polynomials
x := Indeterminate(Rationals, "x");
# This is a value in a polynomial ring, not a function
p := 6*x^3 - 4*x^2 + 7*x - 19;
Value(p, 3);
# 128
u := CoefficientsOfUnivariatePolynomial(p);
# [ -19, 7, -4, 6 ]
# One may also create the polynomial from coefficients
q ... |
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.
| #F.C5.8Drmul.C3.A6 | Fōrmulæ | // General description:
// This code creates Lindenmayer rules via string manipulation
// It can generate many of the examples from the Wikipedia page
// discussing L-system fractals: http://en.wikipedia.org/wiki/L-system
//
// It does not support stochastic, context sensitive or parametric grammars
//
// It supports f... |
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.
| #Frink | Frink | // General description:
// This code creates Lindenmayer rules via string manipulation
// It can generate many of the examples from the Wikipedia page
// discussing L-system fractals: http://en.wikipedia.org/wiki/L-system
//
// It does not support stochastic, context sensitive or parametric grammars
//
// It supports f... |
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... | #Liberty_BASIC | Liberty BASIC |
NoMainWin
Dim hxc(20,2), ltr(26)
Global sw, sh, radius, radChk, mx, my, h$, last
h$="#g": radius = 40: radChk = 35 * 35: last = 0
sw = 400: sh = 380: WindowWidth = sw+6: WindowHeight= sh+32
Open "Liberty BASIC - Honeycombs" For graphics_nsb_nf As #g
#g "Down; Cls; TrapClose xit"
Call shuffle
Call grid 75, 15, "0 0 ... |
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
... | #Erlang | Erlang | -module(holidays).
-export([task/0]).
offsets(easter) -> 0;
offsets(ascension) -> 39;
offsets(pentecost) -> 49;
offsets(trinity) -> 56;
offsets(corpus) -> 60.
month(Month) ->
element(Month, { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } ).
easter_date(Year) ->
... |
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... | #Haskell | Haskell | roundDec :: Int -> Double -> Double
roundDec d = (/ 10.0 ^ d) . fromIntegral . round . (* 10.0 ^ d)
radToDegr = ((180 / pi) *)
degrToRad = ((pi / 180) *)
main = do
let lat = -4.95
long = -150.5
legalMerid = -150
sinOfLat = sin $ degrToRad lat
diff = legalMerid - long
(putStrLn . unline... |
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... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | huffman[s_String] := huffman[Characters[s]];
huffman[l_List] := Module[{merge, structure, rules},
(*merge front two branches. list is assumed to be sorted*)
merge[k_] := Replace[k, {{a_, aC_}, {b_, bC_}, rest___} :> {{{a, b}, aC + bC}, rest}];
structure = FixedPoint[
Composition[merge, SortBy[#, Last... |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Python | Python | import socket
host = socket.gethostname() |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #R | R | Sys.info()[["nodename"]] |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Racket | Racket |
#lang racket/base
(require racket/os)
(gethostname)
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Raku | Raku | my $host = qx[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
⋮
⋮
⋮
⋱
... | #Python | Python | def identity(size):
matrix = [[0]*size for i in range(size)]
#matrix = [[0] * size] * size #Has a flaw. See http://stackoverflow.com/questions/240178/unexpected-feature-in-a-python-list-of-lists
for i in range(size):
matrix[i][i] = 1
for rows in matrix:
for elements in rows:
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #TorqueScript | TorqueScript | $string = "12345";
$string++;
|
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
teststring="0'1'-1'12345'10000000'-10000000"
LOOP/CLEAR n=teststring
n=n+1
PRINT n
ENDLOOP
|
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 |... | #R | R | print("insert number a")
a <- scan(what=numeric(0), nmax=1)
print("insert number b")
b <- scan(what=numeric(0), nmax=1)
if ( a < b ) {
print("a is less than b")
} else if ( a > b ) {
print("a is greater than b")
} else if ( a == b ) { # could be simply else of course...
print("a and b are the same")
} |
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 |... | #Racket | Racket | #lang racket
(define (compare-two-ints a b)
(define compared
(cond ((> a b) "is greated than")
((= a b) "equals")
((< a b) "is lesser than")))
(format "~a ~a ~a" a compared b))
(compare-two-ints (read) (read)) |
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #EchoLisp | EchoLisp |
;; asynchronous call back definition
(define (success name text) (writeln 'Loaded name) (writeln text))
;;
(file->string success "http://www.google.com")
|
http://rosettacode.org/wiki/Hofstadter-Conway_$10,000_sequence | Hofstadter-Conway $10,000 sequence | The definition of the sequence is colloquially described as:
Starting with the list [1,1],
Take the last number in the list so far: 1, I'll call it x.
Count forward x places from the beginning of the list to find the first number to add (1)
Count backward x places from the end of the list to find the secon... | #Erlang | Erlang |
-module( hofstadter_conway ).
-export( [sequence/1, sequence_div_n/1, task/0] ).
-record( power_of_2, {div_n=0, max=4, min=2, n=0} ).
sequence( 1 ) -> [1];
sequence( 2 ) -> [1, 1];
sequence( Up_to ) when Up_to >= 3 ->
From_3 = lists:seq( 3, Up_to ),
Dict = lists:foldl( fun sequence_dict/2, dict:... |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #Arturo | Arturo | panic "Goodbye, World!" |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #ATS | ATS | implement main0 () = fprint (stderr_ref, "Goodbye, World!\n") |
http://rosettacode.org/wiki/Hello_world/Standard_error | Hello world/Standard error | Hello world/Standard error is part of Short Circuit's Console Program Basics selection.
A common practice in computing is to send error messages
to a different output stream than normal text console messages.
The normal messages print to what is called "standard output" or "standard out".
The error messages print to ... | #AutoHotkey | AutoHotkey | ; c:\> autohotkey.exe stderr.ahk 2> error.txt
FileAppend, Goodbye`, World!, stderr ; requires AutoHotkey_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... | #Clojure | Clojure | (defn qs [q]
(let [n (count q)]
(condp = n
0 [1]
1 [1 1]
(conj q (+ (q (- n (q (- n 1))))
(q (- n (q (- n 2)))))))))
(defn qfirst [n] (-> (iterate qs []) (nth n)))
(println "first 10:" (qfirst 10))
(println "1000th:" (last (qfirst 1000)))
(println "extra credit:" (->> (qfirs... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.