g | x | w | all
Bytes Lang Time Link
042AWK250905T193704Zxrs
004Thunno 2230623T155836ZThe Thon
006Vyxal221014T075741ZDialFros
00505AB1E190308T154448ZCowabung
1231. Python 3.5190308T145314ZRene
095SNOBOL4 CSNOBOL4190305T151411ZGiuseppe
020><>190305T123719ZEmigna
006MathGolf190305T101542Zmaxb
124Java 8 JDK 113190305T033740ZBenjamin
045Ink190213T190123ZSara J
2017C compiled with VC++ Visual Studio 2017 264bytes190217T233638Zder bend
052C gcc190213T194527ZJonathan
046C gcc190217T104035Zuser7740
nanAPL+WIN190214T000207ZGraham
023J190216T043501ZJonah
048tinylisp190216T032758ZDLosc
015Brachylog190216T024729ZDLosc
062VBA Excel190215T080123Zremoel
062Clojure190215T073128ZUnrelate
035JavaScript190214T032454Ztsh
054Wolfram Language Mathematica190214T215032ZKai
004Shortcuts for iOS190214T225749Zpfg
449JVM bytecode OpenJDK asmtools JASM190214T223043ZKitten
nanPHP190214T014010Z640KB
008Pyth190213T220853Zuser4854
067F# .NET Core190214T161936ZLSM07
016Cubix190214T164153Zuser4854
046C# Visual C# Interactive Compiler190213T165057ZGymhgy
037JavaScript Node.js190214T100206Zovs
033Ruby190214T105645ZKirill L
030Haskell190214T134824Zproud ha
00605AB1E190213T170202ZEmigna
048Clean190214T012912ZΟurous
030Haskell190214T005637Zxnor
032Perl 6190214T005058ZJo King
017Charcoal190213T214225ZNeil
006Jelly190213T210319ZErik the
036R190213T175909ZdigEmAll
052Java JDK190213T172529ZOlivier
022Gol><>190213T202338ZKrystosT
029Julia 0.7190213T203053ZKirill L
052Forth gforth190213T180203Zreffu
040JavaScript190213T181334ZShaggy
037Perl 5 ln190213T200249ZXcali
062C#Visual C# Interactive Compiler190213T194637ZKramb
052Haskell190213T192925ZJonathan
039Haskell190213T190958Znimi
019cQuents190213T182154ZStephen
060R190213T165830ZSumner18
008MATL190213T175707ZLuis Men
051R190213T175938Zuser2390
048PowerShell190213T155138ZAdmBorkB
007Japt190213T172050ZShaggy
066C# .NET Core190213T173038ZDestroig
039Haskell190213T171538Zovs
044Python 2190213T165805Zovs
007Stax190213T165702Zrecursiv
021APL dzaima/APL190213T160321Zdzaima
014Japt190213T154256ZLuis fel

AWK, 42 bytes

{for(;i++<=$2-$1;)print i%2?h+++$1:$2-g++}

Attempt This Online!

Thunno 2, 4 bytes

IḲIU

Attempt This Online!

Takes the upper number first.

Explanation

IḲIU  # Implicit input
I     # Inclusive range between the two inputs
 Ḳ    # Bifurcate: reverse a copy
  I   # Interleave them together
   U  # Uniquify the list
      # Implicit output

Vyxal, 6 bytes

‹rI÷ṘY

Try it Online!

Explained

‹rI÷ṘY
‹      # decrement
 r     # range
  I÷   # split into two halves
    Ṙ  # reverse
     Y # interleave

05AB1E, 5 bytes

ŸÂ.ιÙ

Takes input as upper first.

Explanation:

ŸÂ.ιÙ   //full program
Ÿ       //push [min .. max]                stack: [[4, 5, 6]]
 Â      //push range and reversed range    stack: [[4, 5, 6], [6, 5, 4]]
  .ι    //interleave                       stack: [[4, 6, 5, 5, 6, 4]]
    Ù   //deduplicate                      stack: [[4, 6, 5]]

Try it online!

1. Python 3.5, 123 bytes

Script takes two params: interval from, interval to.

from sys import*;v=[*range(int(argv[1]),int(argv[2])+1)];o=[]
for i in range(len(v)):v.reverse();o.append(v.pop())
print(o)

example:

