Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -53,35 +53,48 @@ PROC commatize = ( STRING text, INT location, INT period, STRING separator )STRI
|
|||
# commatizing procedure #
|
||||
MODE COMMATIZINGOPTIONS = STRUCT( STRING text, INT location, INT period, STRING separator );
|
||||
PRIO LOCATION = 9;
|
||||
OP LOCATION = ( STRING text, INT location )COMMATIZINGOPTIONS: COMMATIZINGOPTIONS( text, location, 0, "" );
|
||||
OP LOCATION = ( STRING text, INT location )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text, location, 0, "" );
|
||||
PRIO PERIOD = 9;
|
||||
OP PERIOD = ( STRING text, INT period )COMMATIZINGOPTIONS: COMMATIZINGOPTIONS( text, 0, period, "" );
|
||||
OP PERIOD = ( STRING text, INT period )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text, 0, period, "" );
|
||||
PRIO SEPARATOR = 9;
|
||||
OP SEPARATOR = ( STRING text, CHAR separator )COMMATIZINGOPTIONS: COMMATIZINGOPTIONS( text, 0, 0, separator );
|
||||
OP SEPARATOR = ( STRING text, STRING separator )COMMATIZINGOPTIONS: COMMATIZINGOPTIONS( text, 0, 0, separator );
|
||||
OP SEPARATOR = ( STRING text, CHAR separator )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text, 0, 0, separator );
|
||||
OP SEPARATOR = ( STRING text, STRING separator )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text, 0, 0, separator );
|
||||
OP LOCATION = ( COMMATIZINGOPTIONS opts, INT location )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text OF opts, location, period OF opts, separator OF opts );
|
||||
COMMATIZINGOPTIONS( text OF opts, location, period OF opts, separator OF opts );
|
||||
OP PERIOD = ( COMMATIZINGOPTIONS opts, INT period )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text OF opts, location OF opts, period, separator OF opts );
|
||||
COMMATIZINGOPTIONS( text OF opts, location OF opts, period, separator OF opts );
|
||||
OP SEPARATOR = ( COMMATIZINGOPTIONS opts, CHAR separator )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text OF opts, location OF opts, period OF opts, separator );
|
||||
COMMATIZINGOPTIONS( text OF opts, location OF opts, period OF opts, separator );
|
||||
OP SEPARATOR = ( COMMATIZINGOPTIONS opts, STRING separator )COMMATIZINGOPTIONS:
|
||||
COMMATIZINGOPTIONS( text OF opts, location OF opts, period OF opts, separator );
|
||||
COMMATIZINGOPTIONS( text OF opts, location OF opts, period OF opts, separator );
|
||||
OP COMMATIZE = ( STRING text )STRING: commatize( text, 0, 0, "" );
|
||||
OP COMMATIZE = ( COMMATIZINGOPTIONS opts )STRING:
|
||||
commatize( text OF opts, location OF opts, period OF opts, separator OF opts );
|
||||
commatize( text OF opts, location OF opts, period OF opts, separator OF opts );
|
||||
|
||||
# test the commatization procedure and operators #
|
||||
print( ( COMMATIZE( "pi=3.14159265358979323846264338327950288419716939937510582097494459231" PERIOD 5 SEPARATOR " " LOCATION 6 ),
|
||||
newline ) );
|
||||
print( ( COMMATIZE( "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)." SEPARATOR "." ), newline ) );
|
||||
print( ( COMMATIZE """-in Aus$+1411.8millions""", newline ) );
|
||||
print( ( COMMATIZE "===US$0017440 millions=== (in 2000 dollars)", newline ) );
|
||||
print( ( COMMATIZE "123.e8000 is pretty big.", newline ) );
|
||||
print( ( COMMATIZE "The land area of the earth is 57268900(29% of the surface) square miles.", newline ) );
|
||||
print( ( COMMATIZE "Ain't no numbers in this here words, nohow, no way, Jose.", newline ) );
|
||||
print( ( COMMATIZE "James was never known as 0000000007", newline ) );
|
||||
print( ( COMMATIZE "Arthur Eddington wrote: I believe there are 15747724136275002577605653961181555468044717914527116709366231425076185631031296 protons in the universe.",
|
||||
newline ) );
|
||||
print( ( COMMATIZE " $-140000±100 millions.", newline ) );
|
||||
print( ( COMMATIZE "6/9/1946 was a good year for some.", newline ) )
|
||||
print( ( COMMATIZE( "pi=3.14159265358979323846264338327950288419716939937510582097494459231"
|
||||
PERIOD 5 SEPARATOR " " LOCATION 6 ), newline ) );
|
||||
print( ( COMMATIZE( "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)."
|
||||
SEPARATOR "." ), newline ) );
|
||||
print( ( COMMATIZE( "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)."
|
||||
SEPARATOR "." PERIOD 6 ), newline ) );
|
||||
print( ( COMMATIZE( "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)."
|
||||
SEPARATOR "__" ), newline ) );
|
||||
print( ( COMMATIZE( "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)."
|
||||
LOCATION 26 PERIOD 1 SEPARATOR "::" ), newline ) );
|
||||
print( ( COMMATIZE """-in Aus$+1411.8millions""", newline ) );
|
||||
print( ( COMMATIZE "===US$0017440 millions=== (in 2000 dollars)", newline ) );
|
||||
print( ( COMMATIZE "123.e8000 is pretty big.", newline ) );
|
||||
print( ( COMMATIZE "The land area of the earth is 57268900(29% of the surface) square miles.", newline ) );
|
||||
print( ( COMMATIZE "Ain't no numbers in this here words, nohow, no way, Jose.", newline ) );
|
||||
print( ( COMMATIZE "James was never known as 0000000007", newline ) );
|
||||
print( ( COMMATIZE ( "Arthur Eddington wrote: I believe there are "
|
||||
+ "15747724136275002577605653961181555468044717914527116709366231425076185631031296 "
|
||||
+ "protons in the universe."
|
||||
), newline ) );
|
||||
print( ( COMMATIZE " $-140000±100 millions.", newline ) );
|
||||
print( ( COMMATIZE "6/9/1946 was a good year for some.", newline ) )
|
||||
|
|
|
|||
46
Task/Commatizing-numbers/C++/commatizing-numbers.cpp
Normal file
46
Task/Commatizing-numbers/C++/commatizing-numbers.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
bool contains(const std::string& haystack, const char needle) {
|
||||
return haystack.find(needle) != std::string::npos;
|
||||
}
|
||||
|
||||
void commatize(std::string text, const int32_t& start_index = 0,
|
||||
const int32_t& step = 3, const std::string& separator = ",") {
|
||||
std::cout << "Before: " << text << std::endl;
|
||||
const int32_t size = text.size();
|
||||
|
||||
for ( int32_t i = start_index; i < size; ++i ) {
|
||||
if ( contains("123456789", text[i]) ) {
|
||||
for ( int32_t j = i + 1; j <= size; ++j ) {
|
||||
if ( j > size || ! contains("0123456789", text[j]) ) {
|
||||
for ( int32_t k = j - 1 - step; k >= i; k -= step ) {
|
||||
text.insert(k + 1, separator);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << " After: " << text << std::endl << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
commatize("pi=3.14159265358979323846264338327950288419716939937510582097494459231", 6, 5, " ");
|
||||
commatize("The author has two Z$100000000000000 Zimbabwe notes (100 trillion).");
|
||||
commatize("\"-in Aus$+1411.8millions\"");
|
||||
commatize("===US$0017440 millions=== (in 2000 dollars)");
|
||||
commatize("123.e8000 is pretty big.");
|
||||
commatize("The land area of the earth is 57268900(29% of the surface) square miles.");
|
||||
commatize("Ain't no numbers in this here words, nohow, no way, Jose.");
|
||||
commatize("James was never known as 0000000007");
|
||||
commatize("Arthur Eddington wrote: I believe there are "
|
||||
"15747724136275002577605653961181555468044717914527116709366231425076185631031296"
|
||||
" protons in the universe.");
|
||||
commatize(" $-140000±100 millions.");
|
||||
commatize("6/9/1946 was a good year for some.");
|
||||
}
|
||||
45
Task/Commatizing-numbers/Rust/commatizing-numbers.rs
Normal file
45
Task/Commatizing-numbers/Rust/commatizing-numbers.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use itertools::Itertools;
|
||||
|
||||
fn commatize(old_text: &str, start_index: usize, step: usize, sep: &str) -> String {
|
||||
let mut text = old_text.to_string();
|
||||
let len = text.len();
|
||||
let textchars = text.chars().collect_vec();
|
||||
for i in start_index..len {
|
||||
if "123456789".contains(textchars[i]) {
|
||||
for j in i + 1..=len {
|
||||
if j >= len || !"0123456789".contains(textchars[j]) { //start at end
|
||||
if step <= j - i {
|
||||
for k in (i..j - step).rev().step_by(step) {
|
||||
text.insert_str(k + 1, sep);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let tests = [
|
||||
("pi=3.14159265358979323846264338327950288419716939937510582097494459231", 6, 5, " "),
|
||||
("The author has two Z$100000000000000 Zimbabwe notes (100 trillion).", 0, 3, ","),
|
||||
("\"-in Aus$+1411.8millions\"", 0, 3, ","),
|
||||
("===US$0017440 millions=== (in 2000 dollars)", 0, 3, ","),
|
||||
("123.e8000 is pretty big.", 0, 3, ","),
|
||||
("The land area of the earth is 57268900(29% of the surface) square miles.", 0, 3, ","),
|
||||
("Ain't no numbers in this here words, nohow, no way, Jose.", 0, 3, ","),
|
||||
("James was never known as 0000000007", 0, 3, ","),
|
||||
("Arthur Eddington wrote: I believe there are 15747724136275002577605653961181555468044717914527116709366231425076185631031296 protons in the universe.", 0, 3, ","),
|
||||
(" $-140000±100 millions.", 0, 3, ","),
|
||||
("6/9/1946 was a good year for some.", 0, 3, ","),];
|
||||
for t in tests {
|
||||
println!(
|
||||
"Before: {}\nAfter: {}\n",
|
||||
t.0,
|
||||
commatize(t.0, t.1, t.2, t.3)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue