Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Example of using tables
#7
johnno56, 1micha.elok could you test the sped of 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

pln "Reading and processing the file..."
whole_text = lower(system("type Hamlet.txt"))

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

Thanx!
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: 1 Guest(s)