Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

golf off two bytes, per @Dennis
Source Link
user62131
user62131

Jelly, 16(削除) 16 (削除ここまで) 14 bytes (with a little help from @Dennis)

’ÆRṡ2_/2+$$ÐḟFİS

Try it online! Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Dennis suggesting replacing _/2+$$Ðḟ with Iċ\Ðf2; I'd completely forgotten about the possibility of a dyadic filter. As such, this algorithm now ties with the one that Dennis' answer used.

Explanation

’ÆRṡ2_/2+$$ÐḟFİS
’ Decrement.
 ÆR Primes from 2 to the argument inclusive
 (i.e. 2 to the original input exclusive).
 ṡ2 Take overlapping slices of size 2.
 Ðḟ Delete elements where the following isn't 0:
 $$’ÆRṡ2Iċ\Ðf2FİS
’ {the third parse of, which parses like this} Decrement.
 ÆR _/ Primes from 2 to the reductionargument byinclusive
 subtraction (i.e. first2 -to secondthe original input exclusive).
 ṡ2 2+ plusTake overlapping slices of size 2.
 Ðf  Keep only elements where the following is true:
 \ {the second parse of, which parses like this}
 Iċ 2 the differences (I) contain (ċ) 2
 F Flatten.
 İ İ Take 1/x {for every list element}.
 S S Sum.

Incidentally, Jelly has a builtin I to find the differences of a list, but because it'd return the answer wrapped in a list, which is harder to compare to 2 or -2, I can't see a way to save bytes via using it.

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Explanation

’ÆRṡ2_/2+$$ÐḟFİS
’ Decrement.
 ÆR Primes from 2 to the argument inclusive
 (i.e. 2 to the original input exclusive).
 ṡ2 Take overlapping slices of size 2.
 Ðḟ Delete elements where the following isn't 0:
 $$ {the third parse of, which parses like this}
 _/ the reduction by subtraction (i.e. first - second)
 2+ plus 2
 F Flatten.
 İ Take 1/x {for every list element}.
 S Sum.

Incidentally, Jelly has a builtin I to find the differences of a list, but because it'd return the answer wrapped in a list, which is harder to compare to 2 or -2, I can't see a way to save bytes via using it.

Jelly, (削除) 16 (削除ここまで) 14 bytes (with a little help from @Dennis)

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Dennis suggesting replacing _/2+$$Ðḟ with Iċ\Ðf2; I'd completely forgotten about the possibility of a dyadic filter. As such, this algorithm now ties with the one that Dennis' answer used.

Explanation

’ÆRṡ2Iċ\Ðf2FİS
’  Decrement.
 ÆR Primes from 2 to the argument inclusive
 (i.e. 2 to the original input exclusive).
 ṡ2 Take overlapping slices of size 2.
 Ðf  Keep only elements where the following is true:
 \ {the second parse of, which parses like this}
 Iċ 2 the differences (I) contain (ċ) 2
 F Flatten.
 İ Take 1/x {for every list element}.
 S Sum.
and not a duplicate, again
Source Link
user62131
user62131

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Explanation

’ÆRṡ2_/2+$$ÐḟFİS
’ Decrement.
 ÆR Primes from 2 to the argument inclusive
 (i.e. 2 to the original input exclusive).
 ṡ2 Take overlapping slices of size 2.
 Ðḟ Delete elements where the following isn't 0:
 $$ {the third parse of, which parses like this}
 _/ the reduction by subtraction (i.e. first - second)
 2+ plus 2
 F Flatten.
 İ Take 1/x {for every list element}.
 S Sum.

Incidentally, Jelly has a builtin I to find the differences of a list, but because it'd return the answer wrapped in a list, which is harder to compare to 2 or -2, I can't see a way to save bytes via using it.

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Explanation

’ÆRṡ2_/2+$$ÐḟFİS
’ Decrement.
 ÆR Primes from 2 to the argument inclusive
 (i.e. 2 to the original input exclusive).
 ṡ2 Take overlapping slices of size 2.
 Ðḟ Delete elements where the following isn't 0:
 $$ {the third parse of, which parses like this}
 _/ the reduction by subtraction (i.e. first - second)
 2+ plus 2
 F Flatten.
 İ Take 1/x {for every list element}.
 S Sum.

Incidentally, Jelly has a builtin I to find the differences of a list, but because it'd return the answer wrapped in a list, which is harder to compare to 2 or -2, I can't see a way to save bytes via using it.

and not a duplicate, again
Source Link
user62131
user62131

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

(EDIT: Deleting, it's too close to Dennis' answer which was posted while I was working on this.)

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

(EDIT: Deleting, it's too close to Dennis' answer which was posted while I was working on this.)

Jelly, 16 bytes

’ÆRṡ2_/2+$$ÐḟFİS

Try it online!

While trying to improve my previous answer, I thought up a totally different algorithm, and it comes in somewhat shorter. I'm using a different post for it, as is the standard here for an answer that uses a different technique.

Post Undeleted by Community Bot
Post Deleted by Community Bot
Source Link
user62131
user62131
Loading

AltStyle によって変換されたページ (->オリジナル) /