LB Booster
« calculation puzzle »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:46am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: calculation puzzle  (Read 3856 times)
bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx 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 » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: calculation puzzle
« Reply #1 on: Dec 14th, 2015, 8:58pm »

That would be more informative if the actual "puzzle" was included.
User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: calculation puzzle
« Reply #2 on: Dec 15th, 2015, 08:56am »


@ pnlawrence :
- see begin of code in REM
User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx 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
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx 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...
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx 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
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: calculation puzzle
« Reply #7 on: Dec 29th, 2015, 10:34am »

on Dec 29th, 2015, 07:53am, tsh73 wrote:
More on this puzzle on LB forum: calculation puzzle

Not for some of us! Clicking on that link simply displays the message "Sorry, but you have been banned from this forum".

Richard.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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!
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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:
hhfh +  ecc = hkfh 
that makes 'c' equal to 0
Code:
bgak 
  +
  ecc 
  =
ebak
 
that makes e=b+1
Code:
    b
  +
hkfh
  =
hkfe
 
that says e=b+h, hense h = 1
Also,
Code:
dfbf / bgak =    b  
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 
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: calculation puzzle
« Reply #10 on: Dec 29th, 2015, 4:15pm »

direct link to Rosetta code
http://rosettacode.org/wiki/Permutations#Liberty_BASIC

Last thing.
Internet is big. Sometimes, strange things happen.
Then I try to visit http://lbbooster.com/, I always get an error "Could not connect to remote server".
But that not prevents me from updating LBB - there are tools.
I use http://anonymouse.org/

Just my 0.02$
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

AAW
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx 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.
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls