code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
package main
import (
"fmt"
"strings"
)
type ckey struct {
enc, dec func(rune) rune
}
func newCaesar(k int) (*ckey, bool) {
if k < 1 || k > 25 {
return nil, false
}
rk := rune(k)
return &ckey{
enc: func(c rune) rune {
if c >= 'a' && c <= 'z'-rk || c >= 'A' && c... | 1,083Caesar cipher | 0go | x8xwf |
function ShuffleArray(array)
for i=1,#array-1 do
local t = math.random(i, #array)
array[i], array[t] = array[t], array[i]
end
end
function GenerateNumber()
local digits = {1,2,3,4,5,6,7,8,9}
ShuffleArray(digits)
return digits[1] * 1000 +
digits[2] * 100 +
digits[3] * ... | 1,082Bulls and cows | 1lua | 0n8sd |
def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | 1,083Caesar cipher | 7groovy | pwpbo |
>>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... | 1,081Calendar | 3python | 8di0o |
module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | 1,083Caesar cipher | 8haskell | yly66 |
foo();
&foo();
foo($arg1, $arg2);
&foo($arg1, $arg2); | 1,077Call a function | 2perl | x8iw8 |
def factorial(n)
(1..n).reduce(1,:*)
end
def catalan_direct(n)
factorial(2*n) / (factorial(n+1) * factorial(n))
end
def catalan_rec1(n)
return 1 if n == 0
(0...n).inject(0) {|sum, i| sum + catalan_rec1(i) * catalan_rec1(n-1-i)}
end
def catalan_rec2(n)
return 1 if n == 0
2*(2*n - 1) * catalan_rec2(n-1... | 1,068Catalan numbers | 14ruby | 57quj |
fn c_n(n: u64) -> u64 {
match n {
0 => 1,
_ => c_n(n - 1) * 2 * (2 * n - 1) / (n + 1)
}
}
fn main() {
for i in 1..16 {
println!("c_n({}) = {}", i, c_n(i));
}
} | 1,068Catalan numbers | 15rust | 4js5u |
def no_args():
pass
no_args()
def fixed_args(x, y):
print('x=%r, y=%r'% (x, y))
fixed_args(1, 2)
fixed_args(y=2, x=1)
myargs=(1,2)
fixed_args(*myargs)
def opt_args(x=1):
print(x)
opt_args()
opt_args(3.141)
def var_args(*v):
print(v)
var_args(1, 2, 3)
var... | 1,077Call a function | 3python | qonxi |
object CatalanNumbers {
def main(args: Array[String]): Unit = {
for (n <- 0 to 15) {
println("catalan(" + n + ") = " + catalan(n))
}
}
def catalan(n: BigInt): BigInt = factorial(2 * n) / (factorial(n + 1) * factorial(n))
def factorial(n: BigInt): BigInt = BigInt(1).to(n).foldLeft(BigInt(1))(_ * ... | 1,068Catalan numbers | 16scala | 7bor9 |
require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), ]
days = []
date.wday.times { days.push }
while date.month == month
days.push( % date.mday)
da... | 1,081Calendar | 14ruby | itdoh |
public class Cipher {
public static void main(String[] args) {
String str = "The quick brown fox Jumped over the lazy Dog";
System.out.println( Cipher.encode( str, 12 ));
System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 ));
}
public static String decode(String enc, i... | 1,083Caesar cipher | 9java | d3dn9 |
null | 1,081Calendar | 15rust | nzfi4 |
function caesar (text, shift) {
return text.toUpperCase().replace(/[^A-Z]/g,'').replace(/./g, function(a) {
return String.fromCharCode(65+(a.charCodeAt(0)-65+shift)%26);
});
} | 1,083Caesar cipher | 10javascript | 6c638 |
import java.util.{ Calendar, GregorianCalendar }
import language.postfixOps
import collection.mutable.ListBuffer
object CalendarPrint extends App {
val locd = java.util.Locale.getDefault()
val cal = new GregorianCalendar
val monthsMax = cal.getMaximum(Calendar.MONTH)
def JDKweekDaysToISO(dn: Int) = {
val ... | 1,081Calendar | 16scala | ty3fb |
no_args <- function() NULL
no_args()
fixed_args <- function(x, y) print(paste("x=", x, ", y=", y, sep=""))
fixed_args(1, 2)
fixed_args(y=2, x=1)
opt_args <- function(x=1) x
opt_args()
opt_args(3.141)
var_args <- function(...) print(list(...))
var_args(1, 2, 3)
var_args(1, c(2... | 1,077Call a function | 13r | aq01z |
fn main() {
fn no_args() {}
no_args();
fn adds_one(num: i32) -> i32 {
num + 1
}
adds_one(1);
fn prints_argument(maybe: Option<i32>) {
match maybe {
Some(num) => println!(, num),
None => println!(),
};
... | 1,077Call a function | 14ruby | 0nfsu |
null | 1,083Caesar cipher | 11kotlin | 0n0sf |
fn main() { | 1,077Call a function | 15rust | 8dt07 |
def ??? = throw new NotImplementedError | 1,077Call a function | 16scala | nz6ic |
func catalan(_ n: Int) -> Int {
switch n {
case 0:
return 1
case _:
return catalan(n - 1) * 2 * (2 * n - 1) / (n + 1)
}
}
for i in 1..<16 {
print("catalan(\(i)) => \(catalan(i))")
} | 1,068Catalan numbers | 17swift | urxvg |
import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width? string
: String(repeating: " ", count: width - string.count) + s... | 1,081Calendar | 17swift | ofn8k |
use Data::Random qw(rand_set);
use List::MoreUtils qw(uniq);
my $size = 4;
my $chosen = join "", rand_set set => ["1".."9"], size => $size;
print "I've chosen a number from $size unique digits from 1 to 9; you need
to input $size unique digits to guess my number\n";
for ( my $guesses = 1; ; $guesses++ ) {
my $gu... | 1,082Bulls and cows | 2perl | ur5vr |
null | 1,068Catalan numbers | 20typescript | w0yeu |
null | 1,077Call a function | 17swift | sidqt |
<?php
$size = 4;
$chosen = implode(array_rand(array_flip(range(1,9)), $size));
echo ;
for ($guesses = 1; ; $guesses++) {
while (true) {
echo ;
$guess = rtrim(fgets(STDIN));
if (!checkguess($guess))
echo ;
else
break;
}
if ($guess == $chosen) {
... | 1,082Bulls and cows | 12php | 8do0m |
local function encrypt(text, key)
return text:gsub("%a", function(t)
local base = (t:lower() == t and string.byte('a') or string.byte('A'))
local r = t:byte() - base
r = r + key
r = r%26 | 1,083Caesar cipher | 1lua | 8d80e |
'''
Bulls and cows. A game pre-dating, and similar to, Mastermind.
'''
import random
digits = '123456789'
size = 4
chosen = ''.join(random.sample(digits,size))
print '''I have chosen a number from%s unique digits from 1 to 9 arranged in a random order.
You need to input a%i digit, unique digit number as a guess at ... | 1,082Bulls and cows | 3python | 574ux |
void print_jpg(image img, int qual); | 1,084Bitmap/PPM conversion through a pipe | 5c | zyftx |
target <- sample(1:9,4)
bulls <- 0
cows <- 0
attempts <- 0
while (bulls!= 4)
{
input <- readline("Guess a 4-digit number with no duplicate digits or 0s: ")
if (nchar(input) == 4)
{
input <- as.integer(strsplit(input,"")[[1]])
if ((sum(is.na(input)+sum(input==0))>=1) | (length(table(input))!= 4)) {prin... | 1,082Bulls and cows | 13r | l52ce |
package main | 1,084Bitmap/PPM conversion through a pipe | 0go | k1jhz |
null | 1,084Bitmap/PPM conversion through a pipe | 11kotlin | 1wbpd |
use strict;
use warnings;
use Imager;
use Imager::Test 'test_image_raw';
my $img = test_image_raw();
my $IO = Imager::io_new_bufchain();
Imager::i_writeppm_wiol($img, $IO) or die;
my $raw = Imager::io_slurp($IO) or die;
open my $fh, '|-', '/usr/local/bin/convert - -compress none output.jpg' or die;
binmode $fh;
sy... | 1,084Bitmap/PPM conversion through a pipe | 2perl | ml6yz |
from PIL import Image
im = Image.open()
im.save() | 1,084Bitmap/PPM conversion through a pipe | 3python | 92ymf |
def generate_word(len)
[*..].shuffle.first(len)
end
def get_guess(len)
loop do
print
guess = gets.strip
err = case
when guess.match(/[^1-9]/) ;
when guess.length!= len ;
when guess.split().uniq.length!= len;
else return guess.s... | 1,082Bulls and cows | 14ruby | ghr4q |
image read_image(const char *name); | 1,085Bitmap/Read an image through a pipe | 5c | 69t32 |
package main | 1,085Bitmap/Read an image through a pipe | 0go | pehbg |
class Pixmap
PIXMAP_FORMATS = [, ]
PIXMAP_BINARY_FORMATS = []
def write_ppm(ios, format=)
if not PIXMAP_FORMATS.include?(format)
raise NotImplementedError,
end
ios.puts format, ,
ios.binmode if PIXMAP_BINARY_FORMATS.include?(format)
@height.times do |y|
@width.times do |x|... | 1,084Bitmap/PPM conversion through a pipe | 14ruby | lu9cl |
use std::io;
use rand::{Rng,thread_rng};
extern crate rand;
const NUMBER_OF_DIGITS: usize = 4;
static DIGITS: [char; 9] = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
fn generate_digits() -> Vec<char> {
let mut temp_digits: Vec<_> = (&DIGITS[..]).into();
thread_rng().shuffle(&mut temp_digits);
return ... | 1,082Bulls and cows | 15rust | rk7g5 |
null | 1,085Bitmap/Read an image through a pipe | 11kotlin | eqpa4 |
import scala.util.Random
object BullCow {
def main(args: Array[String]): Unit = {
val number=chooseNumber
var guessed=false
var guesses=0
while(!guessed){
Console.print("Guess a 4-digit number with no duplicate digits: ")
val input=Console.readInt
val digits=input... | 1,082Bulls and cows | 16scala | h1kja |
function Bitmap:loadPPM(filename, fp)
if not fp then fp = io.open(filename, "rb") end
if not fp then return end
local head, width, height, depth, tail = fp:read("*line", "*number", "*number", "*number", "*line")
self.width, self.height = width, height
self:alloc()
for y = 1, self.height do
for x = 1, se... | 1,085Bitmap/Read an image through a pipe | 1lua | ws1ea |
use strict;
use warnings;
use Imager;
my $raw;
open my $fh, '-|', 'cat Lenna50.jpg' or die;
binmode $fh;
while ( sysread $fh , my $chunk , 1024 ) { $raw .= $chunk }
close $fh;
my $enable = $Imager::formats{"jpeg"};
my $IO = Imager::io_new_buffer $raw or die;
my $im = Imager::File::JPEG::i_readjpeg_wiol $IO or die... | 1,085Bitmap/Read an image through a pipe | 2perl | cvy9a |
from PIL import Image
im = Image.open()
im.save() | 1,085Bitmap/Read an image through a pipe | 3python | lumcv |
require_relative 'raster_graphics'
class Pixmap
def self.read_ppm(ios)
format = ios.gets.chomp
width, height = ios.gets.chomp.split.map(&:to_i)
max_colour = ios.gets.chomp
if!PIXMAP_FORMATS.include?(format) ||
(width < 1) || (height < 1) ||
(max_colour!= '255')
ios.close
ra... | 1,085Bitmap/Read an image through a pipe | 14ruby | v4c2n |
sub caesar {
my ($message, $key, $decode) = @_;
$key = 26 - $key if $decode;
$message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir;
}
my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY';
my $enc = caesar($msg, 10);
my $dec = caesar($enc, 10, 'decode');
print "msg: $msg\nenc: $enc\n... | 1,083Caesar cipher | 2perl | 575u2 |
<?php
function caesarEncode( $message, $key ){
$plaintext = strtolower( $message );
$ciphertext = ;
$ascii_a = ord( 'a' );
$ascii_z = ord( 'z' );
while( strlen( $plaintext ) ){
$char = ord( $plaintext );
if( $char >= $ascii_a && $char <= $ascii_z ){
$char = ( ( $key + $ch... | 1,083Caesar cipher | 12php | ofo85 |
import Foundation
func generateRandomNumArray(numDigits: Int = 4) -> [Int] {
guard numDigits > 0 else {
return []
}
let needed = min(9, numDigits)
var nums = Set<Int>()
repeat {
nums.insert(.random(in: 1...9))
} while nums.count!= needed
return Array(nums)
}
func parseGuess(_ guess: String) ... | 1,082Bulls and cows | 17swift | 4jg5g |
image get_ppm(FILE *pf); | 1,086Bitmap/Read a PPM file | 5c | luycy |
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen(, );
(void) fprintf(fp, , dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0] = i % 256;
color[1] = j % 256;
color[2] = (i * j) % 256;... | 1,087Bitmap/Write a PPM file | 5c | 7kurg |
def caesar(s, k, decode = False):
if decode: k = 26 - k
return .join([chr((ord(i) - 65 + k)% 26 + 65)
for i in s.upper()
if ord(i) >= 65 and ord(i) <= 90 ])
msg =
print msg
enc = caesar(msg, 11)
print enc
print caesar(enc, 11, decode = True) | 1,083Caesar cipher | 3python | 4j45k |
typedef uint8_t byte;
typedef struct {
FILE *fp;
uint32_t accu;
int bits;
} bit_io_t, *bit_filter;
bit_filter b_attach(FILE *f)
{
bit_filter b = malloc(sizeof(bit_io_t));
b->bits = b->accu = 0;
b->fp = f;
return b;
}
void b_write(byte *buf, size_t n_bits, size_t shift, bit_filter bf)
{
... | 1,088Bitwise IO | 5c | f30d3 |
ceasar <- function(x, key)
{
if (key < 0) {
key <- 26 + key
}
old <- paste(letters, LETTERS, collapse="", sep="")
new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="")
chartr(old, new, x)
}
print(ceasar("hi",2))
print(ceasar("hi",20))
key <- 3
plaintext <- "The five boxing w... | 1,083Caesar cipher | 13r | 242lg |
package raster
import (
"errors"
"io"
"io/ioutil"
"os"
"regexp"
"strconv"
) | 1,086Bitmap/Read a PPM file | 0go | x01wf |
import Bitmap
import Bitmap.RGB
import Bitmap.Gray
import Bitmap.Netpbm
import Control.Monad
import Control.Monad.ST
main =
(readNetpbm "original.ppm" :: IO (Image RealWorld RGB)) >>=
stToIO . toGrayImage >>=
writeNetpbm "new.pgm" | 1,086Bitmap/Read a PPM file | 8haskell | yct66 |
null | 1,086Bitmap/Read a PPM file | 11kotlin | 0iwsf |
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, siz... | 1,086Bitmap/Read a PPM file | 1lua | 8nx0e |
null | 1,088Bitwise IO | 0go | jbu7d |
package raster
import (
"fmt"
"io"
"os"
) | 1,087Bitmap/Write a PPM file | 0go | dz0ne |
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 (ch... | 1,088Bitwise IO | 8haskell | odw8p |
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 path = do
let die = fail "readNetpbm: bad... | 1,087Bitmap/Write a PPM file | 8haskell | 5rcug |
class String
ALFABET = (..).to_a
def caesar_cipher(num)
self.tr(ALFABET.join, ALFABET.rotate(num).join)
end
end
encypted = .caesar_cipher(3)
decrypted = encypted.caesar_cipher(-3) | 1,083Caesar cipher | 14ruby | rkrgs |
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 os =... | 1,087Bitmap/Write a PPM file | 9java | 92zmu |
use strict;
use Image::Imlib2;
my $img = Image::Imlib2->load("out0.ppm");
$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; | 1,086Bitmap/Read a PPM file | 2perl | 5rlu2 |
null | 1,088Bitwise IO | 11kotlin | bagkb |
null | 1,087Bitmap/Write a PPM file | 11kotlin | zyits |
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(&e,... | 1,083Caesar cipher | 15rust | 7b7rc |
local function BitWriter() return {
accumulator = 0, | 1,088Bitwise IO | 1lua | perbw |
null | 1,087Bitmap/Write a PPM file | 1lua | 3mnzo |
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)
private... | 1,083Caesar cipher | 16scala | kakhk |
use strict;
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;
}
return $l;
}
sub flush_bits( $$ )
{
my ($out, $b) = @_;
p... | 1,088Bitwise IO | 2perl | 69n36 |
import io
ppmtxt = '''P3
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 0
'''
def tokenize(f):
for line in f:
if line[0] != '
for t in line.split():
y... | 1,086Bitmap/Read a PPM file | 3python | 4725k |
typedef unsigned int histogram_t;
typedef histogram_t *histogram;
histogram get_histogram(grayimage im);
luminance histogram_median(histogram h); | 1,089Bitmap/Histogram | 5c | 0i1st |
use Imager;
$image = Imager->new(xsize => 200, ysize => 200);
$image->box(filled => 1, color => red);
$image->box(filled => 1, color => black,
xmin => 50, ymin => 50,
xmax => 150, ymax => 150);
$image->write(file => 'bitmap.ppm') or die $image->errstr; | 1,087Bitmap/Write a PPM file | 2perl | bark4 |
class Pixmap
def self.open(filename)
bitmap = nil
File.open(filename, 'r') do |f|
header = [f.gets.chomp, f.gets.chomp, f.gets.chomp]
width, height = header[1].split.map {|n| n.to_i }
if header[0]!= 'P6' or header[2]!= '255' or width < 1 or height < 1
raise StandardError,
e... | 1,086Bitmap/Read a PPM file | 14ruby | rhugs |
class BitWriter(object):
def __init__(self, f):
self.accumulator = 0
self.bcount = 0
self.out = f
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.flush()
def __del__(self):
try:
self.flush()
excep... | 1,088Bitwise IO | 3python | ycd6q |
class Bitmap {
public $data;
public $w;
public $h;
public function __construct($w = 16, $h = 16){
$white = array_fill(0, $w, array(255,255,255));
$this->data = array_fill(0, $h, $white);
$this->w = $w;
$this->h = $h;
}
public function fill($x = 0, $y = 0, $w = null, $h = null, $color = ar... | 1,087Bitmap/Write a PPM file | 12php | 69d3g |
parser.rs:
use super::{Color, ImageFormat};
use std::str::from_utf8;
use std::str::FromStr;
pub fn parse_version(input: &[u8]) -> nom::IResult<&[u8], ImageFormat> {
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::combinator::map;
use nom::seq... | 1,086Bitmap/Read a PPM file | 15rust | 7k5rc |
import scala.io._
import scala.swing._
import java.io._
import java.awt.Color
import javax.swing.ImageIcon
object Pixmap {
private case class PpmHeader(format:String, width:Int, height:Int, maxColor:Int)
def load(filename:String):Option[RgbBitmap]={
implicit val in=new BufferedInputStream(new FileInputStr... | 1,086Bitmap/Read a PPM file | 16scala | k1rhk |
bool? value = null | 1,090Boolean values | 5c | dzxnv |
void quad_bezier(
image img,
unsigned int x1, unsigned int y1,
unsigned int x2, unsigned int y2,
unsigned int x3, unsigned int y3,
color_component r,
color_component g,
color_component b ); | 1,091Bitmap/Bézier curves/Quadratic | 5c | eqrav |
function putpixel {
echo -en "\e[$2;$1H
}
function drawcircle {
x0=$1
y0=$2
radius=$3
for y in $( seq $((y0-radius)) $((y0+radius)) )
do
echo -en "\e[${y}H"
for x in $( seq $((x0+radius)) )
do
echo -n "-"
done
done
x=$((radius-1))
y=0
dx=1
dy=1
err=$((... | 1,092Bitmap/Midpoint circle algorithm | 4bash | eqga3 |
foreach(var 1 42 ON yes True y Princess
0 OFF no False n Princess-NOTFOUND)
if(var)
message(STATUS "${var} is true.")
else()
message(STATUS "${var} is false.")
endif()
endforeach(var) | 1,090Boolean values | 6clojure | 69o3q |
package raster
import "math"
func (g *Grmap) Histogram(bins int) []int {
if bins <= 0 {
bins = g.cols
}
h := make([]int, bins)
for _, p := range g.px {
h[int(p)*(bins-1)/math.MaxUint16]++
}
return h
}
func (g *Grmap) Threshold(t uint16) {
for i, p := range g.px {
i... | 1,089Bitmap/Histogram | 0go | ugyvt |
module Bitmap.BW(module Bitmap.BW) where
import Bitmap
import Control.Monad.ST
newtype BW = BW Bool deriving (Eq, Ord)
instance Color BW where
luminance (BW False) = 0
luminance _ = 255
black = BW False
white = BW True
toNetpbm [] = ""
toNetpbm l = init (concatMap f line) ++ "\n" ++ ... | 1,089Bitmap/Histogram | 8haskell | wshed |
void raster_circle(
image img,
unsigned int x0,
unsigned int y0,
unsigned int radius,
color_component r,
color_component g,
color_component b ); | 1,092Bitmap/Midpoint circle algorithm | 5c | x07wu |
def crunch(ascii)
bitstring = ascii.bytes.collect {|b| % b}.join
[bitstring].pack()
end
def expand(binary)
bitstring = binary.unpack()[0]
bitstring.scan(/[01]{7}/).collect {|b| b.to_i(2).chr}.join
end
original =
puts
filename =
File.open(filename, ) do |fh|
fh.binmode
fh.print crunch(original)
end
... | 1,088Bitwise IO | 14ruby | 92tmz |
import io
ppmfileout = io.StringIO('')
def writeppmp3(self, f):
self.writeppm(f, ppmformat='P3')
def writeppm(self, f, ppmformat='P6'):
assert ppmformat in ['P3', 'P6'], 'Format wrong'
magic = ppmformat + '\n'
comment = '
maxval = max(max(max(bit) for bit in row) for row in self.map)
assert pp... | 1,087Bitmap/Write a PPM file | 3python | pe7bm |
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public enum ImageProcessing {
;
public static void main(String[] args) throws IOException {
BufferedImage img = ImageIO.read(new File("example.png"));
BufferedImage bwimg = toBl... | 1,089Bitmap/Histogram | 9java | k15hm |
pub trait Codec<Input = u8> {
type Output: Iterator<Item = u8>;
fn accept(&mut self, input: Input) -> Self::Output;
fn finish(self) -> Self::Output;
}
#[derive(Debug)]
pub struct BitDiscard {
buf: u16, | 1,088Bitwise IO | 15rust | cvz9z |
library(pixmap)
pixmap::write.pnm
write.pnm(theimage, filename) | 1,087Bitmap/Write a PPM file | 13r | jb578 |
func usage(_ e:String) {
print("error: \(e)")
print("./caeser -e 19 a-secret-string")
print("./caeser -d 19 tskxvjxlskljafz")
}
func charIsValid(_ c:Character) -> Bool {
return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) | 1,083Caesar cipher | 17swift | ghg49 |
null | 1,089Bitmap/Histogram | 11kotlin | gjc4d |
package raster
const b2Seg = 20
func (b *Bitmap) Bzier2(x1, y1, x2, y2, x3, y3 int, p Pixel) {
var px, py [b2Seg + 1]int
fx1, fy1 := float64(x1), float64(y1)
fx2, fy2 := float64(x2), float64(y2)
fx3, fy3 := float64(x3), float64(y3)
for i := range px {
c := float64(i) / b2Seg
a := 1... | 1,091Bitmap/Bézier curves/Quadratic | 0go | 92nmt |
import Bitmap
import Bitmap.Line
import Control.Monad
import Control.Monad.ST
type Point = (Double, Double)
fromPixel (Pixel (x, y)) = (toEnum x, toEnum y)
toPixel (x, y) = Pixel (round x, round y)
pmap :: (Double -> Double) -> Point -> Point
pmap f (x, y) = (f x, f y)
onCoordinates :: (Double -> Double -> Double) -... | 1,091Bitmap/Bézier curves/Quadratic | 8haskell | bauk2 |
(defn draw-circle [draw-function x0 y0 radius]
(letfn [(put [x y m]
(let [x+ (+ x0 x)
x- (- x0 x)
y+ (+ y0 y)
y- (- y0 y)
x0y+ (+ x0 y)
x0y- (- x0 y)
xy0+ (+ y0 x)
xy0- (- y0 x)]
... | 1,092Bitmap/Midpoint circle algorithm | 6clojure | odp8j |
function Histogram( image )
local size_x, size_y = #image, #image[1]
local histo = {}
for i = 0, 255 do
histo[i] = 0
end
for i = 1, size_x do
for j = 1, size_y do
histo[ image[i][j] ] = histo[ image[i][j] ] + 1
end
end
return histo
end
function FindMe... | 1,089Bitmap/Histogram | 1lua | rhlga |
class RGBColour
def values
[@red, @green, @blue]
end
end
class Pixmap
def save(filename)
File.open(filename, 'w') do |f|
f.puts , ,
f.binmode
@height.times do |y|
@width.times do |x|
f.print @data[x][y].values.pack('C3')
end
end
end
end
alias_met... | 1,087Bitmap/Write a PPM file | 14ruby | axh1s |
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; size a... | 1,087Bitmap/Write a PPM file | 15rust | eqkaj |
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.ge... | 1,087Bitmap/Write a PPM file | 16scala | q81xw |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.