Author Topic: 666, mathematics and Satan  (Read 344 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
666, mathematics and Satan
« on: June 12, 2022, 07:28:47 AM »
Code: [Select]
include \Masm32\MasmBasic\Res\JBasic.inc ; ## builds in 32- or 64-bit mode with UAsm, ML, AsmC ##
Init ; OPT_64 1
  Cls
  PrintLine Chr$("This devilish program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
  PrintLine "It shows pairs of numbers that match the formula m*n=666*(m+n)"
outer: inc rsi
xor rdi, rdi
inner: inc rdi
lea rax, [rsi+rdi]
imul rbx, rax, 666 ; (m+n)*666
mov rax, rdi
mul rsi ; m*n
cmp rax, rbx
jne @F
Print Str$("m*n: %i*%i\n", rsi, rdi)
@@: cmp rdi, 66666
jb inner
cmp rsi, 66666
  jb outer
  MsgBox 0, "Incredible, isn't it?", "Hi", MB_OK 
EndOfCode

Code: [Select]
This devilish program was assembled with UAsm64 in 64-bit format.
It shows pairs of numbers that match the formula m*n=666*(m+n)
m*n: 675*49950
m*n: 678*37629
m*n: 684*25308
m*n: 693*17094
m*n: 702*12987
m*n: 703*12654
m*n: 720*8880
m*n: 740*6660
m*n: 747*6142
m*n: 774*4773
m*n: 777*4662
m*n: 814*3663
m*n: 828*3404
m*n: 888*2664
m*n: 990*2035
m*n: 999*1998
m*n: 1110*1665
m*n: 1332*1332
m*n: 1665*1110
m*n: 1998*999
m*n: 2035*990
m*n: 2664*888
m*n: 3404*828
m*n: 3663*814
m*n: 4662*777
m*n: 4773*774
m*n: 6142*747
m*n: 6660*740
m*n: 8880*720
m*n: 12654*703
m*n: 12987*702
m*n: 17094*693
m*n: 25308*684
m*n: 37629*678
m*n: 49950*675

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: 666, mathematics and Satan
« Reply #1 on: June 13, 2022, 04:56:09 AM »
Hi JJ!!

Perfect! That follow the rules  :thumbsup:

How you know initial RSI value?
Equations in Assembly: SmplMath

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: 666, mathematics and Satan
« Reply #2 on: June 13, 2022, 06:07:16 AM »
How you know initial RSI value?

Good question :bgrin:

Actually, I checked at the start of the program, directly after Init:
Code: [Select]
rax     1835008
rbx     5368722336
rcx     0
rdx     0
rsi     0
rdi     0
r8      1244488
r9      1245008
r10     2183232
r11     1243938
r12     0
r13     0
r14     0
r15     0

But it's an undocumented feature, so one should indeed add a xor esi, esi :cool:

P.S. - there is an even more magic number, with 49 matching pairs:
Code: [Select]
This program was assembled with ml64 in 64-bit format.
It shows pairs of numbers that match the formula m*n=840*(m+n)
#1      m*n: 966*6440
#2      m*n: 980*5880
#3      m*n: 984*5740
#4      m*n: 987*5640
#5      m*n: 990*5544
#6      m*n: 1000*5250
#7      m*n: 1008*5040
#8      m*n: 1015*4872
#9      m*n: 1020*4760
#10     m*n: 1032*4515
#11     m*n: 1036*4440
#12     m*n: 1040*4368
#13     m*n: 1050*4200
#14     m*n: 1064*3990
#15     m*n: 1065*3976
#16     m*n: 1080*3780
#17     m*n: 1085*3720
#18     m*n: 1092*3640
#19     m*n: 1120*3360
#20     m*n: 1128*3290
#21     m*n: 1134*3240
#22     m*n: 1140*3192
#23     m*n: 1155*3080
#24     m*n: 1160*3045
#25     m*n: 1176*2940
#26     m*n: 1190*2856
#27     m*n: 1200*2800
#28     m*n: 1232*2640
#29     m*n: 1240*2604
#30     m*n: 1260*2520
#31     m*n: 1281*2440
#32     m*n: 1288*2415
#33     m*n: 1290*2408
#34     m*n: 1320*2310
#35     m*n: 1330*2280
#36     m*n: 1344*2240
#37     m*n: 1365*2184
#38     m*n: 1400*2100
#39     m*n: 1416*2065
#40     m*n: 1428*2040
#41     m*n: 1440*2016
#42     m*n: 1470*1960
#43     m*n: 1512*1890
#44     m*n: 1540*1848
#45     m*n: 1560*1820
#46     m*n: 1575*1800
#47     m*n: 1624*1740
#48     m*n: 1640*1722
#49     m*n: 1680*1680

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: 666, mathematics and Satan
« Reply #3 on: June 13, 2022, 10:43:43 PM »
Hi JJ!!

This is the ML64 version. It's faster because use things we know: minimum number is bigger than q, curve is symmetric, and first pair contain minimum and maximum number  :biggrin:

Code: [Select]
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc
    local q : qword, sum : qword, check : qword
    local pairs : qword, points : qword
    local equals : qword, minimum : qword, maximum : qword

    conout "This devilish program was assembled with ML64",lf
    conout "It shows points of numbers that match the formula m*n="

    mov rax, 840
    mov q, rax
    mov rcx, rax
    inc rax
    imul rax,rcx
    mov maximum, rax

    conout str$(q),"*(m+n)",lf,lf
   
    mov pairs, 0
    mov rax, q
    shl rax, 1
    mov equals, rax
    mov rsi, q
outer:
    inc rsi
    mov rdi, minimum
   
    inner:
        inc rdi
lea rax, [rsi+rdi]
        imul rax, q
mov rbx, rax ; (m+n)*q
        mov rax, rdi
        mul rsi ; m*n
        cmp rax, rbx
        jne @F
       
        mov rax, rsi
        add rax, rdi
        mov sum, rax
        mov rax, rsi
        imul rax, rdi
        idiv q
        mov check, rax

        conout "m*n : ", str$(rsi),"*",str$(rdi)," - ", str$(sum)," ", str$(check),lf
        inc pairs
@@:
        cmp rdi, maximum
        jb inner
        mov maximum, rdi
        mov minimum, rsi
    cmp rsi, equals
    jb outer

    mov rax, pairs
    sub rax, 1
    shl rax, 1
    add rax, 1
    mov points, rax          ; curve is symmetric, only half is calculated
   
    conout lf, "pairs = ",str$(pairs),"   points = ",str$(points),lf,lf
    waitkey
    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

LATER: - a little faster [H666C.zip (2.31 kB - downloaded 4 times.)]
           - estimation of maximum
« Last Edit: June 16, 2022, 01:13:43 AM by HSE »
Equations in Assembly: SmplMath

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: 666, mathematics and Satan
« Reply #4 on: June 13, 2022, 11:00:30 PM »
This is the ML64 version. It's faster because use things we know: minimum number is bigger than q, curve is symmetric, and first pair contain minimum and maximum number  :biggrin:

Excellent :thumbsup:

Try mov q, 10080 ;-)

P.S. Interesting patterns:

Code: [Select]
--- 32 items for magic 120 ---
--- 31 items for magic 168 ---
--- 37 items for magic 180 ---
--- 39 items for magic 210 ---
--- 39 items for magic 240 ---
--- 35 items for magic 252 ---
--- 34 items for magic 300 ---
--- 36 items for magic 330 ---
--- 36 items for magic 336 ---
--- 44 items for magic 360 ---
--- 31 items for magic 390 ---
--- 49 items for magic 420 ---

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: 666, mathematics and Satan
« Reply #5 on: June 13, 2022, 11:33:26 PM »
 :thumbsup:  Still running   :biggrin:
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: 666, mathematics and Satan
« Reply #6 on: June 16, 2022, 12:48:51 AM »
Updated maximum number estimation, in previous post.
Equations in Assembly: SmplMath

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: 666, mathematics and Satan
« Reply #7 on: June 16, 2022, 04:12:25 AM »
I'd like to see that, Hector, but I don't have access to my machine before Tuesday :sad:

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: 666, mathematics and Satan
« Reply #8 on: June 16, 2022, 06:00:15 AM »
I don't have access to my machine

No problem, meanwhile you can check that manually: if q = 10080 then you only need 101,616,480 sums and multiplications just for first number :biggrin: :biggrin: :biggrin:
Equations in Assembly: SmplMath

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9369
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: 666, mathematics and Satan
« Reply #9 on: June 16, 2022, 11:11:19 AM »
Is this topic full of diabolical solutions or is it just the mark of the beast ?  :tongue:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: 666, mathematics and Satan
« Reply #10 on: June 16, 2022, 08:53:53 PM »
Is this topic full of diabolical solutions

Just one solution  :biggrin:

or is it just the mark of the beast ?  :tongue:

If JJ solve manually, I will be scared  :biggrin: :biggrin:
Equations in Assembly: SmplMath