g | x | w | all
Bytes Lang Time Link
042AWK250908T180856Zxrs
009Vyxal 1.0.1210120T071723Zlyxal
004Vyxal230618T090651Zemanresu
8775Scala230419T115117Z138 Aspe
005Thunno 2230618T085437ZThe Thon
033Zsh*230126T074441Zroblogic
073JavaScript230126T100533ZEzioMerc
027Arturo230126T063722Zchunes
008Japt181108T090729ZShaggy
022Ly230126T092022Zcnamejj
046Perl 5 pl210127T192011ZXcali
067F#210127T170021Zroot
005Husk210120T054725ZRazetime
040Python 2181108T091801ZTFeld
075JavaScript181124T181058Zguest271
086C# Visual C# Interactive Compiler181112T061857Zdana
041Python 3181108T091507Zcobaltp
062Haskell181110T165332Zschueler
005APL Dyalog Extended181114T054157ZAdá
140C++181109T130932ZHatsuPoi
441C# .NET Core181108T152410ZNtFreX
068F# Mono181112T051912Zdana
034TIBASIC181108T180834Zkamoroso
099C# .NET Core181110T101006ZJo King
062Bash181110T055633ZJonah
085D181110T023743ZAdalynn
058perl M5.010 alE181109T182542Zuser7392
060C clang181109T143737Zuser3604
028APLNARS181109T155748Zuser5898
068Racket181109T130933ZGalen Iv
062Java 10181108T100641ZKevin Cr
051JavaScript ES6181108T170317ZArnauld
061Clojure181109T041939ZTheGreat
147JAVA181108T223346Zisaace
102PHP181108T200407ZArtistic
048Python 3181108T180157Zglietz
076JavaScript ES6181108T182844ZNikko Kh
057Python 3181108T174812Zdana
555Java181108T165437ZMarco Tu
097JavaScript ES6181108T165722ZJake Tay
085Tcl181108T153008Zsergiol
013J181108T152454ZFrownyFr
035Python 2 Cython181108T132209ZDennis
041Powershell181108T145133Zmazzy
045Octave181108T104905ZLuis Men
029APL Dyalog Classic181108T141002ZGalen Iv
065C gcc181108T112559Znwellnho
026J181108T125807ZGalen Iv
040Python 2181108T130636ZErik the
041Python 2181108T102258ZElPedro
040Ruby181108T090129ZG B
004Jelly181108T124102ZDennis
030R181108T093532ZKirill L
053QBASIC181108T105917Zsteenber
049Clean181108T111507ZΟurous
034Haskell181108T105854Znimi
022Perl 6181108T093507Znwellnho
075Red181108T102540ZGalen Iv
005Pyth181108T102356ZSok
051Python 3181108T092117ZHori
084Dart181108T101032ZElcan
107Batch181108T095428ZNeil
015Charcoal181108T094200ZNeil
00405AB1E181108T090931ZEmigna

AWK, 42 bytes

{for(x=$1;(x-$2)^2>1;)$++NF=x>$2?--x:++x}1

Attempt This Online!

Vyxal 1.0.1, 9 bytes

