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/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #C.23 | C# | using System;
using System.IO;
using System.Text;
namespace RosettaFileByChar
{
class Program
{
static char GetNextCharacter(StreamReader streamReader) => (char)streamReader.Read();
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
char... |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Common_Lisp | Common Lisp | ;; CLISP puts the external formats into a separate package
#+clisp (import 'charset:utf-8 'keyword)
(with-open-file (s "input.txt" :external-format :utf-8)
(loop for c = (read-char s nil)
while c
do (format t "~a" c))) |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #C | C | #include <stdio.h>
#include <time.h>
// We only get one-second precision on most systems, as
// time_t only holds seconds.
struct rate_state_s
{
time_t lastFlush;
time_t period;
size_t tickCount;
};
void tic_rate(struct rate_state_s* pRate)
{
pRate->tickCount += 1;
time_t now = time(NULL);
... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #jq | jq | def reverse_string: explode | reverse | implode; |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
begin
writeln("ha" mult 5);
end func; |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #SenseTalk | SenseTalk |
put "Ho!" repeated 3 times
put "Merry" repeated to length 12
|
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #PHP | PHP | $list = array(1, 2, 3, 'a', 'b', 'c', 2, 3, 4, 'b', 'c', 'd');
$unique_list = array_unique($list); |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Crystal | Crystal | File.open("input.txt") do |file|
file.each_char { |c| p c }
end |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Delphi | Delphi |
program Read_a_file_character_by_character_UTF8;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Classes;
function GetNextCharacter(StreamReader: TStreamReader): char;
begin
Result := chr(StreamReader.Read);
end;
const
FileName: TFileName = 'input.txt';
begin
if not FileExists(FileName) then
r... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #C.2B.2B | C++ | #include <iostream>
#include <ctime>
// We only get one-second precision on most systems, as
// time_t only holds seconds.
class CRateState
{
protected:
time_t m_lastFlush;
time_t m_period;
size_t m_tickCount;
public:
CRateState(time_t period);
void Tick();
};
CRateState::CRateState(time_t perio... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #Jsish | Jsish | var str = "Never odd or even";
puts(str);
puts(str.split('').reverse().join('')); |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Sidef | Sidef | 'ha' * 5; # ==> 'hahahahaha' |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Sinclair_ZX81_BASIC | Sinclair ZX81 BASIC | 10 LET S$="HA"
20 LET N=5
30 GOSUB 60
40 PRINT T$
50 STOP
60 LET T$=""
70 FOR I=1 TO N
80 LET T$=T$+S$
90 NEXT I
100 RETURN |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #PicoLisp | PicoLisp | (uniq (2 4 6 1 2 3 4 5 6 1 3 5)) |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #D.C3.A9j.C3.A0_Vu | Déjà Vu | #helper function that deals with non-ASCII code points
local (read-utf8-char) file tmp:
!read-byte file
if = :eof dup:
drop
raise :unicode-error
resize-blob tmp ++ dup len tmp
set-to tmp
try:
return !decode!utf-8 tmp
catch unicode-error:
if < 3 len tmp:
... |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Factor | Factor | USING: kernel io io.encodings.utf8 io.files strings ;
IN: rosetta-code.read-one
"input.txt" utf8 [
[ read1 dup ] [ 1string write ] while drop
] with-file-reader |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #FreeBASIC | FreeBASIC | Dim As Long f
f = Freefile
Dim As String filename = "file.txt"
Dim As String*1 txt
Open filename For Binary As #f
While Not Eof(f)
txt = String(Lof(f), 0)
Get #f, , txt
Print txt;
Wend
Close #f
Sleep |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Common_Lisp | Common Lisp | (time (do some stuff)) |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Crystal | Crystal | require "benchmark"
struct Document
property :id
def initialize(@id : Int32) end
end
documents_a = [] of Int32 | Document
documents_h = {} of Int32 => Int32 | Document
1.upto(10_000) do |n|
d = Document.new(n)
documents_a << d
documents_h[d.id] = d
end
searchlist = Array.new(1000){ rand(10_000)+1 }
... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #Julia | Julia | julia> reverse("hey")
"yeh" |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Smalltalk | Smalltalk | v := 'ha'.
v,v,v,v,v |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #SNOBOL4 | SNOBOL4 | output = dupl("ha",5)
end |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #PL.2FI | PL/I | *process mar(1,72);
remdup: Proc options(main);
declare t(20) fixed initial (6, 6, 1, 5, 6, 2, 1, 7,
5, 22, 4, 19, 1, 1, 6, 8, 9, 10, 11, 12);
declare (i, j, k, n, e) fixed;
put skip list ('Input:');
put edit ((t(k) do k = 1 to hbound(t))) (skip,20(f(3)));
n = hbound(t,1);
i = 0;
outer:
do ... |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Pop11 | Pop11 | ;;; Initial array
lvars ar = {1 2 3 2 3 4};
;;; Create a hash table
lvars ht= newmapping([], 50, 0, true);
;;; Put all array as keys into the hash table
lvars i;
for i from 1 to length(ar) do
1 -> ht(ar(i))
endfor;
;;; Collect keys into a list
lvars ls = [];
appdata(ht, procedure(x); cons(front(x), ls) -> ls; endp... |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #FunL | FunL | import io.{InputStreamReader, FileInputStream}
r = InputStreamReader( FileInputStream('input.txt'), 'UTF-8' )
while (ch = r.read()) != -1
print( chr(ch) )
r.close() |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Go | Go | package main
import (
"bufio"
"fmt"
"io"
"os"
)
func Runer(r io.RuneReader) func() (rune, error) {
return func() (r rune, err error) {
r, _, err = r.ReadRune()
return
}
}
func main() {
runes := Runer(bufio.NewReader(os.Stdin))
for r, err := runes(); err != nil; r,er... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #D | D |
import std.stdio;
import std.conv;
import std.datetime.stopwatch;
int a;
void f0() {}
void f1() { auto b = a; }
void f2() { auto b = to!string(a); }
void main()
{
auto r = benchmark!(f0, f1, f2)(10_000);
writeln("Time fx took to run 10,000 times:\n");
writeln("f0: ", r[0]);
writeln("f1: ", r[1]);
wr... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #K | K |
|"asdf"
"fdsa"
| 23 4 5 1
1 5 4 23
|
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Sparkling | Sparkling | spn:3> repeat("na", 8) .. " Batman!"
= nananananananana Batman! |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #SQL | SQL | SELECT rpad('', 10, 'ha') |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #PostScript | PostScript |
[10 8 8 98 32 2 4 5 10 ] dup length dict begin aload let* currentdict {pop} map end
|
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Haskell | Haskell | #!/usr/bin/env runhaskell
{- The procedure to read a UTF-8 character is just:
hGetChar :: Handle -> IO Char
assuming that the encoding for the handle has been set to utf8.
-}
import System.Environment (getArgs)
import System.IO (
Handle, IOMode (..),
hGetChar, hIsEOF, hSetEncoding, stdin, ... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Delphi | Delphi |
program Rate_counter;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Diagnostics;
var
a: Integer;
function TickToString(Tick: Int64): string;
var
ns, us, ms, s, t: Cardinal;
begin
Result := '';
ns := (Tick mod 10) * 100;
if ns > 0 then
Result := format(' %dns', [ns]);
t := Tick div 10;
... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #Kotlin | Kotlin | fun main(args: Array<String>) {
println("asdf".reversed())
} |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #SQL_PL | SQL PL |
VALUES REPEAT('ha', 5);
VALUES RPAD('', 10, 'ha');
|
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Standard_ML | Standard ML | fun string_repeat (s, n) =
concat (List.tabulate (n, fn _ => s))
; |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #PowerShell | PowerShell | $data = 1,2,3,1,2,3,4,1 |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #J | J | u8len=: 1 >. 0 i.~ (8#2)#:a.&i. |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Java | Java | import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) throws IOException {
var reader = new FileReader("input.txt", StandardCharsets.UTF_8);
while (true) {
int c = reader.read();
... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #E | E | def makeLamportSlot := <import:org.erights.e.elib.slot.makeLamportSlot>
The rate counter:
/** Returns a function to call to report the event being counted, and an
EverReporter slot containing the current rate, as a float64 in units of
events per millisecond. */
def makeRateCounter(timer, reportPeriod) {
... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #L.2B.2B | L++ | (include "string" "algorithm")
(main
(decl std::string s)
(std::getline std::cin s)
(std::reverse (s.begin) (s.end))
(prn s)) |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Stata | Stata | . scalar a="ha"
. scalar b=a*5
. display b
hahahahaha |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Suneido | Suneido | 'ha'.Repeat(5) --> "hahahahaha"
'*'.Repeat(5) --> "*****" |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #11l | 11l | V f = File(‘input.txt’)
V line = 3
L 0 .< line - 1
f.read_line()
print(f.read_line()) |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Prolog | Prolog | uniq(Data,Uniques) :- sort(Data,Uniques). |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #jq | jq | def readc:
inputs + "\n" | explode[] | [.] | implode; |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Erlang | Erlang |
-module( rate_counter ).
-export( [fun_during_seconds/2, task/0] ).
fun_during_seconds( Fun, Seconds ) ->
My_pid = erlang:self(),
Ref = erlang:make_ref(),
Pid = erlang:spawn( fun() -> fun_during_seconds_loop( My_pid, Fun ) end ),
timer:send_after( Seconds * 1000, My_pid, {stop, Ref} ),
N = fun_... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #LabVIEW | LabVIEW |
{S.reverse hello brave new world}
-> world new brave hello
|
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Swift | Swift | print(String(repeating:"*", count: 5)) |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #Action.21 | Action! | BYTE FUNC ReadLine(CHAR ARRAY fname CARD index CHAR ARRAY result)
CHAR ARRAY line(255)
CARD curr
BYTE status,dev=[1]
Close(dev)
Open(dev,fname,4)
curr=1 status=1
WHILE Eof(dev)=0
DO
InputSD(dev,line)
IF curr=index THEN
SCopy(result,line)
status=0
EXIT
FI
curr==+1
OD... |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #PureBasic | PureBasic | NewMap MyElements.s()
For i=0 To 9 ;Mark 10 items at random, causing high risk of duplication items.
x=Random(9)
t$="Number "+str(x)+" is marked"
MyElements(str(x))=t$ ; Add element 'X' to the hash list or overwrite if already included.
Next
ForEach MyElements()
Debug MyElements()
Next |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Julia | Julia | open("myfilename") do f
while !eof(f)
c = read(f, Char)
println(c)
end
end |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #ERRE | ERRE |
PROGRAM RATE_COUNTER
!
! for rosettacode.org
!
!
! This is an example, replace with the task you want to measure
!
PROCEDURE TASK_TO_MEASURE
LOCAL I
FOR I=1 TO 1000000 DO
END FOR
END PROCEDURE
BEGIN
PRINT("Method 1: Calculate reciprocal of elapsed time:")
FOR TRIAL%=1 TO 3 DO
START=TIME... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #Lambdatalk | Lambdatalk |
{S.reverse hello brave new world}
-> world new brave hello
|
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Tailspin | Tailspin |
'$:1..5 -> 'ha';' -> !OUT::write
|
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
procedure Rosetta_Read is
File : File_Type;
begin
Open (File => File,
Mode => In_File,
Name => "rosetta_read.adb");
Set_Line (File, To => 7);
declare
Line_7 : constant String := Get_Line (File);
begin
if Line_7'Length = 0 then
... |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Python | Python | items = [1, 2, 3, 'a', 'b', 'c', 2, 3, 4, 'b', 'c', 'd']
unique = list(set(items)) |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Kotlin | Kotlin | // version 1.1.2
import java.io.File
const val EOF = -1
fun main(args: Array<String>) {
val reader = File("input.txt").reader() // uses UTF-8 by default
reader.use {
while (true) {
val c = reader.read()
if (c == EOF) break
print(c.toChar()) // echo to console
... |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Lua | Lua |
-- Return whether the given string is a single ASCII character.
function is_ascii (str)
return string.match(str, "[\0-\x7F]")
end
-- Return whether the given string is an initial byte in a multibyte sequence.
function is_init (str)
return string.match(str, "[\xC2-\xF4]")
end
-- Return whether the given stri... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Fortran | Fortran | DO I = FIRST,LAST
IF (PROGRESSNOTE((I - FIRST)/(LAST - FIRST + 1.0))) WRITE (6,*) "Reached ",I,", towards ",LAST
...much computation...
END DO |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #FreeBASIC | FreeBASIC |
Dim Shared As Integer i
Sub timeit
Dim As Integer iter = 0
Dim As Double starter = Timer
While True
iter += 1
If Timer >= starter + i Then Exit While
Wend
Print iter; " iteraciones en"; i; " milisegundo"; Iif(i > 1, "s", "")
End Sub
For i = 1 To 3
timeit
Next i
i = 200 :... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #Lang5 | Lang5 | : flip "" split reverse "" join ;
"qwer asdf" flip . |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Tcl | Tcl | string repeat "ha" 5 ;# => hahahahaha |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #TorqueScript | TorqueScript | function strRep(%str,%int)
{
for(%i = 0; %i < %int; %i++)
{
%rstr = %rstr@%str;
}
return %rstr;
} |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #Aime | Aime | void
read_line(text &line, text path, integer n)
{
file f;
f.affix(path);
call_n(n, f_slip, f);
f.line(line);
}
integer
main(void)
{
if (1 < argc()) {
text line;
read_line(line, argv(1), 6);
o_("7th line is:\n", line, "\n");
}
0;
} |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #ALGOL_68 | ALGOL 68 | # reads the line with number "number" (counting from 1) #
# from the file named "file name" and returns the text of the #
# in "line". If an error occurs, the result is FALSE and a #
# message is returned in "err". If no error occurs, TRUE is #
# returned #
... |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Qi | Qi |
(define remove-duplicates
[] -> []
[A|R] -> (remove-duplicates R) where (element? A R)
[A|R] -> [A|(remove-duplicates R)])
(remove-duplicates [a b a a b b c d e])
|
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Quackery | Quackery | [ dup [] = iff ]else[ done
' sortwith nested
]'[ nested join do
behead dup dip nested rot
witheach
[ tuck != if
[ dup dip
[ nested join ] ] ]
drop ] is uniquewith ( [ --> [ )
' [ 1 2 3 5 6 7 8 1 2 3 4 5 6 7 ] uniquewith > echo |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #M2000_Interpreter | M2000 Interpreter |
Module checkit {
\\ prepare a file
\\ Save.Doc and Append.Doc to file, Load.Doc and Merge.Doc from file
document a$
a$={First Line
Second line
Third Line
Ελληνικά Greek Letters
y䮀
成长汉
}
Save.Doc a$, "checkthis.txt... |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | str = OpenRead["file.txt"];
ToString[Read[str, "Character"], CharacterEncoding -> "UTF-8"] |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
numeric digits 20
runSample(arg)
return
-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
method readCharacters(fName) public static binary returns String
slurped = String('')
slrp = StringBuilder()
fr ... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Go | Go | package main
import (
"fmt"
"math/rand"
"time"
)
// representation of time.Time is nanosecond, actual resolution system specific
type rateStateS struct {
lastFlush time.Time
period time.Duration
tickCount int
}
func ticRate(pRate *rateStateS) {
pRate.tickCount++
now := time.Now(... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #langur | langur | writeln cp2s reverse s2cp q(don't you know) |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Tosh | Tosh | when flag clicked
set String to "meow"
set Count to 4
set Repeated to ""
repeat Count
set Repeated to (join (Repeated) (String))
end
stop this script |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Transact-SQL | Transact-SQL | select REPLICATE( 'ha', 5 ) |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #Amazing_Hopper | Amazing Hopper |
#include <hopper.h>
#define MAX_LINE_SIZE 1000
main:
v=0, fd=0
fsearch("-r $'\n'","archivo.txt")(v)
fopen(OPEN_READ,"archivo.txt")(fd)
{"Line #7 = "}, fgetsline(fd,MAX_LINE_SIZE,7,v), println
try
fgetsline(fd,MAX_LINE_SIZE,10,v),
catch(e)
{"Error search line (code=",e,"): "},get str err... |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #AutoHotkey | AutoHotkey | FileReadLine, OutputVar, filename.txt, 7
if ErrorLevel
MsgBox, There was an error reading the 7th line of the file |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #R | R | items <- c(1,2,3,2,4,3,2)
unique (items) |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Racket | Racket |
-> (remove-duplicates '(2 1 3 2.0 a 4 5 b 4 3 a 7 1 3 x 2))
'(2 1 3 2.0 a 4 5 b 7 x)
|
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Nim | Nim | import unicode
proc readUtf8(f: File): string =
## Return next UTF-8 character as a string.
while true:
result.add f.readChar()
if result.validateUtf8() == -1: break
iterator readUtf8(f: File): string =
## Yield successive UTF-8 characters from file "f".
var res: string
while not f.endOfFile:
... |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Pascal | Pascal | (* Read a file char by char *)
program ReadFileByChar;
var
InputFile,OutputFile: file of char;
InputChar: char;
begin
Assign(InputFile, 'testin.txt');
Reset(InputFile);
Assign(OutputFile, 'testout.txt');
Rewrite(OutputFile);
while not Eof(InputFile) do
begin
... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Haskell | Haskell |
import Control.Monad
import Control.Concurrent
import Data.Time
getTime :: IO DiffTime
getTime = fmap utctDayTime getCurrentTime
addSample :: MVar [a] -> a -> IO ()
addSample q v = modifyMVar_ q (return . (v:))
timeit :: Int -> IO a -> IO [DiffTime]
timeit n task = do
samples <- newMVar []
forM_ [0..n] ... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #Lasso | Lasso | local(input) = 'asdf'
#input->reverse |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
repeatstring=REPEAT ("ha",5)
|
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #UNIX_Shell | UNIX Shell | printf "ha"%.0s {1..5} |
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #AWK | AWK | #!/usr/bin/awk -f
#usage: readnthline.awk -v lineno=6 filename
FNR==lineno { storedline=$0; found++ }
END {
if (found < 1) {
print "ERROR: Line", lineno, "not found"
exit 1
}
print storedline
}
|
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Raku | Raku | my @unique = [1, 2, 3, 5, 2, 4, 3, -3, 7, 5, 6].unique; |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Perl | Perl | binmode STDOUT, ':utf8'; # so we can print wide chars without warning
open my $fh, "<:encoding(UTF-8)", "input.txt" or die "$!\n";
while (read $fh, my $char, 1) {
printf "got character $char [U+%04x]\n", ord $char;
}
close $fh; |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Phix | Phix | constant INVALID_UTF8 = #FFFD
function get_one_utf8_char(integer fn)
-- returns INVALID_UTF8 on error, else a string of 1..4 bytes representing one character
object res
integer headb, bytes, c
-- headb = first byte of utf-8 character:
headb = getc(fn)
if headb=-1 then return -1 end if
res = ""&headb... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #HicEst | HicEst | CHARACTER prompt='Count "Hits++" for 5 sec, get current rate'
DLG(Button="1:&Hits++", CALL="cb", B="2:&Count 5sec", B="3:&Rate", RC=retcod, TItle=prompt, WIN=hdl)
SUBROUTINE cb ! callback after dialog buttons
IF(retcod == 1) THEN ! "Hits++" button
Hits = Hits + 1
ELSEIF(retcod == 2) THEN ! ... |
http://rosettacode.org/wiki/Reverse_a_string | Reverse a string | Task
Take a string and reverse it.
For example, "asdf" becomes "fdsa".
Extra credit
Preserve Unicode combining characters.
For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
... | #LC3_Assembly | LC3 Assembly | .ORIG 0x3000
LEA R1,STRING
LEA R2,GNIRTS
LD R3,MINUS1
NOT R5,R1
ADD R5,R5,1
SCAN LDR R4,R1,0
BRZ COPY
ADD R1,R1,1
BRNZP SCAN
COPY ADD R1,R1,R3
ADD ... |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Ursala | Ursala | #import nat
repeat = ^|DlSL/~& iota
#cast %s
example = repeat('ha',5) |
http://rosettacode.org/wiki/Repeat_a_string | Repeat a string | Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Other tasks re... | #Vala | Vala |
string s = "ha";
string copy = "";
for (int x = 0; x < 5; x++)
copy += s;
|
http://rosettacode.org/wiki/Read_a_specific_line_from_a_file | Read a specific line from a file | Some languages have special semantics for obtaining a known line number from a file.
Task
Demonstrate how to obtain the contents of a specific line within a file.
For the purpose of this task demonstrate how the contents of the seventh line of a file can be obtained, and store it in a variable or in memory (fo... | #BASIC | BASIC | f = freefile
filename$ = "input.txt"
open f, filename$
lineapedida = 7
cont = 0
while not (eof(f))
linea$ = readline(f)
cont += 1
if cont = lineapedida then
if trim(linea$) = "" then print "The 7th line is empty" else print linea$
exit while
end if
end while
if cont < lineapedida then print "There a... |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #Raven | Raven | [ 1 2 3 'a' 'b' 'c' 2 3 4 'b' 'c' 'd' ] as items
items copy unique print
list (8 items)
0 => 1
1 => 2
2 => 3
3 => "a"
4 => "b"
5 => "c"
6 => 4
7 => "d" |
http://rosettacode.org/wiki/Remove_duplicate_elements | Remove duplicate elements |
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
... | #REBOL | REBOL | print mold unique [1 $23.19 2 elbow 3 2 Bork 4 3 elbow 2 $23.19] |
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #PicoLisp | PicoLisp |
(in "wordlist"
(while (char)
(process @))
|
http://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8 | Read a file character by character/UTF8 | Task
Read a file one character at a time, as opposed to reading the entire file at once.
The solution may be implemented as a procedure, which returns the next character in the file on each consecutive call (returning EOF when the end of the file is reached).
The procedure should support the reading of files contain... | #Python | Python |
def get_next_character(f):
# note: assumes valid utf-8
c = f.read(1)
while c:
while True:
try:
yield c.decode('utf-8')
except UnicodeDecodeError:
# we've encountered a multibyte character
# read another byte and try again
c += f.read(1)
else:
# c was... |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #J | J | x (6!:2) y |
http://rosettacode.org/wiki/Rate_counter | Rate counter | Of interest is the code that performs the actual measurements. Any other code (such as job implementation or dispatching) that is required to demonstrate the rate tracking is helpful, but not the focus.
Multiple approaches are allowed (even preferable), so long as they can accomplish these goals:
Run N seconds worth... | #Java | Java | import java.util.function.Consumer;
public class RateCounter {
public static void main(String[] args) {
for (double d : benchmark(10, x -> System.out.print(""), 10))
System.out.println(d);
}
static double[] benchmark(int n, Consumer<Integer> f, int arg) {
double[] timings =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.