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/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Julia | Julia | using Images, FileIO, Netpbm
rgbimg = load("data/bitmapInputTest.ppm")
greyimg = Gray.(rgbimg)
save("data/bitmapOutputTest.ppm", greyimg) |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Kotlin | Kotlin | // Version 1.2.40
import java.awt.Color
import java.awt.Graphics
import java.awt.image.BufferedImage
import java.io.FileInputStream
import java.io.PushbackInputStream
import java.io.File
import javax.imageio.ImageIO
class BasicBitmapStorage(width: Int, height: Int) {
val image = BufferedImage(width, height, Buf... |
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
| #360_Assembly | 360 Assembly | FALSE DC X'00'
TRUE DC X'FF' |
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
| #6502_Assembly | 6502 Assembly | clr bit ; clears
setb bit ; sets |
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... | #Red | Red |
Red ["Ceasar Cipher"]
rot: func [
char [char!]
key [number!]
ofs [char!]
][
to-char key + char - ofs // 26 + ofs
]
caesar: function [
src [string!]
key [integer!]
][
lower: charset [#"a" - #"z"]
upper: charset [#"A" - #"Z"]
parse src [
any [
change s: [... |
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 ... | #Delphi | Delphi |
program Bitwise_IO;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Classes;
type
TBitReader = class
private
readData: Cardinal;
startPosition: Integer;
endPosition: Integer;
Stream: TStream;
procedure Align;
function BaseStream: TStream;
procedure EnsureData(bitCount: Intege... |
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.)
| #Euphoria | Euphoria | constant dimx = 800, dimy = 800
constant fn = open("first.ppm","wb") -- b - binary mode
sequence color
printf(fn, "P6\n%d %d\n255\n", {dimx,dimy})
for j = 0 to dimy-1 do
for i = 0 to dimx-1 do
color = {
remainder(i,256), -- red
remainder(j,256), -- green
remainder(i*j,256... |
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.)
| #FBSL | FBSL | #ESCAPECHARS ON
DIM bmpin = ".\\LenaClr.bmp", ppmout = ".\\Lena.ppm", bmpblob = 54 ' Size of BMP file headers
FILEGET(FILEOPEN(bmpin, BINARY), FILELEN(bmpin)): FILECLOSE(FILEOPEN) ' Fill buffer
DIM ppmheader AS STRING * 256, breadth, height
LET(breadth, height) = 128 ' Image width and height
SPRINTF(ppmheader, "P6\... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Lua | Lua | function Read_PPM( filename )
local fp = io.open( filename, "rb" )
if fp == nil then return nil end
local data = fp:read( "*line" )
if data ~= "P6" then return nil end
repeat
data = fp:read( "*line" )
until string.find( data, "#" ) == nil
local image = {}
local size_x, ... |
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
| #68000_Assembly | 68000 Assembly | clr bit ; clears
setb bit ; sets |
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
| #8051_Assembly | 8051 Assembly | clr bit ; clears
setb bit ; sets |
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... | #Retro | Retro | {{
variable offset
: rotate ( cb-c ) tuck - @offset + 26 mod + ;
: rotate? ( c-c )
dup 'a 'z within [ 'a rotate ] ifTrue
dup 'A 'Z within [ 'A rotate ] ifTrue ;
---reveal---
: ceaser ( $n-$ )
!offset dup [ [ @ rotate? ] sip ! ] ^types'STRING each@ ;
}}
( Example )
"THEYBROKEOURCIPHEREVERYONECA... |
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 ... | #Erlang | Erlang | -module(bitwise_io).
-compile([export_all]).
%% Erlang allows for easy manipulation of bitstrings. Here I'll
%% present a function that can take a message of 8-bit ASCII
%% characters and remove the MSB, leaving the same message in 7-bits.
compress(Message) ->
<< <<X:7>> || <<X:8>> <= Message >>.
%% Here we d... |
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.)
| #Forth | Forth | : write-ppm { bmp fid -- }
s" P6" fid write-line throw
bmp bdim swap
0 <# bl hold #s #> fid write-file throw
0 <# #s #> fid write-line throw
s" 255" fid write-line throw
bmp bdata bmp bdim * pixels
bounds do
i 3 fid write-file throw
pixel +loop ;
s" red... |
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.)
| #Fortran | Fortran | program main
use rgbimage_m
implicit none
integer :: nx, ny, i, j, k
type(rgbimage) :: im
! init image of height nx, width ny
nx = 400
ny = 300
call im%init(nx, ny)
! set some random pixel data
do i = 1, nx
do j = 1, ny
call im%set_pixel(i, j, [(nint(rand()*255), k=1,3)])
e... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #M2000_Interpreter | M2000 Interpreter |
Module Checkit {
Function Bitmap {
If match("NN") then {
Read x as long, y as long
} else.if Match("N") Then {
\\ is a file?
Read f
if not Eof(f) then {
Line Input #f, p3$
... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Mathematica.2F_Wolfram_Language | Mathematica/ Wolfram Language | Import["file.ppm","PPM"]
|
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
| #8th | 8th |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program boolean.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.... |
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
| #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program boolean.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.... |
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... | #REXX | REXX | /*REXX program supports the Caesar cypher for the Latin alphabet only, no punctuation */
/*──────────── or blanks allowed, all lowercase Latin letters are treated as uppercase.*/
parse arg key .; arg . p /*get key & uppercased text to be used.*/
p= space(p, 0) ... |
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 ... | #Forth | Forth | \ writing
: init-write ( -- b m ) 0 128 ;
: flush-bits ( b m -- 0 128 ) drop emit init-write ;
: ?flush-bits ( b m -- b' m' ) dup 128 < if flush-bits then ;
: write-bit ( b m f -- b' m' )
if tuck or swap then
2/ dup 0= if flush-bits then ;
\ reading
: init-read ( -- b m ) key 128 ;
: eof? ( b m -- b m... |
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 ... | #Go | Go | // Package bit provides bit-wise IO to an io.Writer and from an io.Reader.
package bit
import (
"bufio"
"errors"
"io"
)
// Order specifies the bit ordering within a byte stream.
type Order int
const (
// LSB is for Least Significant Bits first
LSB Order = iota
// MSB is for Most Significa... |
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.)
| #GAP | GAP | # Dirty implementation
# Only P3 format, an image is a list of 3 matrices (r, g, b)
# Max color is always 255
WriteImage := function(name, img)
local f, r, g, b, i, j, maxcolor, nrow, ncol, dim;
f := OutputTextFile(name, false);
r := img[1];
g := img[2];
b := img[3];
dim := DimensionsMat(r);
nrow := dim[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.)
| #Go | Go | package raster
import (
"fmt"
"io"
"os"
)
// WriteTo outputs 8-bit P6 PPM format to an io.Writer.
func (b *Bitmap) WritePpmTo(w io.Writer) (err error) {
// magic number
if _, err = fmt.Fprintln(w, "P6"); err != nil {
return
}
// comments
for _, c := range b.Comments {
... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Nim | Nim | import strutils
import bitmap
import streams
type FormatError = object of CatchableError
# States used to parse the header.
type State = enum waitingMagic, waitingWidth, waitingHeight, waitingColors
#---------------------------------------------------------------------------------------------------
iterator tok... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #OCaml | OCaml | let read_ppm ~filename =
let ic = open_in filename in
let line = input_line ic in
if line <> "P6" then invalid_arg "not a P6 ppm file";
let line = input_line ic in
let line =
try if line.[0] = '#' (* skip comments *)
then input_line ic
else line
with _ -> line
in
let width, height =
S... |
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
| #ACL2 | ACL2 | PROC Test(BYTE v)
PrintF("Variable v has value %B%E",v)
IF v THEN
PrintE("Condition IF v is satisfied.")
ELSE
PrintE("Condition IF v is not satisfied.")
FI
IF v=0 THEN
PrintE("Condition IF v=0 is satisfied.")
ELSE
PrintE("Condition IF v=0 is not satisfied.")
FI
IF v<>0 THEN
PrintE("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
| #Action.21 | Action! | PROC Test(BYTE v)
PrintF("Variable v has value %B%E",v)
IF v THEN
PrintE("Condition IF v is satisfied.")
ELSE
PrintE("Condition IF v is not satisfied.")
FI
IF v=0 THEN
PrintE("Condition IF v=0 is satisfied.")
ELSE
PrintE("Condition IF v=0 is not satisfied.")
FI
IF v<>0 THEN
PrintE("C... |
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... | #Ring | Ring |
# Project : Caesar cipher
cipher = "pack my box with five dozen liquor jugs"
abc = "abcdefghijklmnopqrstuvwxyz"
see "text is to be encrypted:" + nl
see cipher+ nl + nl
str = ""
key = random(24) + 1
see "key = " + key + nl + nl
see "encrypted:" + nl
caesarencode(cipher, key)
see str + nl + nl
cipher = str
see "decry... |
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 ... | #Haskell | Haskell | import Data.List
import Data.Char
import Control.Monad
import Control.Arrow
import System.Environment
int2bin :: Int -> [Int]
int2bin = unfoldr(\x -> if x==0 then Nothing
else Just (uncurry(flip(,)) (divMod x 2)))
bin2int :: [Int] -> Int
bin2int = foldr ((.(2 *)).(+)) 0
bitReader = map ... |
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.)
| #Haskell | Haskell | {-# LANGUAGE ScopedTypeVariables #-}
module Bitmap.Netpbm(readNetpbm, writeNetpbm) where
import Bitmap
import Data.Char
import System.IO
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
nil :: a
nil = undefined
readNetpbm :: forall c. Color c => FilePath -> IO (Image RealWorld c)
readNetpbm pat... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Oz | Oz | functor
import
Bitmap
Open
export
Read
%% Write
define
fun {Read Filename}
F = {New Open.file init(name:Filename)}
fun {ReadColor8 _}
Bytes = {F read(list:$ size:3)}
in
{List.toTuple color Bytes}
end
fun {ReadColor16 _}
Bytes = {F read(list:$ size:6)}
in
{L... |
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
| #Ada | Ada | type Boolean is (False, True); |
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
| #ALGOL_68 | ALGOL 68 | BOOL f = FALSE, t = TRUE;
[]BOOL ft = (f, t);
STRING or = " or ";
FOR key TO UPB ft DO
BOOL val = ft[key];
UNION(VOID, INT) void = (val|666|EMPTY);
REF STRING ref = (val|HEAP STRING|NIL);
INT int = ABS val;
REAL real = ABS val;
COMPL compl = ABS val;
BITS bits = BIN ABS val; # or bitspack(val); #
BYTE... |
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... | #Ruby | Ruby | class String
ALFABET = ("A".."Z").to_a
def caesar_cipher(num)
self.tr(ALFABET.join, ALFABET.rotate(num).join)
end
end
#demo:
encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3)
decrypted = encypted.caesar_cipher(-3)
|
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 ... | #J | J | bitReader =: a. {~ _7 #.\ ({.~ <.&.(%&7)@#)
bitWriter =: , @ ((7$2) & #: @ (a.&i.)), 0 $~ 8 | # |
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 ... | #Julia | Julia |
function compress7(inio, outio)
nextwritebyte = read(inio, UInt8) & 0x7f
filled = 7
while !eof(inio)
inbyte = read(inio, UInt8)
write(outio, UInt8(nextwritebyte | inbyte << filled))
nextwritebyte = inbyte >> (8 - filled)
filled = (filled + 7) % 8
if filled == 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.)
| #J | J | require 'files'
NB. ($x) is height, width, colors per pixel
writeppm=:dyad define
header=. 'P6',LF,(":1 0{$x),LF,'255',LF
(header,,x{a.) fwrite y
) |
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.)
| #Java | Java | import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class PPMWriter {
public void bitmapToPPM(File file, BasicBitmapStorage bitmap) throws IOException {
file.delete();
try (var o... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Perl | Perl | #! /usr/bin/perl
use strict;
use Image::Imlib2;
my $img = Image::Imlib2->load("out0.ppm");
# let's do something with it now
$img->set_color(255, 255, 255, 255);
$img->draw_line(0,0, $img->width,$img->height);
$img->image_set_format("png");
$img->save("out1.png");
exit 0; |
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
| #ALGOL_W | ALGOL W |
1 ^ 1
1
1 ^ 0
0
|
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
| #APL | APL |
1 ^ 1
1
1 ^ 0
0
|
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... | #Run_BASIC | Run BASIC | input "Gimme a ofset:";ofst ' set any offset you like
a$ = "Pack my box with five dozen liquor jugs"
print " Original: ";a$
a$ = cipher$(a$,ofst)
print "Encrypted: ";a$
print "Decrypted: ";cipher$(a$,ofst+6)
FUNCTION cipher$(a$,ofst)
for i = 1 to len(a$)
aa$ = mid$(a$,i,1)
code$ = " "
if aa$ <> " " th... |
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 ... | #Kotlin | Kotlin | // version 1.2.31
import java.io.File
class BitFilter(val f: File, var accu: Int = 0, var bits: Int = 0) {
private val bw = f.bufferedWriter()
private val br = f.bufferedReader()
fun write(buf: ByteArray, start: Int, _nBits: Int, _shift: Int) {
var nBits = _nBits
var index = start + ... |
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.)
| #Julia | Julia | using Images, FileIO
h, w = 50, 70
img = zeros(RGB{N0f8}, h, w)
img[10:40, 5:35] = colorant"skyblue"
for i in 26:50, j in (i-25):40
img[i, j] = colorant"sienna1"
end
save("data/bitmapWrite.ppm", img)
save("data/bitmapWrite.png", img) |
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.)
| #Kotlin | Kotlin | // Version 1.2.40
import java.awt.Color
import java.awt.Graphics
import java.awt.image.BufferedImage
import java.io.FileOutputStream
class BasicBitmapStorage(width: Int, height: Int) {
val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)
fun fill(c: Color) {
val g = image.graphic... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Phix | Phix | -- demo\rosetta\Bitmap_read_ppm.exw (runnable version)
function read_ppm(string filename)
sequence image, line
integer dimx, dimy, maxcolor
atom fn = open(filename, "rb")
if fn<0 then
return -1 -- unable to open
end if
line = gets(fn)
if line!="P6\n" then
return -1 -- only ppm6 files a... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #PicoLisp | PicoLisp | (de ppmRead (File)
(in File
(unless (and `(hex "5036") (rd 2)) # P6
(quit "Wrong file format" File) )
(rd 1)
(let (DX 0 DY 0 Max 0 C)
(while (>= 9 (setq C (- (rd 1) `(char "0"))) 0)
(setq DX (+ (* 10 DX) C)) )
(while (>= 9 (setq C (- (rd 1) `(char "0"))) 0... |
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
| #AppleScript | AppleScript | 1 > 2 --> false
not false --> true
{true as integer, false as integer, 1 as boolean, 0 as boolean}
--> {1, 0, true, false}
true = 1 --> 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
| #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program areaString.s */
/* Constantes */
@ The are no TRUE or FALSE constants in ARM Assembly
.equ FALSE, 0 @ or other value
.equ TRUE, 1 @ or other value
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux sy... |
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... | #Rust | Rust | use std::io::{self, Write};
use std::fmt::Display;
use std::{env, process};
fn main() {
let shift: u8 = env::args().nth(1)
.unwrap_or_else(|| exit_err("No shift provided", 2))
.parse()
.unwrap_or_else(|e| exit_err(e, 3));
let plain = get_input()
.unwrap_or_else(|e| exit_err(&... |
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 ... | #Lingo | Lingo | -- parent script "BitArray"
property ancestor
property bitSize
property _pow2
----------------------------------------
-- @constructor
-- @param {integer} [bSize=0]
----------------------------------------
on new (me, bSize)
if voidP(bitSize) then bitSize=0
me.bitSize = bSize
byteSize = bitSize/8 + (bitSize m... |
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 ... | #Lua | Lua | local function BitWriter() return {
accumulator = 0, -- For current byte.
bitCount = 0, -- Bits set in current byte.
outChars = {},
-- writer:writeBit( bit )
writeBit = function(writer, bit)
writer.bitCount = writer.bitCount + 1
if bit > 0 then
writer.accumulator ... |
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.)
| #Lua | Lua |
-- helper function, simulates PHP's array_fill function
local array_fill = function(vbegin, vend, value)
local t = {}
for i=vbegin, vend do
t[i] = value
end
return t
end
Bitmap = {}
Bitmap.__index = Bitmap
function Bitmap.new(width, height)
local self = {}
setmetatable(self, Bitm... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #PL.2FI | PL/I |
/* BITMAP FILE: read in a file in PPM format, P6 (binary). 14/5/2010 */
test: procedure options (main);
declare (m, n, max_color, i, j) fixed binary (31);
declare ch character (1), ID character (2);
declare 1 pixel union,
2 color bit(24) aligned,
2 primary_colors,
3 R 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
| #Arturo | Arturo | a: true
b: false
if? a [ print "yep" ] else [ print "nope" ]
if? b -> print "nope"
else -> print "yep" |
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... | #Scala | Scala | object Caesar {
private val alphaU='A' to 'Z'
private val alphaL='a' to 'z'
def encode(text:String, key:Int)=text.map{
case c if alphaU.contains(c) => rot(alphaU, c, key)
case c if alphaL.contains(c) => rot(alphaL, c, key)
case c => c
}
def decode(text:String, key:Int)=encode(text,-key)
privat... |
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 ... | #MIPS_Assembly | MIPS Assembly | type
BitWriter * = tuple
file: File
bits: uint8
nRemain: int
BitReader * = tuple
file: File
bits: uint8
nRemain: int
nRead: int
proc newBitWriter * (file: File) : ref BitWriter =
result = new BitWriter
result.file = file
result.bits = 0
result.nRemain = 8
proc flushBits (st... |
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 ... | #Nim | Nim | type
BitWriter * = tuple
file: File
bits: uint8
nRemain: int
BitReader * = tuple
file: File
bits: uint8
nRemain: int
nRead: int
proc newBitWriter * (file: File) : ref BitWriter =
result = new BitWriter
result.file = file
result.bits = 0
result.nRemain = 8
proc flushBits (st... |
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.)
| #LiveCode | LiveCode |
export image "test" to file "~/Test.PPM" as paint -- paint format is one of PBM, PGM, or PPM
|
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.)
| #M2000_Interpreter | M2000 Interpreter |
Module Checkit {
Function Bitmap (x as long, y as long) {
if x<1 or y<1 then Error "Wrong dimensions"
structure rgb {
red as byte
green as byte
blue as byte
}
m=len(rgb)*x mod 4
if m>0 then m=4-m ... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #PureBasic | PureBasic | Structure PPMColor
r.c
g.c
b.c
EndStructure
Procedure LoadImagePPM(Image, file$)
; Author Roger Rösch (Nickname Macros)
IDFile = ReadFile(#PB_Any, file$)
If IDFile
If CreateImage(Image, 1, 1)
Format$ = ReadString(IDFile)
ReadString(IDFile) ; skip comment
Dimensions$ = ReadString(IDFi... |
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
| #AutoHotkey | AutoHotkey | BEGIN {
# Do not put quotes round the numeric values, or the tests will fail
a = 1 # True
b = 0 # False
# Boolean evaluations
if (a) { print "first test a is true" } # This should print
if (b) { print "second test b is true" } # This should not print
if (!a) { print "third test... |
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
| #Avail | Avail | BEGIN {
# Do not put quotes round the numeric values, or the tests will fail
a = 1 # True
b = 0 # False
# Boolean evaluations
if (a) { print "first test a is true" } # This should print
if (b) { print "second test b is true" } # This should not print
if (!a) { print "third test... |
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... | #Scheme | Scheme | ;
; Works with R7RS-compatible Schemes (e.g. Chibi).
; Also current versions of Chicken, Gauche and Kawa.
;
(cond-expand
(chicken (use srfi-13))
(gauche (use srfi-13))
(kawa (import (srfi :13)))
(else (import (scheme base) (scheme write)))) ; R7RS
(define msg "The quick brown fox jumps over the lazy ... |
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 ... | #OCaml | OCaml | let write_7bit_string ~filename ~str =
let oc = open_out filename in
let ob = IO.output_bits(IO.output_channel oc) in
String.iter (fun c -> IO.write_bits ob 7 (int_of_char c)) str;
IO.flush_bits ob;
close_out oc;
;; |
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 ... | #Perl | Perl | #! /usr/bin/perl
use strict;
# $buffer = write_bits(*STDOUT, $buffer, $number, $bits)
sub write_bits( $$$$ )
{
my ($out, $l, $num, $q) = @_;
$l .= substr(unpack("B*", pack("N", $num)),
-$q);
if ( (length($l) > 8) ) {
my $left = substr($l, 8);
print $out pack("B8", $l);
$l = $left;
... |
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.)
| #Mathematica.2F_Wolfram_Language | Mathematica/ Wolfram Language | Export["file.ppm",image,"PPM"] |
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.)
| #MATLAB_.2F_Octave | MATLAB / Octave | R=[255,0,0;255,255,0];
G=[0,255,0;255,255,0];
B=[0,0,255;0,0,0];
r = R'; r(:);
g = R'; g(:);
b = R'; b(:);
fid=fopen('p6.ppm','w');
fprintf(fid,'P6\n%i %i\n255\n',size(R));
fwrite(fid,[r,g,b]','uint8');
fclose(fid); |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Python | Python | # With help from http://netpbm.sourceforge.net/doc/ppm.html
# String masquerading as ppm file (version P3)
import io
ppmtxt = '''P3
# feep.ppm
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 ... |
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
| #AWK | AWK | BEGIN {
# Do not put quotes round the numeric values, or the tests will fail
a = 1 # True
b = 0 # False
# Boolean evaluations
if (a) { print "first test a is true" } # This should print
if (b) { print "second test b is true" } # This should not print
if (!a) { print "third test... |
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
| #Axe | Axe | 10 LET A%=0
20 LET B%=NOT(A%)
30 PRINT "THIS VERSION OF BASIC USES"
40 PRINT B%; " AS ITS TRUE VALUE"
50 IF A% THEN PRINT "TEST ONE DOES NOT PRINT"
60 IF B% THEN PRINT "TEST TWO DOES PRINT"
70 IF A%=0 THEN PRINT "TEST THREE (FALSE BY COMPARISON) DOES PRINT"
80 IF B%=0 THEN PRINT "TEST FOUR (FALSE BY COMPARISON) DOES NO... |
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... | #sed | sed | #!/bin/sed -rf
# Input: <number 0..25>\ntext to encode
/^[0-9]+$/ {
# validate a number and translate it to analog form
s/$/;9876543210dddddddddd/
s/([0-9]);.*\1.{10}(.?)/\2/
s/2/11/
s/1/dddddddddd/g
/[3-9]|d{25}d+/ {
s/.*/Error: Key must be <= 25/
q
}
# append from-table
s/$/\nabcdefghijklmnopqrstuvwxyzAB... |
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... | #Action.21 | Action! | INCLUDE "H6:LOADPPM5.ACT"
DEFINE HISTSIZE="256"
PROC PutBigPixel(INT x,y BYTE col)
IF x>=0 AND x<=79 AND y>=0 AND y<=47 THEN
y==LSH 2
col==RSH 4
IF col<0 THEN col=0
ELSEIF col>15 THEN col=15 FI
Color=col
Plot(x,y)
DrawTo(x,y+3)
FI
RETURN
PROC DrawImage(GrayImage POINTER image INT x... |
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 ... | #Phix | Phix | without js -- (file i/o)
enum FN, V, BITS -- fields of a bitwiseioreader/writer
function new_bitwiseio(string filename, mode)
integer fn = open(filename,mode)
return {fn,0,0} -- ie {FN,V=0,BITS=0}
end function
function new_bitwiseiowriter(string filename)
return new_bitwiseio(filename,"wb")
end func... |
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.)
| #Modula-3 | Modula-3 | INTERFACE PPM;
IMPORT Bitmap, Pathname;
PROCEDURE Create(imgfile: Pathname.T; img: Bitmap.T);
END PPM. |
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.)
| #Nim | Nim | import bitmap
import streams
#---------------------------------------------------------------------------------------------------
proc writePPM*(img: Image, stream: Stream) =
## Write an image to a PPM stream.
stream.writeLine("P6 ", $img.w, " ", $img.h, " 255")
for x, y in img.indices:
stream.write(c... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Racket | Racket |
#lang racket
(require racket/draw)
(define (read-ppm port)
(parameterize ([current-input-port port])
(define magic (read))
(define width (read))
(define height (read))
(define maxcol (read))
(define bm (make-object bitmap% width height))
(define dc (new bitmap-dc% [bitmap bm]))
(send d... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #Raku | Raku | class Pixel { has UInt ($.R, $.G, $.B) }
class Bitmap {
has UInt ($.width, $.height);
has Pixel @.data;
}
role PGM {
has @.GS;
method P5 returns Blob {
"P5\n{self.width} {self.height}\n255\n".encode('ascii')
~ Blob.new: self.GS
}
}
sub load-ppm ( $ppm ) {
my $fh = $ppm.IO.open( :enc('IS... |
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
| #BASIC | BASIC | 10 LET A%=0
20 LET B%=NOT(A%)
30 PRINT "THIS VERSION OF BASIC USES"
40 PRINT B%; " AS ITS TRUE VALUE"
50 IF A% THEN PRINT "TEST ONE DOES NOT PRINT"
60 IF B% THEN PRINT "TEST TWO DOES PRINT"
70 IF A%=0 THEN PRINT "TEST THREE (FALSE BY COMPARISON) DOES PRINT"
80 IF B%=0 THEN PRINT "TEST FOUR (FALSE BY COMPARISON) DOES NO... |
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
| #Batch_File | Batch File |
@echo off
::true
set "a=x"
::false
set "b="
if defined a (
echo a is true
) else (
echo a is false
)
if defined b (
echo b is true
) else (
echo b is false
)
pause>nul
|
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const func string: rot (in string: stri, in integer: encodingKey) is func
result
var string: encodedStri is "";
local
var char: ch is ' ';
var integer: index is 0;
begin
encodedStri := stri;
for ch key index range stri do
if ch >= 'a' and ch <= 'z' then
... |
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... | #Ada | Ada | type Pixel_Count is mod 2**64;
type Histogram is array (Luminance) of Pixel_Count;
function Get_Histogram (Picture : Grayscale_Image) return Histogram is
Result : Histogram := (others => 0);
begin
for I in Picture'Range (1) loop
for J in Picture'Range (2) loop
declare
Count : Pixel_Co... |
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... | #BBC_BASIC | BBC BASIC | INSTALL @lib$+"SORTLIB"
Sort% = FN_sortinit(0,0)
Width% = 200
Height% = 200
VDU 23,22,Width%;Height%;8,16,16,128
*display c:\lenagrey
DIM hist%(255), idx%(255)
FOR i% = 0 TO 255 : idx%(i%) = i% : NEXT
REM Build histogram:
FOR y% = 0 TO Height%-1
... |
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 |... | #11l | 11l | V x = 10
V y = 2
print(‘x = ’x)
print(‘y = ’y)
print(‘NOT x = ’(-)x)
print(‘x AND y = ’(x [&] y))
print(‘x OR y = ’(x [|] y))
print(‘x XOR y = ’(x (+) y))
print(‘x SHL y = ’(x << y))
print(‘x SHR y = ’(x >> y))
print(‘x ROL y = ’rotl(x, y))
print(‘x ROR y = ’rotr(x, y)) |
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).
| #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/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 ... | #PicoLisp | PicoLisp | (de write7bitwise (Lst)
(let (Bits 0 Byte)
(for N Lst
(if (=0 Bits)
(setq Bits 7 Byte (* 2 N))
(wr (| Byte (>> (dec 'Bits) N)))
(setq Byte (>> (- Bits 8) N)) ) )
(unless (=0 Bits)
(wr Byte) ) ) )
(de read7bitwise ()
(make
(let (Bits 0 By... |
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 ... | #PL.2FI | PL/I | declare onebit bit(1) aligned, bs bit (1000) varying aligned;
on endfile (sysin) go to ending;
bs = ''b;
do forever;
get edit (onebit) (F(1));
bs = bs || onebit;
end;
ending:
bs = bs || copy('0'b, mod(length(bs), 8) );
/* pad length to a multiple of 8 */
put edit (bs) (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.)
| #OCaml | OCaml | let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) =
let width = Bigarray.Array2.dim1 r_channel
and height = Bigarray.Array2.dim2 r_channel in
Printf.fprintf oc "P6\n%d %d\n255\n" width height;
for y = 0 to pred height do
for x = 0 to pred width do
output_char oc (char_of_int r_channel.{x,y}... |
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.)
| #Oz | Oz | functor
import
Bitmap
Open
export
%% Read
Write
define
%% Omitted: Read
proc {Write B=bitmap(array2d(width:W height:H ...)) Filename}
F = {New Open.file init(name:Filename flags:[write create truncate binary])}
proc {WriteColor8 color(R G B)}
{F write(vs:[R G B])}
end
f... |
http://rosettacode.org/wiki/Bitmap/Read_a_PPM_file | Bitmap/Read a PPM file | Using the data storage type defined on this page for raster images, read an image from a PPM file (binary P6 prefered).
(Read the definition of PPM file on Wikipedia.)
Task: Use write ppm file solution and grayscale image solution with this one in order to convert a color image to grayscale one.
| #REXX | REXX | /*REXX program reads a PPM formatted image file, and creates a gray─scale image of it. */
parse arg iFN oFN /*obtain optional argument from the CL.*/
if iFN=='' | iFN=="," then iFN= 'Lenna50' /*Not specified? Then use the default.*/
if oFN=='' | oFN=="," then oFN= 'greyscale' ... |
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
| #bc | bc | {1?34}
34
{⟨⟩?34}
ERROR |
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
| #Befunge | Befunge | {1?34}
34
{⟨⟩?34}
ERROR |
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... | #SequenceL | SequenceL | import <Utilities/Sequence.sl>;
import <Utilities/Conversion.sl>;
lowerAlphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
upperAlphabet := "abcdefghijklmnopqrstuvwxyz";
caesarEncrypt(ch, key) :=
let
correctAlphabet :=
lowerAlphabet when some(ch = lowerAlphabet)
else
upperAlphabet;
index := Sequence::first... |
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... | #11l | 11l | V majors = ‘north east south west’.split(‘ ’)
majors *= 2
V quarter1 = ‘N,N by E,N-NE,NE by N,NE,NE by E,E-NE,E by N’.split(‘,’)
V quarter2 = quarter1.map(p -> p.replace(‘NE’, ‘EN’))
F degrees2compasspoint(=d)
d = (d % 360) + 360 / 64
V majorindex = Int(d / 90)
V minorindex = Int((d % 90 * 4) I/ 45)
V p1 ... |
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... | #C | C | typedef unsigned int histogram_t;
typedef histogram_t *histogram;
#define GET_LUM(IMG, X, Y) ( (IMG)->buf[ (Y) * (IMG)->width + (X)][0] )
histogram get_histogram(grayimage im);
luminance histogram_median(histogram 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... | #Common_Lisp | Common Lisp | (defpackage #:histogram
(:use #:cl
#:opticl))
(in-package #:histogram)
(defun color->gray-image (image)
(check-type image 8-bit-rgb-image)
(let ((gray-image (with-image-bounds (height width) image
(make-8-bit-gray-image height width :initial-element 0))))
(do-pixels (i j) ima... |
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 |... | #360_Assembly | 360 Assembly | * Bitwise operations 15/02/2017
BITWISE CSECT
USING BITWISE,R13
B 72(R15)
DC 17F'0'
STM R14,R12,12(R13)
ST R13,4(R15)
ST R15,8(R13)
LR R13,R15
L R1,A
XDECO R1,PG
MVC OP,=CL7'A='
... |
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).
| #Action.21 | Action! | INCLUDE "H6:RGBCIRCL.ACT" ;from task Midpoint circle 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/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).
| #Ada | Ada | procedure Circle
( Picture : in out Image;
Center : Point;
Radius : Natural;
Color : Pixel
) is
F : Integer := 1 - Radius;
ddF_X : Integer := 0;
ddF_Y : Integer := -2 * Radius;
X : Integer := 0;
Y : Integer := Radius;
begin
... |
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.