Number Trick

General FreeBASIC programming questions.
deltarho[1859]
Posts: 2846
Joined: Jan 02, 2017 0:34
Location: UK

Re: Number Trick

Postby deltarho[1859] » Aug 23, 2020 17:37

albert wrote:The 4 output digits always add up to 18...

Not all the time - keep adding, and we always get 9; except when we get 0000

3503 -
3053
------
0450 => 9

6111 -
1116
------
4995 => 27 => 9

Of course, 18 => 9

Use Randomize.
angros47
Posts: 1821
Joined: Jun 21, 2005 19:04

Re: Number Trick

Postby angros47 » Aug 23, 2020 18:31

Looks like you discovered the casting out nines

https://en.wikipedia.org/wiki/Casting_out_nines
albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Number Trick

Postby albert » Aug 23, 2020 18:43

Yeah, i ran it through some tests...
And 4 digit outputs mostly add up to 18.. But you sometimes get a 9 or 27.

outputs = 9 or 1+8=9 or 2+7=9

Code: Select all


screen 19

dim as ubyte total

do
   
    dim as string n1 = right( "0000" + str( int( rnd * 10000 ) ) , 4 )
    dim as string n2 = mid( n1 , 4 , 1 ) + mid( n1 , 3 , 1 ) + mid( n1 , 2 , 1 ) + mid( n1 , 1 , 1 )
   
    if n1 > n2 then swap n1 , n2
   
    dim as string n3 = right( "0000" + str( val( n2 ) - val( n1 ) ) , 4 )
   
    total  = val( mid( n3 , 1 , 1 ) )
    total+= val( mid( n3 , 2 , 1 ) )
    total+= val( mid( n3 , 3 , 1 ) )
    total+= val( mid( n3 , 4 , 1 ) )
   
   
    print
    print n2
    print n1
    print n3 , total
   
    sleep
   
loop until inkey = chr( 27 )

sleep
end



With 5 digits , all the outputs total ( 18 , 27 or 36 ) which all add up to 9
deltarho[1859]
Posts: 2846
Joined: Jan 02, 2017 0:34
Location: UK

Re: Number Trick

Postby deltarho[1859] » Aug 23, 2020 19:08

angros47 wrote:Looks like you discovered the casting out nines

We might have gone a bit further with casting out the n's where n = 1, 2, 3, 4, 5, 6, 7, 8, 9 ........

With octal, we would be casting out the 7's. BTW, keep adding with octal, in octal, and we get 7.

That should work with everything so far - keep adding and get to our 'magic' number.

I cannot believe that I have got to my age without knowing this. Mind you I was playing around with the Trachtenberg system in my earl twenties and I have only met a few people who have heard of it.
albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Number Trick

Postby albert » Aug 23, 2020 19:37

Another number trick i just invented..

I found a way to do a 1 digit , mul * 9 , using subtraction..

You might be able to change the 9's to any number you want to mul by???

Code: Select all


screen 19

do
   
    dim as ubyte v1 = int( rnd * 9 ) + 1
    dim as ubyte v2 = 9
   
    dim as ubyte v3 = ( 99 - v2 - v1 ) - ( ( v2 - v1 ) * 10 )
   
    print
    print v1
    print v2
    print v3
   
    sleep
   
loop until inkey = chr( 27 )

sleep
end

deltarho[1859]
Posts: 2846
Joined: Jan 02, 2017 0:34
Location: UK

Re: Number Trick

Postby deltarho[1859] » Aug 23, 2020 21:02

albert wrote:Another number trick i just invented..

Jakow Trachtenberg, see my last post, beat you to it. He has short ways to multiply by 2, 3, ..., 12.

The one that I got quite handy with, in my early twenties, was in multiplying two large integers. At a party I would ask for two integers, say seven digits each, and get folk to see how long it would take them to work out the multiplication. Whilst they were doing that I would just write the answer down and say "Done". A few times somebody would look up and say "You are joking?". After a while they would check their answers with mine and ask "How on earth did you do that?". I never told them and simply said "I am not just a pretty face" and left it at that. Image

Now, we do need a reasonable memory but nothing special. I may struggle now but in my early twenties I was pretty fast.
albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Number Trick

Postby albert » Aug 23, 2020 22:15

===================
Multiply By Subtraction..
===================

I got it doing double digits...01 to 99

Now ; I have to replace the "b" subtraction loop , to another v3 type formula.. Any help would be appreciated!!

Code: Select all


screen 19

do
   
    dim as longint v1 = int( rnd * 99 ) + 1
   
    dim as longint v2 = int( rnd * 99 ) + 1
   
    dim as longint v3 = ( ( ( v2 * 100 ) - v1 ) - ( ( v2 - v1 ) * 100 ) )
   
    for b as longint = 99 to v2 + 1 step - 1
        v3-= v1
    next
   
    print
    print v1
    print v2
    print " = " ; v1 * v2
    print " = " ; v3
   
    sleep
   
loop until inkey = chr( 27 )

sleep
end

albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Number Trick

Postby albert » Aug 24, 2020 0:50

I got it multiplying by ( RND * 1e9 ) x 999

The v3 formula requires 2 , 9's , for each 9 , in the v2 var..

