Computing the number of close to perfect pegs

For each color it is: the min of the total of that color in either string - the number of perfect ones for that color.
For example: if the solution was 12313145 and guess was 12233444.
  • For 1, it is min(3,1)-1=0.
  • For 2, it is min(1,2)-1=0.
  • For 3, it is min(2,2)-1=1.
  • For 4, is it min(1,3)-1=0.
  • For 5, it is min(1,0)-0=0.
This means there is one color correct but in the wrong position (the other 3) and 4 colors in the right position. There are other ways to compute this that will also work nicely.


This topic: CenterForComputing > WebHome > Syllabi > CSC121SylF2025 > CSC121F2025Lab07 > CSC121F2025Lab07Hint03
Topic revision: r1 - 2025-08-04 - CathyBareiss
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback