Skip to main content
added 358 characters in body
Source Link
ydd
  • 8.8k
  • 1
  • 12
  • 28

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], !PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Some primes have crazy large values:

plotData = Table[{i, f[i]}, {i, Prime[Range[285]]}]; ListLinePlot[plotData, PlotRange -> All, ScalingFunctions -> "Log"] 

enter image description here

In fact, some are so large I haven't even gotten an answer: f[1871] just runs indefinitely.

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], !PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], !PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Some primes have crazy large values:

plotData = Table[{i, f[i]}, {i, Prime[Range[285]]}]; ListLinePlot[plotData, PlotRange -> All, ScalingFunctions -> "Log"] 

enter image description here

In fact, some are so large I haven't even gotten an answer: f[1871] just runs indefinitely.

The plot is wrong. Will re-add when corrected
Source Link
ydd
  • 8.8k
  • 1
  • 12
  • 28

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], ! PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Add-on: Unrelated, but I just had to add this plot also because it looks very interesting

ListLinePlot[f[Prime[Range[10000]]], Joined -> True] 

enter image description here

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], ! PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Add-on: Unrelated, but I just had to add this plot also because it looks very interesting

ListLinePlot[f[Prime[Range[10000]]], Joined -> True] 

enter image description here

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], !PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 
Fixed the issue with 1 not being composite, but also not being prime
Source Link
ydd
  • 8.8k
  • 1
  • 12
  • 28

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], CompositeQ[#! PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Add-on: Unrelated, but I just had to add this plot also because it looks very interesting

ListLinePlot[f[Prime[Range[10000]]], Joined -> True] 

enter image description hereenter image description here

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], CompositeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Add-on: Unrelated, but I just had to add this plot also because it looks very interesting

ListLinePlot[f[Prime[Range[10000]]], Joined -> True] 

enter image description here

Another implementation using NestWhile:

f[p_]:=NestWhile[2 # &, 2^Ceiling[Log[2, p]], ! PrimeQ[# - p] &] - p; f[857] f[859] (*167*) (*7333*) 

Add-on: Unrelated, but I just had to add this plot also because it looks very interesting

ListLinePlot[f[Prime[Range[10000]]], Joined -> True] 

enter image description here

added 249 characters in body
Source Link
ydd
  • 8.8k
  • 1
  • 12
  • 28
Loading
Source Link
ydd
  • 8.8k
  • 1
  • 12
  • 28
Loading