Author |
Topic: calculation puzzle (Read 3851 times) |
|
bluatigro
Full Member
member is offline
Gender:
Posts: 111
|
|
calculation puzzle
« Thread started on: Dec 14th, 2015, 10:26am » |
|
i fount a puzzle in the newspaper i didnt want to solve it by hand so i wrote a program
its the slowest way posible its verry brute force
whit a permutation function it can be faster
Code:
''dfbf / bgak = b
'' - + +
''hhfh + ecc = hkfh
''kjkj - ebak = hkfe
for a = 0 to 9
for b = 0 to 9
for c = 0 to 9
for d = 0 to 9
for e = 0 to 9
for f = 0 to 9
for g = 0 to 9
for h = 0 to 9
for j = 0 to 9
for k = 0 to 9
q$ = str$( a );b;c;d;e;f;g;h;j;k
if ispermutation( q$ ) then
print q$
a$ = str4$( d , g , b , f )
b$ = str4$( b , g , a , k )
c$ = str4$( 0 , 0 , 0 , b )
d$ = str4$( h , h , f , h )
e$ = str4$( 0 , e , c , c )
f$ = str4$( h , k , f , h )
g$ = str4$( k , j , k , j )
h$ = str4$( e , b , a , k )
j$ = str4$( h , k , f , e )
if val( a$ ) / val( b$ ) = val( c$ ) then
if val( d$ ) + val( e$ ) = val( f$ ) then
if val( g$ ) - val( h$ ) = val( j$ ) then
if val( a$ ) - val( d$ ) = val( g$ ) then
if val( b$ ) + val( e$ ) = val( h$ ) then
if val( c$ ) + val( f$ ) = val( j$ ) then
print a$ + " / " + b$ + " = " + c$
print " - + +"
print d$ + " + " + e$ + " = " + f$
print g$ + " - " + h$ + " = " + j$
end
end if
end if
end if
end if
end if
end if
end if
next k
next j
next h
next g
next f
next e
next d
next c
next b
next a
end
function str4$( x , y , z , w )
str4$ = str$( x ) ; y ; z ; w
end function
function ispermutation( q$ )
uit = 1
for i = 0 to 9
if instr( q$ , str$( i ) ) = 0 then
uit = 0
end if
next i
ispermutation = uit
end function
|
« Last Edit: Dec 14th, 2015, 10:26am by bluatigro » |
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: calculation puzzle
« Reply #1 on: Dec 14th, 2015, 8:58pm » |
|
That would be more informative if the actual "puzzle" was included.
|
|
Logged
|
|
|
|
bluatigro
Full Member
member is offline
Gender:
Posts: 111
|
|
Re: calculation puzzle
« Reply #2 on: Dec 15th, 2015, 08:56am » |
|
@ pnlawrence : - see begin of code in REM
|
|
Logged
|
|
|
|
bluatigro
Full Member
member is offline
Gender:
Posts: 111
|
|
Re: calculation puzzle
« Reply #3 on: Dec 21st, 2015, 08:55am » |
|
update : - the newspaper had the folowing solution Quote:5928 / 2864 = 2 - + + 1181 + 300 = 1481 4747 - 3264 = 1483 |
|
|
|
Logged
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: calculation puzzle
« Reply #4 on: Dec 22nd, 2015, 09:58am » |
|
I think the first line of the puzzle should be: dfbf / bghk = b NOT dfbf / bgak = b
The first line of the answer should be: 5828 / 2914 = 2 NOT 5928 / 2864 = 2
This makes the correct permutation: a=6, b=2, c=0, d=5, e=3, f=8, g=9, h=1, j=7, k=4
I hope this clarifies it a bit, not confuses it more...
|
|
Logged
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: calculation puzzle
« Reply #5 on: Dec 29th, 2015, 07:06am » |
|
Ten nested for-next statements, each with 10 steps, will cycle through 10 to the 10th power iterations. That is ten billion (10,000,000,000) iterations! On my PC it took 48 minutes just to count them.
3,628,800 of these ten billion iterations are what I call "unique permutations". That is, they contain all the ten digits with no duplicated digits. In the absence of any efficient algorithm to generate unique permutations, the best way I could think of to process them is to write them to a sequential disk file. The program to do that ran for over 24 hours. But look at it like a table of logarithms. It takes a great effort to create a good table, but then you can use it quickly and easily forever for various calculations.
Using the disk file the puzzle can be solved in less than three minutes. You can also use the file to make similar puzzles. Download it using the link below if anyone is interested. Let me know if there are any problems or questions.
https://www.dropbox.com/s/v2w7kmry7cmflj2/Puzzle.ZIP?dl=0
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: calculation puzzle
« Reply #6 on: Dec 29th, 2015, 07:53am » |
|
Quote:algorithm to generate unique permutations |
|
[RC] Permutations More on this puzzle on LB forum: calculation puzzle
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: calculation puzzle
« Reply #7 on: Dec 29th, 2015, 10:34am » |
|
on Dec 29th, 2015, 07:53am, tsh73 wrote: Not for some of us! Clicking on that link simply displays the message "Sorry, but you have been banned from this forum".
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: calculation puzzle
« Reply #8 on: Dec 29th, 2015, 1:29pm » |
|
How can someone be banned from a public forum just to view a puzzle? Amazing!
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: calculation puzzle
« Reply #9 on: Dec 29th, 2015, 4:09pm » |
|
Richard, I posted reply of three identical bluatigro posts on forum with most users. I did not recalled that you will not be able to see it.
So I repost my musings here, for your viewing pleasure.
Dec 14 It is a number puzzle. Each number present single digit You are to find single permutation which makes all conditions ("dfbf / bgak = b" etc) true. As for now, it tries to check all possible permutations And it goes checking each possible number That gives us 10^10 possible variants. So you just as well could quit waiting
But using some maths (or wits, or both) you can significally decrease that time. After all, such kinds of puzzle are supposed to be solved by paper and pen...
(I did some guesses on 4 of digits and got answer in some 20 minutes - not exactly sure - while reading Wiki on Guardian Dark/Summining Dark)
Dec 21 I've got same result. Here are observations I made: Code:that makes 'c' equal to 0 Code: that makes e=b+1 Code: that says e=b+h, hense h = 1 Also, Code: leaves 'b' only be 1, 2 or 3.
With that, revised code: Code:'5928 / 2964 = 0002
' - + +
'1181 + 0300 = 1481
'4747 - 3264 = 1483
''dfbf / bgak = b
'' - + +
''hhfh + ecc = hkfh
''kjkj - ebak = hkfe
for a = 0 to 9
for b = 1 to 3 '0 to 9
for c = 0 to 0 '0 to 9
for d = 0 to 9
'for e = 2 to 4 '0 to 9
e=b+1
for f = 0 to 9
for g = 0 to 9
for h = 1 to 1 '0 to 9
for j = 0 to 9
for k = 0 to 9
scan
q$ = str$( a );b;c;d;e;f;g;h;j;k
if ispermutation( q$ ) then
print q$
a$ = str4$( d , g , b , f )
b$ = str4$( b , g , a , k )
c$ = str4$( 0 , 0 , 0 , b )
d$ = str4$( h , h , f , h )
e$ = str4$( 0 , e , c , c )
f$ = str4$( h , k , f , h )
g$ = str4$( k , j , k , j )
h$ = str4$( e , b , a , k )
j$ = str4$( h , k , f , e )
if val( a$ ) / val( b$ ) = val( c$ ) then
if val( d$ ) + val( e$ ) = val( f$ ) then
if val( g$ ) - val( h$ ) = val( j$ ) then
if val( a$ ) - val( d$ ) = val( g$ ) then
if val( b$ ) + val( e$ ) = val( h$ ) then
if val( c$ ) + val( f$ ) = val( j$ ) then
print a$ + " / " + b$ + " = " + c$
print " - + +"
print d$ + " + " + e$ + " = " + f$
print g$ + " - " + h$ + " = " + j$
end
end if
end if
end if
end if
end if
end if
end if
next k
next j
next h
next g
next f
'next e
next d
next c
next b
next a
end
function str4$( x , y , z , w )
str4$ = str$( x ) ; y ; z ; w
end function
function ispermutation( q$ )
uit = 1
for i = 0 to 9
if instr( q$ , str$( i ) ) = 0 then
uit = 0
end if
next i
ispermutation = uit
end function
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: calculation puzzle
« Reply #11 on: Dec 29th, 2015, 5:34pm » |
|
on Dec 29th, 2015, 1:29pm, pnlawrence wrote:How can someone be banned from a public forum just to view a puzzle? Amazing! |
|
Forum administrators have a number of tools available to control access, one being that certain sections of the forum can be (and indeed in the case of the LB forum are) configured to be visible only to 'members' but not to 'guests'. They may include 'sensitive' sections such as bug reports which they don't want passers-by to see.
As a non-member (and not being allowed to be a member) it's not surprising that I cannot view the 'sensitive' areas, but one might like to think that I would be allowed to see the same sections of the forum that 'guests' can, which I presume to include the 'puzzle' thread that Anatoly linked to. But that is not enough for the LB forum administrators; they don't want me to be able to see anything!
To achieve that I am banned by IP address, which means that any attempt to view the LB forum, even as a guest, results in the error message I quoted. Since my internet connection uses a static IP address it is very difficult for me to bypass that block, other than by connecting from an internet café, WiFi hotspot or 3G/4G cellular data connection (which we don't currently have where I live).
To answer Anatoly I have tried connecting via a proxy server (anonymising service), and can sometimes succeed using that method, but if my presence is spotted the IP address of the proxy server gets banned as well - blocking access not only to me but to anybody else who tries to connect via that service! So doing so is not really worth the effort, and is antisocial.
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline
Gender:
Posts: 157
|
|
Re: calculation puzzle
« Reply #12 on: Dec 30th, 2015, 1:49pm » |
|
Anatoly, you are a moderator on the LB forum. Why don't you get this resolved.
Clearly there is a vendetta against a major contributor to the BASIC community.
It is terribly embarrassing.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: calculation puzzle
« Reply #13 on: Dec 30th, 2015, 2:35pm » |
|
on Dec 30th, 2015, 1:49pm, pnlawrence wrote:Anatoly, you are a moderator on the LB forum. Why don't you get this resolved. |
|
As I have said before, I was told that the moderators had voted to lift the restrictions on my membership, and to allow discussion of LBB there, but that the decision had been vetoed by Carl. If that's the case, Anatoly can't do anything about it.
Precisely why Carl was allowed a veto is another matter. As far as I am aware he has no formal administrative role at the LB forum (it's supposed to be a 'community' forum, unlike the LB Yahoo Group which is Carl's official support outlet to do with whatever he likes).
Richard.
|
|
Logged
|
|
|
|
AAW
New Member
member is offline
Posts: 22
|
|
Re: calculation puzzle
« Reply #14 on: Dec 30th, 2015, 6:18pm » |
|
on Dec 30th, 2015, 1:49pm, pnlawrence wrote:Anatoly, you are a moderator on the LB forum. Why don't you get this resolved.
Clearly there is a vendetta against a major contributor to the BASIC community.
It is terribly embarrassing. |
|
Richard was placed on moderation at the official Yahoo Group many years ago.
He was first banned at the Community Forum in May, 2011. These events happened long before he ever conceived of LBB.
on Dec 29th, 2015, 5:34pm, Richard Russell wrote: But that is not enough for the LB forum administrators; they don't want me to be able to see anything!
To achieve that I am banned by IP address,
Richard. |
|
That is not correct. The cause/effect are reversed. You are banned by IP, therefore you cannot see anything.
on Dec 30th, 2015, 2:35pm, Richard Russell wrote:Precisely why Carl was allowed a veto is another matter. As far as I am aware he has no formal administrative role at the LB forum
Richard. |
|
As I have said before. Carl has been co-owner of the Community forum since Day 1. Since Day 1, he has had complete access to the main admin account. The forum was conceived to be run by Carl and the community. Carl does perform functions as the main admin/owner.
It is a pity that things have not worked out. Carl and Richard have different points of view and different ways of expressing them.
The best thing for the community is to simply write and discuss code, coding techniques, theories, etc. Grow as programmers. Enjoy what you do. Use the tools that suit you best. Acrimony is not productive.
|
|
Logged
|
|
|
|
|