Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need help on a program [Any Language]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
chrono
Expert Cheater
Reputation: 0

Joined: 10 Mar 2006
Posts: 160

PostPosted: Wed Apr 09, 2008 9:36 pm    Post subject: Need help on a program [Any Language] Reply with quote

Hi, it's kind of rare to see a noob programmer in this section, but I need some assistance.

I have a project in math which goes as follows:

Quote:

The product of the digits in the number 126 is 12: 1*2*6 = 12

a. How many different three digit numbers have a product equal to 12? Explain how you know

b. How many three digit numbers have a product equal to 18? Explain.

c. Compare your answers to parts a and b and explain why they work out that way.

d. Extra Credit: How many four digit numbers have a product equal to 12? Explain.

e. Extra Credit 2: Explain alternate methods to solve this problem




Basically, I can solve the problem easily through factorization, but I really need to find a method to answer "Extra Credit 2".

So I thought, why not make a program that can solve which numbers work for me?

Of course, I'm a programming noob, so if anybody can give me some assistance, that'd be great!

Also, If this can be done in VB, that would be even easier for me, but if anybody has any other programming methods to solve this problem, let me know!!

Thanks again~
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Wed Apr 09, 2008 9:42 pm    Post subject: Reply with quote

If this is due anytime soon then I wouldn't count on learning a language for it can take a while.
Back to top
View user's profile Send private message Visit poster's website
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Wed Apr 09, 2008 9:54 pm    Post subject: Reply with quote

Negima wrote:
If this is due anytime soon then I wouldn't count on learning a language for it can take a while.


ahh, but learning how to use math operators is not hard at all. At least, not in most languages.

Then you just have to figure out the correct formula or method for yourself.

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Apr 09, 2008 10:06 pm    Post subject: Reply with quote

I don't think there's really a fast way to do factoring.

The only way I can think of is looping through and trying to sort things out.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Apr 09, 2008 10:15 pm    Post subject: Reply with quote

yea, what slovach said. I would most likely make an triple array or whatever its called (to hold the 3 numbers that multiply to twelve), then like loop each number. Then, you would have to look through those numbers, and see which ones come out to twelve. Which would additionally add to the time it takes. Hehe, I wonder if you could make threads to sort out numbers at the same time? lol. Anyway for example, for something like 1:

Code:

1*1*1
1*1*2
1*1*3
1*1*4
1*1*5
1*1*6
1*1*7
1*1*8
1*1*9
1*1*10
1*1*11
1*1*12

1*2*1
1*2*2
1*2*3
1*2*4
1*2*5
1*2*6
1*2*7
1*2*8
1*2*9
1*2*10
1*2*11
1*2*12


And so forth...So you can see, even for one number it would take you a LONG time. But if you really want, I could help you to write something

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Thu Apr 10, 2008 12:05 am    Post subject: Reply with quote

(In Delphi)
Code:
for i:=100 to 999 do
begin
  units:=i mod 10;
  teens:= (i div 10) mod 10;
  hundreds := i div 100;
  if units*teens*hundreds  = product then //The product you want to check
    //Adding the number to the list of good numbers.
end;

@oib111: You don't have to try 1*1*10, 1*1*11 and 1*1*12 because its three digit numbers and 1110 is 4 digit number.
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Thu Apr 10, 2008 7:37 am    Post subject: Reply with quote

HolyBlah's code in VB6:

Code:
Private Sub Form_Load()
    Dim units As Integer
    Dim tens As Integer
    Dim hundreds As Integer
    Dim product As Integer
   
    product = 12
   
    For i = 100 To 999
        units = i Mod 10
        tens = (i / 10) Mod 10
        hundreds = i / 100
        If units * tens * hundreds = product Then
            Call List1.AddItem(units & " x " & tens & " x " & hundreds & " = " & product)
        End If
    Next i
End Sub


The code above assumes you have a ListBox named List1.

Returns the following:
Code:
6 x 2 x 1 = 12
4 x 3 x 1 = 12
3 x 4 x 1 = 12
1 x 6 x 2 = 12
6 x 1 x 2 = 12
3 x 2 x 2 = 12
2 x 3 x 2 = 12
4 x 1 x 3 = 12
2 x 2 x 3 = 12
1 x 4 x 3 = 12
3 x 1 x 4 = 12
1 x 3 x 4 = 12
2 x 1 x 6 = 12
1 x 2 x 6 = 12
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Apr 10, 2008 8:56 am    Post subject: Reply with quote

