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/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Common_Lisp | Common Lisp | (defun fizzbuzz ()
(loop for x from 1 to 100 do
(princ (cond ((zerop (mod x 15)) "FizzBuzz")
((zerop (mod x 3)) "Fizz")
((zerop (mod x 5)) "Buzz")
(t x)))
(terpri))) |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Prolog | Prolog |
flatten(List, FlatList) :-
flatten(List, [], FlatList).
flatten(Var, T, [Var|T]) :-
var(Var), !.
flatten([], T, T) :- !.
flatten([H|T], TailList, List) :- !,
flatten(H, FlatTail, List),
flatten(T, TailList, FlatTail).
flatten(NonList, T, [NonList|T]).
|
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Coq | Coq |
Require Import Coq.Lists.List.
(* https://coq.inria.fr/library/Coq.Lists.List.html *)
Require Import Coq.Strings.String.
(* https://coq.inria.fr/library/Coq.Strings.String.html *)
Require Import Coq.Strings.Ascii.
(* https://coq.inria.fr/library/Coq.Strings.Ascii.html *)
Require Import Coq.Init.Nat.
(* https://... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #C.2B.2B | C++ |
#include<iostream>
#include<string>
#include<boost/filesystem.hpp>
#include<boost/format.hpp>
#include<boost/iostreams/device/mapped_file.hpp>
#include<optional>
#include<algorithm>
#include<iterator>
#include<execution>
#include"dependencies/xxhash.hpp" // https://github.com/RedSpah/xxhash_cpp
/**
* Find ranges (n... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #PureBasic | PureBasic | Structure RCList
Value.i
List A.RCList()
EndStructure
Procedure Flatten(List A.RCList())
ResetList(A())
While NextElement(A())
With A()
If \Value
Continue
Else
ResetList(\A())
While NextElement(\A())
If \A()\Value: A()\Value=\A()\Value: EndIf
Wend
... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Cowgol | Cowgol | include "cowgol.coh";
var i: uint8 := 1;
while i <= 100 loop
if i % 15 == 0 then
print("FizzBuzz");
elseif i % 5 == 0 then
print("Buzz");
elseif i % 3 == 0 then
print("Fizz");
else
print_i8(i);
end if;
print_nl();
i := i + 1;
end loop; |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Elixir | Elixir | defmodule Files do
def find_duplicate_files(dir) do
IO.puts "\nDirectory : #{dir}"
File.cd!(dir, fn ->
Enum.filter(File.ls!, fn fname -> File.regular?(fname) end)
|> Enum.group_by(fn file -> File.stat!(file).size end)
|> Enum.filter(fn {_, files} -> length(files)>1 end)
|> Enum.each(fn... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Go | Go | package main
import (
"fmt"
"crypto/md5"
"io/ioutil"
"log"
"os"
"path/filepath"
"sort"
"time"
)
type fileData struct {
filePath string
info os.FileInfo
}
type hash [16]byte
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func checksum(file... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #BASIC | BASIC | 100 REM DERIVE SP-ID FROM CHESS960 POS
110 PRINT "ENTER START ARRAY AS SEEN BY WHITE."
120 PRINT: PRINT "STARTING ARRAY:";
130 OPEN 1,0: INPUT#1, AR$: CLOSE 1: PRINT
140 IF LEN(AR$)=0 THEN END
150 IF LEN(AR$)=8 THEN 170
160 PRINT "ARRAY MUST BE 8 PIECES.": GOTO 120
170 FOR I=1 TO 8
180 : P$=MID$(AR$,I,1)
190 : IF P$="Q... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Python | Python | >>> def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6, 7, 8] |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Crystal | Crystal | 1.upto(100) do |v|
p fizz_buzz(v)
end
def fizz_buzz(value)
word = ""
word += "fizz" if value % 3 == 0
word += "buzz" if value % 5 == 0
word += value.to_s if word.empty?
word
end |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Haskell | Haskell | - checks for wrong command line input (not existing directory / negative size)
- works on Windows as well as Unix Systems (tested with Mint 17 / Windows 7)
|
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Java | Java | import java.io.*;
import java.nio.*;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.security.*;
import java.util.*;
public class DuplicateFiles {
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("Directory name and minimum file size are... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Factor | Factor | USING: assocs assocs.extras combinators formatting kernel
literals math math.combinatorics sequences sequences.extras sets
strings ;
! ====== optional error-checking ======
: check-length ( str -- )
length 8 = [ "Must have 8 pieces." throw ] unless ;
: check-one ( str -- )
"KQ" counts [ nip 1 = not ] as... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Go | Go | package main
import (
"fmt"
"log"
"strings"
)
var glyphs = []rune("♜♞♝♛♚♖♘♗♕♔")
var names = map[rune]string{'R': "rook", 'N': "knight", 'B': "bishop", 'Q': "queen", 'K': "king"}
var g2lMap = map[rune]string{
'♜': "R", '♞': "N", '♝': "B", '♛': "Q", '♚': "K",
'♖': "R", '♘': "N", '♗': "B", '♕': "Q"... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Q | Q | (raze/) ((1); 2; ((3;4); 5); ((())); (((6))); 7; 8; ()) |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #CSS | CSS | <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<style>
li {
list-style-position: inside;
}
li:nth-child(3n), li:nth-child(5n) {
list-style-type: none;
}
li:nth-child(3n)::before {
content:'Fizz';
}
li:nth-child(5n)::after {
content:'Buzz';
}
</style>
</head>
<body>
<ol>
<li><... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Julia | Julia | using Printf, Nettle
function find_duplicates(path::String, minsize::Int = 0)
filesdict = Dict{String,Array{NamedTuple}}()
for (root, dirs, files) in walkdir(path), fn in files
filepath = joinpath(root, fn)
filestats = stat(filepath)
filestats.size > minsize || continue
h... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | hash="SHA256";
minSize=Quantity[1,"Megabytes"];
allfiles=Once@Select[FileNames["*","",∞],!Once@DirectoryQ[#]&&Once@FileSize[#]>minSize&];
data={#,Once[FileHash[#,hash,All,"HexString"]]}&/@allfiles[[;;5]];
Grid[Select[GatherBy[data,Last],Length[#]>1&][[All,All,1]]] |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Julia | Julia | const whitepieces = "♖♘♗♕♔♗♘♖♙"
const whitechars = "rnbqkp"
const blackpieces = "♜♞♝♛♚♝♞♜♟"
const blackchars = "RNBQKP"
const piece2ascii = Dict(zip("♖♘♗♕♔♗♘♖♙♜♞♝♛♚♝♞♜♟", "rnbqkbnrpRNBQKBNRP"))
""" Derive a chess960 position's SP-ID from its string representation. """
function chess960spid(position::String = "♖♘♗♕♔♗♘... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Nim | Nim | import sequtils, strformat, strutils, sugar, tables, unicode
type Piece {.pure.} = enum Rook = "R", Knight = "N", Bishop = "B", Queen = "Q", King = "K"
const
GlypthToPieces = {"♜": Rook, "♞": Knight, "♝": Bishop, "♛": Queen, "♚": King,
"♖": Rook, "♘": Knight, "♗": Bishop, "♕": Queen, "♔": King... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Perl | Perl | use strict;
use warnings;
use feature 'say';
use List::AllUtils 'indexes';
sub sp_id {
my $setup = shift // 'RNBQKBNR';
8 == length $setup or die 'Illegal position: should have exactly eight pieces';
1 == @{[ $setup =~ /$_/g ]} or die "Illegal position: should ha... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #QBasic | QBasic | sString$ = "[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8 []]"
FOR siCount = 1 TO LEN(sString$)
IF INSTR("[] ,", MID$(sString$, siCount, 1)) = 0 THEN
sFlatter$ = sFlatter$ + sComma$ + MID$(sString$, siCount, 1)
sComma$ = ", "
END IF
NEXT siCount
PRINT "["; sFlatter$; "]"
END |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #BBC_BASIC | BBC BASIC | HIMEM = PAGE + 3000000
INSTALL @lib$+"HIMELIB"
PROC_himeinit("HIMEkey")
DIM old$(20000), new$(20000)
h1% = 1 : h2% = 2 : h3% = 3 : h4% = 4
FOR base% = 3 TO 17
PRINT "Base "; base% " : " FN_largest_left_truncated_prime(base%)
NEXT
END
DEF FN_largest_lef... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Cubescript | Cubescript | alias fizzbuzz [
loop i 100 [
push i (+ $i 1) [
cond (! (mod $i 15)) [
echo FizzBuzz
] (! (mod $i 3)) [
echo Fizz
] (! (mod $i 5)) [
echo Buzz
] [
echo $i
]
]
]
] |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Nim | Nim | import algorithm
import os
import strformat
import strutils
import tables
import std/sha1
import times
type
# Mapping "size" -> "list of paths".
PathsFromSizes = Table[BiggestInt, seq[string]]
# Mapping "hash" -> "list fo paths".
PathsFromHashes = Table[string, seq[string]]
# Information data.
Info ... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Objeck | Objeck | use System.IO.File;
use System.Time;
use Collection;
class Duplicate {
function : Main(args : String[]) ~ Nil {
if(args->Size() = 2) {
file_sets := SortDups(GetDups(args[0], args[1]->ToInt()));
each(i : file_sets) {
file_set := file_sets->Get(i)->As(Vector);
if(file_set->Size() > 1) ... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Phix | Phix | with javascript_semantics
function spid(string s)
if sort(s)!="BBKNNQRR" then return -1 end if
if filter(s,"in","RK")!="RKR" then return -1 end if
sequence b = find_all('B',s)
if even(sum(b)) then return -1 end if
integer {n1,n2} = find_all('N',filter(s,"out","QB")),
N = {-2,1,3,4}[n1]+n... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Quackery | Quackery | forward is flatten
[ [] swap
witheach
[ dup nest?
if flatten
join ] ] resolves flatten ( [ --> [ ) |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #C | C | #include <stdio.h>
#include <gmp.h>
typedef unsigned long ulong;
ulong small_primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,
43,47,53,59,61,67,71,73,79,83,89,97};
#define MAX_STACK 128
mpz_t tens[MAX_STACK], value[MAX_STACK], answer;
ulong base, seen_depth;
void add_digit(ulong i)
{
ulong d;
for (d = 1; ... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #D | D | import std.stdio, std.algorithm, std.conv;
/// With if-else.
void fizzBuzz(in uint n) {
foreach (immutable i; 1 .. n + 1)
if (!(i % 15))
"FizzBuzz".writeln;
else if (!(i % 3))
"Fizz".writeln;
else if (!(i % 5))
"Buzz".writeln;
else
i.... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Perl | Perl | use File::Find qw(find);
use File::Compare qw(compare);
use Sort::Naturally;
use Getopt::Std qw(getopts);
my %opts;
$opts{s} = 1;
getopts("s:", \%opts);
sub find_dups {
my($dir) = @_;
my @results;
my %files;
find {
no_chdir => 1,
wanted => sub { lstat; -f _ && (-s >= $opt{s} ) && p... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Python | Python |
# optional, but task function depends on it as written
def validate_position(candidate: str):
assert (
len(candidate) == 8
), f"candidate position has invalide len = {len(candidate)}"
valid_pieces = {"R": 2, "N": 2, "B": 2, "Q": 1, "K": 1}
assert {
piece for piece in candidate
} ... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #R | R | x <- list(list(1), 2, list(list(3, 4), 5), list(list(list())), list(list(list(6))), 7, 8, list())
unlist(x) |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Racket | Racket |
#lang racket
(flatten '(1 (2 (3 4 5) (6 7)) 8 9))
|
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #C.23 | C# | using Mpir.NET; // 0.4.0
using System; // 4790@3.6
using System.Collections.Generic;
class MaxLftTrP_B
{
static void Main()
{
mpz_t p; var sw = System.Diagnostics.Stopwatch.StartNew(); L(3);
for (uint b = 3; b < 13; b++)
{
sw.Restart(); p = L(b);
Console.Wri... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Dart | Dart |
main() {
for (int i = 1; i <= 100; i++) {
List<String> out = [];
if (i % 3 == 0)
out.add("Fizz");
if (i % 5 == 0)
out.add("Buzz");
print(out.length > 0 ? out.join("") : i);
}
}
|
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Phix | Phix | without js -- file i/o
integer min_size=1
sequence res = {}
atom t1 = time()+1
function store_res(string filepath, sequence dir_entry)
if not match("backup",filepath) -- (example filter)
and not find('d', dir_entry[D_ATTRIBUTES]) then
atom size = dir_entry[D_SIZE]
if size>=min_size then
... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Raku | Raku | #!/usr/bin/env raku
# derive a chess960 position's SP-ID
unit sub MAIN($array = "♖♘♗♕♔♗♘♖");
# standardize on letters for easier processing
my $ascii = $array.trans("♜♞♝♛♚♖♘♗♕♔" => "RNBQKRNBQK");
# (optional error-checking)
if $ascii.chars != 8 {
die "Illegal position: should have exactly eight pieces\n";
}
f... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Raku | Raku | my @l = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []];
say .perl given gather @l.deepmap(*.take); # lazy recursive version
# Another way to do it is with a recursive function (here actually a Block calling itself with the &?BLOCK dynamic variable):
say { |(@$_ > 1 ?? map(&?BLOCK, @$_) !! $_) }(@l) |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #C.2B.2B | C++ | #include <gmpxx.h>
#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <vector>
using big_int = mpz_class;
const unsigned int small_primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23,
29, 31, 37, 41, 43, 47, 53, 59, 61,
... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #dc | dc | [[Fizz]P 1 sw]sF
[[Buzz]P 1 sw]sB
[li p sz]sN
[[
]P]sW
[
0 sw [w = 0]sz
li 3 % 0 =F [Fizz if 0 == i % 3]sz
li 5 % 0 =B [Buzz if 0 == i % 5]sz
lw 0 =N [print Number if 0 == w]sz
lw 1 =W [print neWline if 1 == w]sz
li 1 + si [i += 1]sz
li 100 !<L [continue Loop if 100 >= i]sz
]sL
1 si ... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #PicoLisp | PicoLisp | `(== 64 64)
(de mmap (L F)
(native "@" "mmap" 'N 0 L 1 2 F 0) )
(de munmap (A L)
(native "@" "munmap" 'N A L) )
(de xxh64 (M S)
(let
(R (native "libxxhash.so" "XXH64" 'N M S 0)
P `(** 2 64) )
(if (lt0 R)
(& (+ R P) (dec P))
R ) ) )
(de walk (Dir)
(recur (Dir)
(fo... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Python | Python | from __future__ import print_function
import os
import hashlib
import datetime
def FindDuplicateFiles(pth, minSize = 0, hashName = "md5"):
knownFiles = {}
#Analyse files
for root, dirs, files in os.walk(pth):
for fina in files:
fullFina = os.path.join(root, fina)
isSymLin... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Ruby | Ruby | def chess960_to_spid(pos)
start_str = pos.tr("♖♘♗♕♔", "RNBQK")
#1 knights score
s = start_str.delete("QB")
n = [0,1,2,3,4].combination(2).to_a.index( [s.index("N"), s.rindex("N")] )
#2 queen score
q = start_str.delete("N").index("Q")
#3 bishops
bs = start_str.index("B"), start_str.rindex("B")
d = bs.d... |
http://rosettacode.org/wiki/Find_Chess960_starting_position_identifier | Find Chess960 starting position identifier | As described on the Chess960 page, Chess960 (a.k.a Fischer Random Chess, Chess9LX) is a variant of chess where the array of pieces behind the pawns is randomized at the start of the game to minimize the value of opening theory "book knowledge". That task is to generate legal starting positions, and some of the solution... | #Wren | Wren | import "/trait" for Indexed
var glyphs = "♜♞♝♛♚♖♘♗♕♔".toList
var letters = "RNBQKRNBQK"
var names = { "R": "rook", "N": "knight", "B": "bishop", "Q": "queen", "K": "king" }
var g2lMap = {}
for (se in Indexed.new(glyphs)) g2lMap[glyphs[se.index]] = letters[se.index]
var g2l = Fn.new { |pieces| pieces.reduce("") { |... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #REBOL | REBOL |
flatten: func [
"Flatten the block in place."
block [any-block!]
][
parse block [
any [block: any-block! (change/part block first block 1) :block | skip]
]
head block
]
|
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #6502_Assembly | 6502 Assembly | ;beginning of your program
lda #$BE
sta $0100
lda #$EF
sta $0101
ldx #$ff
txs ;stack pointer is set to $FF
;later...
lda $0100 ;if this no longer equals $BE the stack has overflowed
cmp #$BE
bne StackHasOverflowed |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Eiffel | Eiffel |
class
LARGEST_LEFT_TRUNCABLE_PRIME
create
make
feature
make
-- Tests find_prime for different bases.
local
i: INTEGER
decimal: INTEGER_64
do
from
i := 3
until
i = 10
loop
largest := 0
find_prime ("", i)
decimal := convert_to_decimal (largest, i)
io.put_string (i.... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Delphi | Delphi | program FizzBuzz;
{$APPTYPE CONSOLE}
uses SysUtils;
var
i: Integer;
begin
for i := 1 to 100 do
begin
if i mod 15 = 0 then
Writeln('FizzBuzz')
else if i mod 3 = 0 then
Writeln('Fizz')
else if i mod 5 = 0 then
Writeln('Buzz')
else
Writeln(i);
end;
end. |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Racket | Racket |
#lang racket
(struct F (name id size [links #:mutable]))
(require openssl/sha1)
(define (find-duplicate-files path size)
(define Fs
(sort
(fold-files
(λ(path type acc)
(define s (and (eq? 'file type) (file-size path)))
(define i (and s (<= size s) (file-or-directory-identity path)... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Raku | Raku | use Digest::SHA256::Native;
sub MAIN( $dir = '.', :$minsize = 5, :$recurse = True ) {
my %files;
my @dirs = $dir.IO.absolute.IO;
while @dirs {
my @files = @dirs.pop;
while @files {
for @files.pop.dir -> $path {
%files{ $path.s }.push: $path if $path.f and $path.... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Red | Red |
flatten: function [
"Flatten the block"
block [any-block!]
][
load form block
]
red>> flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]
== [1 2 3 4 5 6 7 8]
;flatten a list to a string
>> blk: [1 2 ["test"] "a" [["bb"]] 3 4 [[[99]]]]
>> form blk
== "1 2 test a bb 3 4 99" |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #REXX | REXX | /*REXX program (translated from PL/I) flattens a list (the data need not be numeric).*/
list= '[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]' /*the list to be flattened. */
say list /*display the original list. */
c= ',' ... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #8080_Assembly | 8080 Assembly | org 100h
lxi b,0 ; BC holds the amount of calls
call recur ; Call the recursive routine
;;; BC now holds the maximum amount of recursive calls one
;;; can make, and the stack is back to the beginning.
;;; Print the value in BC to the console. The stack is freed by ret
;;; so push and pop can be used.
;;; Make... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #ACL2 | ACL2 | (defun recursion-limit (x)
(if (zp x)
0
(prog2$ (cw "~x0~%" x)
(1+ (recursion-limit (1+ x)))))) |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #F.23 | F# |
(* Find some probable candidates for The Largest Left Trucatable Prime in a given base
Nigel Galloway: April 25th., 2017 *)
let snF Fbase pZ =
let rec fn i g (e:bigint) l =
match e with
| _ when e.IsZero -> i=1I
| _ when e.IsEven -> fn i ((g*g)%l) (e/2I) l
| _ -> fn ((i*g)%l) ((g... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #DeviousYarn | DeviousYarn | each { x range(1 100)
? { divisible(x 3)
p:'Fizz' }
? { divisible(x 5)
p:'Buzz' }
-? { !:divisible(x 3)
p:x }
o
} |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #REXX | REXX | /*REXX program to reads a (DOS) directory and finds and displays files that identical.*/
sep=center(' files are identical in size and content: ',79,"═") /*define the header. */
tFID= 'c:\TEMP\FINDDUP.TMP' /*use this as a temporary FileID. */
arg maxSize aDir ... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Ring | Ring |
aString = "[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]"
bString = ""
cString = ""
for n=1 to len(aString)
if ascii(aString[n]) >= 48 and ascii(aString[n]) <= 57
bString = bString + ", " + aString[n]
ok
next
cString = substr(bString,3,Len(bString)-2)
cString = '"' + cString + '"'
see cString + nl
... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Recursion_Depth is
function Recursion (Depth : Positive) return Positive is
begin
return Recursion (Depth + 1);
exception
when Storage_Error =>
return Depth;
end Recursion;
begin
Put_Line ("Recursion depth on this system is" & Inte... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #ALGOL_68 | ALGOL 68 | PROC recurse = VOID : recurse; recurse |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Fortran | Fortran | USE PRIMEBAG !Gain access to NEXTPRIME and ISPRIME.
Calculates the largest "left-truncatable" digit sequence that is a prime number, in various bases.
INTEGER LBASE,MANY,ENUFF !Some sizes.
PARAMETER (LBASE = 13, MANY = 66666, ENUFF = 66)
INTEGER NS,START(LBASE) !A list of single-digit prime numb... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Draco | Draco | proc nonrec main() void:
byte i;
for i from 1 upto 100 do
if i % 15 = 0 then writeln("FizzBuzz")
elif i % 5 = 0 then writeln("Buzz")
elif i % 3 = 0 then writeln("Fizz")
else writeln(i)
fi
od
corp |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Ring | Ring |
# Project : Find duplicate files
d = "/Windows/System32"
chdir(d)
dir = dir(d)
dirlist = []
for n = 1 to len(dir)
if dir[n][2] = 0
str = read(dir[n][1])
lenstr = len(str)
add(dirlist,[lenstr,dir[n][1]])
ok
next
see "Directory : " + d + nl
see "--------------------------------------... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Ruby | Ruby | require 'digest/md5'
def find_duplicate_files(dir)
puts "\nDirectory : #{dir}"
Dir.chdir(dir) do
file_size = Dir.foreach('.').select{|f| FileTest.file?(f)}.group_by{|f| File.size(f)}
file_size.each do |size, files|
next if files.size==1
files.group_by{|f| Digest::MD5.file(f).to_s}.each do |md5... |
http://rosettacode.org/wiki/Find_if_a_point_is_within_a_triangle | Find if a point is within a triangle | Find if a point is within a triangle.
Task
Assume points are on a plane defined by (x, y) real number coordinates.
Given a point P(x, y) and a triangle formed by points A, B, and C, determine if P is within triangle ABC.
You may use any algorithm.
Bonus: explain why the algorithm you chose works.
Re... | #11l | 11l | V EPS = 0.001
V EPS_SQUARE = EPS * EPS
F side(p1, p2, p)
R (p2.y - p1.y) * (p.x - p1.x) + (-p2.x + p1.x) * (p.y - p1.y)
F distanceSquarePointToSegment(p1, p2, p)
V p1P2SquareLength = sqlen(p2 - p1)
V dotProduct = dot(p - p1, p2 - p1) / p1P2SquareLength
I dotProduct < 0
R sqlen(p - p1)
I dotProd... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Ruby | Ruby | flat = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []].flatten
p flat # => [1, 2, 3, 4, 5, 6, 7, 8] |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #AppleScript | AppleScript | -- recursionDepth :: () -> IO String
on recursionDepth()
script go
on |λ|(i)
try
|λ|(1 + i)
on error
"Recursion limit encountered at " & i
end try
end |λ|
end script
go's |λ|(0)
end recursionDepth
on run
recursionD... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #Arturo | Arturo | recurse: function [x][
print x
recurse x+1
]
recurse 0 |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Go | Go | package main
import (
"fmt"
"math/big"
)
var smallPrimes = [...]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
const maxStack = 128
var (
tens, values [maxStack]big.Int
bigTemp, answer = new(big.Int), new(big.Int)
base, seenDepth int
)
func addDigit(i int) {
for d := 1; d < base; d++ {
... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #DUP | DUP | [$$3/%$[]['F,'i,'z,'z,]?\5/%$[]['B,'u,'z,'z,]?*[$.][]?10,]c: {define function c: mod 3, mod 5 tests, print proper output}
0[$100<][1+c;!]# {loop from 1 to 100} |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Rust | Rust | use std::{
collections::BTreeMap,
fs::{read_dir, File},
hash::Hasher,
io::Read,
path::{Path, PathBuf},
};
type Duplicates = BTreeMap<(u64, u64), Vec<PathBuf>>;
struct DuplicateFinder {
found: Duplicates,
min_size: u64,
}
impl DuplicateFinder {
fn search(path: impl AsRef<Path>, min_... |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Sidef | Sidef | # usage: sidef fdf.sf [size] [dir1] [...]
require('File::Find')
func find_duplicate_files(Block code, size_min=0, *dirs) {
var files = Hash()
%S<File::Find>.find(
Hash(
no_chdir => true,
wanted => func(arg) {
var file = File(arg)
file.is_file... |
http://rosettacode.org/wiki/Find_if_a_point_is_within_a_triangle | Find if a point is within a triangle | Find if a point is within a triangle.
Task
Assume points are on a plane defined by (x, y) real number coordinates.
Given a point P(x, y) and a triangle formed by points A, B, and C, determine if P is within triangle ABC.
You may use any algorithm.
Bonus: explain why the algorithm you chose works.
Re... | #Ada | Ada | -- triangle.ads
generic
type Dimension is private;
Zero, Two: Dimension;
with function "*"(Left, Right: in Dimension) return Dimension is <>;
with function "/"(Left, Right: in Dimension) return Dimension is <>;
with function "+"(Left, Right: in Dimension) return Dimension is <>;
with function "-"(Left, Right: in ... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Run_BASIC | Run BASIC | n$ = "[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8 []]"
for i = 1 to len(n$)
if instr("[] ,",mid$(n$,i,1)) = 0 then
flatten$ = flatten$ + c$ + mid$(n$,i,1)
c$ = ","
end if
next i
print "[";flatten$;"]" |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #AutoHotkey | AutoHotkey | Recurse(0)
Recurse(x)
{
TrayTip, Number, %x%
Recurse(x+1)
} |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #AutoIt | AutoIt | ;AutoIt Version: 3.2.10.0
$depth=0
recurse($depth)
Func recurse($depth)
ConsoleWrite($depth&@CRLF)
Return recurse($depth+1)
EndFunc |
http://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases | Find palindromic numbers in both binary and ternary bases | Find palindromic numbers in both binary and ternary bases
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find and show (in decimal) the first six numbers (non-negative integers) that are palindromes in both:
base 2
base 3
Display 0 ... | #11l | 11l | V digits = ‘0123456789abcdefghijklmnopqrstuvwxyz’
F baseN(=num, b)
I num == 0
R ‘0’
V result = ‘’
L num != 0
(num, V d) = divmod(num, b)
result ‘’= :digits[Int(d)]
R reversed(result)
F pal2(num)
I num == 0 | num == 1
R 1B
V based = bin(num)
R based == reversed(based)
F... |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Haskell | Haskell | primesTo100 = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
-- (eq. to) find2km (2^k * n) = (k,n)
find2km :: Integral a => a -> (Int,a)
find2km n = f 0 n
where f k m
| r == 1 = (k,m)
| otherwise = f (k+1) q
where (q,r) = quotRem m 2
-- n is the number ... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #DWScript | DWScript | var i : Integer;
for i := 1 to 100 do begin
if i mod 15 = 0 then
PrintLn('FizzBuzz')
else if i mod 3 = 0 then
PrintLn('Fizz')
else if i mod 5 = 0 then
PrintLn('Buzz')
else PrintLn(i);
end; |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Tcl | Tcl | package require fileutil
package require md5
proc finddupfiles {dir {minsize 1}} {
foreach fn [fileutil::find $dir] {
file lstat $fn stat
if {$stat(size) < $minsize} continue
dict lappend byino $stat(dev),$stat(ino) $fn
if {$stat(type) ne "file"} continue
set f [open $fn "rb"]
set content ... |
http://rosettacode.org/wiki/Find_if_a_point_is_within_a_triangle | Find if a point is within a triangle | Find if a point is within a triangle.
Task
Assume points are on a plane defined by (x, y) real number coordinates.
Given a point P(x, y) and a triangle formed by points A, B, and C, determine if P is within triangle ABC.
You may use any algorithm.
Bonus: explain why the algorithm you chose works.
Re... | #ALGOL_68 | ALGOL 68 | BEGIN # determine whether a point is within a triangle or not #
# tolerance for the accurate test #
REAL eps = 0.001;
REAL eps squared = eps * eps;
# mode to hold a point #
MODE POINT = STRUCT( REAL x, y );
# returns a readable representation of p #
OP TOSTRING = ( POINT p )STRING... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #Rust | Rust | use std::{vec, mem, iter};
enum List<T> {
Node(Vec<List<T>>),
Leaf(T),
}
impl<T> IntoIterator for List<T> {
type Item = List<T>;
type IntoIter = ListIter<T>;
fn into_iter(self) -> Self::IntoIter {
match self {
List::Node(vec) => ListIter::NodeIter(vec.into_iter()),
... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #AWK | AWK | # syntax: GAWK -f FIND_LIMIT_OF_RECURSION.AWK
#
# version depth messages
# ------------------ ----- --------
# GAWK 3.1.4 2892 none
# XML GAWK 3.1.4 3026 none
# GAWK 4.0 >999999
# MAWK 1.3.3 4976 A stack overflow was encountered at
# addres... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #Axe | Axe | RECURSE(1)
Lbl RECURSE
.Optionally, limit the number of times the argument is printed
Disp r₁▶Dec,i
RECURSE(r₁+1) |
http://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases | Find palindromic numbers in both binary and ternary bases | Find palindromic numbers in both binary and ternary bases
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find and show (in decimal) the first six numbers (non-negative integers) that are palindromes in both:
base 2
base 3
Display 0 ... | #Ada | Ada | with Ada.Text_IO, Base_Conversion;
procedure Brute is
type Long is range 0 .. 2**63-1;
package BC is new Base_Conversion(Long);
function Palindrome (S : String) return Boolean is
(if S'Length < 2 then True
elsif S(S'First) /= S(S'Last) then False
else Palindrome(S(S'First+1 .. S'Last-1)... |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #J | J | ltp=:3 :0
probe=. i.1 0
while. #probe do.
probe=. (#~ 1 p: y #.]),/(}.i.y),"0 _1/have=. probe
end.
>./y#.have
) |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Java | Java | import java.math.BigInteger;
import java.util.*;
class LeftTruncatablePrime
{
private static List<BigInteger> getNextLeftTruncatablePrimes(BigInteger n, int radix, int millerRabinCertainty)
{
List<BigInteger> probablePrimes = new ArrayList<BigInteger>();
String baseString = n.equals(BigInteger.ZERO) ? "" ... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #Dyalect | Dyalect | var n = 1
while n < 20 {
if n % 15 == 0 {
print("fizzbuzz")
} else if n % 3 == 0 {
print("fizz")
} else if n % 5 == 0 {
print("buzz")
} else {
print(n)
}
n = n + 1
} |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #Wren | Wren | import "io" for Directory, File, Stat
import "/crypto" for Sha1
import "/sort" for Sort
var findDuplicates = Fn.new { |dir, minSize|
if (!Directory.exists(dir)) Fiber.abort("Directory does not exist.")
var files = Directory.list(dir).where { |f| Stat.path("%(dir)/%(f)").size >= minSize }
var hashMap = {}
... |
http://rosettacode.org/wiki/Find_if_a_point_is_within_a_triangle | Find if a point is within a triangle | Find if a point is within a triangle.
Task
Assume points are on a plane defined by (x, y) real number coordinates.
Given a point P(x, y) and a triangle formed by points A, B, and C, determine if P is within triangle ABC.
You may use any algorithm.
Bonus: explain why the algorithm you chose works.
Re... | #AutoHotkey | AutoHotkey | T := [[1.5, 2.4], [5.1, -3.1], [-3.8, 1.2]]
for i, p in [[0, 0], [0, 1], [3, 1], [5.4142857, 14.349206]]
result .= "[" p.1 ", " p.2 "] is within triangle?`t" (TriHasP(T, p) ? "ture" : "false") "`n"
MsgBox % result
return
TriHasP(T, P){
Ax := TriArea(T.1.1, T.1.2, T.2.1, T.2.2, T.3.1, T.3.2)
A1 := TriAr... |
http://rosettacode.org/wiki/Flatten_a_list | Flatten a list | Task
Write a function to flatten the nesting in an arbitrary list of values.
Your program should work on the equivalent of this list:
[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
Where the correct result would be the list:
[1, 2, 3, 4, 5, 6, 7, 8]
Related task
Tree traversal
| #S-lang | S-lang | define flatten ();
define flatten (list) {
variable item,
retval,
val;
if (typeof(list) != List_Type) {
retval = list;
} else {
retval = {};
foreach item (list) {
foreach val (flatten(item)) {
list_append(retval, val);
}
... |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #BASIC | BASIC | 100 PRINT "RECURSION DEPTH"
110 PRINT D" ";
120 LET D = D + 1
130 GOSUB 110"RECURSION |
http://rosettacode.org/wiki/Find_limit_of_recursion | Find limit of recursion | Find limit of recursion is part of Short Circuit's Console Program Basics selection.
Task
Find the limit of recursion.
| #Batch_File | Batch File | @echo off
set /a c=c+1
echo [Depth %c%] Mung until no good
cmd /c mung.cmd
echo [Depth %c%] No good
set /a c=c-1 |
http://rosettacode.org/wiki/Find_palindromic_numbers_in_both_binary_and_ternary_bases | Find palindromic numbers in both binary and ternary bases | Find palindromic numbers in both binary and ternary bases
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Find and show (in decimal) the first six numbers (non-negative integers) that are palindromes in both:
base 2
base 3
Display 0 ... | #AppleScript | AppleScript | on intToText(int, base) -- Simple version for brevity.
script o
property digits : {int mod base as integer}
end script
set int to int div base
repeat until (int = 0)
set beginning of o's digits to int mod base as integer
set int to int div base
end repeat
return join(... |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Julia | Julia | using Primes, Printf
function addmsdigit(p::Integer, b::Integer, s::Integer)
a = Vector{typeof(p)}()
q = p
for i in 1:(b-1)
q += s
isprime(q) || continue
push!(a, q)
end
return a
end
function lefttruncprime(pbase::Integer)
a = Vector{BigInt}()
append!(a, primes(pb... |
http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base | Find largest left truncatable prime in a given base | A truncatable prime is one where all non-empty substrings that finish at the end of the number (right-substrings) are also primes when understood as numbers in a particular base. The largest such prime in a given (integer) base is therefore computable, provided the base is larger than 2.
Let's consider what happens in... | #Kotlin | Kotlin | // version 1.1.2
import java.math.BigInteger
fun nextLeftTruncatablePrimes(n: BigInteger, radix: Int, certainty: Int): List<BigInteger> {
val probablePrimes = mutableListOf<BigInteger>()
val baseString = if (n == BigInteger.ZERO) "" else n.toString(radix)
for (i in 1 until radix) {
val p = BigIn... |
http://rosettacode.org/wiki/FizzBuzz | FizzBuzz | Task
Write a program that prints the integers from 1 to 100 (inclusive).
But:
for multiples of three, print Fizz (instead of the number)
for multiples of five, print Buzz (instead of the number)
for multiples of both three and five, print FizzBuzz (instead of the number)
... | #D.C3.A9j.C3.A0_Vu | Déjà Vu | for i range 1 100:
if = 0 % i 15:
"FizzBuzz"
elseif = 0 % i 3:
"Fizz"
elseif = 0 % i 5:
"Buzz"
else:
i
!print |
http://rosettacode.org/wiki/Find_duplicate_files | Find duplicate files | In a large directory structure it is easy to inadvertently leave unnecessary copies of files around, which can use considerable disk space and create confusion.
Task
Create a program which, given a minimum size and a folder/directory, will find all files of at least size bytes with duplicate contents under the dire... | #zkl | zkl | include(zkl.h.zkl);
const FLAGS=FILE.GLOB.IGNORE_CASE + FILE.GLOB.NO_DIRS;
var [const] MsgHash=Import("zklMsgHash");
var recurse=False, fileSpec, minSz=0, maxSz=(0).MAX;
argh:=Utils.Argh(
T("+R","R","Recurse into subdirectories, starting at <arg>",
fcn(arg){ recurse=arg }),
T("+minSz","","Only consider file... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.