[Question]
  [
A biquadratic number is a number that is the fourth power of another integer, for example: `3^4 = 3*3*3*3 = 81`
Given an integer as input, output the closest biquadratic number.
Here are the first 15 double-squares:
```
1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000, 14641, 20736, 28561, 38416, 50625
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so fewest bytes **in each language** wins
This is OEIS [A000583](https://oeis.org/A000583)
  
[Answer]
# [Python 3](https://docs.python.org/3/), 35 bytes
```
lambda n:int((n**.5-.75)**.5+.5)**4
```
[Try it online!](https://tio.run/##LU1BDsIwDLvzCh@TtesoMCFN2ksGhyIoTIVsqnbh9YUwfLET2/L8Xh6T7EvsT@UZXpdrgHSjLERSVa6t3bFlFcYpH0qcMhJGQQ5yv5G38FvuNvhCLVFrIEq11zgM0kqem2ZnQf@TkvkF9Hte64o567RYRBLm8gE "Python 3 ‚Äì Try It Online")
### How it works
The value *n* at which the output switches from (*k* ‚àí 1)4 to *k*4 satisfies ‚àö(‚àön ‚àí 3/4) + 1/2 = *k*, or *n* = ((k ‚àí 1/2)2 + 3/4)2 = (*k*2 ‚àí *k* + 1)2 = ((*k* ‚àí 1)4 + *k*4 + 1)/2, which is exactly the first integer that‚Äôs closer to *k*4.
(Works for all *n* ‚â§ 4504699340341245 = (81924 + 81934 ‚àí 7)/2 > 252, after which floating-point roundoff starts to break it, even though it works mathematically for all *n*.)
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 35 bytes
This challenge [needed](https://codegolf.stackexchange.com/questions/131691/find-the-nearest-biquadratic-number/131708#comment323100_131704) a convolution-based approach.
```
@(n)sum(n>conv((1:n).^4,[1 1]/2))^4
```
[**Try it online!**](https://tio.run/##y08uSSxL/Z@mYKugp6f330EjT7O4NFcjzy45P69MQ8PQKk9TL85EJ9pQwTBW30hTM87kf5qGhSZXmoYliDABM00sNf8DAA "Octave ‚Äì Try It Online")
### Explanation
The expression `(1:n).^4` produces the row vector `[1 16 81 256 ... n^4]`.
This vector is then convolved with `[1 1]/2`, which is equivalent to computing the sliding average of blocks of size `2`. This implicitly assumes that the vector is left- and right-padded with `0`. So the first value in the result is `0.5` (average of an implicit `0` and `1`), the second is `8.5` (average of `1` and `16`), etc.
As an example, for `n = 9` the result of `conv((1:n).^4,[1 1]/2)` is 
```
0.5 8.5 48.5 168.5 440.5 960.5 1848.5 3248.5 5328.5 3280.5
```
The comparison `n>...` then yields
```
1 1 0 0 0 0 0 0 0 0 0
```
and applying `sum(...)` gives `2`. This means that `n` exceeds exactly `2` of the mid-points betwen biquadratic numbers (including the additional mid-point `0.5`). Finally, `^4` raises this to `4` to yield the result, `16`. 
[Answer]
# [Haskell](https://www.haskell.org/), ~~51~~ 49 bytes
Function monad ftw!
```
f n=snd.minimum$(abs.(n-)<$>)>>=zip$(^4)<$>[1..n]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7Y4L0UvNzMvM7c0V0UjMalYTyNPV9NGxU7Tzs62KrNARSPOBMSNNtTTy4v9n5uYmadgq1BQWhJcUuSTp6CiUJyRXw6k0hQMjUz/AwA "Haskell ‚Äì Try It Online")
Explanation:
```
                                (^4)<$>[1..n] -- creates a list of fourth powers
            (abs.(n-)<$>)>>=zip               -- creates a list of |n-(4th powers)| and
                                              -- zips it with the 4th powers list
    minimum                                   -- finds the minimum
                                              -- (only first tuple entry matters)
snd                                           -- exctracts the second entry (the 4th power)
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
t:4^Yk
```
[**Try it online!**](https://tio.run/##y00syfn/v8TKJC4y@/9/I2MA "MATL ‚Äì Try It Online")
### Explanation
Consider input `9` as an example.
```
t    % Implicitly input n. Duplicate         
     % STACK: 9, 9
:    % Range [1 2 ... n]
     % STACK: 9, [1 2 3 4 5 6 7 8 9]
4^   % Raise to 4, element-wise
     % STACK: 9, [1 16 81 256 625 1296 2401 4096 6561]
Yk   % Closest element. Implicitly display
     % STACK: 16
```
[Answer]
# [Neim](https://github.com/okx-code/Neim), 5 bytes
```
ùêà4ùïéSùïî
```
Explanation:
```
ùêà       Inclusive range [1 .. input]
  ùïé    Raise to the  v  power
 4                   4th
     ùïî  Select the value closest to
    S   the input
```
[Try it online!](https://tio.run/##y0vNzP3//8PcCR0mH@ZO7QsGElP@/zc0AAA "Neim ‚Äì Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 9 bytes
```
;I‚âú+.~^‚ÇÑ‚àß
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/39rzUeccbb26uEdNLY86lv//b2T8PwoA "Brachylog ‚Äì Try It Online")
### Explanation
```
;I‚âú          I = 0 / I = 1 / I = -1 / I = 2 / etc. on backtracking
   +.        Output = Input + I
    .~^‚ÇÑ     Output = Something to the power 4
        ‚àß
```
[Answer]
## Excel, 25 bytes
```
=INT((A1^.5-3/4)^.5+.5)^4
```
Excel updates this to `=INT((A1^0.5-3/4)^0.5+0.5)^4`
[Answer]
## Mathematica, 21 bytes
```
Nearest[Range@#^4,#]&
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
LnnI.x
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fJy/PU6/i/39DUwA "05AB1E ‚Äì Try It Online")
### Explanation
```
LnnI.x
L      # Push [1 .. input]
 nn    # Raise every element to the 4th power
   I   # Push input
    .x # Closest element in the array to input
   
```
[Answer]
## JavaScript (ES7), 42 bytes
```
x=>(n=x**.25|0,x-(k=n**4)<++n**4-x?k:n**4)
```
### Recursive version, 44 bytes
```
f=(x,k,b)=>(a=k**4)>x?a-x>x-b?b:a:f(x,-~k,a)
```
### Demo
```
let f =
x=>(n=x**.25|0,x-(k=n**4)<++n**4-x?k:n**4)
console.log(f(16))
console.log(f(48))
console.log(f(49))
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 37 bytes
```
@(n)interp1(t=(1:n).^4,t,n,'nearest')
```
Anonymous function that uses nearest-neighbour interpolation.
[**Try it online!**](https://tio.run/##y08uSSxL/Z@mYKugp6f330EjTzMzryS1qMBQo8RWw9AqT1MvzkSnRCdPRz0vNbEotbhEXfN/moaFJleahqXmfwA "Octave ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
R*4·∫°√ê·πÇ
```
A monadic link returning a list of one item, or a full program that prints the result (using an inefficient method).
**[Try it online!](https://tio.run/##y0rNyan8/z9Iy@ThroWHJzzc2fT//39DM0sA "Jelly ‚Äì Try It Online")**
### How?
```
R*4·∫°√ê·πÇ - Link: number, n
R      - range(n) -> [1,2,3,...,n]
 *4    - raise to the fourth power -> [1,16,81,...,n**4]
    √ê·πÇ - filter keep those (only ever one) minimal:
   ·∫°   -   absolute difference (with n)
       - if a full program: implicit print (one item lists print their content).
```
[Answer]
# APL, 22 bytes
```
{o/‚ç®p=‚åä/p‚Üê|‚çµ-‚ç®o‚Üê4*‚ç®‚ç≥‚çµ}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbhOp8/Ue9KwpsH/V06RcA@TWPerfqAkXygWwTLSDjUe9moFAtULXCIRDH0MAAAA)
**How?**
`o‚Üê4*‚ç®‚ç≥‚çµ` - `o` = range(`‚çµ`)4 [vectorize]
`p‚Üê|‚çµ-‚ç®o` - `p` = abs(`o` - `‚çµ`) [vectorize]
`o/‚ç®` - take the `o` element at the index where ...
`p=‚åä/p` - the `p` minimum element is
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~10~~ 7 bytes
*Edit: -3 bytes thanks to Razetime*
```
‚óÑ‚â†¬πm^4·∏£
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8eGOxYYGBv8fTW951Lng0M7cOBOgyP//AA "Husk ‚Äì Try It Online")
```
‚óÑ‚â†¬πm^4·∏£
‚óÑ               # minimum element based on
 ‚â†¬π             # difference to input,
      ·∏£         # of series from 1 up to input
   m^4          # to the power of 4
```
[Answer]
# [PHP](https://php.net/), 33 bytes
```
<?=(($argn**.5-.75)**.5+.5^0)**4;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwKWSWJSeZ6tkqWTNZW8HFLPV0AALaWnpmerqmZtqghjaeqZxBkCWifX//wA "PHP ‚Äì Try It Online")
# [PHP](https://php.net/), 56 bytes
```
<?=2*$argn-($x=($f=$argn**.25^0)**4)>($y=++$f**4)?$y:$x;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwKWSWJSeZ6tkbGysZM1lbwcUtTXSAgvqaqhU2GqopNmCeVpaekamcQaaWlommnYaKpW22toqaSCOvUqllUqF9f//AA "PHP ‚Äì Try It Online")
[Answer]
**C++, 96 bytes**
```
int Q(int N){int i=1;while (pow(i,4)<N){i++;}if (pow(i,4)-N>N-pow(i-1,4)){i--;}return pow(i,4);}
```
Full version:
```
int Q(int N)
{
    int i = 1;
    while (pow(i, 4) < N)
    {
        i++;
    }
    if (pow(i, 4)-N > N-pow(i - 1, 4))
        i--;
    return pow(i,4);
}
```
[LINK to try](https://tio.run/##RY5BCoMwEEXX5hTBbiI2RaG72BwhtEcIMdUBE8UkSJGc3UZLcTMz/82H/9U00U6p7QJWDaHVuIHR@VlLw9HJjPT9recoOLAdttJoN0mlsfMt28B6/CL7FMW6L3jUbOlh0JhM40Lgei@a/VWWLML7hFRwQQ9B6ySTg1IWZ@3DbPHfxOIRYCRYUqAVZUcQQ5kCizn/nWPwuGlSC1Ek6T7Oa0PypwxO54mguNVVhb4)
[Answer]
# Haskell, 35 bytes
```
f n=(floor$(n**0.5-3/4)**0.5+0.5)^4
```
Port of [Anders' Python3 answer](https://codegolf.stackexchange.com/a/131700/3913).
[Answer]
# [R](https://www.r-project.org/), ~~47~~ ~~44~~ ~~37~~ 35 bytes
```
n=scan();which.min(((1:n)^4-n)^2)^4
```
[Try it online!](https://tio.run/##K/r/P8@2ODkxT0PTujwjMzlDLzczT0NDw9AqTzPORBdIGAHp/yYmhv8B "R ‚Äì Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
```
.maQb^R4S
```
[Try it online!](https://tio.run/##K6gsyfj/Xy83MTApLsgk@P9/UzMA "Pyth ‚Äì Try It Online")
---
### [Pyth](https://github.com/isaacg1/pyth), 17 bytes
A full program that uses the same arithemtic approach as in [@AndersKaseorg's answer](https://codegolf.stackexchange.com/questions/131691/find-the-nearest-biquadratic-number/131700#131700):
```
K.5^s+^-^QK.75KK4
```
[Try it online!](https://tio.run/##K6gsyfj/31vPNK5YO043LtBbz9zU29vk/39TMwA "Pyth ‚Äì Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
√á‚àû¬ßŒ¥o‚ïß‚ïñs‚ñ∫M
```
[Run and debug it](https://staxlang.xyz/#p=80ec15eb6fcfb773104d&i=200)
[Answer]
# [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 38 bytes
```
{p=q^4~p>:|~p-a>a-o|_Xo\_Xp]\o=p‚îòq=q+1
```
## Explanation
```
{           DO infinitely
p=q^4       Set p to q quad (q starts out as 1)
~p>:|       IF p exceeds the input THEN
~p-a>a-o    check the distance to p and to o (the last quad) and
|_Xo        PRINT o, or
\_Xp        PRINT p accordingly
]           END IF
\o=p        ELSE  ( p <= input) store p in o to keep track of this quad
‚îòq=q+1      and raise q for the next iteration
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 64 bytes
```
n->{int i=0,q,Q=0;while((q=i*i*i*i++)<n)Q=q;return q-n<n-Q?q:Q;}
```
[Try it online!](https://tio.run/##XVFdb4IwFH33V9yQmMAEgsYZBjKzx8VshLg9GR46KK4OC7RFZwy/ndWKTm2T3px7z/04t2u0RVZRYrpOf9qy/spJAkmOOIc3RCgcegCdlwskpNkWJIWNjOkLwQhdLWNAbMUNRQVYy3p2LUhuZzVNBCmo/UrFJ0VsH5aYIVEwyCBoqfV8IFQACRyzMqPA8XffJMe6XgXkQd3BwJhSIwoqn2FRMwqVRafUimaVF/lNC@r4qqkstIzlIAJzwSEAincX32ksgINjgtOYZzQ0YfiPRjfIvUFPEk2uEie3eOzeYcl3h9d8994hGaPHSaMcjd9TNpN70dXMSoV30mJcxj/uimFe50Lqy2xUlvn@hcvV6kfi0okNv2Mu9lzgjV3Uwi7lB4lM1/rj1AP5gN7nRp9qJnRJZlfzbINABYbxTAvnmqe9hx8Qzk3AvyVOBE5BgwF0lK7hUUbTa9o/ "Java (OpenJDK 8) ‚Äì Try It Online")
[Answer]
# Common Lisp, 50 bytes
```
(lambda(x)(expt(floor(+(sqrt(-(sqrt x).75)).5))4))
```
[Try it online!](https://tio.run/##HcVBCoAgEEbhq7j8h8iVUdcxSxAmNTWY25u4eN9zHGruyCXEpuC/6Cyz6mD7nJeFEG7JDZ5TKlhQ39KwzikhvW9EemSIujkGPw)
[Answer]
# C#, 95 bytes
```
namespace System.Linq{n=>new int[940].Select((_,i)=>i*i*i*i).OrderBy(i=>Math.Abs(i-n)).First()}
```
We use 940 as a set value as any larger value will overflow the int.
Full/Formatted Version:
```
namespace System.Linq
{
    class P
    {
        static void Main()
        {
            Func<int, int> f = n => new int[940].Select((_, i) => i * i * i * i).OrderBy(i => Math.Abs(i - n)).First();
            for (int i = 1; i <= Int32.MaxValue; ++i)
                Console.WriteLine($"{i} = {f(i)}");
            Console.ReadLine();
        }
    }
}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~23~~ 34 bytes
I have no idea why `0.75` is such an important number for this, but hey, whatever works.
```
->n{((n**0.5-0.75)**0.5).round**4}
```
[Try it online!](https://tio.run/##KypNqvyfZhvzX9cur1pDI09Ly0DPVNdAz9xUE8zU1CvKL81L0dIyqf1foJAWnZ5aUqxXkh@fGfvf0NQQAA "Ruby ‚Äì Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt/) [`-g`](https://codegolf.meta.stackexchange.com/a/14339/), ~~20~~ ~~8~~ 7 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
~~This feels far too long!~~ I was right!
```
√á¬≤¬≤√É√±aU
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWc&code=x7Kyw/FhVQ&input=ODg4)
```
√á¬≤¬≤√É√±aU     :Implicit input of integer U
√á           :Map the range [0,U)
 ¬≤¬≤         :  Square twice
   √É        :End map
    √±       :Sort by
     aU     :  Absolute difference with U
            :Implicit output of first element
```
## Without flag, 8 bytes
```
√à¬¨¬¨v1}cU
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=yKysdjF9Y1U&input=ODg4)
```
√à¬¨¬¨v1}cU     :Implicit input of integer U
√à            :Function taking an integer X as argument
 ¬¨           :  Square root
  ¬¨          :  Square root
   v1        :  Divisible by 1?
     }       :End function
      cU     :Return the first X in the sequence [U,U-1,U+1,U-2,U+2,U-3,...] that returns true
```
]