Re: make 100 by using 1, 7, 7, 7, 7



In article <2007111313515516807-kirakun@earthlinknet>,
Kira Yamato <kirakun@xxxxxxxxxxxxx> wrote:

On 2007-11-13 13:22:13 -0500, Robert Israel
<israel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> said:

"Benjamin A. Bartsch" <benjamin.a.bartsch@xxxxxxxxx> writes:


dangerousgam...@xxxxxxxxx schrieb:
So, using only +, -, x, /, and parentheses, and ONLY these numbers:

1, 7, 7, 7, 7

how can you make 100? Is there more than one solution?

--> (1/7+7)*(7+7)

Benjamin

Yes, and that's the only solution (up to commutativity).

I'm very curious how you concluded this. Was it by a program that
tests through all possible combinations?

I tried to write a program too, but I stop when I couldn't quickly find
a way to list out all possible trees with 7 leaves.

Here is a Perl script that prints out all balanced strings
of parentheses. The balanced strings of 2n parentheses
can be bijected with the binary trees on n vertices.

The script works like this:

P_n is the set of balanced strings of 2n parentheses so
P_{n+1} = (P_{k}) P_{n - k}.

The script is criminally wasteful of time and
space, but it is easy to code, an easy to understand. :)

________________________
#!/usr/bin/perl

$count = $ARGV[0];

print join "\n", pren($count), "";

sub pren
{
my @list = ();

(my $n) = @_;
if ($n == 0) {push(@list, "")}
elsif($n == 1) {push(@list, "()")}
elsif($n > 1)
{
foreach $k (0 .. $n-1)
{
foreach $p1 (pren($k))
{
foreach $p2 (pren($n - 1 - $k))
{
push @list, sprintf "(%s)%s", $p1, $p2;
}
}
}
}
return @list;
}
________________________


$ ./parens.pl 5 | cat -n
1 ()()()()()
2 ()()()(())
3 ()()(())()
4 ()()(()())
5 ()()((()))
6 ()(())()()
7 ()(())(())
8 ()(()())()
9 ()((()))()
10 ()(()()())
11 ()(()(()))
12 ()((())())
13 ()((()()))
14 ()(((())))
15 (())()()()
16 (())()(())
17 (())(())()
18 (())(()())
19 (())((()))
20 (()())()()
21 (()())(())
22 ((()))()()
23 ((()))(())
24 (()()())()
25 (()(()))()
26 ((())())()
27 ((()()))()
28 (((())))()
29 (()()()())
30 (()()(()))
31 (()(())())
32 (()(()()))
33 (()((())))
34 ((())()())
35 ((())(()))
36 ((()())())
37 (((()))())
38 ((()()()))
39 ((()(())))
40 (((())()))
41 (((()())))
42 ((((()))))

--
Michael Press
.



Relevant Pages

  • Re: make 100 by using 1, 7, 7, 7, 7
    ... Here is a Perl script that prints out all balanced strings ... The balanced strings of 2n parentheses ... can be bijected with the binary trees on n vertices. ...
    (sci.math)
  • Re: make 100 by using 1, 7, 7, 7, 7
    ... The balanced strings of 2n parentheses ... can be bijected with the binary trees on n vertices. ... The script works like this: ... P_n is the set of balanced strings of 2n parentheses so ...
    (sci.math)
  • Re: make 100 by using 1, 7, 7, 7, 7
    ... The balanced strings of 2n parentheses ... can be bijected with the binary trees on n vertices. ... The script works like this: ... P_n is the set of balanced strings of 2n parentheses so ...
    (sci.math)
  • Re: [PATCH] Speed up "make headers_*"
    ... 'use strict' and 'use warnings' is recommended. ... The parentheses are not needed for most of the built-in functions. ... More or less the same comments would apply to the next script as well. ...
    (Linux-Kernel)
  • Re: Trailing blanks in batch file
    ... Same applies to parentheses and quotes, ... problem as there *being* a trailing space whose presence creates a problem. ... If someone exclusively used an editor that displayed blanks as grey dots, ... can never be sure that one's script will never be edited by someone else ...
    (microsoft.public.win2000.cmdprompt.admin)