Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic
Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
02-27-2026, 07:45 AM (This post was last modified: 02-27-2026, 03:58 PM by DANILIN.)
my variant can distort your variants
Code: (Select All)
Dim s As Long: t = Timer
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 i = 0 To 9
If a * b - c <> 4 Then 5
If d + e + f <> 8 Then 5
If g / h + i <> 8 Then 5
If a / d + g <> 9 Then 5
If b + e + h <> 8 Then 5
If c + f - i <> 6 Then 5
Print a, b, c
Print d, e, f
Print g, h, i: Print: Print
5 s = s + 1: Next: Next: Next: Next: Next
Next: Next: Next: Next: Print s / 10 ^ 6; " mln", Timer - t
End
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic
Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
02-27-2026, 11:09 AM (This post was last modified: 02-27-2026, 11:18 AM by bplus.)
OHHHHHHHHHHHHHHHH ! I thought the 9 digits had to be a unique permutation of digits 1 to 9. Well there aren't any of those BUT!
There are 65 sets that match e(2) with e(3) and with e(5) (Danilins = 8 equations) some get pretty close to single digit answers to all 6 equations.
There are 5 of the closest = 9 not 8 in e2, e3 and e5.
How I found these as alternate to Danilin's problem:
First I created a file of the permutations of digits 1 to 9:
Code: (Select All)
_Title "Recursive 9 Permutations of symbols to RA" 'mod B+ 2026-02-27
'ordered permutations.bas for SmallBASIC 0.12.6 [B+=MGA] 2016-07-21
'translated from JB v1.01 [B+=MGA] 2016-07-21
'recursive ordered permutations (non repeating)
'if 1st element < 2nd element < 3rd element... then list acsends
'if reverse case then list decsends
' 2026-02-27 this mod
Dim Shared ls, index
Dim Shared record As String * 9
s$ = "987654321"
ls = Len(s$)
index = 0
Dim Shared c$(ls) 'this holds each letter or digit or symbol
Open "9 permutations.RA" For Random As #1 Len = 9
perm s$ '<<<<<<<<<<<<< if s$ is ordered then the permutations will be so also!!!
Sub perm (r$)
'local lr, i, r1
If Len(r$) = 0 Then
index = index + 1
b$ = ""
For i = 1 To ls
b$ = b$ + c$(i)
Next
record = b$
Put #1, index, record
Else
lr = Len(r$)
For i = 1 To lr
c$(ls - lr + 1) = Mid$(r$, i, 1)
If i < Len(r$) And i > 1 Then
r1$ = Mid$(r$, 1, i - 1) + Mid$(r$, i + 1)
'ELSEIF i = 1 AND i = lr THEN
'r1$ = ""
ElseIf i = 1 Then
r1$ = Mid$(r$, i + 1)
Else
r1$ = Mid$(r$, 1, i - 1)
End If
perm r1$
Next
End If
End Sub
Then I checked all permutations with this code:
Code: (Select All)
_Title "Test Danlin's matrix with 9 permutations" 'b+ 2026-02-26
' 2026-02-27 rewrite for RA
Dim record As String * 9
Open "9 permutations.RA" For Random As #1 Len = 9
Dim c(1 To 9) As Integer, index As Long
While index < 362880
index = index + 1
Get #1, index, record
Print index; ":"; record
For i = 1 To 9
c(i) = Val(Mid$(record, i, 1))
Next
If c(1) * c(2) - c(3) = 4 Then
Print "Check First equation: "; record
'Sleep
If c(4) + c(5) + c(6) = 8 Then
Print "Check 2nd equation: "; record
'Sleep
If c(7) / c(8) + c(9) = 8 Then
Print "Check 3rd equation: "; record
Sleep
If c(1) / c(4) + c(7) = 9 Then
If c(2) + c(5) + c(8) = 8 Then
If c(3) + c(6) - c(9) = 6 Then
Print "!!!!!!!!!!!!!!!!!!!!Solution! "; c(1), c(2), c(3)
Print "!!!!!!!!!!!!!!!!!!!!Solution! "; c(4), c(5), c(6)
Print "!!!!!!!!!!!!!!!!!!!!Solution! "; c(7), c(8), c(9)
Sleep
End
End If
End If
End If
End If
End If
End If
Wend
Nope! Nothing stopped and met Danilins 4, 8, 8, 9, 8, 6 answers so there is NOT 9 unique digits that solve Danilin's equations.
So how close can we get?
First I tried to just match e2, e3, and e5 and there I found 65 solutions!
So what combinations get us closest to e2=e3=e5 = 8?
How about e2 = e3 = e5 = 9 !
_Title "Alternate Danlin problem" 'b+ 2026-02-26
' 2026-02-27 mod for RA file
Dim record As String * 9
Dim c(1 To 9) As Integer
Dim eq(1 To 6) As Integer
Open "9 permutations.RA" For Random As #1 Len = 9
Open "Match e2 with e3 and e5 for unique 9 digitsets.dat" For Output As #2
index = 0
tryAgain:
index = index + 1
If index > 362880 Then Print: Print "Through Whole File All done!": End
Get #1, index, record
'Print index, record
For i = 1 To 9
c(i) = Val(Mid$(record, i, 1))
Next
If c(7) / c(8) = Int(c(7) / c(8)) Then
If c(1) / c(4) = Int(c(1) \ c(4)) Then
'Print "index, record is"; index, record
e(1) = c(1) * c(2) - c(3) '4
e(2) = c(4) + c(5) + c(6) '8 match e(2)
e(3) = c(7) / c(8) + c(9) '8 match with e(3)
e(4) = c(1) / c(4) + c(7) '9
e(5) = c(2) + c(5) + c(8) '8 match and with e(5)
e(6) = c(3) + c(6) - c(9) '6
If e(2) = 9 _AndAlso e(3) = 9 _AndAlso e(5) = 9 Then
'If e(2) = e(5) Then ' the middle one across = middle one down
' If 2 * e(1) = e(2) Then
' If e(4) = 1.1 / 8 * e(2) Then
' If e(6) = 3 / 4 * e(2) Then
count = count + 1
Print #2, "index, record is"; index, record, "e()'s match #"; _Trim$(Str$(count))
Print #2, c(1); " *"; c(2); " -"; c(3); " ="; c(1) * c(2) - c(3)
Print #2, c(4); " +"; c(5); " +"; c(6); " ="; c(4) + c(5) + c(6)
Print #2, c(7); " /"; c(8); " +"; c(9); " ="; c(7) / c(8) + c(9)
Print #2, c(1); " /"; c(4); " +"; c(7); " ="; c(1) / c(4) + c(7)
Print #2, c(2); " +"; c(5); " +"; c(8); " ="; c(2) + c(5) + c(8)
Print #2, c(3); " +"; c(6); " -"; c(9); " ="; c(3) + c(6) - c(9)
Print #2, ""
'Sleep
GoTo tryAgain:
'Else
' GoTo tryAgain:
'End If
'Else
' GoTo tryAgain:
'End If
' Else
' GoTo tryAgain:
' End If
' Else
' GoTo tryAgain:
' End If
Else
GoTo tryAgain:
End If
Else
GoTo tryAgain:
End If
Else
GoTo tryAgain:
End If
02-27-2026, 03:55 PM (This post was last modified: 02-27-2026, 03:56 PM by DANILIN.)
Numerals exactly all different are not required
and repetitions possible otherwise squares
were signed as in subject "rebus of letters"
though on greater number possible decision unique
or negative to use but I did not check
New program in source message for qbjs without goto
working slowly in 2 times
Here momentary algorithm with goto
Code: (Select All)
Dim s As Long: t = Timer
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 i = 0 To 9
s = s + 1
If a * b - c <> 4 Then 7
If d + e + f <> 8 Then 4
If g / h + i <> 8 Then 1
If a / d + g <> 9 Then 3
If b + e + h <> 8 Then 2
If c + f - i <> 6 Then 1
Print a, b, c
Print d, e, f
Print g, h, i: Print: Print
1 Next i
2 Next h
3 Next g
4 Next f
5 Next e
6 Next d
7 Next c
8 Next b
9 Next a
Print s / 10 ^ 6; " mln", Timer - t
End
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic
Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
I don't need half a dozen seconds to solve this. I can solve it in 0.01 second, and without any use of GOTO or _CONTINUE! Just simple for loops and elimination logic which cuts down run time by a magnitude of 1000s.
It's simple. It's efficient. It's easy to understand and follow. What's not to love about it?
02-27-2026, 04:58 PM (This post was last modified: 02-27-2026, 05:04 PM by SMcNeill.)
And here I took a few moments to apply the most basic of logic to this to eliminate multiple instances of recursion:
Code: (Select All)
Screen_NewImage(1024, 720, 32) Dim s AsLong: t = Timer(0.001) For a = 1To9' a * b has to be > 4 + c, so neither can be negative values For b = 1To9 If a * b >= 4_AndAlso a * b <= 13Then' a*b -c = 4, so a * b has to be between 4 and 13 since c is from 0 to 9 For c = 0To9 If a * b - c = 4Then For d = 0To8: For e = 0To8 - d 'd + e + f = 8, so d can't be > 8. e can't be greater than 8 -d If d + e <= 8Then' and if d + e are 8 or less, then f has to be the remainer of that formula to make 8
f = 8 - d - e For g = 0To9: For h = 0To9: For i = 0To9 If g / h + i = 8_AndAlso a / d + g = 9_AndAlso b + e + h = 8_AndAlso c + f - i = 6Then Print a, b, c Print d, e, f Print g, h, i: Print: Print
s = s + 1 End If Next i, h, g End If Next e, d End If Next c End If Next b, a Print Using"###,### solutions, in #.#### seconds"; s, Timer(0.001) - t
It now gives the same answers and runs in less than 0.005 seconds on my laptop. That's well over 1000x improvement over the original. Instead of trying to work out any more math logic like this, I'll just call this fast enough and go on with things.
Honestly though, this is getting a little too single-case specific to be all that useful for anything else except this one instance. The previous code is much more flexible as one can just basically substitute any formulas into it as they wish and get the answer in no time at all. I was just playing around with this to kind of showcase how one can often completely skip a ton of work and processing just by applying basic logic to their own thinking before they ever have the computer take over and do the crunching and whatnot for them.
I mean, let's look at two very simple changes here -- both A and B start with a value of 1, as we know A * B = 4 + C. This makes A and B both *have* to be non-zero, as C can't be negative, and if either is 0 then it's going to be 0 = 4 + a non-negative number, which is impossible.
So this one change elimited running A at 0, which then runs B,C,D,E,F,G,H,I each up to 10 times... which is up to 100000000 loops eliminated. B runs the same logic, but to a power of 10 less than A as it's in inner loop and runs C, D, E, F, G, H, I...
So 110,000,000 loops eliminated with the very barest of logic applied to the loop here.
F doesn't even need to be a loop as it's a set value dependent upon D and E. F = 8 - D - E, and it has to non-negative. So that's a whole inner loop gone with just basic logic applied here.
Folks are always looking for a way to make programs faster. Often, the best way to speed up the execution of a program is just like this -- apply a little logic and narrow the scope to easily adjusted bounds and reduce the runtime as much as possible.
02-27-2026, 08:11 PM (This post was last modified: 03-01-2026, 12:10 PM by DANILIN.)
Exclude h=0 and d=0 ?
Possible negative numerals from -9 to 9
and 21 decisions
Code: (Select All)
Dim s As Long: t = Timer ' ussr_puzzle_minus.bas
Open "ussr_puzzle_minus.txt" For Output As #1
For a = -9 To 9: For b = -9 To 9: For c = -9 To 9
For d = -9 To 9: For e = -9 To 9: For f = -9 To 9
For g = -9 To 9: For h = -9 To 9: For i = -9 To 9
s = s + 1
If a * b - c <> 4 Then 7
If d + e + f <> 8 Then 4
If g / h + i <> 8 Then 1
If a / d + g <> 9 Then 3
If b + e + h <> 8 Then 2
If c + f - i <> 6 Then 1
x = x + 1: Print "#"; x
Print a, b, c
Print d, e, f
Print g, h, i: Print: Print
Print #1, "#"; x
Print #1, a, b, c
Print #1, d, e, f
Print #1, g, h, i: Print #1,
1 Next i
2 Next h
3 Next g
4 Next f
5 Next e
6 Next d
7 Next c
8 Next b
9 Next a
Print s / 10 ^ 6; " mln", Timer - t
End
Thank All for decisions
Conditions after first cycles
d>=1 & h>=1
0,0094 mln 2,7E-03 sec
Code: (Select All)
Dim s As Long: t = Timer(0.001) ' ussr_puzzle_subzero.bas
For a = 0 To 9: For b = 0 To 9: For c = 0 To 9
If a * b - c <> 4 Then 7
For d = 1 To 9: For e = 0 To 9: For f = 0 To 9
If d + e + f <> 8 Then 4
For g = 0 To 9: For h = 1 To 9: For i = 0 To 9
If g / h + i <> 8 Then 1
s = s + 1
If a / d + g <> 9 Then 3
If b + e + h <> 8 Then 2
If c + f - i <> 6 Then 1
Print a, b, c
Print d, e, f
Print g, h, i: Print
1 Next i
2 Next h
3 Next g
4 Next f
5 Next e
6 Next d
7 Next c
8 Next b
9 Next a
Print s / 10 ^ 6; " mln", Timer(0.001) - t
End
Nobel Prize will not receive itself
Nobelevskaya premiya sama sebya ne poluchit
Нобелевская премия сама себя не получит
Le prix Nobel ne se recevra pas
Nobelpreis wird sich nicht erhalten
Il Premio Nobel non ricevera se stesso
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic
Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
02-28-2026, 04:50 PM (This post was last modified: 02-28-2026, 05:04 PM by bplus.)
Ah-ha! Allowing for integer division instead of floating division I can:
Find a unique set of 9 digits that will produce = 8 in equations 2, 3 and 5
PLUS get the other equations all below 10 ie single digits!!!
There are 3 solutions like this (like in Danilin's problem) AND 1 is darn close to:
e(1) = 4
e(2) = 8
e(3) = 8
e(4) = 9
e(5) = 8
e(6) = 6