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/Show_the_epoch
Show the epoch
Task Choose popular date libraries used by your language and show the   epoch   those libraries use. A demonstration is preferable   (e.g. setting the internal representation of the date to 0 ms/ns/etc.,   or another way that will still show the epoch even if it is changed behind the scenes by the implementers),   b...
#Wren
Wren
import "/date" for Date   Date.default = Date.isoFull var dt = Date.fromNumber(0) System.print(dt)   var dt2 = Date.unixEpoch System.print(dt2)
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#gnuplot
gnuplot
# Return a string space or star to print at x,y. # Must have x<y. x<0 is the left side of the triangle. # If x<-y then it's before the left edge and the return is a space. char(x,y) = (y+x>=0 && ((y+x)%2)==0 && ((y+x)&(y-x))==0 ? "*" : " ")   # Return a string which is row y of the triangle from character # position x...
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#C.2B.2B
C++
// contributed to rosettacode.org by Peter Helcmanovsky // BCT = Binary-Coded Ternary: pairs of bits form one digit [0,1,2] (0b11 is invalid digit)   #include <cstdint> #include <cstdlib> #include <cstdio>   static constexpr int32_t bct_low_bits = 0x55555555;   static int32_t bct_decrement(int32_t v) { --v; ...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#jq
jq
# jq's length applied to a number is its absolute value. def shoelace: . as $a | reduce range(0; length-1) as $i (0; . + $a[$i][0]*$a[$i+1][1] - $a[$i+1][0]*$a[$i][1] ) | (. + $a[-1][0]*$a[0][1] - $a[0][0]*$a[-1][1])|length / 2;   [ [3, 4], [5, 11], [12, 8], [9, 5], [5, 6] ] | "The polygon with vertices at ...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Julia
Julia
""" Assumes x,y points go around the polygon in one direction. """ shoelacearea(x, y) = abs(sum(i * j for (i, j) in zip(x, append!(y[2:end], y[1]))) - sum(i * j for (i, j) in zip(append!(x[2:end], x[1]), y))) / 2   x, y = [3, 5, 12, 9, 5], [4, 11, 8, 5, 6] @show x y shoelacearea(x, y)
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Gambas
Gambas
Public Sub Main()   Shell "echo Hello World"   End
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Gema
Gema
$ gema -p '\B=Hello\n@end' Hello
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Go
Go
echo 'package main;func main(){println("hlowrld")}'>/tmp/h.go;go run /tmp/h.go
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#Batch_File
Batch File
%=== Batch Files have no booleans. ===% %=== I will instead use 1 as true and 0 as false. ===%   @echo off setlocal enabledelayedexpansion echo AND for /l %%i in (0,1,1) do ( for /l %%j in (0,1,1) do ( echo.a^(%%i^) AND b^(%%j^) call :a %%i set res=!bool_a! if not !res!==0 ( call :b %%j set res=!bool_b! ...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#Applesoft_BASIC
Applesoft BASIC
0 GOTO 10: ONERR AI READ LY RND 10 LET X = 256 * PEEK (104) 11 LET X = X + PEEK (103) + 7 20 CALL - 1184:B$ = CHR$ (8) 21 NORMAL : PRINT :E = 61588 22 PRINT TAB( 29)"APPLESOFT"; 23 PRINT " II"B$:M = - 1 24 PRINT TAB( 22)"BASED ON "; 25 FOR I = E + 9 TO E STEP M 26 POKE 65, PEEK (I): CALL X ...
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#REBOL
REBOL
rebol [author: "Nick Antonaccio"] write/append %rdb "" db: load %rdb switch system/options/args/1 [ "new" [write/append %rdb rejoin [now " " mold/only next system/options/args newline]] "latest" [print copy/part tail sort/skip db 4 -4] "latestcat" [ foreach cat unique extract at db 3 4 [ ...
http://rosettacode.org/wiki/Show_the_epoch
Show the epoch
Task Choose popular date libraries used by your language and show the   epoch   those libraries use. A demonstration is preferable   (e.g. setting the internal representation of the date to 0 ms/ns/etc.,   or another way that will still show the epoch even if it is changed behind the scenes by the implementers),   b...
#zkl
zkl
zkl: Time.Clock.tickToTock(0,False) L(1970,1,1,0,0,0) // y,m,d, h,m,s
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Go
Go
package main   import ( "fmt" "strings" "unicode/utf8" )   var order = 4 var grain = "*"   func main() { t := []string{grain + strings.Repeat(" ", utf8.RuneCountInString(grain))} for ; order > 0; order-- { sp := strings.Repeat(" ", utf8.RuneCountInString(t[0])/2) top := make([]string...
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Clojure
Clojure
(ns example (:require [clojure.contrib.math :as math]))   (defn in-carpet? [x y] (loop [x x, y y] (cond (or (zero? x) (zero? y)) true (and (= 1 (mod x 3)) (= 1 (mod y 3))) false  :else (recur (quot x 3) (quot y 3)))))   (defn carpet [n] (apply str ...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Kotlin
Kotlin
// version 1.1.3   class Point(val x: Int, val y: Int) { override fun toString() = "($x, $y)" }   fun shoelaceArea(v: List<Point>): Double { val n = v.size var a = 0.0 for (i in 0 until n - 1) { a += v[i].x * v[i + 1].y - v[i + 1].x * v[i].y } return Math.abs(a + v[n - 1].x * v[0].y - v...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Groovy
Groovy
$ groovysh -q "println 'Hello'" Hello
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Haskell
Haskell
$ ghc -e 'putStrLn "Hello"' Hello
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Huginn
Huginn
$ huginn -c '"Hello"'
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#BBC_BASIC
BBC BASIC
REM TRUE is represented as -1, FALSE as 0 FOR i% = TRUE TO FALSE FOR j% = TRUE TO FALSE PRINT "For x=a(";FNboolstring(i%);") AND b(";FNboolstring(j%);")" x% = FALSE REM Short-circuit AND can be simulated by cascaded IFs: IF FNa(i%) IF FNb(j%) THEN x%=TRUE ...
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#Bracmat
Bracmat
( (a=.out$"I'm a"&!!arg) & (b=.out$"I'm b"&!!arg) & (false==~) & (true==) & !false !true:?outer & whl ' ( !outer:%?x ?outer & !false !true:?inner & whl ' ( !inner:%?y ?inner & out $ ( Testing (!!x&true|false) AND (!!y&true|false) ...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#ARM_Assembly
ARM Assembly
.equ CursorX,0x02000000 .equ CursorY,0x02000001 ProgramStart: mov sp,#0x03000000 ;Init Stack Pointer   mov r4,#0x04000000 ;DISPCNT -LCD Control mov r2,#0x403 ;4= Layer 2 on / 3= ScreenMode 3 str r2,[r4] ;now the screen is visible bl ResetTextCursors ;set text cursors to top le...
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#REXX
REXX
/* REXX --------------------------------------------------------------- * 05.10.2014 *--------------------------------------------------------------------*/ x05='05'x mydb='sidb.txt' Say 'Enter your commands, ?, or end' Do Forever Parse Pull l Parse Var l command text Select When command='?' Then Call h...
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Golfscript
Golfscript
' /\ /__\ '4/){.+\.{[2$.]*}%\{.+}%+\}3*;n*
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Commodore_BASIC
Commodore BASIC
100 PRINT CHR$(147); CHR$(18); "**** SIERPINSKI CARPET ****" 110 PRINT 120 INPUT "ORDER"; O$ 130 O = VAL(O$) 140 IF O < 1 THEN 120 150 PRINT 160 SZ = 3 ↑ O 170 FOR Y = 0 TO SZ - 1 180 :FOR X = 0 TO SZ - 1 190 : CH$ = "#" 200 : X1 = X 210 : Y1 = Y 220 : IF (X1 = 0) OR (Y1 = 0) THEN 290 230 : X3 = X1 - 3 * ...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Lambdatalk
Lambdatalk
  {def shoelace {lambda {:pol} {abs {/ {- {+ {S.map {{lambda {:pol :i} {* {car {A.get :i :pol}} {cdr {A.get {+ :i 1} :pol}}}} :pol} {S.serie 0 {- {A.length :pol} 2}}} {* {car {A.get {- {A.length :pol} 1} :pol}} ...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Icon_and_Unicon
Icon and Unicon
echo "procedure main();write(\"hello\");end" | icont - -x
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#J
J
$ jconsole -js "exit echo 'Hello'" Hello
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Java
Java
$ echo 'public class X{public static void main(String[]args){' \ > 'System.out.println("Hello Java!");}}' >X.java $ javac X.java && java X
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#C
C
#include <stdio.h> #include <stdbool.h>   bool a(bool in) { printf("I am a\n"); return in; }   bool b(bool in) { printf("I am b\n"); return in; }   #define TEST(X,Y,O) \ do { \ x = a(X) O b(Y); \ printf(#X " " #O " " #Y " = %s\n\n", x ? "true" : "false"); \ } while(false);   int mai...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */ /* program merkleRoot64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "....
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#Arturo
Arturo
loop 32..127 'num [ k: ø case [num] when? [=32] -> k: "␠" when? [=127] -> k: "␡" else -> k: to :string to :char num   prints pad ~"|num|: |k|" 10 if 1 = num%6 -> print "" ]
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#Ruby
Ruby
require 'date' require 'json' require 'securerandom'   class SimpleDatabase def initialize(dbname, *fields) @dbname = dbname @filename = @dbname + ".dat" @fields = fields @maxl = @fields.collect {|f| f.length}.max @data = { 'fields' => fields, 'items' => {}, 'history' => [], ...
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Groovy
Groovy
def stPoints; stPoints = { order, base=[0,0] -> def right = [base[0], base[1]+2**order] def up = [base[0]+2**(order-1), base[1]+2**(order-1)] (order == 0) \ ? [base]  : (stPoints(order-1, base) + stPoints(order-1, right) + stPoints(order-1, up)) }   def stGrid = { order -> def h = 2**orde...
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Common_Lisp
Common Lisp
(defun print-carpet (order) (let ((size (expt 3 order))) (flet ((trinary (x) (format nil "~3,vR" order x)) (ones (a b) (and (eql a #\1) (eql b #\1)))) (loop for i below size do (fresh-line) (loop for j below size do (princ (if (some #'ones (trinary i) (trinary j)) ...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Lua
Lua
function shoeArea(ps) local function det2(i,j) return ps[i][1]*ps[j][2]-ps[j][1]*ps[i][2] end local sum = #ps>2 and det2(#ps,1) or 0 for i=1,#ps-1 do sum = sum + det2(i,i+1)end return math.abs(0.5 * sum) end
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Maple
Maple
  with(ArrayTools):   module Point() option object; local x := 0; local y := 0;   export getX::static := proc(self::Point, $) return self:-x; end proc;   export getY::static := proc(self::Point, $) return self:-y end proc;   export ModuleApply::static := proc() Object(Point, _passed); end proc;   export...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#JavaScript
JavaScript
$ js -e 'print("hello")' hello
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#jq
jq
$ jq -M -n 1+1 2
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Julia
Julia
$ julia -e 'for x in ARGS; println(x); end' foo bar foo bar
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#C.23
C#
using System;   class Program { static bool a(bool value) { Console.WriteLine("a"); return value; }   static bool b(bool value) { Console.WriteLine("b"); return value; }   static void Main() { foreach (var i in new[] { false, true }) { ...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program merkleRoot.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a fil...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#AutoHotkey
AutoHotkey
AutoTrim,Off ;Allows for whitespace at end of variable to separate converted characters   MessageText := ;The text to display in the final message box. CurrentASCII := 32 ;Current ASCII number to convert and add to MessageText ConvertedCharacter := ;Stores the currently converted ASCII code RowLength := 0 ;Keeps track...
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#Run_BASIC
Run BASIC
sqliteconnect #sql, "f:\client.db" ' Connect to the DB   ' ------------------------------- ' show user options ' ------------------------------- [sho] cls ' clear screen button #acd, "Add a new entry", [add] button #acd, "Print the latest entry", [last] button #acd, "Print the latest e...
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Haskell
Haskell
sierpinski 0 = ["*"] sierpinski n = map ((space ++) . (++ space)) down ++ map (unwords . replicate 2) down where down = sierpinski (n - 1) space = replicate (2 ^ (n - 1)) ' '   main = mapM_ putStrLn $ sierpinski 4
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Crystal
Crystal
def sierpinski_carpet(n) carpet = ["#"] n.times do carpet = carpet.map { |x| x + x + x } + carpet.map { |x| x + x.tr("#"," ") + x } + carpet.map { |x| x + x + x } end carpet end   5.times{ |i| puts "\nN=#{i}"; sierpinski_carpet(i).each { |row| puts row } }
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Area[Polygon[{{3, 4}, {5, 11}, {12, 8}, {9, 5}, {5, 6}}]]
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#min
min
((((first) map) ((last) map)) cleave) :dezip (((first) (rest)) cleave append) :rotate ((0 <) (-1 *) when) :abs   ( =b =a a size :n 0 :i () =list (i n <) ( a i get b i get ' prepend list append #list i succ @i ) while list ) :rezip   (rezip (-> *) map sum) :cross-sum   ( ((dezip rotate) (dezip swap rotat...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#MiniScript
MiniScript
shoelace = function(vertices) sum = 0 points = vertices.len   for i in range(0,points-2) sum = sum + vertices[i][0]*vertices[i+1][1] end for sum = sum + vertices[points-1][0]*vertices[0][1]   for i in range(points-1,1) sum = sum - vertices[i][0]*vertices[i-1][1] end for s...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#K
K
$ k -e "\`0: \"hello\\n\""
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Kotlin
Kotlin
echo 'fun main(args: Array<String>) = println("Hello Kotlin!")' >X.kt;kotlinc X.kt -include-runtime -d X.jar && java -jar X.jar
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Lasso
Lasso
echo " 'The date and time is: ' + date " | lasso9 --
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#C.2B.2B
C++
#include <iostream>   bool a(bool in) { std::cout << "a" << std::endl; return in; }   bool b(bool in) { std::cout << "b" << std::endl; return in; }   void test(bool i, bool j) { std::cout << std::boolalpha << i << " and " << j << " = " << (a(i) && b(j)) << std::endl; std::cout << std::boolalpha ...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#C
C
#include <glib.h> #include <stdlib.h> #include <stdio.h> #include <string.h>   guchar* sha256_merkle_tree(FILE* in, size_t block_size) { gchar* buffer = g_malloc(block_size); GPtrArray* hashes = g_ptr_array_new_with_free_func(g_free); gssize digest_length = g_checksum_type_get_length(G_CHECKSUM_SHA256); ...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#AWK
AWK
# syntax: GAWK -f SHOW_ASCII_TABLE.AWK # syntax: MAWK -f SHOW_ASCII_TABLE.AWK BEGIN { for (i=0; i<16; i++) { for (j=32+i; j<128; j+=16) { if (j == 32) { x = "SPC" } else if (j == 127) { x = "DEL" } else { x = sprintf("%c",j) } printf("%3d: %-5s",j,x) } print "" ...
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#Scala
Scala
object SimpleDatabase extends App { type Entry = Array[String] def asTSV(e: Entry) = e mkString "\t" def fromTSV(s: String) = s split "\t" val header = asTSV(Array("TIMESTAMP", "DESCRIPTION", "CATEGORY", "OTHER"))   def read(filename: String) = try { scala.io.Source.fromFile(filename).getLines.drop(1).map...
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Haxe
Haxe
class Main { static function main() { triangle(3); }   static inline var SPACE = ' '; static inline var STAR = '*';   static function triangle(o) { var n = 1 << o; var line = new Array<String>();   for (i in 0...(n*2)) line[i] = SPACE;   line[n] = '*';   for (i in 0...n) { Sys.println(line.join('...
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#D
D
import std.stdio, std.string, std.algorithm, std.array;   auto sierpinskiCarpet(in int n) pure nothrow @safe { auto r = ["#"]; foreach (immutable _; 0 .. n) { const p = r.map!q{a ~ a ~ a}.array; r = p ~ r.map!q{a ~ a.replace("#", " ") ~ a}.array ~ p; } return r.join('\n'); }   void main(...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Modula-2
Modula-2
MODULE ShoelaceFormula; FROM RealStr IMPORT RealToStr; FROM FormatString IMPORT FormatString; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   TYPE Point = RECORD x,y : INTEGER; END;   PROCEDURE PointToString(self : Point; VAR buf : ARRAY OF CHAR); BEGIN FormatString("(%i, %i)", buf, self.x, sel...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Liberty_BASIC
Liberty BASIC
  echo print "hello">oneLiner.bas & liberty -r oneLiner.bas echo print "hello">oneLiner.bas & liberty -r oneLiner.bas  
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Lua
Lua
lua -e 'print "Hello World!"'
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Maple
Maple
maple -c'print(HELLO);' -cquit
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#Clojure
Clojure
(letfn [(a [bool] (print "(a)") bool) (b [bool] (print "(b)") bool)] (doseq [i [true false] j [true false]] (print i "OR" j "= ") (println (or (a i) (b j))) (print i "AND" j " = ") (println (and (a i) (b j)))))
http://rosettacode.org/wiki/SHA-1
SHA-1
SHA-1 or SHA1 is a one-way hash function; it computes a 160-bit message digest. SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections. BitTorrent uses SHA-1 to verify downloads. Git and Mercurial use SHA-1 digests to identify commits. A US government...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program sha1_64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM64....
http://rosettacode.org/wiki/Sexy_primes
Sexy primes
This page uses content from Wikipedia. The original article was at Sexy_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 mathematics, sexy primes are prime numbers that differ from each ot...
#11l
11l
V LIMIT = 1'000'000 F get_primes(limit) V is_prime = [0B] * 2 [+] [1B] * (limit - 1) L(n) 0 .< Int(limit ^ 0.5 + 1.5) I is_prime[n] L(i) (n * n .< limit + 1).step(n) is_prime[i] = 0B R enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)   V primes = get_primes(LIMIT)...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#C.2B.2B
C++
#include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <sstream> #include <vector> #include <openssl/sha.h>   class sha256_exception : public std::exception { public: const char* what() const noexcept override { return "SHA-256 error"; } };   class sha256 { public: sha...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#BASIC
BASIC
10 DEFINT I,J: DEFSTR S: DIM S(2) 20 S(0)="* " 30 S(1)="Spc" 40 S(2)="Del" 50 FOR I=32 TO 47 60 FOR J=I TO 127 STEP 16 70 MID$(S(0),1,1) = CHR$(J) 80 PRINT USING "###: \ \ ";J;S(-(J=32)-2*(J=127)); 90 NEXT J 100 PRINT 110 NEXT I
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#Tcl
Tcl
#!/usr/bin/env tclsh8.6 package require Tcl 8.6 namespace eval udb { variable db {}   proc Load {filename} { variable db if {[catch {set f [open $filename]}]} { set db {} return } set db [read $f] close $f } proc Store {filename} { variable db if {[catch {set f [open $filename w]}]} ret...
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Hoon
Hoon
|= n=@ud =+ m=0 =+ o=(reap 1 '*') |^  ?: =(m n) o $(m +(m), o (weld top bot)) ++ gap (fil 3 (pow 2 m) ' ') ++ top (turn o |=(l=@t (rap 3 gap l gap ~))) ++ bot (turn o |=(l=@t (rap 3 l ' ' l ~))) --
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Delphi
Delphi
function InCarpet(x, y : Integer) : Boolean; begin while (x<>0) and (y<>0) do begin if ((x mod 3)=1) and ((y mod 3)=1) then Exit(False); x := x div 3; y := y div 3; end; Result := True; end;   procedure Carpet(n : Integer); var i, j, p : Integer; begin p := Round(IntPower(3, n)...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Nim
Nim
type Point = tuple x: float y: float   func shoelace(points: openArray[Point]): float = var leftSum, rightSum = 0.0 for i in 0..<len(points): var j = (i + 1) mod len(points) leftSum += points[i].x * points[j].y rightSum += points[j].x * points[i].y 0.5 * abs(leftSum - rightSum)   var points...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Perl
Perl
use strict; use warnings; use feature 'say';   sub area_by_shoelace { my $area; our @p; $#_ > 0 ? @p = @_ : (local *p = shift); $area += $p[$_][0] * $p[($_+1)%@p][1] for 0 .. @p-1; $area -= $p[$_][1] * $p[($_+1)%@p][0] for 0 .. @p-1; return abs $area/2; }   my @poly = ( [3,4], [5,11], [12,8], [9...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
echo Print[2+2] > file & math.exe -script file
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#min
min
min -e:"\"hi from min\" puts!"
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Nanoquery
Nanoquery
nq -e "println \"Hello Nanoquery!\""
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#NetLogo
NetLogo
let x 15 ask turtles [ set xcor x set x x + 1 ]
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#Common_Lisp
Common Lisp
(defun a (F) (print 'a) F )   (defun b (F) (print 'b) F )   (dolist (x '((nil nil) (nil T) (T T) (T nil))) (format t "~%(and ~S)" x) (and (a (car x)) (b (car(cdr x)))) (format t "~%(or ~S)" x) (or (a (car x)) (b (car(cdr x)))))
http://rosettacode.org/wiki/SHA-1
SHA-1
SHA-1 or SHA1 is a one-way hash function; it computes a 160-bit message digest. SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections. BitTorrent uses SHA-1 to verify downloads. Git and Mercurial use SHA-1 digests to identify commits. A US government...
#Ada
Ada
with Ada.Text_IO; with GNAT.SHA1;   procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
http://rosettacode.org/wiki/Sexy_primes
Sexy primes
This page uses content from Wikipedia. The original article was at Sexy_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 mathematics, sexy primes are prime numbers that differ from each ot...
#ALGOL_W
ALGOL W
begin  % find some sexy primes - primes that differ from another prime by 6  %  % implements the sieve of Eratosthenes  % procedure sieve( logical array s ( * ); integer value n ) ; begin  % start with everything flagged as prime  % ...
http://rosettacode.org/wiki/Sexy_primes
Sexy primes
This page uses content from Wikipedia. The original article was at Sexy_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 mathematics, sexy primes are prime numbers that differ from each ot...
#AWK
AWK
  # syntax: GAWK -f SEXY_PRIMES.AWK BEGIN { cutoff = 1000034 for (i=1; i<=cutoff; i++) { n1 = i if (is_prime(n1)) { total_primes++ if ((n2 = n1 + 6) > cutoff) { continue } if (is_prime(n2)) { save(2,5,n1 FS n2) if ((n3 = n2 + 6) > cutoff) { continue } ...
http://rosettacode.org/wiki/Set_right-adjacent_bits
Set right-adjacent bits
Given a left-to-right ordered collection of e bits, b, where 1 <= e <= 10000, and a zero or more integer n : Output the result of setting the n bits to the right of any set bit in b (if those bits are present in b and therefore also preserving the width, e). Some examples: Set of examples showing how one bit in...
#Ada
Ada
with Ada.Text_IO;   procedure Set_Right_Bits is   type Bit_Number is new Positive range 1 .. 10_000; type Bit is new Boolean; type Bit_Collection is array (Bit_Number range <>) of Bit with Pack;   function Right_Adjacent (B : Bit_Collection; N : Natural) return Bit_Co...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#Delphi
Delphi
  program SHA256_Merkle_tree;   {$APPTYPE CONSOLE}   uses System.SysUtils, System.Classes, DCPsha256;   function SHA256(const Input: TArray<Byte>; Len: Integer = -1): TArray<Byte>; var Hasher: TDCP_sha256; l: Integer; begin if Len < 0 then l := length(Input) else l := Len;   Hasher := TDCP_sha25...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#BaCon
BaCon
FOR j = 0 TO 15 FOR i = 32+j TO 127 STEP 16 PRINT i FORMAT "  %3d - "; SELECT i CASE 32 PRINT "Spc"; CASE 127 PRINT "Del"; DEFAULT PRINT i FORMAT "%c " ENDSELECT NEXT PRINT NEXT
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#ToffeeScript
ToffeeScript
#!/usr/local/bin/toffee   prog = require 'commander' fs = require 'fs-extra'   if not fs.exists! 'data.json' fs.outputJson! 'data.json', {}   prog .command('add <name> <category> [date]') .description('Add a new entry') .option('-n <text>', 'notes') .option('-t <tags>', 'tags') .action addentry   prog .co...
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#Icon_and_Unicon
Icon and Unicon
# text based adaptaion of   procedure main(A)   width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4)) # order of arg[1] or 4 write("Triangle order= ",order)   every !(canvas := list(width)) := list(width," ") # prime the canvas every y := 1 to width & x := 1 to width do # traverse it ...
http://rosettacode.org/wiki/Sierpinski_carpet
Sierpinski carpet
Task Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N. For example, the Sierpinski carpet of order   3   should look like this: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#DWScript
DWScript
function InCarpet(x, y : Integer) : Boolean; begin while (x<>0) and (y<>0) do begin if ((x mod 3)=1) and ((y mod 3)=1) then Exit(False); x := x div 3; y := y div 3; end; Result := True; end;   procedure Carpet(n : Integer); var i, j, p : Integer; begin p := Round(IntPower(3, n)...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#Phix
Phix
with javascript_semantics enum X, Y function shoelace(sequence s) atom t = 0 if length(s)>2 then s = append(deep_copy(s),s[1]) for i=1 to length(s)-1 do t += s[i][X]*s[i+1][Y] - s[i+1][X]*s[i][Y] end for end if return abs(t)/2 end function constant test = {{3,4},{5,...
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area
Shoelace formula for polygonal area
Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by: abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) - (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N]) ) / 2 (Where abs returns the absolute value) Task Write ...
#PowerBASIC
PowerBASIC
#COMPILE EXE #DIM ALL #COMPILER PBCC 6   FUNCTION ShoelaceArea(x() AS DOUBLE, y() AS DOUBLE) AS DOUBLE LOCAL i, j AS LONG LOCAL Area AS DOUBLE   j = UBOUND(x()) FOR i = LBOUND(x()) TO UBOUND(x()) Area += (y(j) + y(i)) * (x(j) - x(i)) j = i NEXT i FUNCTION = ABS(Area) / 2 END FUNCTION   FUNCTION PBMAIN (...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#NetRexx
NetRexx
  $ TNRX=`mktemp T_XXXXXXXXXXXX` && test ! -e $TNRX.* && (echo 'say "Goodbye, World!"' >$TNRX; nrc -exec $TNRX; rm $TNRX $TNRX.*; unset TNRX)  
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#NewLISP
NewLISP
newlisp -e "\"Hello\" ->"Hello"
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Nim
Nim
$ echo 'for i in 0..10: echo "Hello World"[0..i]' >/tmp/oneliner.nim; nim r oneliner H He Hel Hell Hello Hello Hello W Hello Wo Hello Wor Hello Worl Hello World
http://rosettacode.org/wiki/Short-circuit_evaluation
Short-circuit evaluation
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Assume functions   a   and   b   return boolean values,   and further, the execution of function   b   takes considerable resources without side effects, an...
#D
D
import std.stdio, std.algorithm;   T a(T)(T answer) { writefln(" # Called function a(%s) -> %s", answer, answer); return answer; }   T b(T)(T answer) { writefln(" # Called function b(%s) -> %s", answer, answer); return answer; }   void main() { foreach (immutable x, immutable y; [fals...
http://rosettacode.org/wiki/SHA-256
SHA-256
SHA-256 is the recommended stronger alternative to SHA-1. See FIPS PUB 180-4 for implementation details. Either by using a dedicated library or implementing the algorithm in your language, show that the SHA-256 digest of the string "Rosetta code" is: 764faf5c61ac315f1497f9dfa542713965b785e5cc2f707d6468d7d1124cdfcf
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program sha256_64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM6...
http://rosettacode.org/wiki/SHA-1
SHA-1
SHA-1 or SHA1 is a one-way hash function; it computes a 160-bit message digest. SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections. BitTorrent uses SHA-1 to verify downloads. Git and Mercurial use SHA-1 digests to identify commits. A US government...
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program sha1-1.s */ /* use with library openssl */ /* link with gcc option -lcrypto -lssl */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this pr...
http://rosettacode.org/wiki/Sexy_primes
Sexy primes
This page uses content from Wikipedia. The original article was at Sexy_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 mathematics, sexy primes are prime numbers that differ from each ot...
#C
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <locale.h>   #define TRUE 1 #define FALSE 0   typedef unsigned char bool;   void sieve(bool *c, int limit) { int i, p = 3, p2; // TRUE denotes composite, FALSE denotes prime. c[0] = TRUE; c[1] = TRUE; // no need to bother with even ...
http://rosettacode.org/wiki/Set_right-adjacent_bits
Set right-adjacent bits
Given a left-to-right ordered collection of e bits, b, where 1 <= e <= 10000, and a zero or more integer n : Output the result of setting the n bits to the right of any set bit in b (if those bits are present in b and therefore also preserving the width, e). Some examples: Set of examples showing how one bit in...
#F.23
F#
  // Set right-adjacent bits. Nigel Galloway: December 21st., 2021 let fN g l=let rec fG n g=[|match n,g with ('0'::t,0)->yield '0'; yield! fG t 0 |('0'::t,n)->yield '1'; yield! fG t (n-1) |(_::t,_) ->yield '1'; yield! fG t l ...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#Factor
Factor
USING: checksums checksums.sha fry grouping io io.encodings.binary io.files kernel make math math.parser namespaces sequences ;   : each-block ( ... size quot: ( ... block -- ... ) -- ... ) input-stream get spin (each-stream-block) ; inline   : >sha-256 ( seq -- newseq ) sha-256 checksum-bytes ;   : (hash-read) ( p...
http://rosettacode.org/wiki/SHA-256_Merkle_tree
SHA-256 Merkle tree
As described in its documentation, Amazon S3 Glacier requires that all uploaded files come with a checksum computed as a Merkle Tree using SHA-256. Specifically, the SHA-256 hash is computed for each 1MiB block of the file. And then, starting from the beginning of the file, the raw hashes of consecutive blocks are pai...
#Go
Go
package main   import ( "crypto/sha256" "fmt" "io" "log" "os" )   func main() { const blockSize = 1024 f, err := os.Open("title.png") if err != nil { log.Fatal(err) } defer f.Close()   var hashes [][]byte buffer := make([]byte, blockSize) h := sha256.New() ...
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#BCPL
BCPL
get "libhdr"   let str(n) = n=32 -> "%I3: Spc ", n=127 -> "%I3: Del ", "%I3: %C "   let start() be for i=32 to 47 do $( for j=i to 127 by 16 do writef(str(j), j, j) wrch('*N') $)
http://rosettacode.org/wiki/Simple_database
Simple database
Task Write a simple tool to track a small set of data. The tool should have a command-line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk. It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, base...
#UNIX_Shell
UNIX Shell
#!/bin/sh   db_create() { mkdir ./"$1" && mkdir "./$1/.tag" && echo "Create DB \`$1'" }   db_delete() { rm -r ./"$1" && echo "Delete DB \`$1'" }   db_show() { if [ -z "$2" ]; then show_help; fi for x in "./$1/$2/"*; do echo "$x:" | sed "s/.*\///" cat "$x" | sed "s/^/ /" echo done   printf "Tags: " ls "....
http://rosettacode.org/wiki/Sierpinski_triangle
Sierpinski triangle
Task Produce an ASCII representation of a Sierpinski triangle of order   N. Example The Sierpinski triangle of order   4   should look like this: * * * * * * * * * * * * * * * ...
#IDL
IDL
pro sierp,n s = (t = bytarr(3+2^(n+1))+32b) t[2^n+1] = 42b for lines = 1,2^n do begin print,string( (s = t) ) for i=1,n_elements(t)-2 do if s[i-1] eq s[i+1] then t[i]=32b else t[i]=42b end end