Welcome to 2023.
#1
Hi,

Happy belated 2023! This is a program to display the factors of 2023:

Code: (Select All)
Year = 2023
z = Year - 1
Do Until z = Year
  z = z + 1
  x = z
  Print x; "=";
  l = 1
  q = 0
  Do Until x = 1
      l = l + 1
      Do While x / l = x \ l ' continue to divide number
        q = q + 1
        If q > 1 Then
            Print "*";
        End If
        Print l;
        x = x / l
      Loop
      If l > Int(z / 2) Then ' test for maximum divisor
        Exit Do
      End If
      If l > Int(Sqr(x)) Then ' test maximum divisor is prime
        If q = 0 Then
            Exit Do
        End If
      End If
  Loop
  If q = 0 Then ' display number is prime
      Print " (prime)";
  End If
  Print
Loop
End
Reply
#2
An interesting program!
I wish I knew how it works though - it's quite cryptic to me!
Any chance of naming some variables, to enlighten dummies like me? 
And do the labels "80" and "0" have a purpose?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#3
Actually the 80 serves no purpose. (removed)

The Year could be set to anything.

Erik.

(vote my reputation)
Reply
#4
(02-08-2023, 05:40 AM)eoredson Wrote: Actually the 80 serves no purpose. (removed)

The Year could be set to anything.

Erik.

(vote my reputation)

Voted!
I tried a variety of years, and all worked correctly (except zero, negative and fractions, which I didn't really expect to work anyway). Good job!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#5
(02-08-2023, 05:31 AM)PhilOfPerth Wrote: An interesting program!
I wish I knew how it works though - it's quite cryptic to me!
Any chance of naming some variables, to enlighten dummies like me? 
And do the labels "80" and "0" have a purpose?

For @PhilOfPerth
Code: (Select All)
'yearInteger/testInteger = yearInteger\testInteger is one way to see if yearInteger is divided by testInteger

' / is for float return a number that might have decimals
' \ is for an Integer return a number without decimals
' When the two divisions return exactly same number the bottom number divides the top exactly.

Dim As Long testInteger, yearInteger

yearInteger = 2023
For testInteger = 2 To Sqr(yearInteger) ' <<< primes of a Number will be less than or = to Square Root of Number
    If yearInteger / testInteger = yearInteger \ testInteger Then Print testInteger; "divides"; yearInteger; yearInteger / testInteger; "times."
Next
b = b + ...
Reply
#6
Thanks bplus. Now I (sort of) get it... I'll work through it now and see if I can absorb it..
and thanks for the tag! Smile

Late extra: I got it!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply




Users browsing this thread: 6 Guest(s)