- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This reminds me of a school maths project we had.
You could use any mathmatical operator (root, power etc)
You had 4 4s and had to use all 4 to get every number between 1 and 100.
I was apparently the only person to get all of them in the 3 years it had been running though I think some questioned the way I used factorial but I was only 14-15 at the time.
Admin
My final one, too: _24x.cc
This exhaustively permutes all numeric arguments and operators and runs them through dc to check the output. A true hack!
Upsides: guaranteed to find a solution if it exists, any number of parameters are allowed.
Downsides: slow, I mean slooOOoow, and many duplicate solutions are generated.
Requires *nix utility dc and optionally sort and uniq. To use more effectively, the output should be sorted and filtered to remove exact duplicates:
Which through inspection leaves two unique solutions, all the others are equivalent to these two: 1 5 + 7 3 - * 3 1 - 5 7 + *
Overall, lots of fun. Would like to see a Haskell or APL solution.
Admin
Sounds like a game I use to play with License Plate numbers (I lived in a state with mostly numbers on the plate). My goal was to use the numbers to create two equal numbers.
Example: 16784
8 - 6 = 2 7 - 4 - 1 = 2
2 = 2
Use to have a contest with my friends to see who could get the most.
Lew
Admin
Prolog-Version (with duplicates, output in Polish notation):
For example, calling
yields:
Admin
Admin
Looks like I am the only one who read it like this:
8♥ + 5♦ = 8♥ + 5♦
8♥ + 5♥ = 13♥
Admin
My solver finds 7/(7/6 - 7/8)
Admin
That's an interesting one indeed.
Admin
Interesting. A favorite numbers game of mine is to form pairs out of 4 digit vehicle registration numbers. The allowed operations are +, -, *, /, ^.
For eg: 5312 would have the two pairs (5 & 1): 5, 3 + 2 or 1, 3 - 2. or 4863 would have pairs of 4: 4, 6 * 8 = 14 = 1 * 4 = 4.
What would be fun is to find if we can have 4 digit numbers that cannot be built as pairs.
Admin
It's similar to project euler No. 93: http://projecteuler.net/index.php?section=problems&id=93
There you don't glue ciphers together, but use 4 operators, braces, reorder the numbers, but don't repeat them.
Then you have to find a mix of ciphers to produce the largest increasing set of numbers, starting from 1. Look yourself for the details.
Admin
I get 37 solutions using the least number of parenthesis for a given order of operators, is it not in this list?
6 * 7 / (7 + 7) * 8 = 24 6 / (7 + 7) * 7 * 8 = 24 6 / ((7 + 7) / 7) * 8 = 24 6 * 7 / ((7 + 7) / 8) = 24 6 / ((7 + 7) / 7 / 8) = 24 6 / (7 + 7) * 8 * 7 = 24 6 / ((7 + 7) / 8) * 7 = 24 6 / ((7 + 7) / 8 / 7) = 24 6 * 7 * 8 / (7 + 7) = 24 6 * 8 * 7 / (7 + 7) = 24 6 * 8 / (7 + 7) * 7 = 24 6 * 8 / ((7 + 7) / 7) = 24 7 * 6 / (7 + 7) * 8 = 24 7 * 6 / ((7 + 7) / 8) = 24 7 * 6 * 8 / (7 + 7) = 24 7 / (7 / 6 - 7 / 8) = 24 7 / (7 + 7) * 6 * 8 = 24 7 / ((7 + 7) / 6) * 8 = 24 7 / ((7 + 7) / 6 / 8) = 24 7 / (7 + 7) * 8 * 6 = 24 7 / ((7 + 7) / 8) * 6 = 24 7 / ((7 + 7) / 8 / 6) = 24 7 * 8 * 6 / (7 + 7) = 24 7 * 8 / (7 + 7) * 6 = 24 7 * 8 / ((7 + 7) / 6) = 24 8 * 6 * 7 / (7 + 7) = 24 8 * 6 / (7 + 7) * 7 = 24 8 * 6 / ((7 + 7) / 7) = 24 8 * 7 * 6 / (7 + 7) = 24 8 / (7 + 7) * 6 * 7 = 24 8 / ((7 + 7) / 6) * 7 = 24 8 / ((7 + 7) / 6 / 7) = 24 8 * 7 / (7 + 7) * 6 = 24 8 / (7 + 7) * 7 * 6 = 24 8 / ((7 + 7) / 7) * 6 = 24 8 * 7 / ((7 + 7) / 6) = 24 8 / ((7 + 7) / 7 / 6) = 24
Admin
No, the alternate solution will have a subtraction operator. It has no associative operators, so it has only one format:
7 / (7 / 6 - 7 / 8) = 24
If you're using floating point it's important to be careful with equalities.
To illustrate, can use a floating point type with 6 decimal digits of accuracy:
7 / (7 / 6 - 7 / 8)
= 7 / (1.16667 - 0.875000)
= 7 / 0.291670
= 23.9997 != 24.0000
Better to take the absolute value of a difference to the value and compare against some tolerance.
The simplest is something like this:
| calculated - target | < tolerance
Or for targets <> 0:
| (calculated - target) / target | < tolerance
Admin
You are correct. The result was in the solution set and I did have to use double precision for the calculation with a tolerance. It was buried in the middle of the solution set.
Admin
Admin
I was pleased to find this solution too. But I no longer know what would pass Mr.'; Drop Database --'s test as "interesting". Is the solution really different? Using grade school maths to calculate the fraction:
7 / (7/6 - 7/8) = 7 / ((78 - 76)/(68)) = 7 / ((72) / (68)) = 7(68) / (72) = 678 / (7+7)
Admin
itnewshub.org
Admin
Наша бригада искусных специалистов приготовлена предъявить вам перспективные средства, которые не только обеспечивают надежную охрану от холодильности, но и преподнесут вашему зданию изысканный вид. Мы практикуем с современными материалами, сертифицируя продолжительный срок службы работы и отличные результаты. Теплоизоляция нар&