algorithm?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kathy

    #1

    algorithm?

    if:
    1. s[n]=2*S[n-1]
    2. s[0]=2
    then:
    s[n]=?
  • Dave Quigley[work]

    #2
    Re: algorithm?

    2 ^ n+1
    "kathy" <kathy@nospam.c om> wrote in message
    news:057d01c36c d1$90d70080$a10 1280a@phx.gbl.. .[color=blue]
    > if:
    > 1. s[n]=2*S[n-1]
    > 2. s[0]=2
    > then:
    > s[n]=?[/color]


    Comment

    • Dave Quigley[work]

      #3
      Re: algorithm?

      if you want that to be recursive for 2^n then make s[0] = 1 otherwise its
      2^(n+1)
      "kathy" <kathy@nospam.c om> wrote in message
      news:057d01c36c d1$90d70080$a10 1280a@phx.gbl.. .[color=blue]
      > if:
      > 1. s[n]=2*S[n-1]
      > 2. s[0]=2
      > then:
      > s[n]=?[/color]


      Comment

      • Zack

        #4
        algorithm?

        [color=blue]
        >-----Original Message-----
        >if:
        >1. s[n]=2*S[n-1]
        >2. s[0]=2
        >then:
        >s[n]=?
        >.
        >[/color]

        s[n] = 2 ^ n+1 (2 raise to the power n+1)

        Comment

        • GC

          #5
          algorithm?

          s[n]=2^(n+1)

          [color=blue]
          >-----Original Message-----
          >if:
          >1. s[n]=2*S[n-1]
          >2. s[0]=2
          >then:
          >s[n]=?
          >.
          >[/color]

          Comment

          • Jon Skeet

            #6
            Re: algorithm?

            kathy <kathy@nospam.c om> wrote:[color=blue]
            > if:
            > 1. s[n]=2*S[n-1]
            > 2. s[0]=2
            > then:
            > s[n]=?[/color]

            s[n]=2^(n+1) (for all n>=0)

            However, what's that got to do with C#?

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • kathy

              #7
              algorithm?

              correction:
              if:
              1. s[n]=2*S[n-1]-1
              2. s[0]=2
              then:
              s[n]=?

              Comment

              • GC

                #8
                algorithm?

                s[n]=2^(n+1)-1

                come on now...
                [color=blue]
                >-----Original Message-----
                >correction:
                >if:
                >1. s[n]=2*S[n-1]-1
                >2. s[0]=2
                >then:
                >s[n]=?
                >
                >.
                >[/color]

                Comment

                • Bruno Jouhier [MVP]

                  #9
                  Re: algorithm?

                  s[n] is (2^n) + 1
                  series looks like: 2, 3, 5, 9, 17, 33, 65, 129, ...

                  What's the point?

                  "kathy" <kathy@nospam.c om> a écrit dans le message de
                  news:05c301c36c d4$888ec3b0$a10 1280a@phx.gbl.. .[color=blue]
                  > correction:
                  > if:
                  > 1. s[n]=2*S[n-1]-1
                  > 2. s[0]=2
                  > then:
                  > s[n]=?
                  >[/color]


                  Comment

                  • Jon Skeet

                    #10
                    Re: algorithm?

                    GC <gcrasher76@yah oo.com> wrote:[color=blue]
                    > s[n]=2^(n+1)-1[/color]

                    No it doesn't.

                    s[0]=2
                    s[1]=3
                    s[2]=5
                    s[3]=9
                    s[4]=17
                    s[5]=33

                    Your sequence would go:
                    s[0]=1 // Disagreement even on the axioms!
                    s[1]=3
                    s[2]=7
                    s[3]=15
                    s[4]=31
                    s[5]=63

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                    If replying to the group, please do not mail me too

                    Comment

                    • GC

                      #11
                      Re: algorithm?

                      Ok, I am being dumb today. Tomorrow I will be smart again.


                      "Jon Skeet" <skeet@pobox.co m> wrote in message
                      news:MPG.19b720 e9f2d68f1a98a3d 6@news.microsof t.com...[color=blue]
                      > GC <gcrasher76@yah oo.com> wrote:[color=green]
                      > > s[n]=2^(n+1)-1[/color]
                      >
                      > No it doesn't.
                      >
                      > s[0]=2
                      > s[1]=3
                      > s[2]=5
                      > s[3]=9
                      > s[4]=17
                      > s[5]=33
                      >
                      > Your sequence would go:
                      > s[0]=1 // Disagreement even on the axioms!
                      > s[1]=3
                      > s[2]=7
                      > s[3]=15
                      > s[4]=31
                      > s[5]=63
                      >
                      > --
                      > Jon Skeet - <skeet@pobox.co m>
                      > http://www.pobox.com/~skeet/
                      > If replying to the group, please do not mail me too[/color]


                      Comment

                      • Fergus Cooney

                        #12
                        Re: algorithm?

                        Hi Kathy, Jon,

                        You've got me puzzled. My question is: What's this got to do with
                        <anything> ?

                        Regards,
                        Fergus


                        Comment

                        • Pete

                          #13
                          Re: algorithm?

                          Hi,

                          s[n] = a big error 'cause when n=0, (n-1) will be an invalid index into s.
                          Unless of course you reorder your statements and correctly setup your loop.

                          Is this a programming group or what?

                          Pete

                          kathy wrote:[color=blue]
                          > correction:
                          > if:
                          > 1. s[n]=2*S[n-1]-1
                          > 2. s[0]=2
                          > then:
                          > s[n]=?[/color]


                          Comment

                          • Stan

                            #14
                            Re: algorithm?

                            Given you say algorithm maybe your assignment expects an answer something
                            along the lines of,

                            function int S(int n)
                            {
                            if (n==0)
                            return 2;
                            else
                            return 2 * S(n - 1) - 1;
                            }

                            Why don't you just tell us exactly what the questions are and we'll get you
                            an A+.


                            "kathy" <kathy@nospam.c om> wrote in message
                            news:05c301c36c d4$888ec3b0$a10 1280a@phx.gbl.. .[color=blue]
                            > correction:
                            > if:
                            > 1. s[n]=2*S[n-1]-1
                            > 2. s[0]=2
                            > then:
                            > s[n]=?
                            >[/color]


                            Comment

                            • Zack

                              #15
                              Re: algorithm?

                              s[n] = (2^n) + 1;
                              [color=blue]
                              >-----Original Message-----
                              >Given you say algorithm maybe your assignment expects an[/color]
                              answer something[color=blue]
                              >along the lines of,
                              >
                              >function int S(int n)
                              >{
                              > if (n==0)
                              > return 2;
                              > else
                              > return 2 * S(n - 1) - 1;
                              >}
                              >
                              >Why don't you just tell us exactly what the questions are[/color]
                              and we'll get you[color=blue]
                              >an A+.
                              >
                              >
                              >"kathy" <kathy@nospam.c om> wrote in message
                              >news:05c301c36 cd4$888ec3b0$a1 01280a@phx.gbl. ..[color=green]
                              >> correction:
                              >> if:
                              >> 1. s[n]=2*S[n-1]-1
                              >> 2. s[0]=2
                              >> then:
                              >> s[n]=?
                              >>[/color]
                              >
                              >
                              >.
                              >[/color]

                              Comment

                              Working...