How to resolve the algorithm Letter frequency step by step in the TUSCRIPT programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Letter frequency step by step in the TUSCRIPT programming language

Table of Contents

Problem Statement

Open a text file and count the occurrences of each letter. Some of these programs count all characters (including punctuation), but some only count letters A to Z.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Letter frequency step by step in the TUSCRIPT programming language

Source code in the tuscript programming language

$$ MODE TUSCRIPT
words = REQUEST ("http://www.puzzlers.org/pub/wordlists/unixdict.txt")

DICT letters create
MODE {}
COMPILE
LOOP word=words
 letters=SPLIT (word,|":?:")
 LOOP letter=letters
  DICT letters ADD/QUIET/COUNT letter
 ENDLOOP
ENDLOOP
ENDCOMPILE
DICT letters unload letter,size,cnt

index    =DIGIT_INDEX (cnt)
index    =REVERSE (index)
letter   =INDEX_SORT (letter,index)
cnt      =INDEX_SORT (cnt,index)
frequency=JOIN (letter," --- ",cnt)

*{frequency}

  

You may also check:How to resolve the algorithm Combinations step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Create a file step by step in the R programming language
You may also check:How to resolve the algorithm Giuga numbers step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Kaprekar numbers step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Call a foreign-language function step by step in the Phix programming language