Skip to main content
Commonmark migration
Source Link

#Mathematica 136 80 75 bytes

Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)⌊z=n-⌊k/2](-1)^k⌋,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌊k/2](-1)^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.


g[5]
g[860782]
g[1425060]

510510

870870

1438710

#Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)⌊z=n-⌊k/2](-1)^k⌋,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌊k/2](-1)^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.


g[5]
g[860782]
g[1425060]

510510

870870

1438710

Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)⌊z=n-⌊k/2](-1)^k⌋,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌊k/2](-1)^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.


g[5]
g[860782]
g[1425060]

510510

870870

1438710

floor instead of ceiling
Source Link
DavidC
  • 25.4k
  • 2
  • 52
  • 105

#Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)[z=n⌊z=n-⌈k⌊k/2](-1)^k⌉^k⌋,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌈k⌊k/2](-1)^k⌉^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.


g[5]
g[860782]
g[1425060]

510510

870870

1438710

#Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)[z=n-⌈k/2](-1)^k⌉,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌈k/2](-1)^k⌉ to return the series, 1, -1, 2, -2...


g[5]
g[860782]
g[1425060]

510510

870870

1438710

#Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)⌊z=n-⌊k/2](-1)^k⌋,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌊k/2](-1)^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.


g[5]
g[860782]
g[1425060]

510510

870870

1438710

ceiling abbreviated
Source Link
DavidC
  • 25.4k
  • 2
  • 52
  • 105

#Mathematica 136 80 8075 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)[z=n-Ceiling[k⌈k/2](-1)^k]^k⌉,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using Ceiling[k⌈k/2](-1)^k]^k⌉ to producereturn the series, 1, -1, 2, -2...


g[5]
g[860782]
g[1425060]

510510

870870

1438710

#Mathematica 136 80 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)[z=n-Ceiling[k/2](-1)^k],k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using Ceiling[k/2](-1)^k] to produce the series, 1, -1, 2, -2...


g[5]
g[860782]
g[1425060]

510510

870870

1438710

#Mathematica 136 80 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)[z=n-⌈k/2](-1)^k⌉,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n. If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product. This more efficient version adopts the approach Dennis took.

The key advance was in using ⌈k/2](-1)^k⌉ to return the series, 1, -1, 2, -2...


g[5]
g[860782]
g[1425060]

510510

870870

1438710

adopted Dennis' more efficient approach. Only one product is returned.
Source Link
DavidC
  • 25.4k
  • 2
  • 52
  • 105
Loading
Source Link
DavidC
  • 25.4k
  • 2
  • 52
  • 105
Loading