=[‿|₌‿⁂JU

Don't even think about trying it Online.

Explained

The output for this challenge is the two input numbers paired together joined with the range between those two numbers. However, there can't be any duplicates in the joined list, so it needs to be uniquified by order of appearance. But we also need to make sure that the two numbers aren't the same: otherwise, a singleton will be returned.

Vyxal, 4 bytes

ṡÞẇJ

Try it Online! (inputs are swapped)

ṡ    # Inclusive range
 Þẇ  # Push [first, last] and rest
   J # Concatenate

Scala, 87 75 bytes

Golfed version. Try it online!

(a,b)=>a::b::(if(a>b)(a to b by-1).drop(1)else(a to b by 1).drop(1)).toList

Ungolfed version.

object Main {
  def main(args: Array[String]): Unit = {
    val f = (a: Int, b: Int) => {
      a :: b :: (if (a > b) (a to b by -1).drop(1) else (a to b by 1).drop(1)).toList
    }
    println(f(0, 5)) // List(0, 5, 1, 2, 3, 4)
    println(f(-3, 8)) // List(-3, 8, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7)
    println(f(4, 4)) // List(4, 4)
    println(f(4, 5)) // List(4, 5)
    println(f(8, 2)) // List(8, 2, 7, 6, 5, 4, 3)
    println(f(-2, -7)) // List(-2, -7, -3, -4, -5, -6)
  }
}

Thunno 2, 5 bytes

ẸIḣṫḥ

Attempt This Online!

Explanation

ẸIḣṫḥ  # Implicit input   ->  [8, 2]
Ẹ      # Dump onto stack  ->  8, 2
 I     # Inclusive range  ->  [8,7,6,5,4,3,2]
  ḣ    # Remove head      ->  [7,6,5,4,3,2]
   ṫ   # Remove tail      ->  [7,6,5,4,3]
    ḥ  # Concatenate      ->  [8,2,7,6,5,4,3]
       # Implicit output

Zsh*, 33 bytes

A=({$1..$2});<<<$@\ ;<<<${A:1:-1}

Try it online!

(*) Using set -o err_return

JavaScript, 73 bytes

Without recursion:

(s,e,m=s>e?-1:1)=>[s,e,...[...Array(m*(e-s||1)-1)].map((_,i)=>s+m*(i+1))]

Try it:

f=(s,e,m=s>e?-1:1)=>[s,e,...[...Array(m*(e-s||1)-1)].map((_,i)=>s+m*(i+1))]

console.log(JSON.stringify(f(0,5)));
console.log(JSON.stringify(f(-3,8)));
console.log(JSON.stringify(f(4,4)));
console.log(JSON.stringify(f(4,5)));
console.log(JSON.stringify(f(8,2)));
console.log(JSON.stringify(f(-2,-7)));

Arturo, 30 28 27 bytes

$[x,y][p:@[x,y]p++--x..y p]

Try it

$[x,y][               ; a function taking arguments x and y
    p: @[x,y]         ; assign the list [x,y] to p
    p ++              ; append something to p
    --x..y p          ; the range x to y without p
]                     ; end function, implicit return

Japt, 8 bytes

cUr!õ kU

Try it here

             :Implicit input of array U
c            :Concatenate
 Ur          :  Reduce U by
   !õ        :   Inclusive range
      kU     :  Remove all elements in original U

Ly, 22 bytes

nnsaRl=[pr0]pu' oru' o

Try it online!

The tricky bits here are that the range function in Ly only works if the start/end are sorted. So the code has to conditionally flip the sequence of numbers before printing them.

nna                    - read in the start/end, stash the 2nd number
   aR                  - sort and generate the inclusive range
     l=                - does the 2nd number match the max of the range?
       [p 0]p          - "then" clause
         r             - reverse the stack
             u' o      - output the starting number and a space
                 r     - reverse the stack
                  u' o - output the ending number
                       - the sequence left on the stack prints automatically

Perl 5 -pl, 46 bytes

/ /;$_.=join$",'',$`+1..$'-1,reverse$'+1..$`-1

Try it online!

F#, 67 bytes

let f x y=if(y-x<0)then[x;y]@List.rev[y+1..x-1]else[x;y]@[x+1..y-1]

Try it online!

Appends a list containing x and y and a list iterating from x+1 to y-1 (if positive) or a list in reverse iteration order from y+1 to x-1 (if negative)

Husk, 5 bytes

+¹ht…

Try it online!

Thanks to Dominic Van Essen for the fix.

Python 2, 47 41 40 bytes

lambda a,b:[a,b]+range(a,b,a<b or-1)[1:]

Try it online!

Here's mine, now that a lot of other Python answers have been posted

-6 bytes, thanks to G B

JavaScript, 75 bytes

(a,b,n=-~(a>b?a-b:b-a)-2)=>[a,b,...[...Array(n<2?0:n)].map(_=>a<b?++a:--a)]

Try it online!

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

x=>y=>{var l=new List<int>{x,y};for(int s=x>y?-1:1;x!=y&(x+=s)!=y;)l.Add(x);return l;}

Try it online!

-1 thanks @auhmaan!

Python 3, 52 48 47 42 41 bytes

lambda a,b:[a,b,*range(a,b,-(a>b)|1)[1:]]

Try it online!


Combined former implementations.

Haskell, 18 34 bytes as function, 46 52 as an IO action, 56 62 as program

x!y=x:y:[x+1..y-1]++[x-1,x-2..y+1]

or, as an IO action to take input, there are these options (all the same length):

main=(\x y->x:y:[x+1..y-1]++[x-1,x-2..y+1])<$>readLn<*>readLn
--
x!y=x:y:[x+1..y-1]++[x-1,x-2..y+1]
main=(!)<$>readLn<*>readLn
--
f x y=x:y:[x+1..y-1]++[x-1,x-2..y+1]
main=f<$>readLn<*>readLn

or, as an IO action taking input and printing the result:

main=((\x y->x:y:[x+1..y-1]++[x-1,x-2..y+1])<$>readLn<*>readLn)>>=print
--
x!y=x:y:[x+1..y-1]++[x- 1,x-2..y+1]
main=((!)<$>readLn<*>readLn)>>=print
--
f x y=x:y:[x+1..y-1]++[x-1,x-2..y+1]
main=(f<$>readLn<*>readLn)>>=print

The last one is also available on Try It Online! (You can try it online there)
Please remember that TIO requires the input be entered beforehand in the "Input" box.

De-golfed:

enumerate' x y = x : y : [x + 1 .. x - 1] ++ [x - 1 , x - 2 .. y + 1]
main = do x <- readLn
          y <- readLn
          print (enumerate' x y)

Note: : is an operator to prefix an element to a list.

Note: a!b will not work if -XBangBatterns is enabled.
Use a#b instead.

Note: -XNegativeLiterals will break this. Insert a space between x- and 1.
This will parse as x + (negate 1) instead of x $ (-1).

APL (Dyalog Extended), 5 bytes

Anonymous infix function.

,,…~,

Try it online!

, the first and last (lit. the concatenation of the arguments)

, and (lit. concatenated to)

 the range

~ without

, the first and last (lit. the concatenation of the arguments)

C++, 143 140 bytes

-3 bytes thanks to Zacharý

#define V std::vector<int
#include<vector>
V>f(int a,int b){V>v{a,b};int c=2*(b>a)-1;for(int i=a+c;a!=b&&b!=i;i+=c)v.push_back(i);return v;}

How to use :

In the main function :

std::cout << f(0, 5) << '\n';
std::cout << f(-3, 8) << '\n';
std::cout << f(4, 4) << '\n';
std::cout << f(4, 5) << '\n';
std::cout << f(8, 2) << '\n';
std::cout << f(-2, -7) << '\n';

also add :

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    os << "[ ";
    for (const auto& a : v) {
        os << a << ' ';
    }
    return os << ']';
}

C# .NET Core, 56 441 bytes

Here is my corrected solution without predefined input variables and without string joining.

(a,b)=>n(a,b).c(k(a-b)>1?b>a?r(a+1,b-a-1):r(b+1,a-b-1).i():n());

Try it online!

n(a,b)               => returns new array with a and b in it
  c(                 => concat the following content
    k(a-b)>1         => when absolute value of a-b greater then one
      b>a            => when b bigger a
        r(a,b-a)     => range from a to b-a
        r(b,a-b).i() => else range from b to a-b reversed
      n()            => else empty array

I've created and used the following declarations. When I include those and the minimum code required to compile in the byte count I get 640 bytes.

public static class Extensions{
  public static IEnumerable<T> c<T>(this IEnumerable<T> a, IEnumerable<T> b) => a.Concat(b);
  public static IEnumerable<T> i<T>(this IEnumerable<T> a) => a.Reverse();
}

public static Func<int, int> k = Math.Abs;
public static Func<int, int, IEnumerable<int>> r = Enumerable.Range;
public static int[] n(params int[] a) => a;

using System.Linq;using System.Collections.Generic;using System;public static class E{public static IEnumerable<T> c<T>(this IEnumerable<T> a,IEnumerable<T> b)=>a.Concat(b);public static IEnumerable<T> i<T>(this IEnumerable<T> a)=>a.Reverse();}public class P{public static Func<int,int> k=Math.Abs;public static Func<int,int,IEnumerable<int>> r=Enumerable.Range;public static int[] n(params int[] a)=>a;public static void Main(string[] args){Console.WriteLine($"[ {string.Join(", ", f(int.Parse(args[0]), int.Parse(args[1])))} ]");}public static Func<int,int,IEnumerable<int>> f=(a,b)=>n(a,b).c(k(a-b)>1?b>a?r(a,b-a):r(b,a-b).i():n());}

F# (Mono), 68 bytes

let f x y=
 let s=if x<y then 1 else-1
 Seq.append[x;y][x+s..s..y-s]

Try it online!

TI-BASIC, 35 34 bytes

-1 byte from Misha Lavrov

Prompt A,B
Disp A,B
cos(π(A>B
For(I,A+Ans,B-Ans,Ans
Disp I
End

C# (.NET Core), 99 bytes

a=>b=>new[]{a,b}.Concat(b>a?Enumerable.Range(a+1,b+~a):Enumerable.Range(b+1,a!=b?a+~b:0).Reverse())

Try it online!

First (and probably last) time golfing in C#.

Bash, 62 bytes

a=($(seq $1 $2|tr $'\n' ' '))
echo $@ ${a[@]:1:((${#a[@]}-2))}

explanation

seq does we want but produces lines, tr turns the lines into space-delimited output, the outer parens make that into an array. $@ is the original input, and the rest of it slices the 0-indexed array from 1 and takes the next "array len - 2" chars.

Try it online!

(NOTE: not all test cases work on TIO for reasons i don't understand, but they do work on my local machine)

D, 85 bytes

T[]f(T)(T a,T b){T[]v=[a,b];T c=2*(b>a)-1;for(T i=a+c;a!=b&&b!=i;i+=c)v~=i;return v;}

Try it online!

A port of @HatsuPointerKun's C++ answer into D.

perl -M5.010 -alE, 58 bytes

@_=($F[0]..$F[1],reverse$F[1]..$F[0]);say"$_ @_[1..$#_-1]"

This reads two integers (on a single line, separated by whitespace) from STDIN and writes the result to STDOUT.

C (clang), 60 bytes

f(a,b,c)int*c;{for(*c++=a,*c++=b;(a<b?++a<b:--a>b);*c++=a);}

Try it online!

APL(NARS), 14 chars, 28 bytes

{⍺⍵,¯1↓1↓⍺..⍵}

test

  f←{⍺⍵,¯1↓1↓⍺..⍵}
  ¯3 f 8
¯3 8 ¯2 ¯1 0 1 2 3 4 5 6 7 
  0 f 5      
0 5 1 2 3 4 

Racket, 68 bytes

(define(f a b)(let([s(if(> a b)-1 1)])(list* a b(range(+ a s)b s))))

Try it online!

The same as TheGreatGeek's Clojure solution

Java 10, 109 108 104 102 93 62 bytes

Using a space-delimited String:

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

Try it online.

Using a List:

b->a->{var r=new java.util.Stack();for(r.add(a),r.add(b);a<b?++a<b:--a>b;)r.add(a);return r;}

Try it online.

(a<b?++a<b:--a>b can be ++a<b||(a-=2)>b for the same byte-count: Try it online for the String or Try it online for the List.)


Old (109 108 104 102 101 bytes) answer using an array:

a->b->{int s=a<b?1:-1,i=a!=b?(b-a)*s+1:2,r[]=new int[i];for(r[0]=a,r[1]=b;i>2;)r[--i]=b-=s;return r;}

-7 bytes thanks to @nwellnhof.

Try it online.

Explanation:

a->b->{                // Method with 2 int parameters & int-array return-type
  int s=               //  Step integer, starting at:
        a<b?1          //   1 if the first input is smaller than the second
        :-1;           //   -1 otherwise
      i=               //  Array-index integer, starting at:
        a!=b?          //   If the inputs aren't equal:
         (b-a)*s+1     //    Set it to the absolute difference + 1
        :              //   Else:
         2,            //    Set it to 2
      r[]=new int[i];  //  Result-array of that size
  for(r[0]=a,          //  Fill the first value with the first input
      r[1]=b;          //  And the second value with the second input
      i>2;)            //  Loop `i` downwards in the range [`i`,2):
    r[--i]=            //   Decrease `i` by 1 first with `--i`
                       //   Set the `i`'th array-value to:
           b-=s;       //    If the step integer is 1: decrease `b` by 1
                       //    If the step integer is -1: increase `b` by 1
                       //    And set the array-value to this modified `b`
  return r;}           //  Return the result-array

JavaScript (ES6), 51 bytes

Takes input as (a)(b).

a=>g=(b,c=b)=>(b+=b<a|-(b>a))-a?[...g(b,c),b]:[a,c]

Try it online!

Commented

a =>                // main function, taking a
  g = (             // g = recursive function
    b,              //     taking b
    c = b           // we save a backup of the original value of b into c
  ) =>              //
    (b +=           // add to b:
      b < a |       //   +1 if b is less than a
      -(b > a)      //   -1 if b is greater than a
    )               //   (or 0 if b = a)
    - a ?           // if the updated value of b is not equal to a:
      [             //   generate a new array:
        ...g(b, c), //     prepend all values generated by a recursive call
        b           //     append the current value of b
      ]             //
    :               // else:
      [a, c]        //   stop recursion and return the first 2 values: a and c

Clojure, 61 bytes

(fn[[a b]](def s(if(> a b)-1 1))(list* a b(range(+ a s)b s)))

An anonymous function that takes a 2-vector as input and returns a list.

Try it online!

Explanation

(fn [[a b]] ; An anonymous function that accepts a 2-vector as input, and destructures it to a and b
  (def s (if (> a b) -1 1)) ; If a > b assigns -1 to s and assigns 1 to s otherwise. This determines the order of the elements of the output list.
  (list* a b ; Creates a list with a and b as the first two elements. The remaining elements will be appended from the following range:
    (range (+ a s) b s))) ; A range starting at a+s and ending at b with step s

JAVA 147 bytes

f(int a, int b){System.out.print(a+""+b);if(a<b){for(int i=a+1; i<b;i++){System.out.print(i);}}else{for(int i=a-1;i>b;i--){System.out.print(i);}}}

PHP (102 bytes)

function t($a,$b){count($r=range($a,$b))>1?array_splice($r,1,0,array_pop($r)):$r=[$a,$b];print_r($r);}

Sandbox

Unfortunately (for golf) PHP has rather verbose function names, which contribute a lot to the length. But the basic idea is to create a range, then pop off the last element and stitch it back in at offset 1. For the 4,4 example I had to add count($r=range($a,$b))>1?...:$r=[$a,$b]; which adds quite a bit, and unfortunately array_splice() is by reference which hit me for a few more bytes ($r= and a ;). All because of that "edge case", lol.

Well anyway enjoy!

Python 3, 53 48 bytes

-5 bytes thanks to @mypetlion.

lambda a,b:[a,b,*range(a+1-2*(a>b),b,1-2*(a>b))]

Try it online!

JavaScript (ES6), 76 bytes

(a,b,c=[a,b])=>{c[c.length]=a<b?++a:--a;return a==b?(c.pop()+1&&c):f(a,b,c)}

invocation should not pass the third argument: f(-9,9)

Try it online!

im still thinking...

Python 3, 57 bytes

def m(a,b):s=(1,-1)[a>b];return[a,b]+list(range(a+s,b,s))

Try it online!

Java, 739, 555 bytes

 public static List<Integer> firstLastAndEverythingBetween(final int a, final int b) { if (a == b) { return addAB(a, b); } final List<Integer> result = addAB(a, b); int initial = getInitial(a, b); for (int n = 1; n < Math.abs(b - a); n++) { result.add(initial); if (b > a) { initial++; } else { initial--; } } return result; } private static int getInitial(int a, int b) { return (b > a) ? (a + 1) : (a - 1); } private static List<Integer> addAB(int a, int b) { final List<Integer> result = new ArrayList<>(); result.add(a); result.add(b); return result; }

JavaScript (ES6), 97 bytes

a=>b=>[a,b,...((c,d)=>c==d?[]:(s=(m=Math).min(a,b),Array(m.abs(a-b)-1).fill().map(n=>++s)))(a,b)]

Can probably be improved!!

Tcl, 85 bytes

proc R a\ b {puts $a\n$b
if $a>$b {lassign $a\ $b b a}
while {[incr a]<$b} {puts $a}}

Try it online!

J, 13 bytes

,,<.+i.@-~-.=

Try it online!

     i.@-~       range [0 .. |difference|-1], reverse if the difference is positive
          -.=    remove the zero (either "=" is 0 or there’s nothing to remove)
  <.+            to each element add the smaller of the args
,,               prepend args

Python 2 (Cython), 36 35 bytes

lambda x:x+range(*x,-cmp(*x)|1)[1:]

Thanks to @nwellnhof for golfing off 1 byte!

Try it online!


Python 2, 37 bytes

lambda x:x+range(*x+[-cmp(*x)|1])[1:]

Thanks to @JonasAusevicius for the port to CPython!

Try it online!

Powershell, 41 bytes

param($a,$b)$a;$b;$a..$b|?{$_-notin$a,$b}

Less golfed test script:

$f = {

param($a,$b)
$a                # push $a to a pipe
$b                # push $b to a pipe
$a..$b|?{         # push to pipe all integers from $a to $b
    $_-notin$a,$b # ...except $a and $b itself
}

}

@(
    ,( 0,  5  ,   0, 5, 1, 2, 3, 4)
    ,(-3,  8  ,   -3, 8, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7)
    ,( 4,  4  ,   4, 4)
    ,( 4,  5  ,   4, 5)
    ,( 8,  2  ,   8, 2, 7, 6, 5, 4, 3)
    ,(-2, -7  ,   -2, -7, -3, -4, -5, -6)
) | % {
    $a,$b,$expected = $_
    $result = &$f $a $b
    "$("$result"-eq"$expected"): $result"
}

Output:

True: 0 5 1 2 3 4
True: -3 8 -2 -1 0 1 2 3 4 5 6 7
True: 4 4
True: 4 5
True: 8 2 7 6 5 4 3
True: -2 -7 -3 -4 -5 -6

Explanation:

The basic concept of Powershell is the pipe. Pipe is an array. All results that push into the pipe fall into the array. So we should just push the values into the pipe in the correct order.

Octave, 45 bytes

@(a,b)[a b linspace(a,b,(t=abs(a-b))+1)(2:t)]

Try it online!

APL (Dyalog Classic), 29 bytes

{⍺,⍵,(⌽⍣(⍺>⍵))(⍺⌊⍵)+¯1↓⍳|⍺-⍵}

Try it online!

A port of my J solution

C (gcc), 65 bytes

f(a,b){for(printf("%d %d",a,b);a<b?++a<b:--a>b;)printf(" %d",a);}

Try it online!

Not very exciting. The loop increment is borrowed from an early version of Kevin Cruijssen's Java answer.

J, 26 bytes

,,[|.@]^:(>{.)<.+1}.i.@|@-

Try it online!

Explanation:

A dyadic verb (takes left and right argument)

                         -    subtracts the arguments
                       |@     and finds the absolute value
                    i.@       and makes a list 0..absolute difference
                 1}.          drops the fist element
                +             adds to the entire list
              <.              the smaller of the arguments
   |.@]                       reverses the list
       ^:                     only if
  [                           the left argument
         (>{.)                is greater than the first item of the list
 ,                            appends the list to
,                             the right argument appended to the left one

Python 2, 40 bytes

lambda x,y:[x,y]+range(x,y,-(y<x)|1)[1:]

Try it online!

Python 2, 52 47 41 bytes

lambda i,j:[i,j]+range(i,j,(i<j)*2-1)[1:]

Try it online!

-5 with thanks to @JoKing

-6 by slicing the first element from the range (idea stolen from and with credit to @TFeld)

Non-lambda version...

Python 2, 51 49 47 bytes

i,j=input();print[i,j]+range(i,j,(i<j)*2-1)[1:]

Try it online!

-2 with thanks to @JoKing

Ruby, 33 40 bytes

->a,b{[a,b]+[*a..b,*a.downto(b)][1..-2]}

Try it online!

Temporary fix, trying to find a better idea

Jelly, 4 bytes

,œ|r

Try it online!

How it works

,œ|r  Main link. Left argument: a. Right argument: b

,     Pair; yield [a, b].
   r  Range; yield [a, ..., b].
 œ|   Perform multiset union.

R, 39 33 30 bytes

c(a<-scan(),setdiff(a:a[2],a))

Try it online!

Thanks for saved bytes to user2390246 and J.Doe.

QBASIC, 39 53 bytes

INPUT a,b
?a
?b
FOR q=a+1TO b-1 STEP SGN(b-a)
?q
NEXT

Added the STEP parameter to account for a>b, and that uses the SGN() function to get a -1 or a +1 as increment. This however breaks the REPL because the SGN() function isn't implemented there...

Try it (the old answer) online!

Clean, 49 bytes

import StdEnv
@a b=init[a,b:tl[a,a+sign(b-a)..b]]

Try it online!

Haskell, 34 bytes

a#b=a:b:[a+1..b-1]++[a-1,a-2..b+1]

Try it online!

Perl 6, 26 22 bytes

{|@_,|[...^](@_).skip}

Try it online!

Explanation

{                    }
 |@_,   # Slip args a,b into result
      [...^](@_)  # Reduce args a,b with ...^ operator, same as a...^b
                .skip  # Skip first element
     |  # Slip into result

Red, 75 bytes

func[a b][s: sign? d: b - a prin[a b]loop absolute d - s[prin[""a: a + s]]]

Try it online!

Pyth, 5 bytes

+QtrF

Input is a two-element list, [input 1, input 2]. Try it online here, or verify all the test cases at once here.

+QtrFQ   Implicit: Q=eval(input())
         Trailing Q inferred
   rFQ   Generate range [input 1 - input 2)
  t      Discard first element
+Q       Prepend Q

Python 3, 64 62 51 bytes

lambda a,b:[a,b]+[*range(a+1,b)]+[*range(a-1,b,-1)]

Try it online!

Python 2, 58 45 bytes

lambda a,b:[a,b]+range(a+1,b)+range(a-1,b,-1)

Try it online!

Dart, 85 84 bytes

f(a,b)=>[a,b]+((a-b).abs()>1?List.generate((a-b).abs()-1,(i)=>(a>b?-i-1:i+1)+a):[]);

Try it online!

  • -1 by going from >= to >

  • Batch, 107 bytes

    @echo %1
    @echo %2
    @for %%s in (1 -1)do @for /l %%i in (%1,%%s,%2)do @if %1 neq %%i if %%i neq %2 echo %%i
    

    Takes input as command-line arguments. Explanation:

    @echo %1
    @echo %2
    

    Output the two integers.

    @for %%s in (1 -1)do
    

    Try both ascending and descending ranges.

    @for /l %%i in (%1,%%s,%2)do
    

    Loop over the inclusive range.

    @if %1 neq %%i if %%i neq %2
    

    Exclude the two integers.

    echo %%i
    

    Output the current value.

    Charcoal, 15 bytes

    IE²NI…⊕θηI⮌…⊕ηθ
    

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

    IE²N
    

    Print the inputs on separate lines.

    I…⊕θη
    

    Print the ascending range, if any.

    I⮌…⊕ηθ
    

    Print the reverse ascending reverse range, if any.

    05AB1E, 4 bytes

    Ÿ¦¨«
    

    Try it online!

    Explanation

        Ÿ      # inclusive range [a ... b]
         ¦¨    # remove the first and last element
           «   # append to input