tough program problems

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

uart

Member
May 26, 2000
174
0
0
Indeed there are not that many possible combinations:
You know, the thing that surprised me when I ran my program was just how many such numbers there actually are. Almost 50% without parentheses and a massive 75% (approx) if parentheses are allowed.

Here is the program output (counts only),
4902 of 10000 without parentheses
7451 of 10000 with parentheses


Ok I did a really quick and nasty job of programming it and haven't thoroughly tested it's correctness by any means, but I've got a feeling that it is giving me the correct figure. The dozen or so output samples that I've tested have all been spot on.
 

sao123

Lifer
May 27, 2002
12,648
201
106
your numbers are correct however....
now you must account for what i stated above...

there arent really 10000 unique problem cards....(by problem cards i mean the equivolent of 1 question)
no 2 problem cards that exist have exactly the same set of 4 numbers.

therefore your results take into account 24 cards with the numbers 1,2,3,&4 on them. This is acutally 1 question.

I am currently calculating the total number of problem cards that exist.
 

uart

Member
May 26, 2000
174
0
0
Yeah I know what you're saying SAO, we're looking at slightly different problems. I initially wrote the program simply to test if a given input number had the "24" property. Later I thought it would be kind of interesting to to let it run through every four digit integer (from 0000 through to 999) and count how many numbers actually had this "24'ness" property.

Interesting result though, if you pick a four digit number at random then there's nearly a 50% chance that it'll be a "24" number.
 

SmoiL

Member
Aug 31, 2002
45
0
0
uart, can you post a list of your combinations without parens?

~Thanks

p.s. my current (but flawed) list can be found here

edit: I think maybe I have the correct answer for the possible cases without parens, not counting number dupes (1*1*8*3 and 1/1*8*3 would be counted as only 1) but including mismatched digits (1*1*8*3 and 1*8*3*1 would both count). However I get 2130 combinations this way....much less than uart. note: I am by no means a genius and am just trying to figure out where my problem lies.
 

sao123

Lifer
May 27, 2002
12,648
201
106
smoil,

i think the problem with your calculation is that you rely on the order of the digits too much.
3344, 3434, 3443, 4334, 4343, 4433 all give the same calculation 3x4 + 3x4.
Your list only includes some of these values... noticibly missing is 3344 & 4433.

I suspect this problem is present throughout your list.
 

SmoiL

Member
Aug 31, 2002
45
0
0
In my list I wasn't searching for just unique combinations of numbers, order was a factor. However I parsed the list and extracted all dupes, leaving a total of 233 unique instances. You can view them here

Note: the way I parsed the results gave presedence to numerically higher combinations. so 4343 is selected instead of 3344 or 3434, etc.
 

uart

Member
May 26, 2000
174
0
0
Interesting results SmoiL. Yeah your results may well be correct and mine wrong. Like I said I only did an extremely quick and nasty job of coding it. Oh well at least this makes it interesting, two different result and neither sure exactly who is correct yet.


Just to make it clear of what I was calculating, my program was initially just written to take one four digit number as input and then to calculate whether or not that number had the "24'ness" property and write this as the output. After testing it on a few numbers and seeing that it seemed to work I thought it would be interesting the run all numbers from 0 to 9999 through in a loop and count how many satisfied the condition. I was interested in the probability that a randomly chosen four digit number would satisfied the condition.

What SAO is interested in is a different thing (I know you understand this). He is interested in the number of unique sets of four decimal digits that satisfy the condition.

BTW, the total number of such sets (not just the ones that satisfy the condition but the total number of unique sets) is C(10,4) + 3*C(10,3) + 3*C(10,2) + C(10,1) = 715, where C(n,r) is the combination function, n!/(r! (n-r)!).

I know how to enumerate these sets pretty easily but dont have time today. If I get time I'll get my program to enumerate just these set tomorrow and set what the satisfy count is.


PS. My crude program was a console application that just spat out results to a command prompt window. I was only looking at the final count but next time I run it I'll make it log the results to a file so we can scrutinize the individual numbers as per your list file.
 

uart

Member
May 26, 2000
174
0
0
Ok I just made my program write the results to a text file and immediately discovered a glaringly obvious bug, it had lots of "divide by zeros" allowed. I knew immediately where abouts in the code I had made this mistake so it was easy to fix.

I originally had some code like : "if den<>0 then temp:=num/den" to prevent div by zero, but no "else" statement to tell the code what to do on the div by zero exception. At the time of writing I knew this was a problem but thought "I'll fix that later". LOL, the usual problem of quick and nasty programming.

OK fixing the above problem resulted in 3466 valid numbwers (out of 0...9999) that satisfy the "24" property.

I then did a quick modification to make the program only enumerate unique sets (all 715 of them) and the result was that there are 233 of these sets that satisfy the "24" property.

Smoil, it's interesting that I still have a different answer to you for the first problem, but our answers are identical on the second problem.
 

sao123

Lifer
May 27, 2002
12,648
201
106
I began comparing lists of uart and smoils outputs...
As i thought...and stated earlier...the difference is clear to me.


uarts program recognizes 3344 as having the 24ness property...
3*4+3*4 (allowing for rearranging the digits within the number to compute 24)

smoils program does not. his program excludes such examples because he does not allow for re-arranging the digits within the number to compute if the 24ness property is present. His program forces the digits to remain in exact order merely placing an operand between them.


The 233 number is correct...as that was exactly the original number of cards included in the 24 challenge contest.
 

SmoiL

Member
Aug 31, 2002
45
0
0
I figured out why our lists have different results. I calculated based on number order being fixed, whereas you allowed for a rearrangement of digits. The first example I found was 9967. In that order my method cant get 24, but you can by moving the digit order to 6799. Of course since all variations are present between 0000->9999 we both get 233 when we filter the end results.


edit: Sorry sao, my brain is worthless [=
 

sao123

Lifer
May 27, 2002
12,648
201
106
Just in case u didnt read my post.....

thats what i said.... twice actually.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |