Author Topic: Pike  (Read 11170 times)

ScriptBasic

  • Guest
Re: Pike
« Reply #15 on: February 13, 2016, 12:14:38 AM »
Quote
Sometimes you don't need C speed and you prefer to choose language that is much easier to use instead.

I agree and that's the goal I have with Script BASIC. The language does a good job of integrating external C functionality and using C BASIC when developing the extensions somehow brings it full circle.

Tomaaz

  • Guest
Re: Pike
« Reply #16 on: February 13, 2016, 11:26:56 AM »
Do you remember the word count challenge from BP.org? For those who don't a little explanation. The task was to count all and unique words in Bible and then count how many times each word appears in the whole text. Then the result should be sorted and written to the file. Here is a Pike version:
Code: [Select]
void main() {
array|mixed a, b, c, b2;
b = ({});
b2 = ({});
c = ({});
int x, x2;
string y;
write("Reading the file...\n");
string content=Stdio.File("Bible.txt")->read();
content = lower_case(content);
a = content / " ";
write("Counting all words...\n");
for(x = 0; x < (sizeof(a) - 1); x++) {
a[x] = Regexp.PCRE("[^a-z]")->replace(a[x]," ");
b = b + (a[x] / " ");
}
for(x = 0; x < (sizeof(b) - 1); x++) {
if (strlen(b[x]) > 1 || b[x] == "a" || b[x] == "i") {
c = c + ({b[x]});
}
}
object plik = Stdio.File();
plik -> open("Words.txt", "wc");
write("All words: ");
plik -> write("All words: ");
write("%d\n", sizeof(c));
plik -> write("%d\n", sizeof(c));
write("Counting unique words...\n");
plik -> write("Counting unique words...\n");
a = Array.uniq(c);
write("Unique words: ");
plik -> write("Unique words: ");
write("%d\n", sizeof(a));
plik -> write("%d\n\n", sizeof(a));
write("Counting numbers of occurences of each word and sorting the result...\n");
b = ({});
x = 0;
foreach (a, y) {
b = b + ({y});
b2 = b2 + ({Array.count(c, y)});
}
c = (b2[0 .. sizeof(b2)]);
c = reverse(sort(c));
for(x = 0; x < sizeof(c); x++) {
for(x2 = 0; x2 < sizeof(b2); x2++) {
if (b2[x2] == c[x]) {
write(b[x2]);
plik -> write(b[x2]);
write(" - ");
plik -> write(" - ");
write("%d\n", b2[x2]);
plik -> write("%d\n", b2[x2]);
b2[x2] = -1000;
}
}
}
plik -> close();
}

BTW That was a very nice challenge. Maybe we should think about bringing it back?

ScriptBasic

  • Guest
Re: Pike
« Reply #17 on: February 13, 2016, 11:41:36 AM »
It started off as a stress test for SPLITA() and became the word count challenge. I agree that was the best one with the most participation.

I have native array sort in SB now and if we did another round, I wouldn't cheat and use the OS sort utility.

jbk

  • Guest
Re: Pike
« Reply #18 on: February 14, 2016, 11:00:23 AM »
Tomaaz, would you check this rosetta code? http://rosettacode.org/wiki/Associative_array/Iteration#Pike
it don't work for me.

Tomaaz

  • Guest
Re: Pike
« Reply #19 on: February 14, 2016, 10:03:55 PM »
I can't get on Rosettacode. Seems to be a problem with the server. Will try later.

ZXDunny

  • Guest
Re: Pike
« Reply #20 on: February 15, 2016, 12:00:37 AM »
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.

D.

jj2007

  • Guest
Re: Pike
« Reply #21 on: February 15, 2016, 07:53:56 AM »
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.

D.

I feel the same ;D

Try here, searching for Dickens.txt

ScriptBasic

  • Guest
Re: Pike
« Reply #22 on: February 15, 2016, 08:17:15 AM »
Quote
It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.

Have you ever heard of the coding bible or tons of other references using the word bible as a substitute for standard?

ZXDunny

  • Guest
