Re: Make 100 by using + - x / and 1~9
- From: Kira Yamato <kirakun@xxxxxxxxxxxxx>
- Date: Thu, 25 Oct 2007 18:35:42 -0400
On 2007-10-25 17:22:50 -0400, 131208@xxxxxxxxx said:
1 ( ) 2 ( ) 3 ( ) 4 ( ) 5 ( ) 6 ( ) 7 ( ) 8 ( ) 9 = 100
( ) only can be among +, - , x, /
The empty space is not allowed.
How many solutions are there?
C++/Perl solution output:
1+2*3*4*5-6-7-8=100
1-2*3+4*5*6-7-8=100
1*2+3*4+5*6+7*8=100
1-2*3+4*5*6*7/8=100
1+2*3*4*5-6-7-8=100
1-2*3+4*5*6-7-8=100
1*2+3*4+5*6+7*8=100
1-2*3+4*5*6*7/8=100
1+2*3*4*5-6-7-8=100
1-2*3+4*5*6-7-8=100
1*2+3*4+5*6+7*8=100
1-2*3+4*5*6*7/8=100
1+2*3*4*5-6-7-8=100
1-2*3+4*5*6-7-8=100
1*2+3*4+5*6+7*8=100
1-2*3+4*5*6*7/8=100
Source code: C++
#include <iostream>
int main()
{
char ops[] = "+-*/";
for(long i = 0; i<= 4*4*4*4*4*4*4*4-1; i++)
{
long j = i;
std::cout << "1";
for(int k = 2; k <= 8; k++)
{
std::cout << ops[j & 3] << k;
j>>=2;
}
std::cout << endl;
}
return 0;
}
Source code: Perl
my $a;
while(<>)
{
chomp;
eval('$a='.$_);
print "$_=$a\n" if $a==100;
}
--
-kira
.
- Follow-Ups:
- Re: Make 100 by using + - x / and 1~9
- From: Kira Yamato
- Re: Make 100 by using + - x / and 1~9
- Prev by Date: Re: JSH: Why do people lie ?
- Next by Date: Re: Foundational Books
- Previous by thread: Re: Make 100 by using + - x / and 1~9
- Next by thread: Re: Make 100 by using + - x / and 1~9
- Index(es):
Relevant Pages
|