Liberty BASIC Community Forum
« splitting the alphabet »

Welcome Guest. Please Login or Register.
Mar 26th, 2017, 1:50pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: splitting the alphabet  (Read 108 times)
alincon2001
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 486
xx splitting the alphabet
« Thread started on: Jul 14th, 2016, 10:43am »

I want the user to pick from a file of names, but want to show the list in a variable number of groups, depending on the alphabetic distribution of the last names in the file. I was going to start with a-i, j-r, s-z; the user would select one of the three groups, and then pick a name from those in the chosen group. But then, as the list grows, I would need more groups, and perhaps some groups might be just one letter.
So I want to analyze the file every time the program runs and determine the new grouping required.
I would hope there is a reasonably simple solution that would not be bigger than the program that now exists and asks the user to input one letter of the alphabet.

r.m.
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1609
xx Re: splitting the alphabet
« Reply #1 on: Jul 14th, 2016, 1:28pm »

Have a look
Basically it counts words, counts words starting from letter
Then it draws a line (a-i) where sum of words exceeds total/3.
c$ just to show words - not needed for a program.
Code:
m$="I want the user to pick from a file of names, but want to show the list in a " +_
   "variable number of groups, depending on the alphabetic distribution of the last " +_
   "names in the file. I was going to start with a-i, j-r, s-z; the user would " +_
   "select one of the three groups, and then pick a name from those in the chosen " +_
   "group. But then, as the list grows, I would need more groups, and perhaps some " +_
   "groups might be just one letter. " +_
   "So I want to analyze the file every time the program runs and determine the new " +_
   "grouping required. " +_
   "I would hope there is a reasonably simple solution that would not be bigger " +_
   "than the program that now exists and asks the user to input one letter of the " +_
   "alphabet."

dim c(26)   'number of words from this letter
dim c$(26)

t$="*"
i = 0
while t$<>""
    i=i+1
    t$=lower$(word$(m$,i))
    if t$ <>"" then
        j = asc(left$(t$, 1)) - asc("a")+1
        c(j)=c(j)+1
        c$(j)=c$(j)+" "+t$ 
    end if
wend
total = i-1   'total number of words
print "by letter"
for i = 1 to 26
    print chr$(i-1+asc("a")), c(i), c$(i)
next
print "Total number ";total

'now, divide it by 3
part = int(total/3)
print "in three parts at ";part

print "a-";
s=0
for i = 1 to 26
    s=s+c(i)
    if s>=part then
        print chr$(i-1+asc("a")), s
        print chr$(i+asc("a"));"-";
        s=0
    end if
next
print "z", s
 
« Last Edit: Jul 14th, 2016, 1:31pm by tsh73 » User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls