ABC words: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{draft task}} A word is ABC word if "a", "b" and "c" letters appear in alphabetical order. =={{header|Ring}}== <lang ring> cStr = read("unixdict.txt") wordList = str2list(c...")
 
Line 11: Line 11:


for n = 1 to len(wordList)
for n = 1 to len(wordList)
cnt1 = count(wordList[n],"a")
cnt2 = count(wordList[n],"b")
cnt3 = count(wordList[n],"c")
bool1 = substr(wordList[n],"a")
bool1 = substr(wordList[n],"a")
bool2 = substr(wordList[n],"b")
bool2 = substr(wordList[n],"b")
Line 16: Line 19:
bool4 = bool1 > 0 and bool2 > 0 and bool3 > 0
bool4 = bool1 > 0 and bool2 > 0 and bool3 > 0
bool5 = bool2 > bool1 and bool3 > bool2
bool5 = bool2 > bool1 and bool3 > bool2
if bool4 = 1 and bool5 = 1
cnt = (cnt1 = 1) and (cnt2 = 1) and (cnt3 = 1)
if bool4 = 1 and bool5 = 1 and cnt
num = num + 1
num = num + 1
see "" + num + ". " + wordList[n] + nl
see "" + num + ". " + wordList[n] + nl
ok
ok
next
next

func count(cString,dString)
sum = 0
while substr(cString,dString) > 0
sum++
cString = substr(cString,substr(cString,dString)+len(string(sum)))
end
return sum
</lang>
</lang>
Output:
Output:
<pre>
<pre>
ABC words are:
ABC words are:
1. aback
1. abc
2. abacus
2. abduct
3. abc
3. abject
4. abdicate
4. abscess
5. abduct
5. absence
6. abeyance
6. aerobic
7. abject
7. alberich
8. abreact
8. albrecht
9. aminobenzoic
9. abscess
10. abscissa
10. diabetic
11. abscissae
11. diabolic
12. absence
12. fabric
13. abstract
13. iambic
14. abstracter
14. metabolic
15. abstractor
15. nabisco
16. adiabatic
16. roadblock
17. aerobacter
17. strabismic
18. aerobic
18. syllabic
19. albacore
19. tablecloth
20. alberich
21. albrecht
22. algebraic
23. alphabetic
24. ambiance
25. ambuscade
26. aminobenzoic
27. anaerobic
28. arabic
29. athabascan
30. auerbach
31. diabetic
32. diabolic
33. drawback
34. fabric
35. fabricate
36. flashback
37. halfback
38. iambic
39. lampblack
40. leatherback
41. metabolic
42. nabisco
43. paperback
44. parabolic
45. playback
46. prefabricate
47. quarterback
48. razorback
49. roadblock
50. sabbatical
51. snapback
52. strabismic
53. syllabic
54. tabernacle
55. tablecloth
</pre>
</pre>

Revision as of 09:14, 5 December 2020

ABC words is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

A word is ABC word if "a", "b" and "c" letters appear in alphabetical order.

Ring

<lang ring> cStr = read("unixdict.txt") wordList = str2list(cStr) num = 0

see "ABC words are:" + nl

for n = 1 to len(wordList)

   cnt1 = count(wordList[n],"a")
   cnt2 = count(wordList[n],"b")
   cnt3 = count(wordList[n],"c")
   bool1 = substr(wordList[n],"a")
   bool2 = substr(wordList[n],"b")
   bool3 = substr(wordList[n],"c")
   bool4 = bool1 > 0 and bool2 > 0 and bool3 > 0
   bool5 = bool2 > bool1 and bool3 > bool2
   cnt = (cnt1 = 1) and (cnt2 = 1) and (cnt3 = 1)
   if bool4 = 1 and bool5 = 1 and cnt
      num = num + 1
      see "" + num + ". " + wordList[n] + nl
   ok

next

func count(cString,dString)

    sum = 0
    while substr(cString,dString) > 0
          sum++
          cString = substr(cString,substr(cString,dString)+len(string(sum)))
    end
    return sum

</lang> Output:

ABC words are:
1. abc
2. abduct
3. abject
4. abscess
5. absence
6. aerobic
7. alberich
8. albrecht
9. aminobenzoic
10. diabetic
11. diabolic
12. fabric
13. iambic
14. metabolic
15. nabisco
16. roadblock
17. strabismic
18. syllabic
19. tablecloth