jj logo
Take a quick tour of JJ
Teacher Registration
Student Registration
Industry Registration
Guest Registration
Some Humor
Friends
Quotes


Name
Password
School


..
Class SevenOfAKindFinder

Import JJIO --using Input, Output, and Outputln

Class SevenOfAKindFinder
--Name: ??? (your login ID goes here)

 Routine startingRoutine(none) is public

  Box num ofType int --winning dollar bill serial number!
  Boxes d1,d2,d3,d4,d5,d6,d7,d8,d9 ofType int --digit counts
  Boxes i1,i2,i3,i4,i5,i6,i7,i8 ofType int --loop counters 
  Box specialDigit ofType int --user decides which 7-of-a-kind to find
  Box whichOne ofType int --set to the appropriate d1..d9

   Start

   Output "Enter digit (1..9) for the 7-of-a-kind list: "
   Input specialDigit
   Outputln specialDigit

   -- Initialize loop counters
   Set i1 = 0
   Set i2 = 0
   Set i3 = 0
   Set i4 = 0
   Set i5 = 0
   Set i6 = 0
   Set i7 = 0
   Set i8 = 0

   -- Our 8 loops
   Repeat
    Repeat
     Repeat
      Repeat
       Repeat
        Repeat
         Repeat
          Repeat
            -- Once inside, gather digit counts

            -- Initialize digit counts to zero
            Set d1 = 0
            Set d2 = 0
            Set d3 = 0
            Set d4 = 0
            Set d5 = 0
            Set d6 = 0
            Set d7 = 0
            Set d8 = 0
            Set d9 = 0

            -- i1 holds the left-most digit.
            -- Update the appropriate digit count
            If (i1==1) then
              Inc d1 by 1
            ElseIf (i1==2) then
              Inc d2 by 1
            ElseIf (i1==3) then
             Inc d3 by 1
            ElseIf (i1==4) then
             Inc d4 by 1
            ElseIf (i1==5) then
             Inc d5 by 1
            ElseIf (i1==6) then
             Inc d6 by 1
            ElseIf (i1==7) then
             Inc d7 by 1
            ElseIf (i1==8) then
             Inc d8 by 1
            ElseIf (i1==9) then
             Inc d9 by 1
            EndIf
            If (i2==1) then
             Inc d1 by 1
            ElseIf (i2==2) then
             Inc d2 by 1
            ElseIf (i2==3) then
             Inc d3 by 1
            ElseIf (i2==4) then
             Inc d4 by 1
            ElseIf (i2==5) then
             Inc d5 by 1
            ElseIf (i2==6) then
             Inc d6 by 1
            ElseIf (i2==7) then
             Inc d7 by 1
            ElseIf (i2==8) then
             Inc d8 by 1
            ElseIf (i2==9) then
             Inc d9 by 1
            EndIf
            If (i3==1) then
             Inc d1 by 1
            ElseIf (i3==2) then
             Inc d2 by 1
            ElseIf (i3==3) then
             Inc d3 by 1
            ElseIf (i3==4) then
             Inc d4 by 1
            ElseIf (i3==5) then
             Inc d5 by 1
            ElseIf (i3==6) then
             Inc d6 by 1
            ElseIf (i3==7) then
             Inc d7 by 1
            ElseIf (i3==8) then
             Inc d8 by 1
            ElseIf (i3==9) then
             Inc d9 by 1
            EndIf
            If (i4==1) then
             Inc d1 by 1
            ElseIf (i4==2) then
             Inc d2 by 1
            ElseIf (i4==3) then
             Inc d3 by 1
            ElseIf (i4==4) then
             Inc d4 by 1
            ElseIf (i4==5) then
             Inc d5 by 1
            ElseIf (i4==6) then
             Inc d6 by 1
            ElseIf (i4==7) then
             Inc d7 by 1
            ElseIf (i4==8) then
             Inc d8 by 1
            ElseIf (i4==9) then
             Inc d9 by 1
            EndIf
            If (i5==1) then
             Inc d1 by 1
            ElseIf (i5==2) then
             Inc d2 by 1
            ElseIf (i5==3) then
             Inc d3 by 1
            ElseIf (i5==4) then
             Inc d4 by 1
            ElseIf (i5==5) then
             Inc d5 by 1
            ElseIf (i5==6) then
             Inc d6 by 1
            ElseIf (i5==7) then
             Inc d7 by 1
            ElseIf (i5==8) then
             Inc d8 by 1
            ElseIf (i5==9) then
             Inc d9 by 1
            EndIf
            If (i6==1) then
             Inc d1 by 1
            ElseIf (i6==2) then
             Inc d2 by 1
            ElseIf (i6==3) then
             Inc d3 by 1
            ElseIf (i6==4) then
             Inc d4 by 1
            ElseIf (i6==5) then
             Inc d5 by 1
            ElseIf (i6==6) then
             Inc d6 by 1
            ElseIf (i6==7) then
             Inc d7 by 1
            ElseIf (i6==8) then
             Inc d8 by 1
            ElseIf (i6==9) then
             Inc d9 by 1
            EndIf
            If (i7==1) then
             Inc d1 by 1
            ElseIf (i7==2) then
             Inc d2 by 1
            ElseIf (i7==3) then
             Inc d3 by 1
            ElseIf (i7==4) then
             Inc d4 by 1
            ElseIf (i7==5) then
             Inc d5 by 1
            ElseIf (i7==6) then
             Inc d6 by 1
            ElseIf (i7==7) then
             Inc d7 by 1
            ElseIf (i7==8) then
             Inc d8 by 1
            ElseIf (i7==9) then
             Inc d9 by 1
            EndIf
            -- i1 holds the right-most digit.
            If (i8==1) then
             Inc d1 by 1
            ElseIf (i8==2) then
             Inc d2 by 1
            ElseIf (i8==3) then
             Inc d3 by 1
            ElseIf (i8==4) then
             Inc d4 by 1
            ElseIf (i8==5) then
             Inc d5 by 1
            ElseIf (i8==6) then
             Inc d6 by 1
            ElseIf (i8==7) then
             Inc d7 by 1
            ElseIf (i8==8) then
             Inc d8 by 1
            ElseIf (i8==9) then
             Inc d9 by 1
            EndIf

            -- Based on the user input, set the whichOne box
            If (specialDigit == 1) then
               Set whichOne = d1
            ElseIf (specialDigit == 2) then
               Set whichOne = d2
            ElseIf (specialDigit == 3) then
               Set whichOne = d3
            ElseIf (specialDigit == 4) then
               Set whichOne = d4
            ElseIf (specialDigit == 5) then
               Set whichOne = d5
            ElseIf (specialDigit == 6) then
               Set whichOne = d6
            ElseIf (specialDigit == 7) then
               Set whichOne = d7
            ElseIf (specialDigit == 8) then
               Set whichOne = d8
            --ElseIf (specialDigit == 9) then--NOTICE error? use Else instead
            Else
               Set whichOne = d9 --incorrect input will come here by default
            EndIf

            -- Does this serial number have a seven-of-a-kind?
            If (whichOne == 7) then
              Set num = i1*10000000+i2*1000000+i3*100000+i4*10000+i5*1000+i6*100+i7*10+i8*1
              If (num < 10000000) then
                 Output "0"
                 Outputln num
              Else
                 Outputln num
              EndIf
            EndIf

            -- Loop maintenance (inc counter, exit, re-initialize to zero)
            Inc i8 by 1
          ExitOn (i8 == 10)
          EndRepeat
          Set i8 = 0
          Inc i7 by 1
         ExitOn (i7 == 10)
         EndRepeat
         Set i7 = 0
         Inc i6 by 1
        ExitOn (i6 == 10)
        EndRepeat
        Set i6 = 0
        Inc i5 by 1
       ExitOn (i5 == 10)
       EndRepeat
       Set i5 = 0
       Inc i4 by 1
      ExitOn (i4 == 10)
      EndRepeat
      Set i4 = 0
      Inc i3 by 1
     ExitOn (i3 == 10)
     EndRepeat
     Set i3 = 0
     Inc i2 by 1
    ExitOn (i2 == 10)
    EndRepeat
    Set i2 = 0
    Inc i1 by 1
   ExitOn (i1 == 10)
   EndRepeat
 EndRoutine startingRoutine
EndClass SevenOfAKindFinder
Return to
    JJ
home page
..