$ ./script.py 1 5
[1, 5, 2, 4, 3]

$ ./script.py -5 6
[-5, 6, -4, 5, -3, 4, -2, 3, -1, 2, 0, 1]

Explanation

# create range input params
v=[*range(int(argv[1]),int(argv[2])+1)]

# define ampty output array
o=[]

# loop input-array-lenght times
for i in range(len(v)):

    # reverse input array
    v.reverse()

    # append last input element to output
    o.append(v.pop())

# print output array
print(o)

SNOBOL4 (CSNOBOL4), 95 bytes

	A =INPUT
	B =INPUT
L	OUTPUT =LE(A,B) A	:F(END)
	OUTPUT =GT(B,A) B
	A =A + 1
	B =B - 1	:(L)
END

Try it online!

><>, 20 bytes

:{:&=?v:1+&}
  oanr/

Try it online!

MathGolf, 6 bytes

↨_x^─▀

Try it online!

Explanation with (1, 5)

↨        inclusive range from a to b    [1, 2, 3, 4, 5]
 _       duplicate TOS                  [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]
  x      reverse int/array/string       [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]
   ^     zip top two elements on stack  [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]
    ─    flatten array                  [1, 5, 2, 4, 3, 3, 4, 2, 5, 1]
     ▀   unique elements of string/list [1, 5, 2, 4, 3]

The reason why this works is due to the fact that all elements in the output should be unique, so the unique elements operator will filter out the second half of the array, producing the correct output.

Java 8 (JDK): 113, 98, 124 bytes

(l,h)->{String s="";while(h>=l)s+=l+++" "+h--+" ";return s.substring(0,s.length()-(l-h==2?(l+(l<0?".":"")).length()+2:1));};

Thanka to Sriotchilism O'Zaic and Embodiment of Ignorance for saving me 15 bytes! Unfortunately those bytes were used to fix a bug Jo King mentioned.
Try it online

My first every golf code submission. Code is a functional interface that takes 2 integers and builds a string from those integers. The substring hack at the end hides a little quirk that duplicates the last element of the "array." Probably not the best solution, but for my first ever submission, I think I did well :)

Ink, 45 bytes

=h(I,A)
{I<=A:{I} {I<A:{A} ->h(I+1,A-1)}}->->

(I don't think there's an online interpreter for Ink, sorry)
Try it online!

Defines a stitch called h, which takes two arguments I and A, which are the bounds of the range.

Outputs by printing values, separated by spaces, to stdout.

Explanation

=h(min, max) // Define the stitch.
{min <= max:{min}/* print min unless it's greater than max */{min < max: {max} /*Also print max if it's greater than min*/->h(min+1, max-1)/*Then divert, with the arguments changed*/}}
->-> // If we didn't divert earlier, divert to wherever the stitch was called from

C (compiled with VC++ (Visual Studio 2017)) 264bytes

#include "stdafx.h"
void f(int l,int u){for(int t=1,h=0,H=0,i=0;i<u-l+1;i++,t^=1)printf("%d ",t?l+h++:u-H++);}void main(){f(1,5);}

choosing other Compiler may eliminate the Need for the include but vs2017 won't let me ommit it w/o Errors. the idea is to just use variables to Keep track of how many numbers have to be added to the Minimum or have to be subtracted from the maximum (2seperate variables) another variable is used to Keep track of from where the value has to be taken from front or from end. Setting it to 1 means lowest bit is set xor-ing it with 1 makes it toggle. i run a loop with the amount of iterations it takes to solve the Problem. inside the printf i use the Array Bounds and my variables to generate the number needed and increment my helper variables all at once. using the ternary Operator exp?then:else saves a few Bytes as it replaces a if-else Statement. further saving come through use of multiple variables defined in the for loop instead of only one (typically i) and putting the xor in the loop Header removes the Need for curly braces.

every Thing else i did is ommit spaces and linebreaks where possible and only use 1 character variable names and omitting ()s where ever possible

C (gcc), 54 53 52 bytes

s=1;f(x,y){printf("%d ",s*x),s=x-y?f(-y,~x,s=-s):1;}

Try it online!

C (gcc), 46 bytes

A recursive function, call as f(low, high). As an extra 0-byte bonus, if you call f(high, low) the opposite arrangement is produced.

f(x,y){printf("%i ",x);x-y&&f(y,x+1-2*(x>y));}