So if you want to mul by 9999 then the v3 formula needs 8 , 9's
So if you want to mul by 99 then the v3 formula needs 4 , 9's

The 10's multiplier at the end is v2 + 1

Code: Select all


screen 19

do
   
    dim as longint v1 = int( rnd * 1e9 ) + 1
   
    dim as longint v2 = 999
   
    dim as longint v3 = ( 999999 - v2 - v1 ) - ( ( v2 - v1 ) * 1000 )
   
    print
    print v1
    print v2
    print " = " ; v1 * v2
    print " = " ; v3 ; " diff = " ; v3 - ( v1 * v2 )
   
    sleep
   
loop until inkey = chr( 27 )

sleep
end

I'll get it working with other numbers.. It might take me a few weeks and many posts..



albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Number Trick

Postby albert » Aug 24, 2020 21:45

A little pattern i found while playing with numbers..

It might be a fast way to square a number with subtraction???
I'll play with multi-digits , to see if it holds true , for all number lengths..

Code: Select all


90   80  70  60  50   40  30  20  10  00  <--- ( num * 10 ) - num
09   08  07  06  05   04  03  02  01  00
----  ---- ----  ----  ----  ---- ----  ---- ----  ----
81  72  63   54  45   36  27  18    9    0 <--- subtraction result
---- ---- ----  ----  ----  ----  ----  ----  ---  ----
81  64  49  36   25  16    9     4    1    0 <--- real mul answer
---- ---- ----  ----  ----  ----  ----  ---- ---- ----
0      8  14  18    20  20  18  14   8    0  <--- mul answer off by:

9 & 0 = 0
8 & 1 = 8
7 & 2 = 14
6 & 3 = 18
5 & 4 = 20

Stonemonkey
Posts: 649
Joined: Jun 09, 2005 0:08

Re: Number Trick

Postby Stonemonkey » Aug 24, 2020 22:39

10x-x=9x

x(9-x)=9x-x²
So
x²=9x-x(9-x)
x²=9x-9x+x²
x²=x²
Last edited by Stonemonkey on Aug 24, 2020 23:01, edited 2 times in total.
deltarho[1859]
Posts: 2846
Joined: Jan 02, 2017 0:34
Location: UK

Re: Number Trick

Postby deltarho[1859] » Aug 24, 2020 22:46

@albert

Code: Select all

0   8   14   18   20   20   18   14   8   0
  8   6    4    2    0    2    4    6   8
  4   3    2    1    0    1    2    3   4

You are now getting into things like Fibonacci ( Born c. 1170) numbers and Pascal's ( Born 19 June 1623) Triangle. Be careful in reckoning you may have discovered something with numbers - people have been kicking around with numbers for a long time.

@Stonemonkey Image
angros47
Posts: 1821
Joined: Jun 21, 2005 19:04

Re: Number Trick

Postby angros47 » Aug 24, 2020 23:20

Try a sum of consecutive odd numbers:
1+3+5+7+9+11... and so on

The result will be:
1+3=4
...+5=9
...+7=16
...+9=25
..+11=36

Basically, a sequence of square numbers.

To figure why it happens, imagine a square made of tiles: the side is n tiles long, and its area is n^2, of course. By increasing n of one, I should add n tiles vertically, n tiles horizontally, and then one more tile in the corner: so 2*n+1 tiles is the difference between one square number (n^2) and the next one. Since n is integer, 2*n is always even, and so 2*n+1 is always odd.
albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Four Step

Postby albert » Aug 28, 2020 2:23

I came up with a way to multiply with 2 subtractions and two additions. Four Steps...

92 * 27 = 2484

step 1
subtract
2727 <-- put the smaller number beside it's self
-0902
-------
1825

step2
subratct
920
-270
----
650

step3
add
1825
+650
------
2475

step4
add or subtract , i haven't figured it out yet... sometimes you need to add and sometimes you need to subtract??
2475
+9 ( 7+2 )
-------
2484 <-- correct answer

I can imagine doing million digit muls in "Four Steps"...
Playing with different 2 digit vals , the 4'th step changes with different numbers.. ( i haven't figured it out yet.. )
Sometimes you need to subtract instead of adding..
albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Four Step

Postby albert » Aug 28, 2020 16:46

90 x 11 = 990

step 1
subtract
1111 <- put smaller number beside it's self
-900
------
211

step 2
subtract
900
-110
------
790

step 3
add
790
+211
-------
1001

step 4
add or subtract , if the bigger number ends in 0 , then you subtract the smaller number..
1001
-11
-------
990 <--- correct answer
albert
Posts: 5951
Joined: Sep 28, 2006 2:41
Location: California, USA

Four Step

Postby albert » Aug 28, 2020 17:47

It should also work with 2 , 4 digit numbers...2 , 8 digit numbers... etc...

I'm not sure about odds , if both numbers aren't the same length??

If one of the numbers ends in a 0 , then you have to subtract a value.. Else you have to add a value..

if the bigger number ends in 0 , then you subtract the smaller number..
If the smaller number ends in 0 , then you have to subtract a value , not sure how to derive the value.
If neither number ends in 0 , then you have to add a value , not sure how to derive the added value.

Return to “General”

Who is online

Users browsing this forum: No registered users and 10 guests