Skip to main content
Post Undeleted by CommunityBot
added 440 characters in body
Source Link
user45941
user45941

Actually, 2634 bytes

;DY⌠;±2k.⌂⌡nfuóD;;1&YτD*k╔;╗3*;±kSix⌠;;AF@;1&@0>*YτD(s**╜=⌡░ 

Try it online! Brute-force saves the day

This answer utilizes the fact that, for all Fibonacci numbers \$ F = Fib(n) \$, \$F \gt 1 \land n \vert 2 \iff F = ExtFib(-n) \$. A special case is used to handle input of 1.Explanation:

;DY⌠;±2k.⌂⌡nfuóD;;1&YτD*k╔;╗3*;±kSix⌠;;AF@;1&@0>*YτD(s**╜=⌡░ ;DY⌠;±2k.⌂⌡n ;╗ special-casing for 1: ;DY save a copy of the input (let's call it duplicate,N) decrement,to logicalregister negate0 (turnsthe 1main intoway 1to andget othersadditional values into 0functions) 3*;± ⌠;±2k.⌂⌡n execute this code that many times: -3*N, 3*N ;±2k kSi make a  push to list, fromsort, flatten (sort the existingtwo 1values on the stack, itsso negativethat they are in the right order for x) x range(min(-13*N, 3*N), andmax(-3*N, 23*N)) .⌂ ⌠;;AF@;1&@0>*YτD(s**╜=⌡░ filter (remove values where function leaves a non-truthy value on top of the stack):  print the list and exit  ;; f make indextwo incopies Fibonacciof sequenceparameter (-1 iflet's notcall Fibonacciit numbern) AF increment and conditionally terminate (terminate if -1 absolute value, Fib(|n|) D;;@; decrement  bring a copy of n to the top of the stack and make twoanother copiescopy 1& 1&Y binary AND with 1, logical negate (1  0 if n is divisible by 2 else 1  @0> 1 if n is negative else 0 (using another copy of n) τD * double multiply those two values (acts as logical AND: is n negative and not divisible by 2) YτD  logical negate, double, decrement (mapmaps [0, 1] to [-1[1, -1]) *k multiply(s Fibonacci index by result, push entire stack to list (eithersign [n,of n]n or(using [n,the -n]last copy)  deduplicate list**  multiply Fib([n]|n|), orsign [-of n, n]and result of complicated logic (deciding whether or not to flip the sign of the value for the extended sequence)   ╜=  push value from register 0, equality comparison (implicit1 printif value equals N else 0) 

Try it online!

Actually, 26 bytes

;DY⌠;±2k.⌂⌡nfuóD;;1&YτD*k╔ 

Try it online!

This answer utilizes the fact that, for all Fibonacci numbers \$ F = Fib(n) \$, \$F \gt 1 \land n \vert 2 \iff F = ExtFib(-n) \$. A special case is used to handle input of 1.

;DY⌠;±2k.⌂⌡nfuóD;;1&YτD*k╔ ;DY⌠;±2k.⌂⌡n  special-casing for 1: ;DY duplicate, decrement, logical negate (turns 1 into 1 and others into 0) ⌠;±2k.⌂⌡n execute this code that many times: ;±2k make a list from the existing 1 on the stack, its negative (-1), and 2 .⌂ print the list and exit  f index in Fibonacci sequence (-1 if not Fibonacci number)  increment and conditionally terminate (terminate if -1) D;; decrement and make two copies 1&Y binary AND with 1, logical negate (1 if divisible by 2 else 0) τD double and decrement (map [0,1] to [-1, 1]) *k multiply Fibonacci index by result, push entire stack to list (either [n, n] or [n, -n])  deduplicate list ([n] or [-n, n]) (implicit print) 

Actually, 34 bytes

;╗3*;±kSix⌠;;AF@;1&@0>*YτD(s**╜=⌡░ 

Brute-force saves the day

Explanation:

;╗3*;±kSix⌠;;AF@;1&@0>*YτD(s**╜=⌡░ ;╗ save a copy of the input (let's call it N) to register 0 (the main way to get additional values into functions) 3*;±  -3*N, 3*N kSi   push to list, sort, flatten (sort the two values on the stack so that they are in the right order for x) x range(min(-3*N, 3*N), max(-3*N, 3*N)) ⌠;;AF@;1&@0>*YτD(s**╜=⌡░ filter (remove values where function leaves a non-truthy value on top of the stack):  ;; make two copies of parameter (let's call it n) AF  absolute value, Fib(|n|) @;   bring a copy of n to the top of the stack and make another copy 1&   0 if n is divisible by 2 else 1  @0> 1 if n is negative else 0 (using another copy of n) *  multiply those two values (acts as logical AND: is n negative and not divisible by 2) YτD  logical negate, double, decrement (maps [0, 1] to [1, -1]) (s sign of n (using the last copy) **  multiply Fib(|n|), sign of n, and result of complicated logic (deciding whether or not to flip the sign of the value for the extended sequence)   ╜=  push value from register 0, equality comparison (1 if value equals N else 0) 

Try it online!

Post Deleted by CommunityBot
Source Link
user45941
user45941

Actually, 26 bytes

;DY⌠;±2k.⌂⌡nfuóD;;1&YτD*k╔ 

Try it online!

This answer utilizes the fact that, for all Fibonacci numbers \$ F = Fib(n) \$, \$F \gt 1 \land n \vert 2 \iff F = ExtFib(-n) \$. A special case is used to handle input of 1.

;DY⌠;±2k.⌂⌡nfuóD;;1&YτD*k╔ ;DY⌠;±2k.⌂⌡n special-casing for 1: ;DY duplicate, decrement, logical negate (turns 1 into 1 and others into 0) ⌠;±2k.⌂⌡n execute this code that many times: ;±2k make a list from the existing 1 on the stack, its negative (-1), and 2 .⌂ print the list and exit f index in Fibonacci sequence (-1 if not Fibonacci number) uó increment and conditionally terminate (terminate if -1) D;; decrement and make two copies 1&Y binary AND with 1, logical negate (1 if divisible by 2 else 0) τD double and decrement (map [0,1] to [-1, 1]) *k multiply Fibonacci index by result, push entire stack to list (either [n, n] or [n, -n]) ╔ deduplicate list ([n] or [-n, n]) (implicit print)