Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Figure out the lineup
Message
Information générale
Forum:
Games
Catégorie:
Mathématique
Divers
Thread ID:
01002486
Message ID:
01006567
Vues:
9
Kenneth,

This one is easily solved by a brute force constraint satisfaction method

The line up is 9,2,6,4,8,1,5,3,7

In fact the last constraint is not even needed there is only one possible solution left after applying Between 3 and 4, the total is 14
create cursor x1 ( i1 i )
for i = 1 to 9
   insert into x1 values ( i )
endfor

select x1.i1 as p1, x2.i1 as p2, x3.i1 as p3, x4.i1 as p4, x5.i1 as p5, x6.i1 as p6, x7.i1 as p7, x8.i1 as p8, x9.i1 as p9 ;
   from x1 ;
   left join x1 as x2 on x1.i1 != x2.i1 ;
   left join x1 as x3 on x1.i1 != x3.i1 and x2.i1 != x3.i1 ;
   left join x1 as x4 on x1.i1 != x4.i1 and x2.i1 != x4.i1 and x3.i1 != x4.i1 ;
   left join x1 as x5 on x1.i1 != x5.i1 and x2.i1 != x5.i1 and x3.i1 != x5.i1 and x4.i1 != x5.i1 ;
   left join x1 as x6 on x1.i1 != x6.i1 and x2.i1 != x6.i1 and x3.i1 != x6.i1 and x4.i1 != x6.i1 and x5.i1 != x6.i1 ;
   left join x1 as x7 on x1.i1 != x7.i1 and x2.i1 != x7.i1 and x3.i1 != x7.i1 and x4.i1 != x7.i1 and x5.i1 != x7.i1 and x6.i1 != x7.i1 ;
   left join x1 as x8 on x1.i1 != x8.i1 and x2.i1 != x8.i1 and x3.i1 != x8.i1 and x4.i1 != x8.i1 and x5.i1 != x8.i1 and x6.i1 != x8.i1 and x7.i1 != x8.i1 ;
   left join x1 as x9 on x1.i1 != x9.i1 and x2.i1 != x9.i1 and x3.i1 != x9.i1 and x4.i1 != x9.i1 and x5.i1 != x9.i1 and x6.i1 != x9.i1 and x7.i1 != x9.i1 and x8.i1 != x9.i1 ;
   into cursor ThePermutations readwrite

*Each of the uniform numbers of the first four batters totals 21.
*Batting between players 1 and 2, are players whose uniforms total 18.
*Between players 2 and 3, the uniforms total 24.
*Between 3 and 4, the total is 14, and
*Between 4 and 5, the total is 9.

delete for p1 + p2 + p3 + p4 != 21 && apply first constraint
* 31680 left

scan
   scatter to thisLineup
   i = ascan( thisLineup, 1 )
   j = ascan( thisLineUp, 2 )
   i1 = min( i, j )
   i2 = max( i, j )
   lnTotal = 0
   for i = i1 + 1 to i2 - 1
      lnTotal = lnTotal + thisLineup[i]
   endfor
   if ( lnTotal != 18 )
      delete
   endif
endscan

* 640 left

scan
   scatter to thisLineup
   i = ascan( thisLineup, 2 )
   j = ascan( thisLineUp, 3 )
   i1 = min( i, j )
   i2 = max( i, j )
   lnTotal = 0
   for i = i1 + 1 to i2 - 1
      lnTotal = lnTotal + thisLineup[i]
   endfor
   if ( lnTotal != 24 )
      delete
   endif
endscan

* 4 left

scan
   scatter to thisLineup
   i = ascan( thisLineup, 3 )
   j = ascan( thisLineUp, 4 )
   i1 = min( i, j )
   i2 = max( i, j )
   lnTotal = 0
   for i = i1 + 1 to i2 - 1
      lnTotal = lnTotal + thisLineup[i]
   endfor
   if ( lnTotal != 14 )
      delete
   endif
endscan

* 1 left
>To anyone interested in this puzzle
>
>
>>The players in the baseball lineup wear uniform numbers 1, 2, 3, 4, 5, 6, 7, 8, and 9.
>>Each of the uniform numbers of the first four batters totals 21.
>>Batting between players 1 and 2, are players whose uniforms total 18.
>>Between players 2 and 3, the uniforms total 24.
>>Between 3 and 4, the total is 14, and
>>Between 4 and 5, the total is 9.
>
>
>Either no one else was working on this one, or they got about as far as I did and didn’t want to ask for help.
>
>Well, I hate to admit, but there is a third option: Maybe you thought it was so easy that you did not bother to reply to this thread. For my own egos sake, I’ll assume it was one of the first two options ;-)
>
>I like this puzzle. Because no one has replied to this thread in a while, and I assume “out of sight, out of mind”, I’ll go ahead and give you some hints to keep this thread active.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform