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/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #D | D | import bitmap: Image, RGB;
void circle(Color)(Image!Color img, in int x0, in int y0,
in int radius, in Color color)
pure nothrow @nogc @safe {
int f = 1 - radius;
int ddfX = 1;
int ddfY = -2 * radius;
int x = 0;
int y = radius;
img[x0, y0 + radius] = color;
img[x0, y0 - ... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #11l | 11l | T Colour
Byte r, g, b
F ==(other)
R .r == other.r & .g == other.g & .b == other.b
F (r, g, b)
.r = r
.g = g
.b = b
V black = Colour(0, 0, 0)
V white = Colour(255, 255, 255)
T Bitmap
Int width, height
Colour background
[[Colour]] map
F (width = 40, height = 40, back... |
http://rosettacode.org/wiki/Bitwise_IO | Bitwise IO | The aim of this task is to write functions (or create a class if your
language is Object Oriented and you prefer) for reading and writing sequences of
bits, most significant bit first. While the output of a asciiprint "STRING" is the ASCII byte sequence
"S", "T", "R", "I", "N", "G", the output of a "print" of the bits ... | #Wren | Wren | import "io" for File
class BitFilter {
construct new(name) {
_name = name
_accu = 0
_bits = 0
}
openWriter() {
_bw = File.create(_name)
}
openReader() {
_br = File.open(_name)
_offset = 0
}
write(buf, start, nBits, shift) {
var ... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #REXX | REXX | /*REXX program writes a PPM formatted image file, also known as a P6 (binary) file. */
green = 00ff00 /*define a pixel with the color green. */
parse arg oFN width height color . /*obtain optional arguments from the CL*/
if oFN=='' | oFN=="," then oFN='IMAGE... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Ruby | Ruby | class RGBColour
def values
[@red, @green, @blue]
end
end
class Pixmap
def save(filename)
File.open(filename, 'w') do |f|
f.puts "P6", "#{@width} #{@height}", "255"
f.binmode
@height.times do |y|
@width.times do |x|
f.print @data[x][y].values.pack('C3')
end
... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #Ada | Ada | procedure Flood_Fill
( Picture : in out Image;
From : Point;
Fill : Pixel;
Replace : Pixel;
Distance : Luminance := 20
) is
function Diff (A, B : Luminance) return Luminance is
pragma Inline (Diff);
begin
if A > B then... |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #Crystal | Crystal | if false
puts "false"
elsif nil
puts "nil"
elsif Pointer(Nil).new 0
puts "null pointer"
elsif true && "any other value"
puts "finally true!"
end |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #D | D | #t // <boolean> true
#f // <boolean> false |
http://rosettacode.org/wiki/Caesar_cipher | Caesar cipher |
Task
Implement a Caesar cipher, both encoding and decoding.
The key is an integer from 1 to 25.
This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).
The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).
So key 2 encrypts "HI" to... | #TUSCRIPT | TUSCRIPT | $$ MODE TUSCRIPT
text="THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
PRINT "text orginal ",text
abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ",key=3,caesarskey=key+1
secretbeg=EXTRACT (abc,#caesarskey,0)
secretend=EXTRACT (abc,0,#caesarskey)
secretabc=CONCAT (secretbeg,secretend)
abc=STRINGS (abc,":</:"),secretabc=STRINGS (sec... |
http://rosettacode.org/wiki/Box_the_compass | Box the compass | There be many a land lubber that knows naught of the pirate ways and gives direction by degree!
They know not how to box the compass!
Task description
Create a function that takes a heading in degrees and returns the correct 32-point compass heading.
Use the function to print and display a table of Index, Compass... | #BASIC256 | BASIC256 | arraybase 1
dim names$ = {"North", "North by east", "North-northeast", "Northeast by north", "Northeast", "Northeast by east", "East-northeast", "East by north", "East", "East by south", "East-southeast", "Southeast by east", "Southeast", "Southeast by south", "South-southeast", "South by east", "South", "South by we... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | ImageLevels[img] |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #Nim | Nim | import bitmap
import grayscale_image
type Histogram = array[Luminance, Natural]
#---------------------------------------------------------------------------------------------------
func histogram*(img: GrayImage): Histogram =
## Build and return gray scale image histogram.
for lum in img.pixels:
inc resul... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #OCaml | OCaml | type histogram = int array
let get_histogram ~img:gray_channel =
let width = Bigarray.Array2.dim1 gray_channel
and height = Bigarray.Array2.dim2 gray_channel in
let t = Array.make 256 0 in
for x = 0 to pred width do
for y = 0 to pred height do
let v = gray_get_pixel_unsafe gray_channel x y in
... |
http://rosettacode.org/wiki/Bitwise_operations | Bitwise operations |
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 |... | #ActionScript | ActionScript | function bitwise(a:int, b:int):void
{
trace("And: ", a & b);
trace("Or: ", a | b);
trace("Xor: ", a ^ b);
trace("Not: ", ~a);
trace("Left Shift: ", a << b);
trace("Right Shift(Arithmetic): ", a >> b);
trace("Right Shift(Logical): ", a >>> b);
} |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #Julia | Julia | // Version 1.2.40
import java.awt.Color
import java.awt.Graphics
import java.awt.image.BufferedImage
import kotlin.math.abs
import java.io.File
import javax.imageio.ImageIO
class Point(var x: Int, var y: Int)
class BasicBitmapStorage(width: Int, height: Int) {
val image = BufferedImage(width, height, Buffered... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #ERRE | ERRE | PROGRAM BCircle
!$INCLUDE="PC.LIB"
PROCEDURE BCircle(cx%,cy%,r%)
local f%,x%,y%,ddx%,ddy%
f%=1-r% y%=r% ddy%=-2*r%
PSET(cx%,cy%+r%,1)
PSET(cx%,cy%-r%,1)
PSET(cx%+r%,cy%,1)
PSET(cx%-r%,cy%,1)
WHILE x%<y% DO
IF f%>=0 THEN
y%=y%-1
ddy%=ddy%+2
... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #FBSL | FBSL | #DEFINE WM_LBUTTONDOWN 513
#DEFINE WM_CLOSE 16
FBSLSETTEXT(ME, "Bresenham Circle") ' Set form caption
FBSLSETFORMCOLOR(ME, RGB(0, 255, 255)) ' Cyan: persistent background color
FBSL.GETDC(ME) ' Use volatile FBSL.GETDC below to avoid extra assignments
RESIZE(ME, 0, 0, 220, 220)
CENTER(ME)
SHOW(ME)
DIM Breadth AS I... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #Action.21 | Action! | INCLUDE "H6:RGBLINE.ACT" ;from task Bresenham's line algorithm
INCLUDE "H6:REALMATH.ACT"
RGB black,yellow,violet,blue
TYPE IntPoint=[INT x,y]
PROC CubicBezier(RgbImage POINTER img
IntPoint POINTER p1,p2,p3,p4 RGB POINTER col)
INT i,n=[20],prevX,prevY,nextX,nextY
REAL one,two,three,ri,rn,rt,ra,rb,rc,rd,tmp1,... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #Ada | Ada | procedure Cubic_Bezier
( Picture : in out Image;
P1, P2, P3, P4 : Point;
Color : Pixel;
N : Positive := 20
) is
Points : array (0..N) of Point;
begin
for I in Points'Range loop
declare
T : constant Float := Fl... |
http://rosettacode.org/wiki/Bitwise_IO | Bitwise IO | The aim of this task is to write functions (or create a class if your
language is Object Oriented and you prefer) for reading and writing sequences of
bits, most significant bit first. While the output of a asciiprint "STRING" is the ASCII byte sequence
"S", "T", "R", "I", "N", "G", the output of a "print" of the bits ... | #Z80_Assembly | Z80 Assembly | StoreBinaryString:
;INPUT:
; HL = SOURCE ADDRESS
; DE = OUTPUT STRING RAM
; BC = HOW MANY BYTES OF SOURCE DATA TO CONVERT
ld a,(hl)
push bc
ld b,a ;backup a for later
ld c,%10000000 ;a "revolving bit mask" is used to compare
; each bit of A, in sequence.
loop:
ld a,b ;restore A
and c
ld a,'0... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Rust | Rust | use std::path::Path;
use std::io::Write;
use std::fs::File;
pub struct RGB {
r: u8,
g: u8,
b: u8,
}
pub struct PPM {
height: u32,
width: u32,
data: Vec<u8>,
}
impl PPM {
pub fn new(height: u32, width: u32) -> PPM {
let size = 3 * height * width;
let buffer = vec![0; siz... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Scala | Scala | object Pixmap {
def save(bm:RgbBitmap, filename:String)={
val out=new DataOutputStream(new FileOutputStream(filename))
out.writeBytes("P6\u000a%d %d\u000a%d\u000a".format(bm.width, bm.height, 255))
for(y <- 0 until bm.height; x <- 0 until bm.width; c=bm.getPixel(x, y)){
out.writeByte(c... |
http://rosettacode.org/wiki/Bitcoin/public_point_to_address | Bitcoin/public point to address | Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.
The encoding steps are:
take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed st... | #C | C | #include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <openssl/sha.h>
#include <openssl/ripemd.h>
#define COIN_VER 0
const char *coin_err;
typedef unsigned char byte;
int is_hex(const char *s) {
int i;
for (i = 0; i < 64; i++)
if (!isxdigit(s[i])) return 0;
return 1;
}
void str_to_byte(const c... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #AutoHotkey | AutoHotkey | SetBatchLines, -1
CoordMode, Mouse
CoordMode, Pixel
CapsLock::
KeyWait, CapsLock
MouseGetPos, X, Y
PixelGetColor, color, X, Y
FloodFill(x, y, color, 0x000000, 1, "CapsLock")
MsgBox Done!
Return
FloodFill(x, y, target, replacement, mode=1, key="")
{
If GetKeyState(key, "P")
Return
PixelGetColor, color, x, y
... |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #Dc | Dc | #t // <boolean> true
#f // <boolean> false |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #Delphi | Delphi | #t // <boolean> true
#f // <boolean> false |
http://rosettacode.org/wiki/Caesar_cipher | Caesar cipher |
Task
Implement a Caesar cipher, both encoding and decoding.
The key is an integer from 1 to 25.
This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).
The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).
So key 2 encrypts "HI" to... | #TXR | TXR | @(next :args)
@(cases)
@{key /[0-9]+/}
@text
@(or)
@ (throw error "specify <key-num> <text>")
@(end)
@(do
(defvar k (int-str key 10)))
@(bind enc-dec
@(collect-each ((i (range 0 25)))
(let* ((p (tostringp (+ #\a i)))
(e (tostringp (+ #\a (mod (+ i k) 26))))
(P (upc... |
http://rosettacode.org/wiki/Box_the_compass | Box the compass | There be many a land lubber that knows naught of the pirate ways and gives direction by degree!
They know not how to box the compass!
Task description
Create a function that takes a heading in degrees and returns the correct 32-point compass heading.
Use the function to print and display a table of Index, Compass... | #BBC_BASIC | BBC BASIC | DIM bearing(32)
bearing() = 0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37, \
\ 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75, \
\ 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, \
\ 270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38
... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #Octave | Octave | function h = imagehistogram(imago)
if ( isgray(imago) )
for j = 0:255
h(j+1) = numel(imago( imago == j ));
endfor
else
error("histogram on gray img only");
endif
endfunction
% test
im = jpgread("Lenna100.jpg");
img = rgb2gray(im);
h = imagehistogram(img);
% let's try to show the histogram
bar(... |
http://rosettacode.org/wiki/Bitwise_operations | Bitwise operations |
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 |... | #Ada | Ada | with Ada.Text_IO, Interfaces;
use Ada.Text_IO, Interfaces;
procedure Bitwise is
subtype Byte is Unsigned_8;
package Byte_IO is new Ada.Text_Io.Modular_IO (Byte);
A : constant Byte := 2#00011110#;
B : constant Byte := 2#11110100#;
X : constant Byte := 128;
N : constant Natural := 1;
begin... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #Kotlin | Kotlin | // Version 1.2.40
import java.awt.Color
import java.awt.Graphics
import java.awt.image.BufferedImage
import kotlin.math.abs
import java.io.File
import javax.imageio.ImageIO
class Point(var x: Int, var y: Int)
class BasicBitmapStorage(width: Int, height: Int) {
val image = BufferedImage(width, height, Buffered... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #Forth | Forth | : circle { x y r color bmp -- }
1 r - 0 r 2* negate 0 r { f ddx ddy dx dy }
color x y r + bmp b!
color x y r - bmp b!
color x r + y bmp b!
color x r - y bmp b!
begin dx dy < while
f 0< 0= if
dy 1- to dy
ddy 2 + dup to ddy
f + to f
then
dx 1+ ... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #Fortran | Fortran | interface draw_circle
module procedure draw_circle_sc, draw_circle_rgb
end interface
private :: plot, draw_circle_toch |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #ALGOL_68 | ALGOL 68 | # -*- coding: utf-8 -*- #
cubic bezier OF class image :=
( REF IMAGE picture,
POINT p1, p2, p3, p4,
PIXEL color,
UNION(INT, VOID) in n
)VOID:
BEGIN
INT n = (in n|(INT n):n|20); # default 20 #
[0:n]POINT points;
FOR i FROM LWB points TO UPB points DO... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #BBC_BASIC | BBC BASIC | Width% = 200
Height% = 200
REM Set window size:
VDU 23,22,Width%;Height%;8,16,16,128
REM Draw cubic Bézier curve:
PROCbeziercubic(160,150, 10,120, 30,0, 150,50, 20, 0,0,0)
END
DEF PROCbeziercubic(x1,y1,x2,y2,x3,y3,x4,y4,n%,r%,g%,b%)
LOCAL i%, t, t1, a, b, c, d... |
http://rosettacode.org/wiki/Bitwise_IO | Bitwise IO | The aim of this task is to write functions (or create a class if your
language is Object Oriented and you prefer) for reading and writing sequences of
bits, most significant bit first. While the output of a asciiprint "STRING" is the ASCII byte sequence
"S", "T", "R", "I", "N", "G", the output of a "print" of the bits ... | #zkl | zkl | // stream of numBits sized ints to bytes, numBits<8
fcn toBytes(n,[(numBits,acc,bitsSoFar)]state){
acc=acc.shiftLeft(numBits) + n; bitsSoFar+=numBits;
reg r;
if(bitsSoFar>=8){
bitsSoFar-=8;
r=acc.shiftRight(bitsSoFar);
acc=acc.bitAnd((-1).shiftLeft(bitsSoFar).bitNot());
}
else r=Void... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Scheme | Scheme | (define (write-ppm image file)
(define (write-image image)
(define (write-row row)
(define (write-colour colour)
(if (not (null? colour))
(begin (write-char (integer->char (car colour)))
(write-colour (cdr colour)))))
(if (not (null? row))
(begin (write... |
http://rosettacode.org/wiki/Bitcoin/public_point_to_address | Bitcoin/public point to address | Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.
The encoding steps are:
take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed st... | #Common_Lisp | Common Lisp |
;;;; This is a revised version, inspired by a throwaway script originally
;;;; published at http://deedbot.org/bundle-381528.txt by the same Adlai.
;;; package definition
(cl:defpackage :bitcoin-address-encoder
(:use :cl . #.(ql:quickload :ironclad))
(:shadowing-import-from :ironclad #:null)
(:import-from :ir... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #BBC_BASIC | BBC BASIC | MODE 8
GCOL 15
CIRCLE FILL 640, 512, 500
GCOL 0
CIRCLE FILL 500, 600, 200
GCOL 3
PROCflood(600, 200, 15)
GCOL 4
PROCflood(600, 700, 0)
END
DEF PROCflood(X%, Y%, C%)
LOCAL L%, R%
IF POINT(X%,Y%) <> C% ENDPROC
L% = X%
R% = X%
... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #C | C | /*
* RosettaCode: Bitmap/Flood fill, language C, dialects C89, C99, C11.
*
* This is an implementation of the recursive algorithm. For the sake of
* simplicity, instead of reading files as JPEG, PNG, etc., the program
* read and write Portable Bit Map (PBM) files in plain text format.
* Portable Bit Map files c... |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #DWScript | DWScript | #t // <boolean> true
#f // <boolean> false |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #Dyalect | Dyalect | #t // <boolean> true
#f // <boolean> false |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #Dylan | Dylan | #t // <boolean> true
#f // <boolean> false |
http://rosettacode.org/wiki/Caesar_cipher | Caesar cipher |
Task
Implement a Caesar cipher, both encoding and decoding.
The key is an integer from 1 to 25.
This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).
The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).
So key 2 encrypts "HI" to... | #TypeScript | TypeScript | function replace(input: string, key: number) : string {
return input.replace(/([a-z])/g,
($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 97) % 26 + 97)
).replace(/([A-Z])/g,
($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 65) % 26 + 65));
}
// test
var str = 'The five boxing wizards jum... |
http://rosettacode.org/wiki/Box_the_compass | Box the compass | There be many a land lubber that knows naught of the pirate ways and gives direction by degree!
They know not how to box the compass!
Task description
Create a function that takes a heading in degrees and returns the correct 32-point compass heading.
Use the function to print and display a table of Index, Compass... | #Befunge | Befunge | >>::"}"9**\4+3%79*9*5-*79*9*5--+:5>>>06p:55+%68*+v
^_@#!`*84:+1<v*9"}"*+55,,,".",,,$$_^#!:-1g60/+55\<
>_06g:v>55+,^>/5+55+/48*::::,,,,%:1+.9,:06p48*\-0v
|p60-1<|<!p80:<N|Ev"northwest"0"North by west"0p8<
>:#,_>>>_08g1-^W|S>"-htroN"0"htron yb tsewhtroN"0v
#v"est-northwest"0"Northwest by west"0"Northwest"<
N>"W"0"htron y... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #Phix | Phix | -- demo\rosetta\Bitmap_Histogram.exw (runnable version)
include ppm.e -- black, white, read_ppm(), write_ppm() (covers above requirements)
function to_bw(sequence image)
sequence hist = repeat(0,256)
for x=1 to length(image) do
for y=1 to length(image[x]) do
integer pixel = image[x][y]... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #PHP | PHP |
define('src_name', 'input.jpg'); // source image
define('dest_name', 'output.jpg'); // destination image
$img = imagecreatefromjpeg(src_name); // read image
if(empty($img)){
echo 'Image could not be loaded!';
exit;
}
$black = imagecolorallocate($img, 0, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255... |
http://rosettacode.org/wiki/Bitwise_operations | Bitwise operations |
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 |... | #Aikido | Aikido | function bitwise(a, b){
println("a AND b: " + (a & b))
println("a OR b: "+ (a | b))
println("a XOR b: "+ (a ^ b))
println("NOT a: " + ~a)
println("a << b: " + (a << b)) // left shift
println("a >> b: " + (a >> b)) // arithmetic right shift
println("a >>> b: " + (a >>> b)) // logical right shift
} |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #Lua | Lua | Bitmap.quadraticbezier = function(self, x1, y1, x2, y2, x3, y3, nseg)
nseg = nseg or 10
local prevx, prevy, currx, curry
for i = 0, nseg do
local t = i / nseg
local a, b, c = (1-t)^2, 2*t*(1-t), t^2
prevx, prevy = currx, curry
currx = math.floor(a * x1 + b * x2 + c * x3 + 0.5)
curry = math.flo... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | pts = {{0, 0}, {1, -1}, {2, 1}};
Graphics[{BSplineCurve[pts], Green, Line[pts], Red, Point[pts]}] |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #FreeBASIC | FreeBASIC | ' version 15-10-2016
' compile with: fbc -s gui
' Variant with Integer-Based Arithmetic from Wikipedia page:
' Midpoint circle algorithm
Sub circle_(x0 As Integer, y0 As Integer , radius As Integer, Col As Integer)
Dim As Integer x = radius
Dim As Integer y
' Decision criterion divided by 2 evaluated at x=r, ... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #Go | Go | package raster
// Circle plots a circle with center x, y and radius r.
// Limiting behavior:
// r < 0 plots no pixels.
// r = 0 plots a single pixel at x, y.
// r = 1 plots four pixels in a diamond shape around the center pixel at x, y.
func (b *Bitmap) Circle(x, y, r int, p Pixel) {
if r < 0 {
return
... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #C | C | void cubic_bezier(
image img,
unsigned int x1, unsigned int y1,
unsigned int x2, unsigned int y2,
unsigned int x3, unsigned int y3,
unsigned int x4, unsigned int y4,
color_component r,
color_component g,
color_component b ); |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #D | D | import grayscale_image, bitmap_bresenhams_line_algorithm;
struct Pt { int x, y; } // Signed.
void cubicBezier(size_t nSegments=20, Color)
(Image!Color im,
in Pt p1, in Pt p2, in Pt p3, in Pt p4,
in Color color)
pure nothrow @nogc if (nSegments > 0) {
Pt[nSegment... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "draw.s7i";
include "color.s7i";
const proc: writePPM (in string: fileName, in PRIMITIVE_WINDOW: aWindow) is func
local
var file: ppmFile is STD_NULL;
var integer: x is 0;
var integer: y is 0;
var color: pixColor is black;
begin
ppmFile := open(fileName, "... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Sidef | Sidef | subset Int < Number {|n| n.is_int }
subset UInt < Int {|n| n >= 0 }
subset UInt8 < Int {|n| n ~~ ^256 }
struct Pixel {
R < UInt8,
G < UInt8,
B < UInt8
}
class Bitmap(width < UInt, height < UInt) {
has data = []
method fill(Pixel p) {
data = (width*height -> of { Pixel(p.R,... |
http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm | Bitmap/Bresenham's line algorithm | Task
Using the data storage type defined on the Bitmap page for raster graphics images,
draw a line given two points with Bresenham's line algorithm.
| #11l | 11l | T Colour
Byte r, g, b
F (r, g, b)
.r = r
.g = g
.b = b
F ==(other)
R .r == other.r & .g == other.g & .b == other.b
V black = Colour(0, 0, 0)
V white = Colour(255, 255, 255)
T Bitmap
Int width, height
Colour background
[[Colour]] map
F (width = 40, height = 40, back... |
http://rosettacode.org/wiki/Bitcoin/public_point_to_address | Bitcoin/public point to address | Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.
The encoding steps are:
take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed st... | #D | D | import std.stdio, std.algorithm, std.digest.ripemd, sha_256_2;
// A Bitcoin public point.
struct PPoint { ubyte[32] x, y; }
private enum bitcoinVersion = 0;
private enum RIPEMD160_digest_len = typeof("".ripemd160Of).length;
private alias sha = SHA256.digest;
alias Address = ubyte[1 + 4 + RIPEMD160_digest_len];
... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #C.23 | C# |
using System;
using System.Collections.Generic;
using System.Drawing;
namespace FloodFill
{
class Program
{
private static bool ColorMatch(Color a, Color b)
{
return (a.ToArgb() & 0xffffff) == (b.ToArgb() & 0xffffff);
}
static void FloodFill(Bitmap bmp, Point pt... |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #D.C3.A9j.C3.A0_Vu | Déjà Vu | ? if (true) { "a" } else { "b" }
# value: "a"
? if (false) { "a" } else { "b" }
# value: "b"
? if (90) { "a" } else { "b" }
# problem: the int 90 doesn't coerce to a boolean |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #E | E | ? if (true) { "a" } else { "b" }
# value: "a"
? if (false) { "a" } else { "b" }
# value: "b"
? if (90) { "a" } else { "b" }
# problem: the int 90 doesn't coerce to a boolean |
http://rosettacode.org/wiki/Caesar_cipher | Caesar cipher |
Task
Implement a Caesar cipher, both encoding and decoding.
The key is an integer from 1 to 25.
This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).
The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).
So key 2 encrypts "HI" to... | #UNIX_Shell | UNIX Shell | caesar() {
local OPTIND
local encrypt n=0
while getopts :edn: option; do
case $option in
e) encrypt=true ;;
d) encrypt=false ;;
n) n=$OPTARG ;;
:) echo "error: missing argument for -$OPTARG" >&2
return 1 ;;
?) echo "error: un... |
http://rosettacode.org/wiki/Box_the_compass | Box the compass | There be many a land lubber that knows naught of the pirate ways and gives direction by degree!
They know not how to box the compass!
Task description
Create a function that takes a heading in degrees and returns the correct 32-point compass heading.
Use the function to print and display a table of Index, Compass... | #C | C | #include <stdio.h>
int main()
{
int i, j;
double degrees[] = { 0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5,
84.37, 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88,
168.75, 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12,
253.13, 270.0, 286.87... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #PicoLisp | PicoLisp | (de histogram (Pgm)
(let H (need 256 0)
(for L Pgm
(for G L
(inc (nth H (inc G))) ) )
H ) ) |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #PureBasic | PureBasic | Procedure getHistogram(image, Array histogram(1))
Protected w = ImageWidth(image) - 1
Protected h = ImageHeight(image) - 1
Dim histogram(255) ;output
StartDrawing(ImageOutput(image))
For x = 0 To w
For y = 0 To h
lum = Red(Point(x, y)) ;the Green or Blue color components could be used also
... |
http://rosettacode.org/wiki/Bitwise_operations | Bitwise operations |
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 |... | #ALGOL_68 | ALGOL 68 | main:(
PRIO SLC = 8, SRC = 8; # SLC and SRC are not built in, define and overload them here #
OP SLC = (BITS b, INT rotate) BITS: b SHL rotate OR b SHR ( bits width - rotate );
OP SRC = (BITS b, INT rotate) BITS: b SHR rotate OR b SHL ( bits width - rotate );
# SRC and SRL are non-standard, but versions are b... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #MATLAB | MATLAB |
function bezierQuad(obj,pixel_0,pixel_1,pixel_2,color,varargin)
if( isempty(varargin) )
resolution = 20;
else
resolution = varargin{1};
end
%Calculate time axis
time = (0:1/resolution:1)';
timeMinus = 1-time;
%The formula for the curve is expanded for clarity, the lac... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #Nim | Nim | import bitmap
import bresenham
import lenientops
proc drawQuadraticBezier*(
image: Image; pt1, pt2, pt3: Point; color: Color; nseg: Positive = 20) =
var points = newSeq[Point](nseg + 1)
for i in 0..nseg:
let t = i / nseg
let a = (1 - t) * (1 - t)
let b = 2 * t * (1 - t)
let c = t * t
... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #OCaml | OCaml | let quad_bezier ~img ~color
~p1:(_x1, _y1)
~p2:(_x2, _y2)
~p3:(_x3, _y3) =
let (x1, y1, x2, y2, x3, y3) =
(float _x1, float _y1, float _x2, float _y2, float _x3, float _y3)
in
let bz t =
let a = (1.0 -. t) ** 2.0
and b = 2.0 *. t *. (1.0 -. t)
and c = t ** 2.0
in
le... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #Haskell | Haskell | module Circle where
import Data.List
type Point = (Int, Int)
-- Takes the center of the circle and radius, and returns the circle points
generateCirclePoints :: Point -> Int -> [Point]
generateCirclePoints (x0, y0) radius
-- Four initial points, plus the generated points
= (x0, y0 + radius) : (x0, y0 - radius... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #F.23 | F# |
/// Uses Vector<float> from Microsoft.FSharp.Math (in F# PowerPack)
module CubicBezier
/// Create bezier curve from p1 to p4, using the control points p2, p3
/// Returns the requested number of segments
let cubic_bezier (p1:vector) (p2:vector) (p3:vector) (p4:vector) segments =
[0 .. segments - 1]
|> Li... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #Factor | Factor | USING: arrays kernel locals math math.functions
rosettacode.raster.storage sequences ;
IN: rosettacode.raster.line
! this gives a function
:: (cubic-bezier) ( P0 P1 P2 P3 -- bezier )
[ :> x
1 x - 3 ^ P0 n*v
1 x - sq 3 * x * P1 n*v
1 x - 3 * x sq * P2 n*v
x 3 ^ P3 n*v
v+ v+... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #FBSL | FBSL | #DEFINE WM_LBUTTONDOWN 513
#DEFINE WM_CLOSE 16
FBSLSETTEXT(ME, "Bezier Cubic")
FBSLSETFORMCOLOR(ME, RGB(0, 255, 255)) ' Cyan: persistent background color
DRAWWIDTH(5) ' Adjust point size
FBSL.GETDC(ME) ' Use volatile FBSL.GETDC below to avoid extra assignments
RESIZE(ME, 0, 0, 235, 235)
CENTER(ME)
SHOW(ME)
DIM He... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Stata | Stata | mata
void writeppm(name, r, g, b) {
n = rows(r)
p = cols(r)
f = fopen(name, "w")
fput(f, "P3")
fput(f, strofreal(p) + " " + strofreal(n) + " 255")
for (i = 1; i <= n; i++) {
for (j = 1; j <= p; j++) {
fput(f, strofreal(r[i,j]) + " " + strofreal(g[i,j]) + " " + strofreal(b[i,j]))
}
}
fclose(f)
}
r = J(1... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Tcl | Tcl | package require Tk
proc output_ppm {image filename} {
$image write $filename -format ppm
}
set img [newImage 150 150]
fill $img red
setPixel $img green 40 40
output_ppm $img filename.ppm
# check the file format:
set fh [open filename.ppm]
puts [gets $fh] ;# ==> P6
puts [gets $fh] ;# ==> 150 150
puts [gets $fh... |
http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm | Bitmap/Bresenham's line algorithm | Task
Using the data storage type defined on the Bitmap page for raster graphics images,
draw a line given two points with Bresenham's line algorithm.
| #360_Assembly | 360 Assembly | * Bitmap/Bresenham's line algorithm - 13/05/2019
BRESENH CSECT
USING BRESENH,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST R13,4(R15) link backward
... |
http://rosettacode.org/wiki/Bitcoin/address_validation | Bitcoin/address validation | Bitcoin/address validation
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Write a program that takes a bitcoin address as argument,
and checks whether or not this address is valid.
A bitcoin address uses a base58 encoding, which uses an alphabet of th... | #Ada | Ada | with Ada.Exceptions, Interfaces;
with Ada.Streams;
use Ada.Exceptions, Interfaces;
use Ada.Streams;
package Bitcoin is
subtype BT_Raw_Addr is Stream_Element_Array(1..25);
subtype BT_Checksum is Stream_Element_Array(1..4);
subtype BT_Addr is String(1..34);
subtype Sha256String is String(1..64);
Inv... |
http://rosettacode.org/wiki/Bitcoin/public_point_to_address | Bitcoin/public point to address | Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.
The encoding steps are:
take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed st... | #Delphi | Delphi |
program Public_point_to_address;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Winapi.Windows,
DCPsha256,
DCPripemd160;
const
bitcoinVersion = 0;
type
TByteArray = array of Byte;
TA25 = TByteArray;
TPPoint = record
x, y: TByteArray;
constructor SetHex(xi, yi: ansistring);
end;
TA2... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #C.2B.2B | C++ | #ifndef PROCESSING_FLOODFILLALGORITHM_H_
#define PROCESSING_FLOODFILLALGORITHM_H_
#include <opencv2/opencv.hpp>
#include <string.h>
#include <queue>
using namespace cv;
using namespace std;
class FloodFillAlgorithm {
public:
FloodFillAlgorithm(Mat* image) :
image(image) {
}
virtual ~FloodFillA... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #D | D | import std.array, bitmap;
void floodFill(Color)(Image!Color img, in uint x, in uint y,
in Color color)
/*pure*/ nothrow in {
assert (y < img.ny && x < img.nx);
} body {
immutable target = img[x, y];
static struct Pos { uint x, y; }
auto stack = [Pos(x, y)];
while (!stack.em... |
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #EchoLisp | EchoLisp |
(not #t) → #f
(not #f) → #t
(not null) → #f
(not 0) → #f
|
http://rosettacode.org/wiki/Boolean_values | Boolean values | Task
Show how to represent the boolean states "true" and "false" in a language.
If other objects represent "true" or "false" in conditionals, note it.
Related tasks
Logical operations
| #EGL | EGL |
myBool boolean = 0;
SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));
myBool = 1;
SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));
myBool = 2;
SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));
myBool = false;
SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool))... |
http://rosettacode.org/wiki/Caesar_cipher | Caesar cipher |
Task
Implement a Caesar cipher, both encoding and decoding.
The key is an integer from 1 to 25.
This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).
The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).
So key 2 encrypts "HI" to... | #Ursa | Ursa | decl string mode
while (not (or (= mode "encode") (= mode "decode")))
out "encode/decode: " console
set mode (lower (in string console))
end while
decl string message
out "message: " console
set message (upper (in string console))
decl int key
out "key: " console
set key (in int console)
if (or (>... |
http://rosettacode.org/wiki/Box_the_compass | Box the compass | There be many a land lubber that knows naught of the pirate ways and gives direction by degree!
They know not how to box the compass!
Task description
Create a function that takes a heading in degrees and returns the correct 32-point compass heading.
Use the function to print and display a table of Index, Compass... | #C.23 | C# |
using System;
using System.Collections.Generic;
namespace BoxTheCompass
{
class Compass
{
string[] cp = new string[] {"North", "North by east", "North-northeast", "Northeast by north", "Northeast","Northeast by east",
"East-northeast", "East by north", "East", "East by south", "East-southeast"... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #Python | Python | from PIL import Image
# Open the image
image = Image.open("lena.jpg")
# Get the width and height of the image
width, height = image.size
# Calculate the amount of pixels
amount = width * height
# Total amount of greyscale
total = 0
# B/W image
bw_image = Image.new('L', (width, height), 0)
# Bitmap image
bm_image = ... |
http://rosettacode.org/wiki/Bitmap/Histogram | Bitmap/Histogram | Extend the basic bitmap storage defined on this page to support dealing with image histograms. The image histogram contains for each luminance the count of image pixels having this luminance. Choosing a histogram representation take care about the data type used for the counts. It must have range of at least 0..NxM, wh... | #Racket | Racket | #lang racket
(require racket/draw math/statistics racket/require
(filtered-in
(lambda (name) (regexp-replace #rx"unsafe-" name ""))
racket/unsafe/ops))
;; CIE formula as discussed in "Greyscale image" task
(define (L r g b)
;; In fact there is no need, statistically for L to be divided... |
http://rosettacode.org/wiki/Bitwise_operations | Bitwise operations |
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 |... | #ALGOL_W | ALGOL W | % performs bitwise and, or, not, left-shift and right shift on the integers n1 and n2 %
% Algol W does not have xor, arithmetic right shift, left rotate or right rotate %
procedure bitOperations ( integer value n1, n2 ) ;
begin
bits b1, b2;
% the Algol W bitwse operations operate on bits values, so we firs... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #Phix | Phix | -- demo\rosetta\Bitmap_BezierQuadratic.exw
include ppm.e -- black, green, red, white, new_image(), write_ppm(), bresLine() -- (covers above requirements)
function quadratic_bezier(sequence img, atom x1, y1, x2, y2, x3, y3, integer colour, segments)
sequence pts = repeat(0,segments*2)
for i=0 to segments*2-1 ... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #PicoLisp | PicoLisp | (scl 6)
(de quadBezier (Img N X1 Y1 X2 Y2 X3 Y3)
(let (R (* N N) X X1 Y Y1 DX 0 DY 0)
(for I N
(let (J (- N I) A (*/ 1.0 J J R) B (*/ 2.0 I J R) C (*/ 1.0 I I R))
(brez Img X Y
(setq DX (- (+ (*/ A X1 1.0) (*/ B X2 1.0) (*/ C X3 1.0)) X))
(setq DY (- ... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Quadratic | Bitmap/Bézier curves/Quadratic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve
(definition on Wikipedia).
| #PureBasic | PureBasic | Procedure quad_bezier(img, p1x, p1y, p2x, p2y, p3x, p3y, Color, n_seg)
Protected i
Protected.f T, t1, a, b, c, d
Dim pts.POINT(n_seg)
For i = 0 To n_seg
T = i / n_seg
t1 = 1.0 - T
a = Pow(t1, 2)
b = 2.0 * T * t1
c = Pow(T, 2)
pts(i)\x = a * p1x + b * p2x + c * p3x
pts(i)\y = a * p1... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #J | J | NB.*getBresenhamCircle v Returns points for a circle given center and radius
NB. y is: y0 x0 radius
getBresenhamCircle=: monad define
'y0 x0 radius'=. y
x=. 0
y=. radius
f=. -. radius
pts=. 0 2$0
while. x <: y do.
pts=. pts , y , x
if. f >: 0 do.
y=. <:y
f=. f + _2 * y
end.
x=. >... |
http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm | Bitmap/Midpoint circle algorithm | Task
Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm (also known as Bresenham's circle algorithm).
(definition on Wikipedia).
| #Java | Java |
import java.awt.Color;
public class MidPointCircle {
private BasicBitmapStorage image;
public MidPointCircle(final int imageWidth, final int imageHeight) {
this.image = new BasicBitmapStorage(imageWidth, imageHeight);
}
private void drawCircle(final int centerX, final int centerY, final int radius) {
in... |
http://rosettacode.org/wiki/Bitmap/B%C3%A9zier_curves/Cubic | Bitmap/Bézier curves/Cubic | Using the data storage type defined on this page for raster images, and the draw_line function defined in this other one, draw a cubic bezier curve
(definition on Wikipedia).
| #Fortran | Fortran | subroutine cubic_bezier(img, p1, p2, p3, p4, color)
type(rgbimage), intent(inout) :: img
type(point), intent(in) :: p1, p2, p3, p4
type(rgb), intent(in) :: color
integer :: i, j
real :: pts(0:N_SEG,0:1), t, a, b, c, d, x, y
do i = 0, N_SEG
t = real(i) / real(N_SEG)
a = (1.0 - t)**3.0
b = ... |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #UNIX_Shell | UNIX Shell | function write {
_.to_s > "$1"
} |
http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file | Bitmap/Write a PPM file | Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
| #Vedit_macro_language | Vedit macro language | /////////////////////////////////////////////////////////////////////
//
// Save image as PPM file.
// @10 = filename. Buffer #10 contains the Pixel data.
//
:SAVE_PPM:
Buf_Switch(#10)
BOF
IT("P6") IN
Num_Ins(#11, LEFT) // width of image
Num_Ins(#12, LEFT) // height of image
Num_Ins(255, LEFT+NOCR) // maxval
I... |
http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm | Bitmap/Bresenham's line algorithm | Task
Using the data storage type defined on the Bitmap page for raster graphics images,
draw a line given two points with Bresenham's line algorithm.
| #Action.21 | Action! | INCLUDE "H6:RGBLINE.ACT" ;from task Bresenham's line algorithm
RGB black,yellow,violet,blue
PROC DrawImage(RgbImage POINTER img BYTE x,y)
RGB POINTER ptr
BYTE i,j
ptr=img.data
FOR j=0 TO img.h-1
DO
FOR i=0 TO img.w-1
DO
IF RgbEqual(ptr,yellow) THEN
Color=1
ELSEIF RgbEqual(ptr... |
http://rosettacode.org/wiki/Bitcoin/address_validation | Bitcoin/address validation | Bitcoin/address validation
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Write a program that takes a bitcoin address as argument,
and checks whether or not this address is valid.
A bitcoin address uses a base58 encoding, which uses an alphabet of th... | #C | C | #include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
const char *coin_err;
#define bail(s) { coin_err = s; return 0; }
int unbase58(const char *s, unsigned char *out) {
static const char *tmpl = "123456789"
"ABCDEFGHJKLMNPQRSTUVWXYZ"
"abcdefghijkmnopqrstuvwxyz";
int i, j, c;
const char *p;
mems... |
http://rosettacode.org/wiki/Bitcoin/public_point_to_address | Bitcoin/public point to address | Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.
The encoding steps are:
take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed st... | #Factor | Factor | USING: checksums checksums.ripemd checksums.sha io.binary kernel
math sequences ;
IN: rosetta-code.bitcoin.point-address
CONSTANT: ALPHABET "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
: btc-checksum ( bytes -- checksum-bytes )
2 [ sha-256 checksum-bytes ] times 4 head ;
: bigint>base58 ( n --... |
http://rosettacode.org/wiki/Bitcoin/public_point_to_address | Bitcoin/public point to address | Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.
The encoding steps are:
take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed st... | #Go | Go | package main
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"golang.org/x/crypto/ripemd160"
)
// Point is a type for a bitcoin public point.
type Point struct {
x, y [32]byte
}
// SetHex takes two hexidecimal strings and decodes them into the receiver.
func (p *Point) SetHex(x, y... |
http://rosettacode.org/wiki/Bitmap/Flood_fill | Bitmap/Flood fill | Implement a flood fill.
A flood fill is a way of filling an area using color banks to define the contained area or a target color which "determines" the area (the valley that can be flooded; Wikipedia uses the term target color). It works almost like a water flooding from a point towards the banks (or: inside the vall... | #Delphi | Delphi | def floodFill(image, x, y, newColor) {
def matchColor := image[x, y]
def w := image.width()
def h := image.height()
/** For any given pixel x,y, this algorithm first fills a contiguous
horizontal line segment of pixels containing that pixel, then
recursively scans the two adjacent rows over the s... |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.