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

added explanation
Source Link
FrodCube
  • 589
  • 1
  • 3
  • 10

CJam, 26 bytes

qi_[XY@{_2$+}*]_@\f%:!.*:+

Try it online!

I'm sure it can be done better. WritingExplanation:

The idea is to have an array of Fibonacci numbers and dot product it with an array with 1s and 0s if that number is or is not a divisor of the explanation..input.

qi Read the input (n)
 [XY ] Array starting with [1,2,...]
 _ @{_2$+}* Append n times the sum of the previous two
 _ Duplicate the array
 @\f% Modulo each item with n (0 if divisor, a number otherwise)
 :! Logical NOT everything (1 if divisor, 0 otherwise) 
 .*:+ Dot product those two arrays

CJam, 26 bytes

qi_[XY@{_2$+}*]_@\f%:!.*:+

Try it online!

I'm sure it can be done better. Writing the explanation...

CJam, 26 bytes

qi_[XY@{_2$+}*]_@\f%:!.*:+

Try it online!

I'm sure it can be done better. Explanation:

The idea is to have an array of Fibonacci numbers and dot product it with an array with 1s and 0s if that number is or is not a divisor of the input.

qi Read the input (n)
 [XY ] Array starting with [1,2,...]
 _ @{_2$+}* Append n times the sum of the previous two
 _ Duplicate the array
 @\f% Modulo each item with n (0 if divisor, a number otherwise)
 :! Logical NOT everything (1 if divisor, 0 otherwise) 
 .*:+ Dot product those two arrays
Source Link
FrodCube
  • 589
  • 1
  • 3
  • 10

CJam, 26 bytes

qi_[XY@{_2$+}*]_@\f%:!.*:+

Try it online!

I'm sure it can be done better. Writing the explanation...

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