Group Abstract Group Abstract

Message Boards Message Boards

1
|
9.1K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Search for consecutive twin primes

Posted 6 years ago
POSTED BY: Koichi Ohno
2 Replies
Posted 6 years ago

Hello Claudio,

Thank you for your helpful comments.An example of use was shown, so it will be very helpful.

The Module [] and OptionsPattern [] you indicated are functions that I have never used before. I think these functions are useful for writing efficient programs.

The problem is whether my old brain can manage it.

Thank you for opening my sight.

Sincerely, Koichi Ohno

POSTED BY: Koichi Ohno

Hello Koichi, very interesting your posts.

Have you thought about getting your work done specifically using function and Module[], so the definitions do not interfere with other lines outside the function? e.g.:

func[n_] := 
 Module[{a, b, c, d}, a = n; b = n^2; c = n^3; d = n^4; {a, b, c, d}]

func[3]

i1

Note that using the definitions after using the function they remain restricted only within the function:

{a, b, c, d}

i2

Another thing that would be interesting for you to do is to merge all your posts into one function (a same function that finds prime numbers: above, below, twins, etc.) with options to switch between them, using OptionsPattern[], e.g.:

func2[n_, OptionsPattern[]] := 
 Module[{a, b}, Options[func2] = {"Type" -> "Subtraction"}; 
  a = n + 10; 
  b = 2*n; {a - b > 0, 
   OptionValue["Type"] /. {"Subtraction" -> (a - b), "Sum" -> (a + b),
      "Divide" -> (a/b), "Multiply" -> (a*b)}}]

i3

Module and OptionsPattern can be found in the documentation for a better understanding.

POSTED BY: Claudio Chaib
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard