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/I_before_E_except_after_C | I before E except after C | The phrase "I before E, except after C" is a
widely known mnemonic which is supposed to help when spelling English words.
Task
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
check if the two sub-clauses of the phrase are plausible individually:
"I before E when not pre... | #Yabasic | Yabasic | open "unixdict.txt" for reading as #1
repeat
line input #1 pal$
if instr(pal$, "ie") then
if instr(pal$, "cie") then CI = CI + 1 else XI = XI + 1 : fi
endif
if instr(pal$, "ei") then
if instr(pal$, "cei") then CE = CE + 1 else XE = XE + 1 : fi
endif
until eof(1)
close #1
print "CIE: ", CI
print ... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Prolog | Prolog | incr_numerical_string(S1, S2) :-
string_to_atom(S1, A1),
atom_number(A1, N1),
N2 is N1+1,
atom_number(A2, N2),
string_to_atom(S2, A2).
|
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 |... | #Nim | Nim | import rdstdin, strutils
var a = parseInt(readLineFromStdin "Enter value of a: ")
var b = parseInt(readLineFromStdin "Enter value of b: ")
if a < b:
echo "a is less than b"
elif a > b:
echo "a is greater than b"
elif a == b:
echo "a is equal to 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... | #Nemerle | Nemerle | using System;
using System.Console;
using System.Net;
using System.IO;
module HTTP
{
Main() : void
{
def wc = WebClient();
def myStream = wc.OpenRead(https://sourceforge.com);
def sr = StreamReader(myStream);
WriteLine(sr.ReadToEnd());
myStream.Close()
}
} |
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... | #NewLISP | NewLISP | (! "curl 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... | #Nim | Nim | import httpclient
var client = newHttpClient()
echo client.getContent("https://sourceforge.net") |
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #Amazing_Hopper | Amazing Hopper |
#include <hopper.h>
main:
s=`curl -s -L https://rosettacode.org/wiki/HTTP`
{s}len, lenght=0, mov(lenght)
{"Size = ",lenght,"\nContent = \n",s}println
exit(0)
|
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #Arturo | Arturo | print read "http://rosettacode.org" |
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... | #APL | APL | h←⊥∘⌽ |
http://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation | Horner's rule for polynomial evaluation | A fast scheme for evaluating a polynomial such as:
−
19
+
7
x
−
4
x
2
+
6
x
3
{\displaystyle -19+7x-4x^{2}+6x^{3}\,}
when
x
=
3
{\displaystyle x=3\;}
.
is to arrange the computation as follows:
(
(
(
(
0
)
x
+
6
)
x
+
(
−
4
)
)
x
+
7
)
x
+
(
−
19
)
{\displaystyle ((((0)x+6)x+(-4))x... | #ATS | ATS | #include
"share/atspre_staload.hats"
fun
horner
(
x: int, cs: List int
) : int = let
//
implement
list_foldright$fopr<int><int> (a, b) = a + b * x
//
in
list_foldright<int><int> (cs, 0)
end // end of [horner]
implement
main0 () = let
val x = 3
val cs = $list{int}(~19, 7, ~4, 6)
val res = horner (x, cs)
in... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #J | J | step =: -.&' '&.":@q:
hseq =: [,$:@step`(0&$)@.(1&p:)
fmtHP =: (' is prime',~":@])`('HP',":@],'(',":@[,')'&[)@.(*@[)
fmtlist =: [:;@}.[:,(<' = ')&,"0@(|.@i.@# fmtHP each [)
printHP =: 0 0&$@stdout@(fmtlist@hseq,(10{a.)&[)
printHP"0 [ 2}.i.21
exit 0 |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Julia | Julia | using Primes
function homeprimechain(n::BigInt)
isprime(n) && return [n]
concat = prod(string(i)^j for (i, j) in factor(n).pe)
return pushfirst!(homeprimechain(parse(BigInt, concat)), n)
end
homeprimechain(n::Integer) = homeprimechain(BigInt(n))
function printHPiter(n, numperline = 4)
chain = homepr... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | ClearAll[HP, HPChain]
HP[n_] := FromDigits[Catenate[IntegerDigits /@ Sort[Catenate[ConstantArray @@@ FactorInteger[n]]]]]
HPChain[n_] := NestWhileList[HP, n, PrimeQ/*Not]
Row[Prepend["Home prime chain for " <> ToString[#] <> ": "]@Riffle[HPChain[#], ", "]] & /@ Range[2, 20] // Column
Row[Prepend["Home prime chain for 6... |
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... | #AWK | AWK |
# syntax: GAWK -f HORIZONTAL_SUNDIAL_CALCULATIONS.AWK
BEGIN {
printf("enter latitude (degrees): ") ; getline latitude
printf("enter longitude (degrees): ") ; getline longitude
printf("enter legal meridian (degrees): ") ; getline meridian
printf("\nhour sun hour angle dial hour line angle\n")
sla... |
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... | #Erlang | Erlang | -module(huffman).
-export([encode/1, decode/2, main/0]).
encode(Text) ->
Tree = tree(freq_table(Text)),
Dict = dict:from_list(codewords(Tree)),
Code = << <<(dict:fetch(Char, Dict))/bitstring>> || Char <- Text >>,
{Code, Tree, Dict}.
decode(Code, Tree) ->
decode(Code, Tree, Tree, []).
main(... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Icon_and_Unicon | Icon and Unicon | procedure main()
write(if 0 = ishift(1,-1) then "little" else "big"," endian")
if match("flags",line := !open("/proc/cpuinfo")) then # Unix-like only
write(if find(" lm ",line) then 64 else 32," bits per word")
else write("Cannot determine word size.")
end |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #J | J | IF64 {32 64
64 |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Haskell | Haskell | import Network.BSD
main = do hostName <- getHostName
putStrLn hostName |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Icon_and_Unicon | Icon and Unicon | procedure main()
write(&host)
end |
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #VBScript | VBScript |
Function validate_iban(s)
validate_iban = Chr(34) & s & Chr(34) & " is NOT valid."
Set cn_len = CreateObject("Scripting.Dictionary")
With cn_len
.Add "AL",28 : .Add "AD",24 : .Add "AT",20 : .Add "AZ",28 : .Add "BH",22 : .Add "BE",16
.Add "BA",20 : .Add "BR",29 : .Add "BG",22 : .Add "CR",21 : .Add "HR",21 : .Ad... |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Raku | Raku | use GD;
my $filename = 'pentagon.ppm';
my $in = open($filename, :r, :enc<iso-8859-1>);
my ($type, $dim, $depth) = $in.lines[^3];
my ($xsize,$ysize) = split ' ', $dim;
my ($width, $height) = 460, 360;
my $image = GD::Image.new($width, $height);
my @canvas = [255 xx $width] xx $height;
my $rmax = sqrt($xsize**2 +... |
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
⋮
⋮
⋮
⋱
... | #Nim | Nim | proc identityMatrix(n: Positive): auto =
result = newSeq[seq[int]](n)
for i in 0 ..< result.len:
result[i] = newSeq[int](n)
result[i][i] = 1 |
http://rosettacode.org/wiki/I_before_E_except_after_C | I before E except after C | The phrase "I before E, except after C" is a
widely known mnemonic which is supposed to help when spelling English words.
Task
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt,
check if the two sub-clauses of the phrase are plausible individually:
"I before E when not pre... | #zkl | zkl | fcn wcnt(wordList,altrs,aAdjust,bltrs,bAdjust,text){
a:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(altrs) },0) - aAdjust;
b:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(bltrs) },0) - bAdjust;
ratio:=a.toFloat()/b;
"%s is %splausible".fmt(text,ratio<2 and "im" or "").println();
" %d cases for an... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #PureBasic | PureBasic | string$="12345"
string$=Str(Val(string$)+1)
Debug 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 |... | #NSIS | NSIS |
Function IntergerComparison
Push $0
Push $1
StrCpy $0 8
StrCpy $1 2
IntCmp $0 $1 Equal Val1Less Val1More
Equal:
DetailPrint "$0 = $1"
Goto End
Val1Less:
DetailPrint "$0 < $1"
Goto End
Val1More:
DetailPrint "$0 > $1"
Goto End
End:
Pop $1
Pop $0
FunctionEnd
|
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... | #Objeck | Objeck |
use HTTP;
class HttpsTest {
function : Main(args : String[]) ~ Nil {
client := HttpsClient->New();
lines := client->Get("https://sourceforge.net");
each(i : lines) {
lines->Get(i)->As(String)->PrintLine();
};
}
}
|
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... | #Ol | Ol |
(import (lib curl))
(define curl (make-curl))
(curl 'url "https://www.w3.org/")
(curl 'perform)
|
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.
| #AutoHotkey | AutoHotkey |
UrlDownloadToFile, http://rosettacode.org, url.html
Run, cmd /k type url.html
|
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... | #11l | 11l | V qseq = [0] * 100001
qseq[1] = 1
qseq[2] = 1
L(i) 3 .< qseq.len
qseq[i] = qseq[i - qseq[i-1]] + qseq[i - qseq[i-2]]
print(‘The first 10 terms are: ’qseq[1..10].map(q -> String(q)).join(‘, ’))
print(‘The 1000'th term is ’qseq[1000])
V less_than_preceding = 0
L(i) 2 .< qseq.len
I qseq[i] < qseq[i-1]
le... |
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... | #Arturo | Arturo | horner: function [coeffs, x][
result: 0
loop reverse coeffs 'c ->
result: c + result * x
return result
]
print horner @[neg 19, 7, neg 4, 6] 3 |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Nim | Nim | import algorithm, sequtils, strformat, strutils
import bignum
let
Two = newInt(2)
Three = newInt(3)
Five = newInt(5)
proc primeFactorsWheel(n: Int): seq[Int] =
const Inc = [4, 2, 4, 2, 4, 6, 2, 6]
var n = n
while (n mod 2).isZero:
result.add Two
n = n div 2
while (n mod 3).isZero:
result... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Perl | Perl | use strict;
use warnings;
use ntheory 'factor';
for my $m (2..20, 65) {
my (@steps, @factors) = $m;
push @steps, join '_', @factors while (@factors = factor $steps[-1] =~ s/_//gr) > 1;
my $step = $#steps;
if ($step >= 1) { print 'HP' . $_ . "($step) = " and --$step or last for @steps }
else ... |
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... | #BASIC | BASIC |
10 REM Horizontal sundial calculations
20 DEF FNM(X) = INT(X*1000+0.5)/1000
30 PRINT "Enter latitude";
40 INPUT L
50 PRINT "Enter longitude";
60 INPUT L1
70 PRINT "Enter legal meridian";
80 INPUT R
90 PRINT
100 LET P = 4*ATN(1)
110 LET S1 = SIN(L*P/180)
120 PRINT " sine of latitude:"; S1
130 PRINT " diff longit... |
http://rosettacode.org/wiki/Huffman_coding | Huffman coding | Huffman encoding is a way to assign binary codes to symbols that reduces the overall number of bits used to encode a typical string of those symbols.
For example, if you use letters as symbols and have details of the frequency of occurrence of those letters in typical strings, then you could just encode each letter wi... | #F.23 | F# | type 'a HuffmanTree =
| Leaf of int * 'a
| Node of int * 'a HuffmanTree * 'a HuffmanTree
let freq = function Leaf (f, _) | Node (f, _, _) -> f
let freqCompare a b = compare (freq a) (freq b)
let buildTree charFreqs =
let leaves = List.map (fun (c,f) -> Leaf (f,c)) charFreqs
let freqSort = List.sortW... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Java | Java | import java.nio.ByteOrder;
public class ShowByteOrder {
public static void main(String[] args) {
// Print "BIG_ENDIAN" or "LITTLE_ENDIAN".
System.out.println(ByteOrder.nativeOrder());
}
} |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Julia | Julia |
print("This host's word size is ", WORD_SIZE, ".")
if ENDIAN_BOM == 0x04030201
println("And it is a little-endian machine.")
elseif ENDIAN_BOM == 0x01020304
println("And it is a big-endian machine.")
else
println("ENDIAN_BOM = ", ENDIAN_BOM, ", which is confusing")
end
|
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #IDL | IDL | hostname = GETENV('computername') |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #J | J | NB. Load the socket libraries
load 'socket'
coinsert 'jsocket'
NB. fetch and implicitly display the hostname
> {: sdgethostname ''
NB. If fetching the hostname is the only reason for loading the socket libraries,
NB. and the hostname is fetched only once, then use a 'one-liner' to accomplish it:
> {: ... |
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #Wren | Wren | import "/big" for BigInt
var countryCodes =
"AD24 AE23 AL28 AT20 AZ28 BA20 BE16 BG22 BH22 BR29 " +
"BY28 CH21 CR22 CY28 CZ24 DE22 DK18 DO28 EE20 ES24 " +
"FI18 FO18 FR27 GB22 GE22 GI23 GL18 GR27 GT28 HR21 " +
"HU28 IE22 IL23 IQ23 IS26 IT27 JO30 KW30 KZ20 LB28 " +
"LC32 LI21 LT20 LU20 LV21 MC27 MD2... |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Ruby | Ruby |
require 'mathn'
require 'rubygems'
require 'gd2'
include GD2
def hough_transform(img)
mx, my = img.w*0.5, img.h*0.5
max_d = Math.sqrt(mx**2 + my**2)
min_d = max_d * -1
hough = Hash.new(0)
(0..img.w).each do |x|
puts "#{x} of #{img.w}"
(0..img.h).each do |y|
if img.pixel2color(img.get_pixel(x... |
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
⋮
⋮
⋮
⋱
... | #Objeck | Objeck | class IdentityMatrix {
function : Matrix(n : Int) ~ Int[,] {
array := Int->New[n,n];
for(row:=0; row<n; row+=1;){
for(col:=0; col<n; col+=1;){
if(row = col){
array[row, col] := 1;
}
else{
array[row,col] := 0;
};
};
};
return array;
}
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Python | Python | next = str(int('123') + 1) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Quackery | Quackery | /O> $ "1.2.3.4.5" $->n
... not if [ $ "not a valid integer" fail ]
... 1+
... number$ echo$
...
Problem: not a valid integer
Quackery Stack: 12345
Return stack: {[...] 0} {quackery 1} {[...] 11} {shell 5} {quackery 1} {[...] 4}
/O> $ "12345" $->n
... not if [ $ "not a valid integer" fail ]
... 1+
... nu... |
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 |... | #Oberon-2 | Oberon-2 | MODULE Compare;
IMPORT In, Out;
VAR a,b: INTEGER;
BEGIN
In.Int(a);
In.Int(b);
IF a < b THEN
Out.Int(a,0);
Out.String(" is less than ");
Out.Int(b,0);
Out.Ln;
ELSIF a = b THEN
Out.Int(a,0);
Out.String(" is equal to ");
Out.Int(b,0);
Out.Ln;
ELSI... |
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... | #Pascal | Pascal | {$mode objfpc}{$H+}
uses fphttpclient;
var
s: string;
hc: tfphttpclient;
begin
hc := tfphttpclient.create(nil);
try
s := hc.get('https://www.example.com')
finally
hc.free
end;
writeln(s)
end. |
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... | #Perl | Perl |
use strict;
use LWP::UserAgent;
my $url = 'https://www.rosettacode.org';
my $response = LWP::UserAgent->new->get( $url );
$response->is_success or die "Failed to GET '$url': ", $response->status_line;
print $response->as_string;
|
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.
| #AWK | AWK | BEGIN {
site="en.wikipedia.org"
path="/wiki/"
name="Rosetta_Code"
server = "/inet/tcp/0/" site "/80"
print "GET " path name " HTTP/1.0" |& server
print "Host: " site |& server
print "\r\n\r\n" |& server
while ( (server |& getline fish) > 0 ) {
if ( ++scale == 1 )
ship = fish
else
... |
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... | #360_Assembly | 360 Assembly | * Hofstrader q sequence for any n - 18/10/2015
HOFSTRAD CSECT
USING HOFSTRAD,R15 set base register
MVC Q,=F'1' q(1)=1
MVC Q+4,=F'1' q(2)=1
LA R4,1 i=1
LOOPI C R4,N do i=1 to n
BH ELOOPI
... |
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... | #AutoHotkey | AutoHotkey | Coefficients = -19, 7, -4, 6
x := 3
MsgBox, % EvalPolynom(Coefficients, x)
;---------------------------------------------------------------------------
EvalPolynom(Coefficients, x) { ; using Horner's rule
;---------------------------------------------------------------------------
StringSplit, Co, coefficie... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Phix | Phix | with javascript_semantics
requires("1.0.0")
include mpfr.e
procedure test(integer n)
string s = sprintf("%d",n), lastp = ""
sequence res = {s}
atom t0 = time()
while true do
s = substitute(s,"_","")
sequence rr = mpz_pollard_rho(s,true)
if length(rr)=1 then exit end if
s... |
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... | #BBC_BASIC | BBC BASIC | INSTALL @lib$+"FNUSING"
INPUT "Enter latitude (degrees) : " latitude
INPUT "Enter longitude (degrees) : " longitude
INPUT "Enter legal meridian (degrees): " meridian
PRINT '" Time", "Sun hour angle", "Dial hour line angle"
FOR hour = 6 TO 18
hra = 15*hour - lon... |
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... | #C | C | #include <stdio.h>
#include <math.h>
#define PICKVALUE(TXT, VM) do { \
printf("%s: ", TXT); \
scanf("%lf", &VM); \
} while(0);
#if !defined(M_PI)
#define M_PI 3.14159265358979323846
#endif
#define DR(X) ((X)*M_PI/180.0)
#define RD(X) ((X)*180.0/M_PI)
int main()
{
double lat, slat, lng, ref;
... |
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... | #Factor | Factor |
USING: kernel sequences combinators accessors assocs math hashtables math.order
sorting.slots classes formatting prettyprint ;
IN: huffman
! -------------------------------------
! CLASSES -----------------------------
! -------------------------------------
TUPLE: huffman-node
weight element encoding left ... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
println("Word size : ${System.getProperty("sun.arch.data.model")} bits")
println("Endianness: ${System.getProperty("sun.cpu.endian")}-endian")
} |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Lua | Lua | ffi = require("ffi")
print("size of int (in bytes): " .. ffi.sizeof(ffi.new("int")))
print("size of pointer (in bytes): " .. ffi.sizeof(ffi.new("int*")))
print((ffi.abi("le") and "little" or "big") .. " endian") |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Java | Java | import java.net.*;
class DiscoverHostName {
public static void main(final String[] args) {
try {
System.out.println(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) { // Doesn't actually happen, but Java requires it be handled.
}
}
} |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #JavaScript | JavaScript | var network = new ActiveXObject('WScript.Network');
var hostname = network.computerName;
WScript.echo(hostname); |
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #Yabasic | Yabasic | // List updated to release 72, 25 November 2016, of IBAN Registry (75 countries)
countryCodes$ = "AD24 AE23 AL28 AT20 AZ28 BA20 BE16 BG22 BH22 BR29 BY28 CH21 CR22 CY28 CZ24 DE22 "
countryCodes$ = countryCodes$ + "DK18 DO28 EE20 ES24 FI18 FO18 FR27 GB22 GE22 GI23 GL18 GR27 GT28 HR21 HU28 IE22 "
countryCodes$ = countryCo... |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Rust | Rust |
//! Contributed by Gavin Baker <gavinb@antonym.org>
//! Adapted from the Go version
use std::fs::File;
use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
use std::iter::repeat;
/// Simple 8-bit grayscale image
struct ImageGray8 {
width: usize,
height: usize,
data: Vec<u8>,
}
fn load_pg... |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Scala | Scala | import java.awt.image._
import java.io.File
import javax.imageio._
object HoughTransform extends App {
override def main(args: Array[String]) {
val inputData = readDataFromImage(args(0))
val minContrast = if (args.length >= 4) 64 else args(4).toInt
inputData(args(2).toInt, args(3).toInt, m... |
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
⋮
⋮
⋮
⋱
... | #OCaml | OCaml | $ ocaml
# let make_id_matrix n =
let m = Array.make_matrix n n 0.0 in
for i = 0 to pred n do
m.(i).(i) <- 1.0
done;
(m)
;;
val make_id_matrix : int -> float array array = <fun>
# make_id_matrix 4 ;;
- : float array array =
[| [|1.; 0.; 0.; 0.|];
[|0.; 1.; 0.; 0.|];
[|0.; 0.; 1.; 0.|];
... |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #R | R | s = "12345"
s <- as.character(as.numeric(s) + 1) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Racket | Racket |
#lang racket
(define next (compose number->string add1 string->number))
|
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 |... | #Objeck | Objeck |
bundle Default {
class IntCompare {
function : Main(args : String[]) ~ Nil {
a := Console->GetInstance()->ReadString()->ToInt();
b := Console->GetInstance()->ReadString()->ToInt();
if (a < b) {
Console->GetInstance()->Print(a)->Print(" is less than ")->PrintLine(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... | #Phix | Phix | without js
include builtins\libcurl.e
curl_global_init()
atom curl = curl_easy_init()
curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/")
object res = curl_easy_perform_ex(curl)
curl_easy_cleanup(curl)
curl_global_cleanup()
puts(1,res)
|
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... | #PHP | PHP |
echo file_get_contents('https://sourceforge.net');
|
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #BaCon | BaCon | '
' Read and display a website
'
IF AMOUNT(ARGUMENT$) = 1 THEN
website$ = "www.basic-converter.org"
ELSE
website$ = TOKEN$(ARGUMENT$, 2)
ENDIF
OPEN website$ & ":80" FOR NETWORK AS mynet
SEND "GET / HTTP/1.1\r\nHost: " & website$ & "\r\n\r\n" TO mynet
REPEAT
RECEIVE dat$ FROM mynet
total$ = total$ & da... |
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... | #11l | 11l | V last = 1 << 20
V a_list = [0] * (last+1)
a_list[0] = -50'000
a_list[1] = 1
a_list[2] = 1
V v = a_list[2]
V k1 = 2
V lg2 = 1
V amax = 0.0
L(n) 3..last
v = a_list[v] + a_list[n - v]
a_list[n] = v
amax = max(amax, Float(v) / n)
I (k1 [&] n) == 0
print(‘Maximum between 2^#. and 2^#. was #.6’.format(... |
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... | #8080_Assembly | 8080 Assembly | puts: equ 9 ; CP/M call to print a string
org 100h
;;; Generate the first 1000 members of the Q sequence
lxi b,3 ; Start at 3rd element (1 and 2 already defined)
genq: dcx b ; BC = N-1
call q
mov e,m ; DE = Q(N-1)
inx h
mov d,m
inx b ; BC = (N-1)+1 = N
xchg ; HL = Q(N-1)
call neg ; HL = -Q(N-1)
dad b ; HL ... |
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... | #AWK | AWK | #!/usr/bin/awk -f
function horner(x, A) {
acc = 0;
for (i = length(A); 0<i; i--) {
acc = acc*x + A[i];
}
return acc;
}
BEGIN {
split(p,P);
print horner(x,P);
} |
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... | #Batch_File | Batch File |
@echo off
call:horners a:-19 b:7 c:-4 d:6 x:3
call:horners x:3 a:-19 c:-4 d:6 b:7
pause>nul
exit /b
:horners
setlocal enabledelayedexpansion
set a=0
set b=0
set c=0
set d=0
set x=0
for %%i in (%*) do (
for /f "tokens=1,2 delims=:" %%j in ("%%i") do (
set %%j=%%k
)
)
set /a return=((((0)*%x%+%d%)*%x%+(%c... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #Raku | Raku | use Prime::Factor;
my $start = now;
(flat 2..20, 65).map: -> $m {
my ($now, @steps, @factors) = now, $m;
@steps.push: @factors.join('_') while (@factors = prime-factors @steps[*-1].Int) > 1;
say (my $step = +@steps) > 1 ?? (@steps[0..*-2].map( { "HP$_\({--$step})" } ).join: ' = ') !! ("HP$m"),
... |
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... | #C.23 | C# | using System;
namespace RosettaCode
{
internal sealed class Program
{
private static void Main()
{
Func<double> getDouble = () => Convert.ToDouble(Console.ReadLine());
double h = 0, lat, lng, lme, slat, hra, hla;
Console.Write("Enter latitude => ");
lat = getDouble();
... |
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... | #Fantom | Fantom |
class Node
{
Float probability := 0.0f
}
class Leaf : Node
{
Int character
new make (Int character, Float probability)
{
this.character = character
this.probability = probability
}
}
class Branch : Node
{
Node left
Node right
new make (Node left, Node right)
{
this.left = left
... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
\\ Always run in Little-endian, 32 bits (in Wow64 in 64 bit os)
Module EndiannessAndSize {
Buffer Check as Long
Return Check, 0:=1
if eval(Check, 0 as byte)=1 then {
Print "Little-endian"
}
\\ 4 bytes
... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #MACRO-10 | MACRO-10 |
title Host Introspection
subttl PDP-10 assembly (MACRO-10 on TOPS-20). KJX 2022.
search monsym,macsym
comment \
The wordsize is detected by putting 1 into a re-
gister, counting the leading zeros (resulting in
wordsize-1) and adding 1 to the result.
Endianness doesn't really apply... |
http://rosettacode.org/wiki/Host_introspection | Host introspection | Print the word size and endianness of the host machine.
See also: Variable size/Get
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | If[$ByteOrdering > 0, Print["Big endian"], Print["Little endian" ]]
$SystemWordLength "bits" |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #jq | jq | HOST=$(hostname) jq -n --arg hostname $(hostname) '[env.HOST, $hostname]' |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Jsish | Jsish | var hn = exec("hostname", {retAll:true}).data.trim(); |
http://rosettacode.org/wiki/Hostname | Hostname | Task
Find the name of the host on which the routine is running.
| #Julia | Julia |
println(gethostname())
|
http://rosettacode.org/wiki/IBAN | IBAN |
This page uses content from Wikipedia. The original article was at IBAN. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
The International Bank Account Number (IBAN) is an internationally agree... | #zkl | zkl | var BN=Import("zklBigNum");
fcn validateIBAN(iban){
iban=iban-" \t";
alphaNums.matches(iban) and (ibans.find(iban[0,2])==iban.len()) and
( BN((iban[4,*]+iban[0,4]).apply("toInt",36)) % 97 == 1 )
} |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #SequenceL | SequenceL | import <Utilities/Sequence.sl>;
import <Utilities/Math.sl>;
hough: int(2) * int * int * int -> int(2);
hough(image(2), thetaAxisSize, rAxisSize, minContrast) :=
let
initialResult[r,theta] := 0 foreach r within 1 ... rAxisSize, theta within 1 ... thetaAxisSize;
result := houghHelper(image, minCon... |
http://rosettacode.org/wiki/Hough_transform | Hough transform | Task
Implement the Hough transform, which is used as part of feature extraction with digital images.
It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation.
The transform maps each point in the target image,
(
ρ
,
θ
)
{\displaystyle (\rho ,\theta )}
, ... | #Sidef | Sidef | require('Imager')
func hough(im, width=460, height=360) {
height = 2*floor(height / 2)
var xsize = im.getwidth
var ysize = im.getheight
var ht = %s|Imager|.new(xsize => width, ysize => height)
var canvas = height.of { width.of(255) }
ht.box(filled => true, color => 'white')
var r... |
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
⋮
⋮
⋮
⋱
... | #Octave | Octave | I = eye(10) |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Raku | Raku | my $s = "12345";
$s++; |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Rascal | Rascal |
import String;
public str IncrNumStr(str s) = "<toInt(s) + 1>";
|
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #OCaml | OCaml | let my_compare a b =
if a < b then "A is less than B"
else if a > b then "A is greater than B"
else if a = b then "A equals B"
else "cannot compare NANs"
let () =
let a = read_int ()
and b = read_int () in
print_endline (my_compare a b) |
http://rosettacode.org/wiki/HTTPS | HTTPS | Task
Send a GET request to obtain the resource located at the URL "https://www.w3.org/", then print it to the console.
Checking the host certificate for validity is recommended.
Do not authenticate. That is the subject of other tasks.
Readers may wish to contrast with the HTTP Request task, and also the task on HTT... | #PicoLisp | PicoLisp |
(in '(curl "https://sourceforge.net") # Open a pipe to 'curl'
(out NIL (echo)) ) # Echo to standard output
|
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... | #Pike | Pike |
int main() {
write("%s\n", Protocols.HTTP.get_url_data("https://sourceforge.net"));
}
|
http://rosettacode.org/wiki/HTTP | HTTP | Task
Access and print a URL's content (the located resource) to the console.
There is a separate task for HTTPS Requests.
| #Batch_File | Batch File |
curl.exe -s -L http://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... | #360_Assembly | 360 Assembly | * Hofstadter-Conway $10,000 sequence 07/05/2016
HOFSTADT START
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) save registers
ST R13,4(R15) link backward SA
ST R15,8(R13) link forward SA
... |
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... | #Ada | Ada | -- Ada95 version
-- Allocation of arrays on the heap
with Ada.Text_IO; use Ada.Text_IO;
with Unchecked_Deallocation;
procedure Conway is
package Real_io is new Float_IO (Float);
Maxrange : constant := 2 ** 20;
type Sequence is array (Positive range 1 .. Maxrange) of Positive;
type Sequence_Ptr is ... |
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... | #8086_Assembly | 8086 Assembly | puts: equ 9 ; MS-DOS syscall to print a string
cpu 8086
org 100h
section .text
;;; Generate first 1000 elements of Q sequence
mov dx,3 ; DX = N
mov di,Q+4 ; DI = place to store elements
mov cx,998 ; Generate 998 more terms
genq: mov si,dx ; SI = N
sub si,[di-2] ; SI -= Q[N-1]
mov bp,dx ; BP = N
sub bp,[... |
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... | #BBC_BASIC | BBC BASIC | DIM coefficients(3)
coefficients() = -19, 7, -4, 6
PRINT FNhorner(coefficients(), 3)
END
DEF FNhorner(coeffs(), x)
LOCAL i%, v
FOR i% = DIM(coeffs(), 1) TO 0 STEP -1
v = v * x + coeffs(i%)
NEXT
= v |
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... | #Bracmat | Bracmat | ( ( Horner
= accumulator coefficients x coeff
. !arg:(?coefficients.?x)
& 0:?accumulator
& whl
' ( !coefficients:?coefficients #%@?coeff
& !accumulator*!x+!coeff:?accumulator
)
& !accumulator
)
& Horner$(-19 7 -4 6.3)
); |
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... | #ActionScript | ActionScript |
package {
import flash.display.GraphicsPathCommand;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
/**
* A honeycomb.
*/
public class Honeycomb extends Sprite {
/**
* The sine of... |
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
... | #360_Assembly | 360 Assembly | * Holidays related to Easter 29/05/2016
HOLIDAYS CSECT
USING HOLIDAYS,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) prolog
ST R13,4(R15) "
ST R15,8(R13) ... |
http://rosettacode.org/wiki/Home_primes | Home primes |
This page uses content from Wikipedia. The original article was at Home prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In number theory, the home prime HP(n) of an integer n greater than 1 is... | #REXX | REXX | /*REXX program finds and displays the home prime of a range of positive integers. */
numeric digits 20 /*ensure handling of larger integers. */
parse arg LO HI . /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 2 ... |
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... | #C.2B.2B | C++ | #include <cmath>
#include <iostream>
#include <numbers>
// constants used in the calculations
static const double DegreesPerHour = 15.0;
static const double DegreesPerRadian = 180.0 * std::numbers::inv_pi;
// a structure for the calculation results
struct SundialCalculation
{
double HourAngle;
double HourLineAn... |
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... | #Fortran | Fortran | ! output:
! d-> 00000, t-> 00001, h-> 0001, s-> 0010,
! c-> 00110, x-> 00111, m-> 0100, o-> 0101,
! n-> 011, u-> 10000, l-> 10001, a-> 1001,
! r-> 10100, g-> 101010, p-> 101011,
! e-> 1011, i-> 1100, f-> 1101, -> 111
!
! 00001|0001|1100|0010|111|1100|0010|111|1001|011|
! 111|1011|00111|1001|0100|101011|10001|1011|... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.