Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

I can look around a bit, what file type are you using?

I can tutor you for either type of green

Probably prefer .fbx but .3ds would also work. I use 3ds max when I do model and other softwares I use have converters to those two formats. Plus a bit familiar with the fbx sdk just itā€™s documentation is complete shit.

checks thread outā€¦reads a bit, then assigns Jonathan Coultonā€™s ā€œCode Monkeyā€ as thread bgm

Itā€™s wintermute man. He just appears and drops knowledge.

I remember reading a really well written article that walked me through making a skeletal system for use in rag doll stuff, back when I thought I still cared about 3d programming. Iā€™ll see if I can track it down, as this was like 5 years ago.

Damn, thatā€™s embarrassing. An example for my defense, XNA refers to them as ā€œbonesā€, other APIs often call them ā€œframesā€, so maybe I can be forgiven for taking your question too literally. Sorry, I would have known what context you were using had I noticed your post after that, which I didnā€™t. My bad.

Copy all the bone transforms to a matrix array. To preserve the relative positioning of meshes within the model, look up the relative transform matrix from the bone data attached to your model, then include this when setting the world matrix for your effects.

[SIZE=16px]
[/SIZE]

I think the way it works is it registers an event handler on the object for a sliding motion in a certain direction (left, right, up, down) and then specifies how many pixels it takes to trigger that event (in this case 20). Then it gets passed to some sort of function that handles the slide input, where it passes in the direction (ActionMoveLeft, etc) and he just moves the ball in that direction 80 pixels. Again without actually seeing the entirety of the input handling code youā€™re right that weā€™re kind of shooting in the dark.

But thatā€™s why I figured if hes using 80 pixel wide squares and calling a move event event every 20 pixels heā€™s gonna see his ball moving 4 squares for every 1 square he slides his fingers, making it look super sensitive.

Re-edited so this doesnā€™t waste space:
http://news.bbc.co.uk/2/hi/programmes/click_online/9503255.stm

Getting children interesting in programming can be done through making simple, yet fun, games. Video games people will want to play and make are the ones they can play on the web, share with friends through facebook, ipod, or whatever social networking scheme is available. Then some of these students will go on to be engineers and artists as they keep up their dedication, inspired at a young age by their experiences.

Iā€™m currently making a prototype game in Flash, and I seem to be having a hard time manipulating objects in an array (as in objects derived from classes). Does anyone know how I would do this? It seems to be harder than it should be, compared to C++.

EDIT: It seems the answer is to use a Vector for what it is Iā€™m trying to do.

Nice to know that we have a Computer Programming thread. Anyway Iā€™m taking Compe 160 @ SDSU right and itā€™s nothing I canā€™t handle so far but on this one particular homework thatā€™s due this Friday, I have no idea where to start which is kind of embarrassing haha. Anyway all sorts of help is appreciated!

homework assignment

[details=Spoiler]
An integer x is a perfect number if the sum of the divisors of x (including 1 but not including x itself) is equal to x. For example, 6 is a perfect number since 6 = 1+2+3. Write a function that determines whether an integer is perfect.
int isperfect(int x);
The function returns 1 if x is a perfect number and 0 if it is not.
Hint. The function isperfect needs to find all factors of x and add them together. In searching for the factors of x, start at f=2 and increment until ff > x. For each value of f such that x % f == 0 you have found two factors: f and x/f.*

Write a main program that finds all the perfect numbers between 2 and 10,000. The program will determine whether a number is perfect by calling the function isperfect. Print each perfect number on a separate line along with its expansion as a sum of factors. The factors should appear in ascending order. For example, the first line produced by your program should be
6 = 1 + 2 + 3

[LEFT][/details]
[/LEFT]

What are you actually stuck on, the logic? Iā€™m not sure what sort of stuff youā€™ve learned so far or what language youā€™re even working in for that class. C++? Java?

The way the answer is supposed to be done doesnā€™t really seem super efficient, since they want you to write a function that returns 1 if itā€™s true, but in that function you need to determine all the factors, then outside of the function you need to recalculate the factors so you can print them out again. You could print them inside the isperfect function, but Iā€™m not sure if that would be wise because the function doesnā€™t say to print anything, only determine if itā€™s perfect.

Iā€™d write int IsPerfect(int x) and a separate function Vector getfactors(int x) that returns an array of the factors, then you can call the getfactors in your main loop again if itā€™s perfect just to output the line

Iā€™ll write some pseudocode:



