Skip to main content
Only care about the last two elements anyway, so no need for an array
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell, 8080 74 bytes

param($n)for($a=1$a,0;$a[0]$b=1,0;$a-lt$n;$a=lt$n;$a,$b=$b,($a[0]+$a[1]$a+$b)+$a){}$a[+($a[0]$b,$a)[($b-$n-gt$n-$a[1]$a)]

(Try it online! temporarily unresponsive)

Iterative solution. Takes input $n, sets $a,$b to be (1,0), and prepends ontothen loops with Fibonacci until $a the next Fibonacci number until we reach a numberis larger than the input. At that point, we index into ($b,$a) based on Boolean of whether the difference between the first element and $n is greater than between $n and the second element. That's left on the pipeline, output is implicit.

PowerShell, 80 bytes

param($n)for($a=1,0;$a[0]-lt$n;$a=,($a[0]+$a[1])+$a){}$a[+($a[0]-$n-gt$n-$a[1])]

(Try it online! temporarily unresponsive)

Iterative solution. Takes input $n, sets $a to be (1,0), and prepends onto $a the next Fibonacci number until we reach a number larger than the input. At that point, we index into $a based on Boolean of whether the difference between the first element and $n is greater than between $n and the second element. That's left on the pipeline, output is implicit.

PowerShell, 80 74 bytes

param($n)for($a,$b=1,0;$a-lt$n;$a,$b=$b,($a+$b)){}($b,$a)[($b-$n-gt$n-$a)]

(Try it online! temporarily unresponsive)

Iterative solution. Takes input $n, sets $a,$b to be 1,0, and then loops with Fibonacci until $a is larger than the input. At that point, we index into ($b,$a) based on Boolean of whether the difference between the first element and $n is greater than between $n and the second element. That's left on the pipeline, output is implicit.

Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell, 80 bytes

param($n)for($a=1,0;$a[0]-lt$n;$a=,($a[0]+$a[1])+$a){}$a[+($a[0]-$n-gt$n-$a[1])]

(Try it online! temporarily unresponsive)

Iterative solution. Takes input $n, sets $a to be (1,0), and prepends onto $a the next Fibonacci number until we reach a number larger than the input. At that point, we index into $a based on Boolean of whether the difference between the first element and $n is greater than between $n and the second element. That's left on the pipeline, output is implicit.