HolyBlah wrote:
(In Delphi)
Code:
for i:=100 to 999 do
begin
  units:=i mod 10;
  teens:= (i div 10) mod 10;
  hundreds := i div 100;
  if units*teens*hundreds  = product then //The product you want to check
    //Adding the number to the list of good numbers.
end;

@oib111: You don't have to try 1*1*10, 1*1*11 and 1*1*12 because its three digit numbers and 1110 is 4 digit number.


Oh get whats hes saying. Now, at first I thought he meant three numbers, but he menat three digits.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Thu Apr 10, 2008 2:10 pm    Post subject: Reply with quote

Code:
6 x 2 x 1 = 12
4 x 3 x 1 = 12
3 x 4 x 1 = 12
1 x 6 x 2 = 12
6 x 1 x 2 = 12
3 x 2 x 2 = 12
2 x 3 x 2 = 12
4 x 1 x 3 = 12
2 x 2 x 3 = 12
1 x 4 x 3 = 12
3 x 1 x 4 = 12
1 x 3 x 4 = 12
2 x 1 x 6 = 12
1 x 2 x 6 = 12

It's missing 261 o.O


Last edited by HalfPrime on Thu Apr 10, 2008 2:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
chrono
Expert Cheater
Reputation: 0

Joined: 10 Mar 2006
Posts: 160

PostPosted: Thu Apr 10, 2008 2:10 pm    Post subject: Reply with quote

thanks a million~ i owe you guys an A+ ~
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Thu Apr 10, 2008 5:41 pm    Post subject: Reply with quote

Here's how I thought of it (if I were to make a program), if anyone is interested

Code:

12 / 2 = 6
 6 = max


If you go over 6, your result is over 12. Which we don't want.

Code:

6 / 2 = 3
3 = end of algorithm

You'll see why.

Since there is three, we would want to increase the second number and decrease the third. The third will start at max and the second will start with two. When you find that the number that equals 12, you keep the index of the third and use that when the second is increased. If the number didn't equal 12, remember the third number you started with.
Code:

1 * 2 * 6 = 12 12 == 12
1 * 3 * 6 = 18 18 != 12
1 * 3 * 5 = 15 15 != 12
1 * 3 * 4 = 12 12 == 12


If I were to expand it so that the third number goes all the way down to 1 and always starts at 6, you will notice when the second number is 4, you will just repeat. It makes for less of a loop.

So, for this one, there is really only two solutions. Unless you count the ones where you use the same number more than once. The algorithm will still apply to that as well.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Apr 10, 2008 7:45 pm    Post subject: Reply with quote

HolyBlah wrote:
(In Delphi)
Code:
for i:=100 to 999 do
begin
  units:=i mod 10;
  teens:= (i div 10) mod 10;
  hundreds := i div 100;
  if units*teens*hundreds  = product then //The product you want to check
    //Adding the number to the list of good numbers.
end;

@oib111: You don't have to try 1*1*10, 1*1*11 and 1*1*12 because its three digit numbers and 1110 is 4 digit number.


Its fine to use this code. But if you're going to use code that isn't made by you (don't get confused with stealing, the code thats given right now is basically an outline) it's always good to know how it works instead of just copying and pasting. And seeing as your new to programming, it helps you to understand. I looked at HolyBlah's code and thought, man that's smart. Basically, he's using simple division and remainder tactics to get the digits of the number. Take the 3-digit number 126.

126 divided by 10 equals 12 remainder 6. Mod returns the remainder. So now you have the variable units (aliasing the ones digit place) to equal 6.

Now you divide 126 by 10 and that equals as we've stated 12 with a remainder of 6. The div function throws away the remainder, so now you have twelve. Then you divide again using the mod function, which we know returns the remainder. So 12 divided by 10 equals 1 with a remainder of 2. So now in teens (I think it was a typo, and HolyBlah meant tens) we have the value 2.

Now we just divided 126 by 100 and throw away the remainder. 126 divided by 100 equals 1. So now in the variable hundreds you have the value 1. Now look at the number you got.

Hundreds=1
Teens=2
Units=6

126. Then if you multiply each one of those variables: 1 times 2 equals 2. 2 times 6 equals 12. So then you can store that in whatever. As Estx used, he did it in a list box.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites