Re: Make 100 by using + - x / and 1~9
- From: Kira Yamato <kirakun@xxxxxxxxxxxxx>
- Date: Thu, 25 Oct 2007 18:41:15 -0400
On 2007-10-25 18:35:42 -0400, Kira Yamato <kirakun@xxxxxxxxxxxxx> said:
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?
Ooops. My code had a "off-by-1" bug. The correct output should be
1*2*3*4+5+6+7*8+9=100
1-2+3*4*5+6*7+8-9=100
1-2+3*4*5-6+7*8-9=100
1+2+3+4+5+6+7+8*9=100
1*2*3+4+5+6+7+8*9=100
1-2*3+4*5+6+7+8*9=100
1+2*3+4*5-6+7+8*9=100
1-2*3-4+5*6+7+8*9=100
1+2-3*4+5*6+7+8*9=100
1+2*3*4*5/6+7+8*9=100
1*2*3*4+5+6-7+8*9=100
1-2*3-4-5+6*7+8*9=100
1+2-3*4-5+6*7+8*9=100
1+2+3-4*5+6*7+8*9=100
1*2*3-4*5+6*7+8*9=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 <= 9; 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: Michael Press
- Re: Make 100 by using + - x / and 1~9
- From: Alfred Heiligenbrunner
- Re: Make 100 by using + - x / and 1~9
- References:
- 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: Foundational Books
- Next by Date: Explain 7 O'Clock please.
- 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
|