Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Complicated Internal Marticies Addition


  • Please log in to reply
31 replies to this topic

#1 haun

haun

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 12 January 2009 - 11:16 PM

Ok, this is a continuation of my 'Universal Machine'

I have done a lot to it since i last came here for help.

But now i have a REAL RULE!!!!! but it's very complicated to explain.

What you will want to do is get a piece of graph paper (and a calculator). Start in the middle, top of the paper (while leaving a row) and place a 1 in the square. Now pretend that all the blanks are 0's, but dont put any anywhere. Now go strait down once and add, (0+1=1) then start back at the original 1 and add diagonally (down 1, over left 1) (0+1=1). Now do the same for the other side diagonal (down 1, over right 1), (0+1=1). Now go back to the top, and add along that diagonal into the blank square. Then go to the blank next to the one you just added (right 1), and look up 1, there should be a 1. Now look at the 2 diagonals, there should be another 1, and a blank. Add these 3 values (1+1+0=2) into that blank square. Now go to the blank square next to that (over right 1). Look vertically, there should be a 1, and another 1 above that. Then look at the 2 diagonals, there should be a 1 on upper left and upper right. Now add ALL those values (1+1+1+1=4). Then go to the next blank square, and the next one, and the next one...

For all you math geeks out there (me included), its basically adding all the values verticaly, all the values in left diagonal and all the values right diagonal.
so what should happen is this:

1
1 1 1
2 2 4 2 2
4 5 10 10 10 5 4
8 12 26 30 40 30 26 12 8

except square... dang forum system. oh well.

now here is the programming question.

How do i make it so that i get that form of addition automatically for much much much much longer, around 100 rows or more.
right now im going to start with a matrix that is 6x11 (I already build did this size of matrix on paper... twice...)

I was thinking for() loops, but im not sure.

Here is the current code:
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <fstream>

using namespace std;

//Variables
int row; //Used for placing rows in matrix
int col; //col number 
int next; //used as another portion to the rule
int row_size = 6 //numbers of rows ( -- )
int col_size = 11 //Number or colums ( | )
int matrix[row_size][row_size]; //Matrix, row_size x col_size 

// Functions

void txtclr() //Text Clear, used to clear the out file before the next print
{
ofstream UM("Out.txt", ios::out); //Opens "Out.txt" for clean, overwriting
}

void rule()
{
   //Here is where the Matrix addition code will be
}

void txtprnt() //Text Print, prints out the data from rule() to a file
{
rule(); //Runs the Rule
ofstream UM("Out.txt", ios::out | ios::app); //Dump arrays onto "Out.txt" at end of 
	 for( row = 0; row != row_size; row++) //Used to advance to next row once the first row is completed
	 {
		  UM << "|"; //Visual Character
		  cout << "|"; //View Real time generation
		  for( col = 0; col != col_size; col++ ) //Matrix Colum Builder
		  {
			   UM << matrix[row][col] << "|"; //Print the number in the space [row]x[col], and a Visual Character
			   cout << matrix[row][col] << "|"; //View Real time generation
		  }
		  UM << '\n'; //once row completed, move down a line
		  cout << '\n'; //View Real time generation
	 }

}
	
//Program

int main(int argc, char *argv[])
{
txtclr(); //Clear text
txtprnt(); //Print text [Generate numbers]
return 0;
}

Edited by haun, 12 January 2009 - 11:44 PM.

Annnnd you're, asking, me...

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:01:52 PM

Posted 12 January 2009 - 11:19 PM

I'm sorry to interrupt... but shouldn't such a triangle look like this?
http://en.wikipedia.org/wiki/Pascal%27s_triangle

Posted Image

Billy3

Edited by Billy O'Neal, 12 January 2009 - 11:20 PM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 12 January 2009 - 11:24 PM

thats what i thought, but when you have SQUARE graphing paper squares as entry spaces, there are not triangles that look like that

Be kinda fun to have hexagonal graphing paper

Edited by haun, 12 January 2009 - 11:25 PM.

Annnnd you're, asking, me...

#4 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 12 January 2009 - 11:31 PM

Made an image of the arrangement

Edited by haun, 12 January 2009 - 11:32 PM.

Annnnd you're, asking, me...

#5 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 12 January 2009 - 11:39 PM

AHHHHHHHH. The internet world doesnt like me.
Cant seem to get a picture to you guys.

EDIT

Have a picture, just cant seem to get it up.

Edited by haun, 12 January 2009 - 11:52 PM.

Annnnd you're, asking, me...

#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:01:52 PM

Posted 13 January 2009 - 05:01 PM

Go back to the wiki article, and read the section on "Calculating an individual row"

Might make things easier to calculate.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#7 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 18 January 2009 - 12:08 PM

im not seein how thats going to work. my triangle is MUCH different.
Annnnd you're, asking, me...

#8 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 24 January 2009 - 01:11 PM

Here we go
Posted Image
Annnnd you're, asking, me...

#9 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:52 PM

Posted 24 January 2009 - 01:40 PM

Shouldn't that last row be 2,4,6,4,2? Your pattern does not match. What does the 4th row look like then?

#10 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 24 January 2009 - 07:26 PM

fourth row is:
4 5 10 10 10 5 4
the 5th row is
8 12 26 30 40 30 26 12 8

Heres a better animation
Posted Image

Edited by haun, 24 January 2009 - 07:55 PM.

Annnnd you're, asking, me...

#11 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:52 PM

Posted 24 January 2009 - 07:56 PM

Can you just put up an ASCII representation? THe animation moves so quickly that I can't even think about what is going on.

#12 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 24 January 2009 - 09:56 PM

I tried that, just imagine that all this is triangular

1
1 1 1
2 2 4 2 2
4 5 10 10 10 5 4
8 12 26 30 40 30 26 12 8
Annnnd you're, asking, me...

#13 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:01:52 PM

Posted 24 January 2009 - 10:02 PM

EDIT: Nvm

Food for thought: How would you calculate that if it was left aligned :thumbsup:. Remember that computers don't store data as triangles....

Billy3

Edited by Billy O'Neal, 24 January 2009 - 10:02 PM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#14 haun

haun
  • Topic Starter

  • Members
  • 156 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Denver, CO
  • Local time:02:52 PM

Posted 24 January 2009 - 10:09 PM

thats where the matrix come in.

EDIT: Grove, i slowed it down.

Edited by haun, 24 January 2009 - 10:14 PM.

Annnnd you're, asking, me...

#15 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:52 PM

Posted 24 January 2009 - 10:38 PM

Its Groove (2 o's). It still does not make sense. I will pick on it when I have a bit more time. I am trying to get through some Nietzsche at the moment as part of an ethics class. The pattern, from what I have seen so far, is not logical. Perhaps it is just because I am not following it exactly yet.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users