Re: Pike
« Reply #23 on: February 15, 2016, 12:06:46 PM »
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.

I feel the same ;D

Try here, searching for Dickens.txt

Thanks JJ, that's much better - I'll see what I can find and propose that those who don't want to taint their good lives with that other text use something a little more... less aggressive? :)

D.

jbk

  • Guest
Re: Pike
« Reply #24 on: February 15, 2016, 05:08:37 PM »
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.

D.
I feel the same, using the Bible in such a trivial manner is disrespectful, here you will find other text files to consider ftp://ftp.cs.princeton.edu/pub/cs226/textfiles/
how about using dickens.txt it's about 29 MB in size or lilwomen.txt it's size about 1 MB

Tomaaz

  • Guest
Re: Pike
« Reply #25 on: February 15, 2016, 06:01:59 PM »
I feel the same, using the Bible in such a trivial manner is disrespectful...

I don't feel this way, but I understand others may do. So, what about Leo Tolstoy's "War and Peace"? I found a free copy in .txt format. It's 3 MB. The file is attached.

Result:
Quote
All words: 569924
Unique words: 17599

the - 34721
and - 22303
to - 16755
of - 15008
a - 10608
he - 10004
in - 9036
that - 8205
his - 7984
was - 7360
with - 5710
it - 5617
had - 5365
her - 4725
not - 4697
him - 4637
at - 4547
i - 4541
but - 4055
as - 4036
on - 4014
...

jj2007

  • Guest
Re: Pike
« Reply #26 on: February 15, 2016, 09:29:25 PM »
Weighted by string length:
Code: [Select]
Using warandpeace.txt on Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
22      ms for reading the file and converting to Lower$
402     ms for counting
9       ms for sorting
00104163 the
00066909 and
00033510 to
00032820 that
00030016 of
00023952 his
00022840 with
00022080 was
00020008 he
00018072 in
00016095 had
00014175 her
00014091 not
00013911 him
00012165 but
00011778 pierre
00011613 you
00011568 prince
00011368 said
00011234 it
00010836 from
00010665 for
00010608 a
00010467 she
00010320 which
00009700 were
00009596 what
00009094 at
00009024 they
00008491 natasha
Average=5.07 bytes
540895 duplicates, 17622 unique words

ScriptBasic

  • Guest
Re: Pike
« Reply #27 on: February 15, 2016, 10:31:43 PM »
Tomaaz,

Can you verify that you changed the original word count challenge focus and the goal is something else?  Looks like the JJ nuked thread and my SB post got deleted.  :-\

Tomaaz

  • Guest
Re: Pike
« Reply #28 on: February 15, 2016, 11:15:37 PM »
Can you verify that you changed the original word count challenge focus and the goal is something else? 

I haven' changed anything. The goal is to count all and unique words, count how many times each word appears in the file and sort the result by occurrence (not alphabetically!).

But I don't care anymore. The whole topic has been wiped out without any information. On the other forum I found posts saying that the whole word count challenge is just boring. Well, it may be not the most exciting programming task ever, but is definitely more interesting that another combination of color dots, circles and rectangles in 20 lines of code. On the same forum I just read that I'm a a copy/paste programmer and a liar. I really can't see a point of being part of this community. Having high-school like fights? Risking all my posts being wiped out only because someone else got angry at someone? No, thanx.
« Last Edit: February 15, 2016, 11:17:22 PM by Tomaaz »

ScriptBasic

  • Guest
Re: Pike
« Reply #29 on: February 15, 2016, 11:26:28 PM »
I feel your pain Tomaaz. That was the reason I bailed from the old PB.org forum was due to JJ speed freak antics and calling anything other than his work crap. I think the guy is whacked and needs to retire.

Quote
I haven' changed anything.

If you look at the the Script BASIC version that was the first example and what the code challenge was based on. Produce a sorted (by word - no dups) with instance count next to it. The SB version remarks out the by rank listing as that was an option to the challenge.
« Last Edit: February 15, 2016, 11:53:42 PM by John »