All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > General > Word Problems
Select the right subset (Posted on 2020-04-10) Difficulty: 4 of 5
To list the 4 countries - CHINA, CHAD,CANADA & CHILE you need only 8 distinct letters: A,C,D,E,H,I,L & N.

Find a 10-member subset of ABC such that enables to create the longest list of currently existing countries.

The following restrictions apply:
- Only UN current official members
- English spelling of names e.g. Spain, not Espana
- No abbreviations!

Google's list https://www.un.org/en/member-states/ recommended as database.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
re: max found by computer | Comment 2 of 3 |
(In reply to max found by computer by Charlie)

the program:


DefDbl A-Z
Dim crlf$
Dim ltrCt(26), srtCt(26), src$, sometimes$, mx, best$, abc$
 

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
  
  abc$ = "abcdefghijklmnopqrstuvwxyz"
  Open "un members.txt" For Input As #1
  Do
    Line Input #1, l$
    l = RTrim(LCase(l))
    For i = 1 To 26
      ix = InStr(l, Mid(abc, i, 1))
      If ix > 0 Then
       ltrCt(i) = ltrCt(i) + 1
       srtCt(i) = srtCt(i) + 1
      End If
    Next
  Loop Until EOF(1)
  Close #1
  
  Do
    done = 1
    For i = 1 To 25
      If srtCt(i) > srtCt(i + 1) Then
        h = srtCt(i): srtCt(i) = srtCt(i + 1): srtCt(i + 1) = h
        done = 0
      End If
    Next
  Loop Until done
   
  For i = 1 To 26
    Text1.Text = Text1.Text & mform(srtCt(i), "###0")
  Next
  Text1.Text = Text1.Text & crlf & crlf
  For i = 1 To 26
    Text1.Text = Text1.Text & "   " & Mid(abc, i, 1)
  Next
  Text1.Text = Text1.Text & crlf
  For i = 1 To 26
    Text1.Text = Text1.Text & mform(ltrCt(i), "###0")
  Next
  Text1.Text = Text1.Text & crlf & crlf
    
  For i = 1 To 26
    If ltrCt(i) > 69 Then
     always$ = always$ + Mid(abc, i, 1)
    ElseIf ltrCt(i) > 6 Then
     sometimes$ = sometimes$ + Mid(abc, i, 1)
    End If
  Next
  Text1.Text = Text1.Text & always & crlf & sometimes & Str(Len(sometimes)) & crlf
  
  src$ = always
  addOn 1
  
  
   
  Text1.Text = Text1.Text & crlf & crlf & " done"
  DoEvents

End Sub

Sub addOn(wh)
  DoEvents
  For i = wh To 18 - (4 - wh)
    src = src + Mid(sometimes, i, 1)
    If Len(src) = 10 Then
      ct = 0
  Open "un members.txt" For Input As #1
  Do
    Line Input #1, l$
    l = RTrim(LCase(l))
    good = 1
    For j = 1 To Len(l)
     If InStr(abc, Mid(l, j, 1)) > 0 Then
      ix = InStr(src, Mid(l, j, 1))
      If ix = 0 Then
       good = 0
       Exit For
      End If
     End If
    Next
    If good Then ct = ct + 1
  Loop Until EOF(1)
  Close #1
      good = 1
      For j = 7 To 9
       If Mid(src, j, 1) > Mid(src, j + 1, 1) Then good = 0: Exit For
      Next
      If ct >= mx And good = 1 Then
        mx = ct
        best$ = src
        Text1.Text = Text1.Text & mx & "   " & src & crlf
        If mx = 19 Then
  Open "un members.txt" For Input As #1
  Do
    Line Input #1, l$
    l = RTrim(LCase(l))
    good = 1
    For j = 1 To Len(l)
     If InStr(abc, Mid(l, j, 1)) > 0 Then
      ix = InStr(src, Mid(l, j, 1))
      If ix = 0 Then
       good = 0
       Exit For
      End If
     End If
    Next
    If good Then Text1.Text = Text1.Text & "       " & l & crlf
  Loop Until EOF(1)
  Close #1
          Text1.Text = Text1.Text & crlf
        End If
      End If
    ElseIf Len(src) < 10 Then
      addOn wh + 1
    End If
    src = Left(src, Len(src) - 1)
  Next
End Sub

Function mform$(x, t$)
  a$ = Format$(x, t$)
  If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
  mform$ = a$
End Function

and its output:

   2   4   7  11  15  16  17  18  19  28  30  45  46  54  56  57  64  67  69  69  70  91  98 114 121 164

   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t   u   v   w   x   y   z
 164  54  46  56  91  17  45  30 121   7  19  69  57 114  70  28   4  98  69  67  64  16  11   2  18  15

aeinor
bcdfghjklmpstuvwyz 18
6   aeinorbcdf
12   aeinorbcdg
14   aeinorbcdm
16   aeinorbcgm
18   aeinorbglm
18   aeinorcgmt

The list of countries for 18 was produced by changing the 19 in the program to 18.

  Posted by Charlie on 2020-04-10 11:34:42
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (23)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information