Data update

This commit is contained in:
Ingy dot Net 2024-04-19 16:56:29 -07:00
parent 0df55f9f24
commit aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions

View file

@ -2,7 +2,7 @@ F shortest_abbreviation_length(line, list_size)
V words = line.split( )
V word_count = words.len
I word_count != list_size
X ValueError(Not enough entries, expected #. found #..format(list_size, word_count))
X.throw ValueError(Not enough entries, expected #. found #..format(list_size, word_count))
V abbreviation_length = 1
L

View file

@ -0,0 +1,60 @@
Function Tokenize(text As String, tokens() As String) As Integer
Dim As Integer count = 0, posic = 1, start
While posic <= Len(text)
If Mid(text, posic, 1) <> " " Then
start = posic
While posic <= Len(text) Andalso Mid(text, posic, 1) <> " "
posic += 1
Wend
count += 1
tokens(count) = Mid(text, start, posic - start)
End If
posic += 1
Wend
Return count
End Function
Function Buscar(s As String) As Integer
Dim As Integer n, d, i, j
Dim As Boolean s_flag
Dim As String a, b
Dim As String r(1 To 100) ' Assuming a maximum of 100 tokens
n = Tokenize(s, r())
d = 1
Do
s_flag = True
For i = 1 To n
For j = i + 1 To n
a = Left(r(i), d)
b = Left(r(j), d)
If a = "" Or b = "" Then
s_flag = True
Exit For
Elseif a = b Then
s_flag = False
d += 1
Exit For
End If
Next j
If Not s_flag Then Exit For
Next i
Loop Until s_flag
Return d
End Function
Dim As Integer fileNum = Freefile()
If Open("days_of_week.txt" For Input As #fileNum) = 0 Then
Dim As String s
While Not Eof(fileNum)
Line Input #fileNum, s
Print Buscar(s); " "; s
Wend
Close #fileNum
Else
Print "Error opening file."
End If
Sleep

View file

@ -1,29 +1,44 @@
/*REXX program finds the minimum length abbreviation for a lists of words (from a file).*/
parse arg uw /*obtain optional arguments from the CL*/
iFID= 'ABBREV_A.TAB' /*name of the file that has the table. */
say 'minimum' /*display the first part of the title. */
say 'abbrev' center("days of the week", 80) /*display the title for the output. */
say '' center("", 80, '') /*display separator for the title line.*/
/* [↓] process the file until done. */
do while lines(iFID)\==0; days=linein(iFID) /*read a line (should contain 7 words).*/
minLen= abb(days) /*find the minimum abbreviation length.*/
say right(minLen, 4) ' ' days /*display a somewhat formatted output. */
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
abb: procedure; parse arg x; #=words(x) /*obtain list of words; find how many.*/
if #==0 then return '' /*check for a blank line or null line. */
@.= /*@. is a stemmed array of the words.*/
L=0 /*L is the max length of " " */
do j=1 for #; @.j=word(x, j) /*assign to array for faster processing*/
L.j=length(@.j); L= max(L, L.j) /*find the maximum length of any item. */
end /*L*/
/* [↓] determine minimum abbrev length*/
do m=1 for L; $= /*for all lengths, find a unique abbrev*/
do k=1 to #; a=left(@.k, m) /*get an abbreviation (with length M).*/
if wordpos(a,$)\==0 then iterate M /*test this abbreviation for uniquness.*/
$=$ a /*so far, it's unique; add to the list.*/
end /*k*/
leave m /*a good abbreviation length was found.*/
end /*m*/
return m
/*REXX program finds the minimum length abbreviation for a lists of words (from a file).*/
iFID= 'ABBREV_A.TAB' /*name of the file that has the table. */
Say 'minimum' /*display the first part of the title. */
Say 'abbrev' center('days of the week',80) /*display the title for the output. */
Say '------' center('',80,'-') /*display separator for the title line. */
/* process the file until done. */
Do While lines(iFID)\==0
days=linein(iFID) /* read a line (should contain 7 words).*/
If days='' Then /* check for a blank line or null line. */
Say ''
Else Do
minLen=abb(days) /*find the minimum abbreviation length. */
Say right(minLen,4) ' ' days /*display a somewhat formatted output. */
If minlen='????' Then
Say ' >>> No unique abbreviation found <<<'
End
End
Exit /*stick a fork in it,we're all done. */
/*----------------------------------------------------------------------------------*/
abb: Procedure
Parse Arg daylist /* obtain list of words */
dayn=words(daylist) /* find how many. */
day.='' /*day. is a stemmed array of the words. */
L=0 /*L is the max length of the words. */
Do j=1 for dayn
day.j=word(daylist,j) /*assign to array for faster processing */
L.j=length(day.j)
L= max(L,L.j) /* find the maximum length of any item. */
End
/* [?] determine minimum abbrev length */
Do m=1 To L
abblist='' /* for all lengths,find a unique abbrev */
Do k=1 to dayn
abbrev=strip(left(day.k,m)) /* get an abbreviation (with length M). */
If wordpos(abbrev,abblist)>0 Then /* not unique */
Iterate M /* try next length */
If length(abbrev)>=m Then
abblist=abblist abbrev /* so far,it's unique add to the list. */
End
leave /* a good abbreviation length was found. */
End
If m>L Then /* no unique abbreviation length found */
m='????'
Return m