Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
11
Task/Generate-lower-case-ASCII-alphabet/00DESCRIPTION
Normal file
11
Task/Generate-lower-case-ASCII-alphabet/00DESCRIPTION
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Generate an array, list, lazy sequence, or even an indexable string
|
||||
of all the lower case ASCII characters, from 'a' to 'z'.
|
||||
|
||||
If the standard library contains such sequence, show how to access it,
|
||||
but don't fail to show how to generate a similar sequence.
|
||||
For this basic task use a reliable style of coding, a style fit for a very large program, and use strong typing if available.
|
||||
|
||||
It's bug prone to enumerate all the lowercase chars manually in the code.
|
||||
During code review it's not immediate to spot the bug in a Tcl line like this contained in a page of code:
|
||||
|
||||
<lang tcl>set alpha {a b c d e f g h i j k m n o p q r s t u v w x y z}</lang>
|
||||
2
Task/Generate-lower-case-ASCII-alphabet/00META.yaml
Normal file
2
Task/Generate-lower-case-ASCII-alphabet/00META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: String_manipulation
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# in ALGOL 68, a STRING is an array of characters with flexible bounds #
|
||||
# so we can declare an array of 26 characters and assign a string #
|
||||
# containing the lower-case letters to it #
|
||||
|
||||
[ 26 ]CHAR lc := "abcdefghijklmnopqrstuvwxyz"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# fills lc with the 26 lower-case letters, assuming that #
|
||||
# they are consecutive in the character set, as they are in ASCII #
|
||||
|
||||
[ 26 ]CHAR lc;
|
||||
|
||||
FOR i FROM LWB lc TO UPB lc
|
||||
DO
|
||||
lc[ i ] := REPR ( ABS "a" + ( i - 1 ) )
|
||||
OD
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
(* ****** ****** *)
|
||||
//
|
||||
// How to compile:
|
||||
//
|
||||
// patscc -DATS_MEMALLOC_LIBC -o lowercase lowercase.dats
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
#include
|
||||
"share/atspre_staload.hats"
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
implement
|
||||
main0 () =
|
||||
{
|
||||
//
|
||||
val N = 26
|
||||
//
|
||||
val A =
|
||||
arrayref_tabulate_cloref<char>
|
||||
(
|
||||
i2sz(N), lam(i) => int2char0(char2int0('a') + sz2i(i))
|
||||
) (* end of [val] *)
|
||||
//
|
||||
} (* end of [main0] *)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# syntax: GAWK -f GENERATE_LOWER_CASE_ASCII_ALPHABET.AWK
|
||||
BEGIN {
|
||||
for (i=0; i<=255; i++) {
|
||||
c = sprintf("%c",i)
|
||||
if (c ~ /[[:lower:]]/) {
|
||||
lower_chars = lower_chars c
|
||||
}
|
||||
}
|
||||
printf("%s %d: %s\n",ARGV[0],length(lower_chars),lower_chars)
|
||||
exit(0)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
type Lower_Case is new Character range 'a' .. 'z';
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
type Arr_Type is array (Integer range <>) of Lower_Case;
|
||||
A : Arr_Type (1 .. 26) := "abcdefghijklmnopqrstuvwxyz";
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
B : Arr_Type (1 .. 26);
|
||||
begin
|
||||
B(B'First) := 'a';
|
||||
for I in B'First .. B'Last-1 loop
|
||||
B(I+1) := Lower_Case'Succ(B(I));
|
||||
end loop; -- now all the B(I) are different
|
||||
|
|
@ -0,0 +1 @@
|
|||
L$="abcdefghijklmnopqrstuvwxyz"
|
||||
|
|
@ -0,0 +1 @@
|
|||
L$="":FORI=1TO26:L$=L$+CHR$(96+I):NEXT
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a :={}
|
||||
Loop, 26
|
||||
a.Insert(Chr(A_Index + 96))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
DIM lower&(25)
|
||||
FOR i%=0TO25
|
||||
lower&(i%)=ASC"a"+i%
|
||||
NEXT
|
||||
END
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a:?seq:?c
|
||||
& whl
|
||||
' ( chr$(asc$!c+1):~>z:?c
|
||||
& !seq !c:?seq
|
||||
)
|
||||
& !seq
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#include <string>
|
||||
#include <numeric>
|
||||
|
||||
int main() {
|
||||
std::string lower(26,' ');
|
||||
|
||||
std::iota(lower.begin(), lower.end(), 'a');
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
namespace RosettaCode.GenerateLowerCaseASCIIAlphabet
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static IEnumerable<char> Alphabet
|
||||
{
|
||||
get
|
||||
{
|
||||
for (var character = 'a'; character <= 'z'; character++)
|
||||
{
|
||||
yield return character;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Main()
|
||||
{
|
||||
Console.WriteLine(string.Join(string.Empty, Alphabet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#define N 26
|
||||
|
||||
int main() {
|
||||
unsigned char lower[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
lower[i] = i + 'a';
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
(map char (range (int \a) (inc (int \z))))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(defvar *lower*
|
||||
(loop with a = (char-code #\a)
|
||||
for i upto 25
|
||||
collect (code-char (+ a i))))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import std.ascii: lowercase;
|
||||
|
||||
void main() {}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
void main() {
|
||||
char['z' - 'a' + 1] arr;
|
||||
|
||||
foreach (immutable i, ref c; arr)
|
||||
c = 'a' + i;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
void main() {
|
||||
import std.range, std.algorithm, std.array;
|
||||
|
||||
char[26] arr = 26.iota.map!(i => cast(char)('a' + i)).array;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
void main() {
|
||||
char[] arr;
|
||||
|
||||
foreach (immutable char c; 'a' .. 'z' + 1)
|
||||
arr ~= c;
|
||||
|
||||
assert(arr == "abcdefghijklmnopqrstuvwxyz");
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
program atoz;
|
||||
|
||||
var
|
||||
ch : char;
|
||||
|
||||
begin
|
||||
for ch in ['a'..'z'] do
|
||||
begin
|
||||
write(ch);
|
||||
end;
|
||||
end.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
USING: spelling ; ! ALPHABET
|
||||
|
||||
ALPHABET print
|
||||
0x61 0x7A [a,b] >string print
|
||||
: russian-alphabet-without-io ( -- str ) 0x0430 0x0450 [a,b) >string ;
|
||||
: russian-alphabet ( -- str ) 0x0451 6 russian-alphabet-without-io insert-nth ;
|
||||
russian-alphabet print
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
character(26) :: alpha
|
||||
integer :: i
|
||||
|
||||
do i = 1, 26
|
||||
alpha(i:i) = achar(iachar('a') + i - 1)
|
||||
end do
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
func loweralpha() string {
|
||||
p := make([]byte, 26)
|
||||
for i := range p {
|
||||
p[i] = 'a' + byte(i)
|
||||
}
|
||||
return string(p)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
def lower = ('a'..'z')
|
||||
|
|
@ -0,0 +1 @@
|
|||
assert 'abcdefghijklmnopqrstuvwxyz' == lower.join('')
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
lower = ['a' .. 'z']
|
||||
|
||||
main = do
|
||||
print lower
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
every a := put([], !&lcase) # array of 1 character per element
|
||||
c := create !&lcase # lazy generation of letters in sequence
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
([+i.@-.@-)&.(a.&i.)/'az'
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
public class LowerAscii {
|
||||
|
||||
public static void main(String[] args) {
|
||||
StringBuilder sb = new StringBuilder(26);
|
||||
for (char ch = 'a'; ch <= 'z'; ch++)
|
||||
sb.append(ch);
|
||||
System.out.printf("lower ascii: %s, length: %s", sb, sb.length());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var letters = []
|
||||
for (var i = 97; i <= 122; i++) {
|
||||
letters.push(String.fromCodePoint(i))
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
['a':'z']
|
||||
|
||||
[c for c = 'a':'z']
|
||||
|
||||
string('a':'z'...)
|
||||
|
|
@ -0,0 +1 @@
|
|||
show map "char iseq 97 122
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
start = 97;
|
||||
lowerCaseLetters = Table[FromCharacterCode[start + i], {i, 0, 25}]
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
:- module gen_lowercase_ascii.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- import_module char, int, list.
|
||||
|
||||
main(!IO) :-
|
||||
list.map(char.det_from_int, 0'a .. 0'z, Alphabet),
|
||||
io.print_line(Alphabet, !IO).
|
||||
|
||||
:- end_module gen_lowercase_ascii.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
$lower = range('a', 'z');
|
||||
var_dump($lower);
|
||||
?>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
gen: procedure options (main); /* 7 April 2014. */
|
||||
declare 1 ascii union,
|
||||
2 letters (26) character (1),
|
||||
2 iletters(26) unsigned fixed binary (8),
|
||||
letter character(1);
|
||||
declare i fixed binary;
|
||||
|
||||
letters(1), letter = lowercase('A');
|
||||
|
||||
do i = 2 to 26;
|
||||
iletters(i) = iletters(i-1) + 1;
|
||||
end;
|
||||
put edit (letters) (a);
|
||||
|
||||
end gen;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/* Accessing library lower-case ASCII (PC only). */
|
||||
|
||||
letter = lowercase('A');
|
||||
i = index(collate(), letter);
|
||||
put skip list (substr(collate, i, 26));
|
||||
|
|
@ -0,0 +1 @@
|
|||
say 'a'..'z'
|
||||
|
|
@ -0,0 +1 @@
|
|||
print 'a'..'z'
|
||||
|
|
@ -0,0 +1 @@
|
|||
(mapcar char (range (char "a") (char "z")))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
a_to_z(From, To, L) :-
|
||||
maplist(atom_codes, [From, To], [[C_From], [C_To]]),
|
||||
bagof([C], between(C_From, C_To, C), L1),
|
||||
maplist(atom_codes,L, L1).
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Dim lower_case('z' - 'a') ;indexing goes from 0 -> 25
|
||||
For i = 0 To ArraySize(lower_case())
|
||||
lower_case(i) = i + 'a'
|
||||
Next
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# From the standard library:
|
||||
from string import ascii_lowercase
|
||||
|
||||
# Generation:
|
||||
lower = [chr(i) for i in range(ord('a'), ord('z') + 1)]
|
||||
1
Task/Generate-lower-case-ASCII-alphabet/README
Normal file
1
Task/Generate-lower-case-ASCII-alphabet/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Data source: http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* 08.02.2014 Walter Pachl
|
||||
*--------------------------------------------------------------------*/
|
||||
say xrange('a','z')
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
/*REXX pgm creates an indexable string of lowercase ASCII characters a ──► z */
|
||||
LC='' /*set lowercase letters list to null*/
|
||||
do j=0 for 2**8; _=d2c(j) /*convert decimal J to character. */
|
||||
if datatype(_,'L') then LC=LC||_ /*Lowercase? Then add it to LC list*/
|
||||
end /*j*/ /* [↑] add lowercase letters ──► LC*/
|
||||
say LC /*stick a fork in it, we're all done*/
|
||||
|
|
@ -0,0 +1 @@
|
|||
(define lowercase-letters (build-list 26 (lambda (x) (integer->char (+ x (char->integer #\a))))))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
p ('a' .. 'z').to_a
|
||||
p [*'a' .. 'z']
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
object Abc extends App {
|
||||
val lowAlfa = 'a' to 'z' //That's all
|
||||
// Now several tests
|
||||
assert(lowAlfa.toSeq == Seq('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'),
|
||||
"No complete lowercase alfabet.")
|
||||
assert(lowAlfa.size == 26, "No 26 characters in alfabet")
|
||||
assert(lowAlfa.start == 'a', "Character 'a' not first char! ???")
|
||||
assert(lowAlfa.head == 'a', "Character 'a' not heading! ???")
|
||||
assert(lowAlfa.head == lowAlfa(0), "Heading char is not first char.")
|
||||
assert(lowAlfa contains 'n', "Character n not present.")
|
||||
assert(lowAlfa.indexOf('n') == 13, "Character n not on the 14th position.")
|
||||
assert(lowAlfa.last == lowAlfa(25), "Expected character (z)on the last and 26th pos.")
|
||||
|
||||
println(s"Successfully completed without errors. [within ${
|
||||
scala.compat.Platform.currentTime - executionStart
|
||||
} ms]")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
(map integer->char (iota 26 (char->integer #\a)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
val lowercase_letters = List.tabulate (26, fn x => chr (x + ord #"a"));
|
||||
|
|
@ -0,0 +1 @@
|
|||
set alpha {a b c d e f g h i j k l m n o p q r s t u v w x y z}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
set alpha [apply {{} {
|
||||
scan "az" "%c%c" from to
|
||||
for {set i $from} {$i <= $to} {incr i} {
|
||||
lappend l [format "%c" $i]
|
||||
}
|
||||
return $l
|
||||
}}]
|
||||
|
|
@ -0,0 +1 @@
|
|||
lower=({a..z})
|
||||
|
|
@ -0,0 +1 @@
|
|||
lower=({a-z})
|
||||
|
|
@ -0,0 +1 @@
|
|||
echo "${lower[@]}"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
let lower = []
|
||||
for c in range(0, 25)
|
||||
let lower += [nr2char(c + char2nr("a"))]
|
||||
endfor
|
||||
|
|
@ -0,0 +1 @@
|
|||
echo map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)')
|
||||
Loading…
Add table
Add a link
Reference in a new issue