View Full Version : some numerical recreations
suppose this equation:
A * const = R .............."A, const, R are integer numbers"
and over a range for A up to 3000 how many times the following equation will be true:
(A reversed) * const = (R reversed)
for example for the const = 53, it will happened 17 times within range 3000 for A
example:
884 * 53 = 46852
488 * 53 = 25864
so if it happened that your birthday or lotto number or a book you have borrowed have a bibliography number like 884-53-46852 this is may be your luck day.
note that const = 11 have big chances.
Uses "console"
Dim tot, i, n , arr(200) As Long
Dim num1, num2 As Quad
Dim Num, RNum As String
For n = 1 To 200 'the numbers we want to check
For i=1 To 3000
Num = Str$(i)
RNum = StrReverse$(Num)
num1 = Val(Num) * n
num2 = Val(RNum) * n
If Val(Str$(num1))= Val(StrReverse$(Str$(num2))) Then
tot=tot + 1
'If n=53 then
'PrintL num
'End If
End If
Next i
arr(n)=tot : tot=0
Next n
For i=1 To 200
PrintL i,arr(i)
Next i
WaitKey
danbaron
23-05-2011, 07:42
You have,
a * b = c.
How about if you try to find a, b, and c, such that,
(a reversed) * (b reversed) = (c reversed)?
Here are some easy examples.
0 * 0 = 0
0 * 1 = 0
.
.
0 * 9 = 0
1 * 1 = 1
1 * 2 = 2
.
.
1 * 9 = 9
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
3 * 3 = 9
11 * 11 = 121
11 * 121 = 1331
11 * 12321 = 135531
11 * 1234321 = 13577531
.
.
121 * 121 = 14641
111 * 12321 = 1367631
yes i have thought of that but after i have posted.
but also keeping the constant number can be used as a fantasia about that specific number like that in the numerology
danbaron
24-05-2011, 08:35
I always learn a lot about the language when I do these puzzles.
:idea:
' code ----------------------------------------------------------------------------------------------------
#lang racket
(define num-list (list))
(define (reverse-num n)
(define s (number->string n))
(define l (string->list s))
(set! l (reverse l))
(set! s (list->string l))
(string->number s))
(define (make-num-list const n)
(set! num-list null)
(define count-list (build-list n (lambda (x) (+ x 1))))
(define (loop l)
(cond ((empty? l) num-list)
(else
(define a (car l))
(define b (* a const))
(define c (reverse-num a))
(define d (reverse-num b))
(when (= (* c const) d) (set! num-list (append num-list (list a))))
(loop (cdr l)))))
(loop count-list))
' REPL interactions ---------------------------------------------------------------------------------------
Welcome to DrRacket, version 5.1 [3m].
Language: racket.
> (make-num-list 53 3000)
'(4 8 40 44 48 80 84 88 400 404 408 440 444 448 480 484 488 800 804 808 840 844 848 880 884)
> (length num-list)
25
> (make-num-list 173 1000000)
'(181 1810 1991 18100 18281 19910 181000 181181 182810 182991 199100 199281)
> (* 19910 173)
3444430
> (* 1991 173)
344443
> (* 199281 173)
34475613
> (* 182991 173)
31657443
>
danbaron
24-05-2011, 20:39
' REPL interactions ---------------------------------------------------------------------------------------
Welcome to DrRacket, version 5.1 [3m].
Language: racket.
> (make-num-list 757 10000000)
'(1 10 100 1000 1001 10000 10001 10010 100000 100001 100010 100100 1000000 1000001 1000010 1000100 1001000 1001001 8421248 10000000)
> (* 8421248 757)
6374884736
> (make-num-list 677 10000000)
'(11 110 1100 11000 110000 110011 1100000 1100011 1100110)
> (* 1100011 677)
744707447
> (make-num-list 223 10000000)
'(77 770 7700 77000 77077 770000 770077 770770 7700000 7700077 7700770 7707700)
> (* 7700077 223)
1717117171
> (make-num-list 397 10000000)
'(189981 1899810 1899981)
> (* 1899981 397)
754292457
>
John Spikowski
26-05-2011, 08:58
I'm in the process of creating a GNU Scientific Library (GSL) (http://www.gnu.org/software/gsl/) extension module for ScriptBasic. The combination GSL example would be a interesting mini-code challenge to do the same in Basic.
#include <stdio.h>
#include <gsl/gsl_combination.h>
int
main (void)
{
gsl_combination * c;
size_t i;
printf ("All subsets of {0,1,2,3} by size:\n") ;
for (i = 0; i <= 4; i++)
{
c = gsl_combination_calloc (4, i);
do
{
printf ("{");
gsl_combination_fprintf (stdout, c, " %u");
printf (" }\n");
}
while (gsl_combination_next (c) == GSL_SUCCESS);
gsl_combination_free (c);
}
return 0;
}
jrs@laptop:~/C/gsl/doc/examples$ ./combo
All subsets of {0,1,2,3} by size:
{ }
{ 0 }
{ 1 }
{ 2 }
{ 3 }
{ 0 1 }
{ 0 2 }
{ 0 3 }
{ 1 2 }
{ 1 3 }
{ 2 3 }
{ 0 1 2 }
{ 0 1 3 }
{ 0 2 3 }
{ 1 2 3 }
{ 0 1 2 3 }
jrs@laptop:~/C/gsl/doc/examples$
This is the beginning of my GSL extension module. I'm developing it on Ubuntu 64 but it should compile to a DLL for Windows as well.
interface.c
/*
GNU Scientific Library
Based on GSL 1.15
Interface By: John Spikowski
*/
#include <stdio.h>
#include "../../basext.h"
#include <gsl/gsl_sf_bessel.h>
besVERSION_NEGOTIATE
return (int)INTERFACE_VERSION;
besEND
besSUB_START
besEND
besSUB_FINISH
besEND
besFUNCTION(sf_bessel_J0)
VARIABLE Argument;
Argument = besARGUMENT(1);
besDEREFERENCE(Argument);
besRETURN_DOUBLE(gsl_sf_bessel_J0 (DOUBLEVALUE(Argument)));
besEND
bj0.sb
DECLARE SUB besselJ0 ALIAS "sf_bessel_J0" LIB "gsl"
PRINT FORMAT("J0(%g) = %.48g", 5, besselJ0(5.0)),"\n"
jrs@laptop:~/sb/test/gsl$ scriba bj0.sb
J0(5) = -0.177596771314338264247112419980112463235855102539
jrs@laptop:~/sb/test/gsl$
http://mathworld.wolfram.com/images/eps-gif/BesselJ_800.gif
The Bessel functions of the first kind J_n(x) are defined as the solutions to the Bessel differential equation