Try it online!

Degolf

f(x,y)
{
  printf("%i ",x); // Print the value of x
  x-y&& // If x-y == 0, the && operator shorts and the
        // recursion ends.
    f(y,x+1-2*(x>y)); // Adjust x by 1 towards y, and
                      // recurse with x and y swapped.
}

APL+WIN, bytes 17, 13, 26

4 bytes saved thank to Adám plus 13 bytes see Jonah's comment

(⍴m)↑∊m,¨⌽m←(1↓m)+0,⍳-/m←⎕

Try it online! Courtesy of Dyalog Classic

Explanation:

m←(1↓m)+0,⍳-/m←⎕ Prompts high end of range followed by low end and generates vector

∊m,¨⌽m Reverse the vector, pair elements from both vectors and flatten.           

(⍴m)↑ Select the elements to the length of the original vector

J, 23 bytes

[:(#$],@,.|.)[+i.@>:@-~

Try it online!

tinylisp, 48 bytes

(d f(q((A B)(c A(i(e A B)()(f B((i(l A B)a s)A 1

Try it online!

Explanation

The code defines a recursive function f that takes two arguments A and B, which are initially the lower and upper bounds of the range.

For example, with initial arguments 1 and 5:

Value   Next call
1       5, 2
5       2, 4
2       4, 3
4       3, 3
3       Return

with a resulting list of (1 5 2 4 3).

Somewhat ungolfed:

(load lib/utilities)

(def f
  (lambda (A B)
    (cons A
      (if (equal? A B)
        nil
        (f B
          ((if (less? A B) add2 sub2)
            A
            1))))))

Brachylog, 15 bytes

⟦₂{∅|b↔↰T&hg,T}

Input is a 2-element list [lo, hi]. Note that underscore is used for negative numbers. Try it online!

Explanation

⟦₂               2-argument inclusive range: [1,5] -> [1,2,3,4,5]
  {           }  Call this recursive predicate to calculate the output:
   ∅               Base case: the input is empty list; nothing to do
    |              Otherwise (recursive case):      [1,2,3,4,5]
     b             Behead the input list            [2,3,4,5]
      ↔            Reverse                          [5,4,3,2]
       ↰           Call the predicate recursively   [5,2,4,3]
        T          Label the result T
         &         Also, with the input list,
          h        Take the head                    1
           g       Wrap it in a list                [1]
            ,T     Append T from earlier            [1,5,2,4,3]

VBA (Excel), 62 bytes

Using immediate window and [a1] and [a2] as input.

a=[a1]:b=[a2]:For x=0To(b-a)/2:?a+x &IIf(b-x=a+x,"",b-x);:Next

Clojure, 62 bytes

#(distinct(let[r(range %1(inc %2))](interleave r(reverse r)))

Try it online!

Wow Clojure is a terrible golfing language. Still fun though.

JavaScript, 35 bytes

f=(a,b,s=1)=>a-b?a+[,f(b,a+s,-s)]:a

Try it online!

Thanks to Arnauld, 1 byte saved.

Wolfram Language (Mathematica), 56 54 bytes

This is my first time golfing!

f[a_,b_]:=(c=a~Range~b;Drop[c~Riffle~Reverse@c,a-b-1])

Try it online!

Saved 2 bytes using infix notation.

Explanation:

f[a_,b_]:=                                   \function of two variables
c=a~Range~b;                                 \list of integers from a to b 
                           Reverse@c         \same list in reverse
                  c~Riffle~Reverse@c         \interleave the two lists
             Drop[c~Riffle~Reverse@c,a-b-1]  \drop last |a-b-1| elements (note a-b-1 < 0)

Alternatively, we could use Take[...,b-a+1] for the same result.

Tests:

f[4, 6]
f[1, 5]
f[-1, 1]
f[-1, 2]

Ouput:

{4, 6, 5}
{1, 5, 2, 4, 3}
{-1, 1, 0}
{-1, 2, 0, 1}

Shortcuts for iOS, 20 Actions, 4 KB

Shortcuts is a visual scripting language, so the code is linked as a screenshot and download.

Screenshot (very tall) / Shortcut iCloud link

How it works:

getVariable (input.s)
if Equals (input.s)

This tests if input.s exists. input.s will be nothing if it does not exist. In shortcuts, nothing does not equal itself.

otherwise

There is no way to test for not equal in shortcuts other than using the else side of an if statement

dictionary {a:input.a, b:input.b, c:1}
setVariable (input)

To set a single key in a dictionary, you need to get the variable, set dictionary value, and re-set the variable. Creating a new dictionary here saves one action but takes more bytes. I am optimizing for actions here.

getVariable (input.a)
if Equals (input.b)
  getVariable(input.a)
otherwise

If both a and b are the same, this range only has one value. Values passed to otherwise are returned by End, similar to how ternary operators work in many languages.

number 0
calculate - (input.s)
getVariable (input.a)
calculate + (input.s)

No set variable is required because instead, magic variables are used to get the values from the calculate actions

dictionary{a: input.b, b:(Calculation Result), c: (Calculation Result)}

The two calculation results refer to different actions. The first to the a+s, and the second to the 0-s.

runShortcut ch-arrangement

Run this shortcut again with the new input and return the result.

To run, pass a dictionary containing a and b to the shortcut. Output is the list as a string (comma seperated). Screenshot / Link

There is no online interpreter for this. You need an iOS device and the Shortcuts app.

Logic from @ovs's javascript answer

JVM bytecode (OpenJDK asmtools JASM), 449 bytes

enum b{const #1=Method java/io/PrintStream.print:(I)V;static Method a:(II)V stack 2 locals 4{getstatic java/lang/System.out:"Ljava/io/PrintStream;";astore 3;ldc 0;istore 2;l:iload 2;ldc 1;if_icmpeq t;aload 3;iload 0;invokevirtual #1;iinc 0,1;iinc 2,1;goto c;t:aload 3;iload 1;invokevirtual #1;iinc 1,-1;iinc 2,-1;c:aload 3;ldc 32;i2c;invokevirtual java/io/PrintStream.print:(C)V;iload 0;iload 1;if_icmpne l;aload 3;iload 0;invokevirtual #1;return;}}

Ungolfed (and slightly cleaner)

 enum b {    
    public static Method "a":(II)V stack 5 locals 4 {
        getstatic "java/lang/System"."out":"Ljava/io/PrintStream;";
        astore 3;
        ldc 0;
        istore 2;
    loop:
        iload 2;
        ldc 1;
        if_icmpeq true;
    false:
        aload 3;
        iload 0;
        invokevirtual "java/io/PrintStream"."print":"(I)V";
        iinc 0,1;
        iinc 2,1;
        goto cond;
    true:
        aload 3;
        iload 1;
        invokevirtual "java/io/PrintStream"."print":"(I)V";
        iinc 1,-1;
        iinc 2,-1;
        goto cond;
    cond:
        iload 0;
        iload 1;
        if_icmpne loop;
        aload 3;
        iload 0;
        invokevirtual "java/io/PrintStream"."print":"(I)V";
        return;
    }
}

Standalone function, needs to be called from Java as b.a(num1,num2).

Explanation

This code uses the method parameters as variables, as well as a boolean in local #3 deciding which number to output. Each loop iteration either the left or right is output, and that number is incremented for the left or decremented for the right. Loop continues until both numbers are equal, then that number is output.

...I have a distinct feeling I'm massively outgunned on the byte count

PHP, 93 92 81 bytes

Standalone program, 81 bytes:

for($a=range($argv[1],$argv[2]);$a;)echo$x++%2?array_pop($a):array_shift($a),' ';

Try it online!

As a function, 92 bytes:

function($l,$h){for($a=range($l,$h);$a;)$b[]=$x++%2?array_pop($a):array_shift($a);return$b;}

Try it online!

function ( $l, $h ) {
    for( $a = range( $l, $h ); $a; ) {
        $b[] = $x++ % 2 ? array_pop( $a ) : array_shift( $a );
    }
    return $b;
}

Well, I thought it was a worth-trying idea. Perhaps in a more succinct language, this would work better. The Golf is not strong with this one.

Pyth, 10 8 bytes

{.iF_B}F

Try it here

Explanation

{.iF_B}F
      }FQ  Generate the range between the (implicit) inputs.
 .iF_B     Interleave it with its reverse.
{          Deduplicate.

F# (.NET Core), 69 67 bytes

Translation of @nimi's answer.

fun a b->let rec h=function|a::b->[a]@h(List.rev b)|n->n in h[a..b]

Try it online!

Cubix, 16 bytes

;w(.II>sO-?@;)^/

Try it here

Cubified

    ; w
    ( .
I I > s O - ? @
; ) ^ / . . . .
    . .
    . .

Explanation

Basically, this moves the two bounds closer together one step at a time until they meet. Each time through the loop, we swap the bounds, Output, take the difference, and increment with ) or decrement with ( based on the sign.

C# (Visual C# Interactive Compiler), 46 bytes

a=>b=>{for(;a<=b;Write(a+(b>a++?b--+"":"")));}

Saved 4 bytes thanks to dana!

Try it online!

C# (Visual C# Interactive Compiler), 65 bytes

void z(int a,int b){if(a<=b){Write(a+(b>a?b+"":""));z(a+1,b-1);}}

Try it online!

JavaScript (Node.js), 39 37 bytes

f=a=>b=>a+[,a-b?f(b)(a<b?a+1:a-1):[]]

Try it online!

Ruby, 37 36 33 bytes

f=->a,b{a>b ?[]:[a,b]|f[a+1,b-1]}

Try it online!

Recursive version with 3 bytes saved by G B.

Ruby, 38 bytes

->a,b{d=*c=a..b;c.map{d.reverse!.pop}}

Try it online!

Non-recursive version.

Haskell, 30 bytes

l%h=l:take(h-l)(h:(l+1)%(h-1))

Usage: 3%7 gives `[3,7,4,6,5]

For the inputs l, h the function calls recursively with the inputs l+1, h-1, and adds l,h to the beggining. Instead of any halting condition, the code uses take(h-l) to shorten the sequence to the right length (which would otherwise be an infinite sequence of increasing and decreasing numbers).

05AB1E, 6 bytes

ŸDvć,R

Try it online!

Explanation

Ÿ        # push range [min ... max]
 D       # duplicate
  v      # for each element in the copy
   ć,    # extract and print the head of the original list
     R   # and then reverse it

Clean, 48 bytes

import StdEnv
$a b|a<>b=[a: $b(a+sign(b-a))]=[a]

Try it online!

Haskell, 30 bytes

a%b=a:take(b-a)(b:(a+1)%(b-1))

Try it online!

Perl 6, 32 bytes

{flat($_ Z [R,] $_)[^*/2]}o&[..]

Try it online!

Not too complicated, but there's a couple of tricks that help make the program shorter

Explanation:

{                        }o&[..]   # Convert the two inputs to a range
      $_ Z [R,] $_                 # Zip the range with its reverse
 flat(            )                # Flatten
                   [^*/2]          # And take the first half of the elements

Charcoal, 17 bytes

≔…·NNθWθ«≔⮌θθ⟦I⊟θ

Try it online! Link is to verbose version of code. Explanation:

≔…·NNθ

Create an inclusive range between the two inputs.

Wθ«

Repeat until it is empty.

≔⮌θθ

Reverse it.

⟦I⊟θ

Remove the last element and print it on its own line.

Jelly, 6 bytes

rạṂ¥Þ,

Try it online!

R, 38 37 36 bytes

function(a,b)rbind(a:b,b:a)[a:b-a+1]

Try it online!

Exploiting the fact that R stores matrices column-wise

Java (JDK), 52 bytes

(l,h,o)->{for(int i=0;l<=h;i^=1)o.add(i<1?l++:h--);}

Try it online!

Gol><>, 22 bytes

IIT}:nP}:nM2K(?t2K=?h;

Fixed!!! It had a major bug where it would sometimes append a zero when not necessary, but no longer!

Try it online!

Julia 0.7, 29 bytes

f(a,b)=[a:b b:-1:a]'[1:1+b-a]

Try it online!

Forth (gforth), 52 bytes

: f 2dup - 1+ 0 do dup . i 2 mod 2* 1- - swap loop ;

Try it online!

Explanation

Loop from 0 to (End - Start). Place End and Start on top of the stack.

Each Iteration:

Code Explanation

: f           \ start new word definition
  2dup -      \ get the size of the range (total number of integers)
  1+ 0        \ add 1 to the size because forth loops are [Inclusive, Exclusive) 
  do          \ start counted loop from 0 to size+1
    dup .     \ output the current top of the stack
    i 2 mod   \ get the index of the loop modulus 2
    2* 1-     \ convert from 0,1 to -1,1
    -         \ subtract result from top of stack (adds 1 to lower bound and subtracts 1 from upper)
    swap      \ swap the top two stack numbers 
  loop        \ end the counted loop
;             \ end the word definition

JavaScript, 40 bytes

l=>g=h=>h>l?[l++,h--,...g(h)]:h<l?[]:[l]

Try It Online!

Perl 5 -ln, 37 bytes

@.=$_..<>;say shift@.,$/,pop@.while@.

Try it online!

C#(Visual C# Interactive Compiler), 62 bytes

void a(int i,int j){Write((j-i)%2==0?i++:j--);if(i<=j)a(i,j);}

Try it online!

Haskell, 52 bytes

x?y=take(y+1-x).map head$iterate(reverse.tail)[x..y]

Try it online!

Haskell, 39 bytes

f(a:b)=a:f(reverse b)
f x=x
a#b=f[a..b]

Try it online!

cQuents, 19 bytes

#|B-A+1&A+k-1,B-k+1

Try it online!

Note that it does not work on TIO right now because TIO's interpreter is not up to date.

Explanation

#|B-A+1&A+k-1,B-k+1
                      A is the first input, B is the second input
#|B-A+1               n = B - A + 1
       &              Print the first n terms of the sequence
                      k starts at 1 and increments whenever we return to the first term
        A+k-1,         Terms alternate between A + k - 1 and
              B-k+1     B - k + 1
                       increment k

R, 65 64 61 60 bytes

-1 byte thanks to Robert S.

-4 more thanks to digEmAll

x=scan();z=x:x[2];while(sum(z|1)){cat(z[1],"");z=rev(z[-1])}

Try it online!

MATL, 8 bytes

&:t"1&)P

Try it online!

Explanation

&:      % Take two inputs (implicit). Two-input range
t       % Duplicate
"       % For each
  1&)   %   Push first element, then an array with the rest
  P     %   Reverse array
        % End (implicit). Display (implicit)

R, 51 bytes

function(x,y,z=x:y)matrix(c(z,rev(z)),2,,T)[seq(z)]

Try it online!

Explanation: For a sequence x:y of length N, create a two-by-N matrix consisting of the sequence x:y in the top row and y:x in the bottom row matrix(c(z,rev(z)),2,,T). If we select the first N elements of the matrix [seq(z)], they will be chosen by column, giving the required output.

Outgolfed by digEmAll

PowerShell, 59 48 bytes

param($a,$b)(($z=0..($b-$a))|%{$a+$_;$b-$_})[$z]

Try it online!

(Seems long...)

Takes input $a and $b, constructs the range 0 .. ($b-$a), stores that into $z, then loops through that range. The looping through that range is just used as a counter to ensure we get enough iterations. Each iteration, we put $a and $b on the pipeline with addition/subtraction. That gives us something like 1,5,2,4,3,3,4,2,5,1 so we need to slice into that from 0 up to the $b-$a (i.e., the count) of the original array so we're only left with the appropriate elements. That's left on the pipeline and output is implicit.

-11 bytes thanks to mazzy.

Japt, 7 bytes

Takes input as an array.

rõ
ÊÆÔv

Try it or run all test cases

         :Implicit input of array U=[low,high]
r        :Reduce by
 õ       :  Inclusive, reversed range (giving the range [high,low])
\n       :Reassign to U
Ê        :Length
 Æ       :Map the range [0,Ê)
  Ô      :  Reverse U
   v     :  Remove the first element

C# (.NET Core), 66 bytes

a=>b=>{var s="";for(;b>=a;)s+=a+" "+(b==a++?"":b--+" ");return s;}

Try it online!

Haskell, 39 bytes

a#b|a>b=a:b#(a-1)|a<b=a:b#(a+1)|1>0=[a]

Try it online!

Python 2, 44 bytes

f=lambda a,b:[a]*(a==b)or[a]+f(b,a-cmp(a,b))

Try it online!

Stax, 7 bytes

É╓ÅìΔà▲

Run and debug it

APL (dzaima/APL), 21 bytes

⌈⊢+.5×-+∘(⌽ׯ1*)∘⍳1+-

Try it online!

Japt, 14 bytes

òV
íUs w)c vUl

Try it online!