task_url large_stringlengths 31 69 | task_name large_stringlengths 3 41 | task_description large_stringlengths 39 5.64k | language_url large_stringlengths 2 33 | language_name large_stringlengths 1 30 | code large_stringlengths 26 20.9k | task_description_num_tokens int64 14 1.83k | code_num_tokens int64 13 8.47k | num_tokens int64 29 8.98k | loc large_stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime | Create a two-dimensional array at runtime |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ... | #Clean | Clean | import StdEnv
Start :: *World -> { {Real} }
Start world
# (console, world) = stdio world
(_, dim1, console) = freadi console
(_, dim2, console) = freadi console
= createArray dim1 (createArray dim2 1.0) | 100 | 82 | 182 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Range_expansion | Range expansion | A format for expressing an ordered list of integers is to use a comma separated list of either
individual integers
Or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. (The range includes all integers in the interval including both endpoints)
The range s... | #Prolog | Prolog | range_expand :-
L = '-6,-3--1,3-5,7-11,14,15,17-20',
writeln(L),
atom_chars(L, LA),
extract_Range(LA, R),
maplist(study_Range, R, LR),
pack_Range(LX, LR),
writeln(LX).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% extract_Range(?In, ?Out)
% In : '-6,-3--1,3-5,7-11,14,15,17-20'
% Out : [-6], [-3... | 293 | 874 | 1,167 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/A%2BB | A+B | A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B.
Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
(
−
1000
≤... | #ABAP | ABAP | report z_sum_a_b.
data: lv_output type i.
selection-screen begin of block input.
parameters:
p_first type i,
p_second type i.
selection-screen end of block input.
at selection-screen output.
%_p_first_%_app_%-text = 'First Number: '.
%_p_second_%_app_%-text = 'Second Number: '.
start-of-selection.
... | 232 | 141 | 373 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Find_common_directory_path | Find common directory path | Create a routine that, given a set of strings representing directory paths and a single character directory separator, will return a string representing that part of the directory tree that is common to all the directories.
Test your routine using the forward slash '/' character as the directory separator and the foll... | #OCaml | OCaml | let rec aux acc paths =
if List.mem [] paths
then (List.rev acc) else
let heads = List.map List.hd paths in
let item = List.hd heads in
let all_the_same =
List.for_all ((=) item) (List.tl heads)
in
if all_the_same
then aux (item::acc) (List.map List.tl paths)
else (List.rev acc)
let common_prefi... | 1,036 | 268 | 1,304 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Determine_if_a_string_is_collapsible | Determine if a string is collapsible | Determine if a character string is collapsible.
And if so, collapse the string (by removing immediately repeated characters).
If a character string has immediately repeated character(s), the repeated characters are to be
deleted (removed), but not the primary (1st) character(s).
An immediatel... | #Visual_Basic_.NET | Visual Basic .NET | Module Module1
Function Collapse(s As String) As String
If String.IsNullOrEmpty(s) Then
Return ""
End If
Return s(0) + New String(Enumerable.Range(1, s.Length - 1).Where(Function(i) s(i) <> s(i - 1)).Select(Function(i) s(i)).ToArray)
End Function
Sub Main()
Di... | 1,829 | 380 | 2,209 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Increment_a_numerical_string | Increment a numerical string | Task
Increment a numerical string.
| #Python | Python | next = str(int('123') + 1) | 14 | 15 | 29 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/System_time | System time | Task
Output the system time (any units will do as long as they are noted) either by a system command or one built into the language.
The system time can be used for debugging, network information, random number seeds, or something as simple as program performance.
Related task
Date format
See also
Retr... | #Nemerle | Nemerle | System.Console.Write(System.DateTime.Now); | 93 | 13 | 106 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Hello_world/Web_server | Hello world/Web server | The browser is the new GUI !
Task
Serve our standard text Goodbye, World! to http://localhost:8080/ so that it can be viewed with a web browser.
The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.
Note that starting a web browser or... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "listener.s7i";
const proc: main is func
local
var listener: aListener is listener.value;
var file: sock is STD_NULL;
begin
aListener := openInetListener(8080);
listen(aListener, 10);
while TRUE do
sock := accept(aListener);
write(sock, "HTTP/1.1... | 155 | 194 | 349 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Smarandache_prime-digital_sequence | Smarandache prime-digital sequence | The Smarandache prime-digital sequence (SPDS for brevity) is the sequence of primes whose digits are themselves prime.
For example 257 is an element of this sequence because it is prime itself and its digits: 2, 5 and 7 are also prime.
Task
Show the first 25 SPDS primes.
Show the hundredth SPDS prime.
See also
... | #Action.21 | Action! | INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
BYTE FUNC IsZero(REAL POINTER a)
CHAR ARRAY s(10)
StrR(a,s)
IF s(0)=1 AND s(1)='0 THEN
RETURN (1)
FI
RETURN (0)
CARD FUNC MyMod(CARD a,b)
REAL ar,br,dr
CARD d,m
IF a>32767 THEN
;Built-in DIV and MOD
;do not work properly
;for numbers... | 156 | 602 | 758 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Average_loop_length | Average loop length | Let f be a uniformly-randomly chosen mapping from the numbers 1..N to the numbers 1..N (note: not necessarily a permutation of 1..N; the mapping could produce a number in more than one way or not at all). At some point, the sequence 1, f(1), f(f(1))... will contain a repetition, a number that occurring for the second t... | #Clojure | Clojure | (ns cyclelengths
(:gen-class))
(defn factorial [n]
" n! "
(apply *' (range 1 (inc n)))) ; Use *' (vs. *) to allow arbitrary length arithmetic
(defn pow [n i]
" n^i"
(apply *' (repeat i n)))
(defn analytical [n]
" Analytical Computation "
(->>(range 1 (inc n))
(map #(/ (factorial n)... | 710 | 461 | 1,171 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Josephus_problem | Josephus problem | Josephus problem is a math puzzle with a grim description:
n
{\displaystyle n}
prisoners are standing on a circle, sequentially numbered from
0
{\displaystyle 0}
to
n
−
1
{\displaystyle n-1}
.
An executioner walks along the circle, starting from prisoner
0
{\displaystyle 0}
,
removing eve... | #Eiffel | Eiffel |
class
APPLICATION
create
make
feature
make
do
io.put_string ("Survivor is prisoner: " + execute (12, 4).out)
end
execute (n, k: INTEGER): INTEGER
-- Survivor of 'n' prisoners, when every 'k'th is executed.
require
n_positive: n > 0
k_positive: k > 0
n_larger: n > k
local
killidx:... | 764 | 453 | 1,217 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Comma_quibbling | Comma quibbling | Comma quibbling is a task originally set by Eric Lippert in his blog.
Task
Write a function to generate a string output which is the concatenation of input words from a list/sequence where:
An input of no words produces the output string of just the two brace characters "{}".
An input of just one word, e.g. ["AB... | #Groovy | Groovy | def commaQuibbling = { it.size() < 2 ? "{${it.join(', ')}}" : "{${it[0..-2].join(', ')} and ${it[-1]}}" } | 301 | 48 | 349 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Flow-control_structures | Flow-control structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
Document common flow-control structures.
One common example of a flow-control structure is the goto construct.
Note that Conditional Struc... | #PicoLisp | PicoLisp |
LEAVE
The LEAVE statement terminates execution of a loop.
Execution resumes at the next statement after the loop.
ITERATE
The ITERATE statement causes the next iteration of the loop to
commence. Any statements between ITERATE and the end of the loop
are not executed.
STOP
Terminates execution of ei... | 125 | 313 | 438 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/User_input/Text | User input/Text | User input/Text is part of Short Circuit's Console Program Basics selection.
Task
Input a string and the integer 75000 from the text console.
See also: User input/Graphical
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | mystring = InputString["give me a string please"];
myinteger = Input["give me an integer please"]; | 56 | 25 | 81 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Numerical_integration | Numerical integration | Write functions to calculate the definite integral of a function ƒ(x) using all five of the following methods:
rectangular
left
right
midpoint
trapezium
Simpson's
composite
Your functions should take in the upper and lower bounds (a and b), and the number of approximations to make in that range (n).
Assume t... | #Swift | Swift | public enum IntegrationType : CaseIterable {
case rectangularLeft
case rectangularRight
case rectangularMidpoint
case trapezium
case simpson
}
public func integrate(
from: Double,
to: Double,
n: Int,
using: IntegrationType = .simpson,
f: (Double) -> Double
) -> Double {
let integrationFunc: (Dou... | 747 | 1,107 | 1,854 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Kernighans_large_earthquake_problem | Kernighans large earthquake problem | Brian Kernighan, in a lecture at the University of Nottingham, described a problem on which this task is based.
Problem
You are given a a data file of thousands of lines; each of three `whitespace` separated fields: a date, a one word name and the magnitude of the event.
Example lines from the file would be lines li... | #Phixmonti | Phixmonti | argument tail nip len dup
if
get nip
else
drop drop "data.txt"
endif
dup "r" fopen
dup 0 < if drop "Could not open '" print print "' for reading" print -1 quit endif
nip
true
while
dup fgets
dup 0 < if
drop false
else
dup split 3 get tonum 6 > if drop print else drop drop endif
... | 232 | 119 | 351 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Sort_an_integer_array | Sort an integer array |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Io | Io | mums := list(2,4,3,1,2)
sorted := nums sort # returns a new sorted array. 'nums' is unchanged
nums sortInPlace # sort 'nums' "in-place" | 475 | 51 | 526 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Water_collected_between_towers | Water collected between towers | Task
In a two-dimensional world, we begin with any bar-chart (or row of close-packed 'towers', each of unit width), and then it rains,
completely filling all convex enclosures in the chart with water.
9 ██ 9 ██
8 ██ 8 ██
7 ██ ... | #Groovy | Groovy |
Integer waterBetweenTowers(List<Integer> towers) {
// iterate over the vertical axis. There the amount of water each row can hold is
// the number of empty spots, minus the empty spots at the beginning and end
return (1..towers.max()).collect { height ->
// create a string representing the row, ... | 629 | 347 | 976 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
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 |... | #Common_Lisp | Common Lisp | (let ((a (read *standard-input*))
(b (read *standard-input*)))
(cond
((not (numberp a)) (format t "~A is not a number." a))
((not (numberp b)) (format t "~A is not a number." b))
((< a b) (format t "~A is less than ~A." a b))
((> a b) (format t "~A is greater than ~A." a b))
((= ... | 199 | 161 | 360 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Machine_code | Machine code | The task requires poking machine code directly into memory and executing it. The machine code is the architecture-specific opcodes which have the simple task of adding two unsigned bytes together and making the result available to the high-level language.
For example, the following assembly language program is given f... | #Common_Lisp | Common Lisp | ;;Note that by using the 'CFFI' library, one can apply this procedure portably in any lisp implementation;
;; in this code however I chose to demonstrate only the implementation-dependent programs.
;;CCL
;; Allocate a memory pointer and poke the opcode into it
(defparameter ptr (ccl::malloc 9))
(loop for i in '(13... | 329 | 697 | 1,026 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/String_length | String length | Task
Find the character and byte length of a string.
This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters.
By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters.
F... | #SNOBOL4 | SNOBOL4 |
output = "Byte length: " size(trim(input))
end
| 1,294 | 25 | 1,319 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Lambdatalk | Lambdatalk |
{def A
{A.new
{S.map {lambda {:x} {* :x :x}}
{S.serie 0 10}
}}}
{A.get 3 {A}} // equivalent to A[3]
-> 9
{A.get 4 {A}}
-> 16
| 237 | 97 | 334 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Generator/Exponential | Generator/Exponential | A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.
Generators are often built on top of coroutines or objects so that the internal state of the objec... | #Haskell | Haskell | import Data.List.Ordered
powers :: Int -> [Int]
powers m = map (^ m) [0..]
squares :: [Int]
squares = powers 2
cubes :: [Int]
cubes = powers 3
foo :: [Int]
foo = filter (not . has cubes) squares
main :: IO ()
main = print $ take 10 $ drop 20 foo | 283 | 110 | 393 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Ruby | Ruby | n = 20
# select Pythagorean triplets
r = ((1..n).flat_map { |x|
(x..n).flat_map { |y|
(y..n).flat_map { |z|
[[x, y, z]].keep_if { x * x + y * y == z * z }}}})
p r # print the array _r_ | 186 | 103 | 289 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Count_the_coins | Count the coins | There are four types of common coins in US currency:
quarters (25 cents)
dimes (10 cents)
nickels (5 cents), and
pennies (1 cent)
There are six ways to make change for 15 cents:
A dime and a nickel
A dime and 5 pennies
3 nickels
2 nickels and 5 pennies
A nickel and 10 pen... | #Clojure | Clojure | (def denomination-kind [1 5 10 25])
(defn- cc [amount denominations]
(cond (= amount 0) 1
(or (< amount 0) (empty? denominations)) 0
:else (+ (cc amount (rest denominations))
(cc (- amount (first denominations)) denominations))))
(defn count-change
"Calculates the number of time... | 323 | 144 | 467 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Substring | Substring |
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 |... | #Elixir | Elixir | s = "abcdefgh"
String.slice(s, 2, 3) #=> "cde"
String.slice(s, 1..3) #=> "bcd"
String.slice(s, -3, 2) #=> "fg"
String.slice(s, 3..-1) #=> "defgh"
# UTF-8
s = "αβγδεζηθ"
String.slice(s, 2, 3) #=> "γδε"
String.slice(s, 1..3) #=> "βγδ"
String.slice(s, -3, 2) ... | 1,204 | 195 | 1,399 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Monte_Carlo_methods | Monte Carlo methods | A Monte Carlo Simulation is a way of approximating the value of a function
where calculating the actual value is difficult or impossible.
It uses random sampling to define constraints on the value
and then makes a sort of "best guess."
A simple Monte Carlo Simulation can be used to calculate the value for
π
{\... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
procedure Test_Monte_Carlo is
Dice : Generator;
function Pi (Throws : Positive) return Float is
Inside : Natural := 0;
begin
for Throw in 1..Throws loop
if Random (Dice) **... | 363 | 361 | 724 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Append_a_record_to_the_end_of_a_text_file | Append a record to the end of a text file | Many systems offer the ability to open a file for writing, such that any data written will be appended to the end of the file. Further, the file operations will always adjust the position pointer to guarantee the end of the file, even in a multitasking environment.
This feature is most useful in the case of log files,... | #zkl | zkl | var [const]
gnames=T("fullname","office","extension","homephone","email"),
pnames=T("account","password","uid","gid","gecos","directory","shell");
class Gecos{
var fullname, office, extension, homephone, email;
fcn init(str){ gnames.zipWith(setVar,vm.arglist) }
fcn toString { gnames.apply(setVar).conc... | 895 | 184 | 1,079 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Latin_Squares_in_reduced_form | Latin Squares in reduced form | A Latin Square is in its reduced form if the first row and first column contain items in their natural order. The order n is the number of items. For any given n there is a set of reduced Latin Squares whose size increases rapidly with n. g is a number which identifies a unique element within the set of reduced Latin S... | #J | J |
redlat=: {{
perms=: (A.&i.~ !)~ y
sqs=. i.1 1,y
for_j.}.i.y do.
p=. (j={."1 perms)#perms
sel=.-.+./"1 p +./@:="1/"2 sqs
sqs=.(#~ 1-0*/ .="1{:"2),/sqs,"2 1 sel#"2 p
end.
}}
| 324 | 130 | 454 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Chat_server | Chat server | Task
Write a server for a minimal text based chat.
People should be able to connect via ‘telnet’, sign on with a nickname, and type messages which will then be seen by all other connected users. Arrivals and departures of chat members should generate appropriate notification messages.
| #Ol | Ol |
(define (timestamp) (syscall 201 "%c"))
(fork-server 'chat-room (lambda ()
(let this ((visitors #empty))
(let* ((envelope (wait-mail))
(sender msg envelope))
(case msg
(['join who name]
(let ((visitors (put visitors who name)))
(for-each (lambda (who)
(print-to... | 65 | 731 | 796 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Tokenize_a_string_with_escaping | Tokenize a string with escaping | Task[edit]
Write a function or program that can split a string at each non-escaped occurrence of a separator character.
It should accept three input parameters:
The string
The separator character
The escape character
It should output a list of strings.
Details
Rules for splitting:
The fields that were s... | #CLU | CLU | tokenize = iter (sep, esc: char, s: string) yields (string)
escape: bool := false
part: array[char] := array[char]$[]
for c: char in string$chars(s) do
if escape then
escape := false
array[char]$addh(part,c)
elseif c=esc then
escape := true
els... | 1,192 | 266 | 1,458 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Happy_numbers | Happy numbers | From Wikipedia, the free encyclopedia:
A happy number is defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not inclu... | #Locomotive_Basic | Locomotive Basic | 10 mode 1:defint a-z
20 for i=1 to 100
30 i2=i
40 for l=1 to 20
50 a$=str$(i2)
60 i2=0
70 for j=1 to len(a$)
80 d=val(mid$(a$,j,1))
90 i2=i2+d*d
100 next j
110 if i2=1 then print i;"is a happy number":n=n+1:goto 150
120 if i2=4 then 150 ' cycle found
130 next l
140 ' check if we have reached 8 numbers yet
150 if n=8 th... | 279 | 203 | 482 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
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)
... | #QB64 | QB64 | For n = 1 To 100
If n Mod 15 = 0 Then
Print "FizzBuzz"
ElseIf n Mod 5 = 0 Then
Print "Buzz"
ElseIf n Mod 3 = 0 Then
Print "Fizz"
Else
Print n
End If
Next | 229 | 83 | 312 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/RIPEMD-160 | RIPEMD-160 | RIPEMD-160 is another hash function; it computes a 160-bit message digest.
There is a RIPEMD-160 home page, with test vectors and pseudocode for RIPEMD-160.
For padding the message, RIPEMD-160 acts like MD4 (RFC 1320).
Find the RIPEMD-160 message digest of a string of octets.
Use the ASCII encoded string “Rosetta Cod... | #Ruby | Ruby | require 'digest'
puts Digest::RMD160.hexdigest('Rosetta Code') | 143 | 26 | 169 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Abundant_odd_numbers | Abundant odd numbers | An Abundant number is a number n for which the sum of divisors σ(n) > 2n,
or, equivalently, the sum of proper divisors (or aliquot sum) s(n) > n.
E.G.
12 is abundant, it has the proper divisors 1,2,3,4 & 6 which sum to 16 ( > 12 or n);
or alternately, has the sigma sum of ... | #Java | Java | import java.util.ArrayList;
import java.util.List;
public class AbundantOddNumbers {
private static List<Integer> list = new ArrayList<>();
private static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
System.out.println("First 25: ");
abundantOdd(1,10... | 453 | 534 | 987 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Extreme_floating_point_values | Extreme floating point values | The IEEE floating point specification defines certain 'extreme' floating point values such as minus zero, -0.0, a value distinct from plus zero; not a number, NaN; and plus and minus infinity.
The task is to use expressions involving other 'normal' floating point values in your language to calculate these, (and maybe ... | #bc | bc | $ bc
# trying for negative zero
-0
0
# trying to underflow to negative zero
-1 / 2
0
# trying for NaN (not a number)
0 / 0
dc: divide by zero
0
sqrt(-1)
dc: square root of negative number
dc: stack empty
dc: stack empty
| 180 | 83 | 263 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Detect_division_by_zero | Detect division by zero | Task
Write a function to detect a divide by zero error without checking if the denominator is zero.
| #Eiffel | Eiffel | class MAIN
creation main
feature main is
local
x, y: INTEGER;
retried: BOOLEAN;
do
x := 42;
y := 0;
if not retried then
io.put_real(x / y);
else
print("NaN%N");
end
rescu... | 32 | 119 | 151 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Nonoblock | Nonoblock | Nonoblock is a chip off the old Nonogram puzzle.
Given
The number of cells in a row.
The size of each, (space separated), connected block of cells to fit in the row, in left-to right order.
Task
show all possible positions.
show the number of positions of the blocks for the following cases within the row. ... | #REXX | REXX | /*REXX program enumerates all possible configurations (or an error) for nonogram puzzles*/
$.=; $.1= 5 2 1
$.2= 5
$.3= 10 8
$.4= 15 2 3 2 3
$.5= 5 2 3
do i=1 while $.i\==''
parse var $.i N bl... | 678 | 1,039 | 1,717 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Sidef | Sidef | require('DateTime')
var (year=2016) = ARGV.map{.to_i}...
for month (1..12) {
var dt = %O<DateTime>.last_day_of_month(year => year, month => month)
while (dt.day_of_week != 5) {
dt.subtract(days => 1)
}
say dt.ymd
} | 248 | 109 | 357 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Dot_product | Dot product | Task
Create a function/use an in-built function, to compute the dot product, also known as the scalar product of two vectors.
If possible, make the vectors of arbitrary length.
As an example, compute the dot product of the vectors:
[1, 3, -5] and
[4, -2, -1]
If implementing the dot ... | #VBScript | VBScript |
WScript.Echo DotProduct("1,3,-5","4,-2,-1")
Function DotProduct(vector1,vector2)
arrv1 = Split(vector1,",")
arrv2 = Split(vector2,",")
If UBound(arrv1) <> UBound(arrv2) Then
WScript.Echo "The vectors are not of the same length."
Exit Function
End If
DotProduct = 0
For i = 0 To UBound(arrv1)
DotProduct =... | 176 | 167 | 343 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Command-line_arguments | Command-line arguments | Command-line arguments is part of Short Circuit's Console Program Basics selection.
Scripted main
See also Program name.
For parsing command line arguments intelligently, see Parsing command-line arguments.
Example command line:
myprogram -c "alpha beta" -h "gamma"
| #Vlang | Vlang | import os
fn main() {
for i, x in os.args[1..] {
println("the argument #$i is $x")
}
} | 67 | 46 | 113 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Stair-climbing_puzzle | Stair-climbing puzzle | From Chung-Chieh Shan (LtU):
Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a... | #Prolog | Prolog | step_up :- \+ step, step_up, step_up. | 377 | 16 | 393 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Matrix_transposition | Matrix transposition | Transpose an arbitrarily sized rectangular Matrix.
| #Visual_Basic | Visual Basic | Option Explicit
'----------------------------------------------------------------------
Function TransposeMatrix(InitMatrix() As Long, TransposedMatrix() As Long)
Dim l1 As Long, l2 As Long, u1 As Long, u2 As Long, r As Long, c As Long
l1 = LBound(InitMatrix, 1)
l2 = LBound(InitMatrix, 2)
u1 = UBound(InitMatrix, ... | 14 | 584 | 598 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Integer_comparison | Integer comparison |
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 |... | #PL.2FI | PL/I |
declare (a, b) fixed binary;
get list (a, b);
if a = b then
put skip list ('The numbers are equal');
if a > b then
put skip list ('The first number is greater than the second');
if a < b then
put skip list ('The second number is greater than the first');
| 199 | 89 | 288 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Walk_a_directory/Non-recursively | Walk a directory/Non-recursively | Task
Walk a given directory and print the names of files matching a given pattern.
(How is "pattern" defined? substring match? DOS pattern? BASH pattern? ZSH pattern? Perl regular expression?)
Note: This task is for non-recursive methods. These tasks should read a single directory, not an entire directory tree.
... | #BBC_BASIC | BBC BASIC | directory$ = "C:\Windows\"
pattern$ = "*.ini"
PROClistdir(directory$ + pattern$)
END
DEF PROClistdir(afsp$)
LOCAL dir%, sh%, res%
DIM dir% LOCAL 317
SYS "FindFirstFile", afsp$, dir% TO sh%
IF sh% <> -1 THEN
REPEAT
PRINT $$(dir%+44)
SYS ... | 121 | 151 | 272 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/N-smooth_numbers | N-smooth numbers | n-smooth numbers are positive integers which have no prime factors > n.
The n (when using it in the expression) n-smooth is always prime,
there are no 9-smooth numbers.
1 (unity) is always included in n-smooth numbers.
2-smooth numbers are non-negative powers of two.
5-smooth numbers are... | #Julia | Julia | using Primes
function nsmooth(N, needed)
nexts, smooths = [BigInt(i) for i in 2:N if isprime(i)], [BigInt(1)]
prim, count = deepcopy(nexts), 1
indices = ones(Int, length(nexts))
while count < needed
x = minimum(nexts)
push!(smooths, x)
count += 1
for j in 1:length(nexts... | 869 | 429 | 1,298 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Hailstone_sequence | Hailstone sequence | The Hailstone sequence of numbers can be generated from a starting positive integer, n by:
If n is 1 then the sequence ends.
If n is even then the next n of the sequence = n/2
If n is odd then the next n of the sequence = (3 * n) + 1
The (unproven) Collatz conje... | #jq | jq | # Generate the hailstone sequence as a stream to save space (and time) when counting
def hailstone:
recurse( if . > 1 then
if . % 2 == 0 then ./2|floor else 3*. + 1 end
else empty
end );
def count(g): reduce g as $i (0; .+1);
# return [i, length] for the first maximal-length ha... | 548 | 201 | 749 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Input_loop | Input loop | Input loop is part of Short Circuit's Console Program Basics selection.
Task
Read from a text stream either word-by-word or line-by-line until the stream runs out of data.
The stream will have an unknown amount of data on it.
| #Raku | Raku | rebol [
Title: "Basic Input Loop"
URL: http://rosettacode.org/wiki/Basic_input_loop
]
; Slurp the whole file in:
x: read %file.txt
; Bring the file in by lines:
x: read/lines %file.txt
; Read in first 10 lines:
x: read/lines/part %file.txt 10
; Read data a line at a time:
f: open/lines %file.txt
while [not ta... | 62 | 166 | 228 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Ethiopian_multiplication | Ethiopian multiplication | Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.
Method:
Take two numbers to be multiplied and write them down at the top of two columns.
In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last ... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | IntegerHalving[x_]:=Floor[x/2]
IntegerDoubling[x_]:=x*2;
OddInteger OddQ
Ethiopian[x_, y_] :=
Total[Select[NestWhileList[{IntegerHalving[#[[1]]],IntegerDoubling[#[[2]]]}&, {x,y}, (#[[1]]>1&)], OddQ[#[[1]]]&]][[2]]
Ethiopian[17, 34] | 515 | 126 | 641 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
http://rosettacode.org/wiki/Set | Set |
Data Structure
This illustrates a data structure, a means of storing data within a program.
You may see other such structures in the Data Structures category.
A set is a collection of elements, without duplicates and without order.
Task
Show each of these set operations:
Set creation
Test m ∈ S -- "m is an... | #ATS | ATS | (*------------------------------------------------------------------*)
#define ATS_DYNLOADFLAG 0
#include "share/atspre_staload.hats"
(*------------------------------------------------------------------*)
(* String hashing using XXH3_64bits from the xxHash suite. *)
#define ATS_EXTERN_PREFIX "hashsets_... | 510 | 8,471 | 8,981 | main/data/train-00000-of-00001-8b4da49264116bbf.parquet |
README.md exists but content is empty.
- Downloads last month
- 4