SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    43 03' 16" N :::: 77 36' 03" W
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    constructing a base2 multiplication table

    can someone help me with my multiplication table. it's not one that goes: 1 2 3 4 5 6 etc. it goes like this instead: 2 4 8 16 32 64 etc. (or at least it's supposed to)

    only the first row works. here's my code. i have 2 tables, and neither of them work the way i want them too. the first row is supposed to have the same values at the first column

    Code:
    <% 
    	Dim row, col, outp, exp
    
    %>
    <table>
    <%
    exp = 1
    
    for row = 1 to 10
    	response.write "<tr>"
    	
    	
    	for col = 1 to 10
    		outp = 2 * exp
    		response.write "<td>" & outp & "</td>"
    		exp = 2 * exp
    	next
    	
    	exp = row
    	exp = 2 * exp
    	response.write "</tr>"
    next
    %>
    </table>
    Code:
    <% 
    	Dim row, col, outp, exp
    
    %>
    <table>
    <%
    exp = 1
    
    for row = 1 to 10
    	response.write "<tr>"
    	
    	
    	for col = 1 to 10
    		outp = 2 * exp
    		response.write "<td>" & outp & "</td>"
    		exp = 2 * exp
    	next
    	
    	exp = 2 * row * row
    
    	response.write "</tr>"
    next
    %>
    </table>
    you can view the output @ www.stoneviper.com/asp

    please help. thanks.
    There's no place like 127.0.0.1

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    I think this code will give you what you're expecting...
    Code:
    <table width="100%" border="1">
    <%
    For RowIndex = 1 to 10
     StartValue = 1
     For i = 1 to RowIndex
      StartValue = StartValue * 2
     Next
     Response.Write " <tr>"
     For ColumnIndex = 1 to 10
      ColumnValue = StartValue
      ' Start with 2 since you want to leave column 1 alone...
      For i = 2 to ColumnIndex
       ColumnValue = ColumnValue * 2
      Next
      Response.Write "<td>" & ColumnValue & "</td>"
     Next
     Response.Write "</tr>" & vbNewLine
    Next
    %>
    </table>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    43 03' 16" N :::: 77 36' 03" W
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's a better version that what i later came up with.
    Code:
    <table class="inside">
    <%
    exp = 1
    
    for row = 1 to 10
    	response.write "<tr>"
    	
    	
    	for col = 1 to 10
    		outp = 2 * exp
    		response.write "<td>" & outp & "</td>"
    		
    		exp = 2 * exp
    	next
    	outp = outp / 512
    	exp = outp
    			
    	response.write "</tr>"
    next
    %>
    </table>
    Quote Originally Posted by DaveMaxwell
    I think this code will give you what you're expecting...
    Code:
    <table width="100%" border="1">
    <%
    For RowIndex = 1 to 10
     StartValue = 1
     For i = 1 to RowIndex
      StartValue = StartValue * 2
     Next
     Response.Write " <tr>"
     For ColumnIndex = 1 to 10
      ColumnValue = StartValue
      ' Start with 2 since you want to leave column 1 alone...
      For i = 2 to ColumnIndex
       ColumnValue = ColumnValue * 2
      Next
      Response.Write "<td>" & ColumnValue & "</td>"
     Next
     Response.Write "</tr>" & vbNewLine
    Next
    %>
    </table>
    mine only works if the table is 10 x 10, yours works no matter the size of the table..

    thanks a lot man

    only one thing.. when you multiply 128 x 4, you don't get 256.
    how do i alter the code to allow for this?
    There's no place like 127.0.0.1

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    If you're talking about the display that my code comes up with, that's because you're not doing a multiplication table. It's a factor table. All I coded for was so that column1 = row1, column2 = row2, etc. What you're talking about is a multiplication table, and that would take a totally different set of code to get it to work. Which do you want?
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    43 03' 16" N :::: 77 36' 03" W
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveMaxwell
    If you're talking about the display that my code comes up with, that's because you're not doing a multiplication table. It's a factor table. All I coded for was so that column1 = row1, column2 = row2, etc. What you're talking about is a multiplication table, and that would take a totally different set of code to get it to work. Which do you want?
    i was only testing my skills in the first place and i get caught up in something i couldn't let go .

    i can't ask anyone to spend many hours devising an equation to figure this out, cause technically i'm not going to use it for anything. i just want to see what it would take to perform such a task. a factor table was what i want, but i thought they multiplied themselves automatically. i still have yet to look at your code to see how you did it.

    if it'll only take a few short extra lines, sure i'd like to see it, if not, that's ok. it won't technically be used for anything really though.
    There's no place like 127.0.0.1

  6. #6
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    It's not a difficult solution to come up with. Just had to rework the process a bit. Here's the next round of code (even made it a bit more generic to make it easy to factor X to the Nth power....)

    Code:
    <p>To see the factorials multiplied...<br />
    <table width="100%" border="1">
    <%
    ' Dimming requires a constant value, so I made it 100 to allow for a lot of factorializing...
    Dim ColumnArray(100), RowArray(100)
    Dim Factorial, NumFactors, NumberToFactor
    NumbertoFactor = 2  ' Number being factored
    Factorial  = 1  ' Number to the 0th power
    NumFactors  = 10 ' Number of factorials
     
    'Create the factorial arrays...
    For i = 0 to NumFactors
     ColumnArray(i) = Factorial
     RowArray(i)  = Factorial
     Factorial  = Factorial * NumberToFactor
    Next
     
    '....Now create the table to be displayed..
    For RowIndex = 0 to NumFactors
     Response.Write " <tr>"
     For ColumnIndex = 0 to NumFactors
      DisplayValue = RowArray(RowIndex) * ColumnArray(ColumnIndex)
      If RowIndex = 0 and ColumnIndex = 0 then
       ' Since NumberToFactor to the zero power = 1, don't display it....
       DisplayValue = "&nbsp;"
      End If
      Response.Write "<td>" & DisplayValue & "</td>"
     Next
     Response.Write "</tr>" & vbNewLine
    Next
    %>
    </table>
    </p>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    43 03' 16" N :::: 77 36' 03" W
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveMaxwell
    It's not a difficult solution to come up with. Just had to rework the process a bit. Here's the next round of code (even made it a bit more generic to make it easy to factor X to the Nth power....)

    Code:
    <p>To see the factorials multiplied...<br />
    <table width="100%" border="1">
    <%
    ' Dimming requires a constant value, so I made it 100 to allow for a lot of factorializing...
    Dim ColumnArray(100), RowArray(100)
    Dim Factorial, NumFactors, NumberToFactor
    NumbertoFactor = 2  ' Number being factored
    Factorial  = 1  ' Number to the 0th power
    NumFactors  = 10 ' Number of factorials
     
    'Create the factorial arrays...
    For i = 0 to NumFactors
     ColumnArray(i) = Factorial
     RowArray(i)  = Factorial
     Factorial  = Factorial * NumberToFactor
    Next
     
    '....Now create the table to be displayed..
    For RowIndex = 0 to NumFactors
     Response.Write " <tr>"
     For ColumnIndex = 0 to NumFactors
      DisplayValue = RowArray(RowIndex) * ColumnArray(ColumnIndex)
      If RowIndex = 0 and ColumnIndex = 0 then
       ' Since NumberToFactor to the zero power = 1, don't display it....
       DisplayValue = "&nbsp;"
      End If
      Response.Write "<td>" & DisplayValue & "</td>"
     Next
     Response.Write "</tr>" & vbNewLine
    Next
    %>
    </table>
    </p>
    holy god you're freakin' amazing.

    here it is in action :: www.stoneviper.com/asp/index2.asp
    the bottom 2 are yours.

    thanks a lot man! i'm gonna review them both tonight hopefully
    There's no place like 127.0.0.1

  8. #8
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by StoneViper
    holy god you're freakin' amazing.
    Why THANK YOU!! Can I quote you on that

    Quote Originally Posted by StoneViper
    thanks a lot man! i'm gonna review them both tonight hopefully [img]images/smilies/smile.gif[/img]
    If there's anything I didn't document well enough, let me know so I can explain better and update my code. Makes it easier in case someone ever needs it again.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    43 03' 16" N :::: 77 36' 03" W
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveMaxwell
    Why THANK YOU!! Can I quote you on that
    yes you may
    Quote Originally Posted by DaveMaxwell
    If there's anything I didn't document well enough, let me know so I can explain better and update my code. Makes it easier in case someone ever needs it again.
    yea, the commenting was well done. it was quite easy to understand.

    thanks once again man.
    There's no place like 127.0.0.1


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •