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

Home > Logic
Five Cards III (Posted on 2015-03-13) Difficulty: 3 of 5
  • Andy, Belinda, Carl, and Debbie guess at four aces and a joker.
  • Each card is correctly identified by at least one person.
  • Nobody gets them all right or all wrong.
  • No two people make the same number of correct guesses.
The guesses are as follows:
           1st Card    2nd Card   3rd Card    4th Card   5th Card
Andy        Club         Joker      Heart     Diamond     Club
Belinda    Diamond       Joker      Heart      Club      Spade
Carl        Heart        Club       Spade     Diamond    Joker  
Debbie     Diamond       Joker      Club       Club      Spade
What are the five cards?

See The Solution Submitted by K Sengupta    
Rating: 4.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 3
DefDbl A-Z
Dim crlf$


Private Sub Form_Load()
 ChDir "C:\VB5 projects\flooble"
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
 DoEvents
  
 cd$ = "hdcsj": h$ = cd$
 Do
  ReDim score(5)
  good = 1
  
  sc = 0
  For i = 1 To 5
    If Mid("cjhdc", i, 1) = Mid(cd$, i, 1) Then sc = sc + 1
  Next
  If score(sc) > 0 Or sc = 0 Or sc = 5 Then good = 0
  score(sc) = 1
  
  sc = 0
  For i = 1 To 5
    If Mid("djhcs", i, 1) = Mid(cd$, i, 1) Then sc = sc + 1
  Next
  If score(sc) > 0 Or sc = 0 Or sc = 5 Then good = 0
  score(sc) = 1
  
  sc = 0
  For i = 1 To 5
    If Mid("hcsdj", i, 1) = Mid(cd$, i, 1) Then sc = sc + 1
  Next
  If score(sc) > 0 Or sc = 0 Or sc = 5 Then good = 0
  score(sc) = 1
  
  sc = 0
  For i = 1 To 5
    If Mid("djccs", i, 1) = Mid(cd$, i, 1) Then sc = sc + 1
  Next
  If score(sc) > 0 Or sc = 0 Or sc = 5 Then good = 0
  score(sc) = 1
  
  If good Then Text1.Text = Text1.Text & cd$ & crlf: DoEvents
  
  permute cd$
 Loop Until cd$ = h$

Text1.Text = Text1.Text & "done"
End Sub

Sub permute(a$)

 x$ = ""
 For i = Len(a$) To 1 Step -1
  l$ = x$
  x$ = Mid$(a$, i, 1)
  If x$ < l$ Then Exit For
 Next


 If i = 0 Then
  For j = 1 To Len(a$) \ 2
   x$ = Mid$(a$, j, 1)
   Mid$(a$, j, 1) = Mid$(a$, Len(a$) - j + 1, 1)
   Mid$(a$, Len(a$) - j + 1, 1) = x$
  Next
 Else
  For j = Len(a$) To i + 1 Step -1
   If Mid$(a$, j, 1) > x$ Then Exit For
  Next
  Mid$(a$, i, 1) = Mid$(a$, j, 1)
  Mid$(a$, j, 1) = x$
  For j = 1 To (Len(a$) - i) \ 2
   x$ = Mid$(a$, i + j, 1)
   Mid$(a$, i + j, 1) = Mid$(a$, Len(a$) - j + 1, 1)
   Mid$(a$, Len(a$) - j + 1, 1) = x$
  Next
 End If
End Sub

finds the sequence

cjhds

  Posted by Charlie on 2015-03-13 15:42:15
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 (3)
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