Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Example of using tables
#4
And this version?

Code:
unwanted_characters = []
counter = 0

for a = 0 to 96
    unwanted_characters[counter] = chr(a)
    counter = counter + 1
next
for a = 123 to 127
    unwanted_characters[counter] = chr(a)
    counter = counter + 1
next

open file 1, ("Hamlet.txt")
pln "Reading the file..."
x = fread(1)
while x
    whole_text = whole_text + " " + x
    x = fread(1)
wend
free file 1

whole_text = lower(whole_text)

foreach y in unwanted_characters
    whole_text = replace(whole_text, y, " ")
next

all_words = split(whole_text, " ")

pln "Counting..."
words_number = 0
unique_words = []
foreach n in all_words
    if len(n) > 1 or n = "a" or n = "i"
        unique_words[n] = unique_words[n] + 1
        words_number = words_number + 1
    endif
next

pln "Saving the result..."
create file 2, "Words.txt"
wln file 2, "All words - " + words_number
wln file 2, "Unique words - " + sizeof(unique_words)
wln file 2, ""

y = 1
while sizeof(unique_words)
    foreach a, b in unique_words
        if b = y then
            wln file 2, a + " - " + b
        endif
    next    
    free val unique_words, y
    y = y + 1
wend

free file 2

Should be around 3-4 times faster. What's interesting is that the old version takes around 30 sec. on my laptop. How is it possible? My laptop is pretty old and slow, so how come it is faster than your machines??? The new one takes 8 sec., btw.
Reply


Messages In This Thread
Example of using tables - by Tomaaz - 02-09-2024, 01:47 PM
RE: Example of using tables - by 1micha.elok - 02-12-2024, 02:55 AM
RE: Example of using tables - by johnno56 - 02-12-2024, 06:58 PM
RE: Example of using tables - by Tomaaz - 02-12-2024, 10:08 PM
RE: Example of using tables - by 1micha.elok - 02-13-2024, 01:19 AM
RE: Example of using tables - by johnno56 - 02-13-2024, 02:46 AM
RE: Example of using tables - by Tomaaz - 02-13-2024, 04:27 PM
RE: Example of using tables - by johnno56 - 02-13-2024, 07:44 PM
RE: Example of using tables - by Tomaaz - 02-13-2024, 08:07 PM
RE: Example of using tables - by 1micha.elok - 02-15-2024, 12:16 AM

Forum Jump:


Users browsing this thread: 4 Guest(s)