Psuedo Code Problem!!! Urgent!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pharcyde
    Grand Master
    • Oct 2000
    • 228

    #1

    Psuedo Code Problem!!! Urgent!!!

  • pharcyde
    Grand Master
    • Oct 2000
    • 228

    #2
    ok i may have solved the first two, but i really need help on the last one.

    Comment

    • MagMan5446
      .....
      • Jun 2001
      • 2572

      #3
      Yeah, I don't know anything about what you're talking about, but I was wondering about your name. Pharcyde as in the group? I just listened to their remix of Doin' Time, it rocks.

      Comment

      • pharcyde
        Grand Master
        • Oct 2000
        • 228

        #4
        yeah i got the name from the group but, i don't listen to there music. i just needed a name, and my brother had a pharcyde cd laying around.

        Comment

        • alf
          Owner of the RFH Emag
          • Jun 2001
          • 1141

          #5
          arrays

          can you put the values into an array?

          do you have icq? im 19631307, if you do

          i know....read it left to right, keep concatenating it into a string...(the highest order digit will be put in first)

          then process the string first 0/1 gets the value of 2 to the 0th power (= 1), second 0/1 gets 2 to the 1st power (=2), third 0/1 gets 2 to the 2nd power (=4), just accumulate it till you reach the end of the string

          will that work for ya?

          -alf

          Comment

          • pharcyde
            Grand Master
            • Oct 2000
            • 228

            #6
            no cant use arrays, i'll read over what you wrote now

            Comment

            • Miscue
              Super Moderator

              • Oct 2000
              • 7105

              #7
              a.

              1.

              (turn the date into YYYYMMDD format. YYYY carries most weight, so it is put in front. In this way you can directly compare it to other dates using < > =, etc.)

              todayDate = yearToday * 1000 + (monthToday) * 100 + dayToday

              otherDate = yearOther * 1000 + (monthOther) * 100 + dayOther

              if todayDate == otherDate
              present
              if todayDate > otherDate
              past
              else
              future

              2.
              (Easier to understand, but not as efficient and harder to code)

              if yearToday > yearOther
              past
              else if yearToday < yearOther
              future
              else
              if monthToday > monthOther...

              pattern continues...

              b.


              main

              repeat until end of file
              read letter
              if y read in
              yFoundProcedure
              end if
              end repeat

              end main

              yFoundProcedure
              read letter
              if end of file, quit
              else
              if y read in
              yFoundProcedure (call itself, takes the 'yyy' case into consideration)
              else if . or , or (space) read in
              increment wordsEndInY
              end if
              end yFoundProcedure

              c. (are you sure it's left-most digit? or right?)

              The left-most digits is way harder... I'm working on it now...

              Comment

              • Miscue
                Super Moderator

                • Oct 2000
                • 7105

                #8
                Re: arrays

                Originally posted by alf
                can you put the values into an array?


                i know....read it left to right, keep concatenating it into a string...
                A string is an array of characters. If he can't use an array, he can't use a string.

                Going right to left there is a super simple formula... left to right... a pain. I can't see why your teacher would ask you to do it that way...

                Comment

                • pharcyde
                  Grand Master
                  • Oct 2000
                  • 228

                  #9
                  left most for sure

                  Comment

                  • alf
                    Owner of the RFH Emag
                    • Jun 2001
                    • 1141

                    #10
                    i think i got it...miscue, whatcha think?

                    alright...
                    i wont do the pseudo code for you but here is the theory

                    for every new digit, you will add 1 or 0 (since it is the least significant bit)...before you do that, you have to shift the others left...do to this, just multiply by 2

                    (do some examples)

                    111=7
                    promote 111 to 1110 and that is 14, then add 1 or 0

                    11011 = 27
                    promote (shift left) to 110110 and that is 54, then add 0 or 1

                    will that work?

                    Comment

                    • Miscue
                      Super Moderator

                      • Oct 2000
                      • 7105

                      #11
                      c. Here goes...

                      main
                      getBinary
                      convertToDec
                      end main

                      begin getBinary
                      digit=0
                      accumulator=0
                      repeat until end
                      accumulator = accumulator * 10 // move digit over
                      read digit
                      if not end
                      accumulator = accumulator + digit // tack on next dig
                      end if
                      digit = digit+1
                      end repeat
                      end getBinary

                      begin convertToDec
                      currExp = 0
                      decimalAnswer = 0
                      repeat until digit = 0
                      decimalAnswer = decimalAnswer + (accumulator modulo 10) * 2^(currExp)
                      digit = digit - 1
                      currExp = currExp + 1
                      accumulator = accumulator div 10
                      end repeat
                      end convertToDec


                      I did not double check this for three reasons.... It's probably right... close enough for pseudocode... and it does you no good if I just give you the answer and you don't understand it. You need to go through it and see how it works. If you catch an error, great.
                      Last edited by Miscue; 09-18-2001, 10:10 PM.

                      Comment

                      • Miscue
                        Super Moderator

                        • Oct 2000
                        • 7105

                        #12
                        Dammit alf. That's the easy way.


                        accumulator = 0
                        repeat until end
                        accumulator = accumulator * 2
                        readDigit
                        accumulator = accumulator + readDigit
                        end repeat

                        Comment

                        • alf
                          Owner of the RFH Emag
                          • Jun 2001
                          • 1141

                          #13
                          oops

                          lol

                          sorry miscue!

                          what line of work are you in anyway?

                          Comment

                          • pharcyde
                            Grand Master
                            • Oct 2000
                            • 228

                            #14
                            thanks guys, i'll have to go over all this and figure out what the heck you typed.

                            Comment

                            • Miscue
                              Super Moderator

                              • Oct 2000
                              • 7105

                              #15
                              I take pictures of people and print them out onto school ID cards for $7/hour.

                              Comment

                              Working...