int isperfect(int x)
{
int isPerfect;  //returns 1 if perfect number, 0 if not
int f = 2;
Vector factors;  //holds all values of f

If x is less than 2 or if it's greater than 10,000, then isPerfect should return 0. Otherwise
while (f*f <= x)
{
  if (f modulus x equals 0)
      push f into the vector
      increment f by 1
}

Take each element in the vector, and add them together. If the total is not equal to x, then isPerfect = 0.  Otherwise, return 1.

return isPerfect;

}


Thanks King, Iā€™ll take a look at that later.

Hereā€™s what I came up with


main()
{
  int n,x,sum;
 
  printf("Perfect numbers are: ");
  for(n=1;n<=10000;n++){
    x=1;
    sum = 0;

    while(x<n){
      if(n%x==0)
           sum=sum+i;
          i++;
    }

    if(sum==n)
      printf("%d ",n);
  }

  return 0;
}

Now itā€™s a matter of me using isperfect and having my code produce the lines my professor wants to program to produce.

Oh wow vectors? I donā€™t think our professor taught us that yet. :eek:

Thereā€™s ways to do it without, it just becomes more messy. But in a classroom assignment, I guess it works kind of. Doesnā€™t need to be super efficient to pass the assignment

Did a little bit of digging to see how other people did this and found this.


#include<stdio.h>
int perfect(int x);
int main()
{
    int a,b,c;

    printf("
Please enter your range of number: ");
    scanf("%d", &a);
    printf("The list of perfect number between 1 and  %d is
",a);

    for(c=1 ; c<=a ; c++ )
    {

        b=perfect(c);
        if ( b == c)
        {
            printf("%d
",c);
        }

    }

    return 0;
}
int perfect( int x)
{
    int i,sum =0;

    for( i=1 ; i<x ; i++)
    {
      if(x%i == 0)
      sum +=i;
    }
    return sum;
}


I think this person is ā€œcloserā€ to what my professor wanted it to produce, but for our homework assignment, we canā€™t input anything into the program so thereā€™s no scanf, like how my first take at the homework assignment is like, but this person used something thatā€™s like int isperfect but itā€™s int perfect instead.

Anyway I mixed both my program and this personā€™s program and got this.


#include <stdio.h>
int perfect (int x);
int main()
{
  int y, z;

  printf( "" );

  for( z=2; z<=10000; z++ )
  {
      y = perfect(z);
      if ( y == z)
      {
        printf( "%d
",z );
      }
  }
return 0;
}
int perfect( int x)
{
  int i,sum =0;

  for( i=1 ; i<x ; i++)
  {
      if( x%i == 0 )
      sum += i;
  }
return sum;
}

OUTPUT:
6
28
496
8128


Which is great because I feel like Iā€™m getting closer now. Now all I need it to do is have the output read:


6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064

Since those are the only 4 numbers between 2 and 10000 that are perfect numbers. Any ideas guys?

Also another question, I tried using int isperfect(int x) like my professor wanted me to but when I tried to run the program it gave me a message saying


Undefined                      first referenced
symbol                            in file
perfect                            Project3ver2.o

So instead I just modified it into int perfect(int x) and now the program works. But Iā€™d still would like to follow my professorā€™s instructions for the homework exactly as he had told us so again, if you guys have any ideas why using int isperfect(int x) is not working for me, it would be greatly appreciated. :tup:

Your program doesnā€™t fulfill the requirement, because isperfect needs to return 0 if itā€™s not a perfect number, and 1 if it is. You have it returning the sum, which doesnā€™t meet the assignment criteria, even if your solution works.

You want something closer to this:


#include <stdio.h>

int isPerfect (int x);

int main()
{
 int isPerfect;

  printf( "" );

  for(int i = 2; i <= 10000; i++)
  {
      isPerfect = isperfect(i);
      if (isPerfect == 1)
      {
        //output all the factors
        printf("%d = 1", i); //1 is always a factor so output it and make the logic of adding "+" easier
        for(int j = 1; j*j < i; j++)
        {
           if(i%j == 0)
             printf("+ %d", j);
        }
        printf("
");
      }
  }
return 0;
}

int isPerfect( int x)
{
  int sum =0;

  for(int i=1 ; i*i<x ; i++)
  {
      if( x%i == 0 )
      sum += i;
  }

if(sum == x)
 return 1;
else
 return 0;

}



Iā€™d break out the outputting into its own function to just to make everything look cleaner but at the level youā€™re currently at, it isnā€™t a big deal.

and yes, thereā€™s not that many perfect numbers so your solution is correct

Oh yeah, I forgot about the return 1 and 0 stuff. My professor is really nitpicky about the requirements so thanks for that.

Anyway after going through your program, making sense of it, cleaning it a bit, etc. I tried running it but I get the ā€œundefined first referencedā€ error. :sad:

posting to subscribe

Post it up word for word how you cleaned it up so we can see whatā€™s wrong