| Bytes | Lang | Time | Link |
|---|---|---|---|
| 042 | AWK | 250908T180856Z | xrs |
| 009 | Vyxal 1.0.1 | 210120T071723Z | lyxal |
| 004 | Vyxal | 230618T090651Z | emanresu |
| 8775 | Scala | 230419T115117Z | 138 Aspe |
| 005 | Thunno 2 | 230618T085437Z | The Thon |
| 033 | Zsh* | 230126T074441Z | roblogic |
| 073 | JavaScript | 230126T100533Z | EzioMerc |
| 027 | Arturo | 230126T063722Z | chunes |
| 008 | Japt | 181108T090729Z | Shaggy |
| 022 | Ly | 230126T092022Z | cnamejj |
| 046 | Perl 5 pl | 210127T192011Z | Xcali |
| 067 | F# | 210127T170021Z | root |
| 005 | Husk | 210120T054725Z | Razetime |
| 040 | Python 2 | 181108T091801Z | TFeld |
| 075 | JavaScript | 181124T181058Z | guest271 |
| 086 | C# Visual C# Interactive Compiler | 181112T061857Z | dana |
| 041 | Python 3 | 181108T091507Z | cobaltp |
| 062 | Haskell | 181110T165332Z | schueler |
| 005 | APL Dyalog Extended | 181114T054157Z | Adá |
| 140 | C++ | 181109T130932Z | HatsuPoi |
| 441 | C# .NET Core | 181108T152410Z | NtFreX |
| 068 | F# Mono | 181112T051912Z | dana |
| 034 | TIBASIC | 181108T180834Z | kamoroso |
| 099 | C# .NET Core | 181110T101006Z | Jo King |
| 062 | Bash | 181110T055633Z | Jonah |
| 085 | D | 181110T023743Z | Adalynn |
| 058 | perl M5.010 alE | 181109T182542Z | user7392 |
| 060 | C clang | 181109T143737Z | user3604 |
| 028 | APLNARS | 181109T155748Z | user5898 |
| 068 | Racket | 181109T130933Z | Galen Iv |
| 062 | Java 10 | 181108T100641Z | Kevin Cr |
| 051 | JavaScript ES6 | 181108T170317Z | Arnauld |
| 061 | Clojure | 181109T041939Z | TheGreat |
| 147 | JAVA | 181108T223346Z | isaace |
| 102 | PHP | 181108T200407Z | Artistic |
| 048 | Python 3 | 181108T180157Z | glietz |
| 076 | JavaScript ES6 | 181108T182844Z | Nikko Kh |
| 057 | Python 3 | 181108T174812Z | dana |
| 555 | Java | 181108T165437Z | Marco Tu |
| 097 | JavaScript ES6 | 181108T165722Z | Jake Tay |
| 085 | Tcl | 181108T153008Z | sergiol |
| 013 | J | 181108T152454Z | FrownyFr |
| 035 | Python 2 Cython | 181108T132209Z | Dennis |
| 041 | Powershell | 181108T145133Z | mazzy |
| 045 | Octave | 181108T104905Z | Luis Men |
| 029 | APL Dyalog Classic | 181108T141002Z | Galen Iv |
| 065 | C gcc | 181108T112559Z | nwellnho |
| 026 | J | 181108T125807Z | Galen Iv |
| 040 | Python 2 | 181108T130636Z | Erik the |
| 041 | Python 2 | 181108T102258Z | ElPedro |
| 040 | Ruby | 181108T090129Z | G B |
| 004 | Jelly | 181108T124102Z | Dennis |
| 030 | R | 181108T093532Z | Kirill L |
| 053 | QBASIC | 181108T105917Z | steenber |
| 049 | Clean | 181108T111507Z | Οurous |
| 034 | Haskell | 181108T105854Z | nimi |
| 022 | Perl 6 | 181108T093507Z | nwellnho |
| 075 | Red | 181108T102540Z | Galen Iv |
| 005 | Pyth | 181108T102356Z | Sok |
| 051 | Python 3 | 181108T092117Z | Hori |
| 084 | Dart | 181108T101032Z | Elcan |
| 107 | Batch | 181108T095428Z | Neil |
| 015 | Charcoal | 181108T094200Z | Neil |
| 004 | 05AB1E | 181108T090931Z | Emigna |
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ḣṫḥ
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
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]
$[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
: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
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
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]
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)
Python 2, 47 41 40 bytes
lambda a,b:[a,b]+range(a,b,a<b or-1)[1:]
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)]
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;}
-1 thanks @auhmaan!
Python 3, 52 48 47 42 41 bytes
lambda a,b:[a,b,*range(a,b,-(a>b)|1)[1:]]
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.
,,…~,
, 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());
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]
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())
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.
(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;}
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.
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))))
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;}
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;}
(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.
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]
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.
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);}
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))]
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)
im still thinking...
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}}
J, 13 bytes
,,<.+i.@-~-.=
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!
Python 2, 37 bytes
lambda x:x+range(*x+[-cmp(*x)|1])[1:]
Thanks to @JonasAusevicius for the port to CPython!
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.
C (gcc), 65 bytes
f(a,b){for(printf("%d %d",a,b);a<b?++a<b:--a>b;)printf(" %d",a);}
Not very exciting. The loop increment is borrowed from an early version of Kevin Cruijssen's Java answer.
J, 26 bytes
,,[|.@]^:(>{.)<.+1}.i.@|@-
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, 52 47 41 bytes
lambda i,j:[i,j]+range(i,j,(i<j)*2-1)[1:]
-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:]
-2 with thanks to @JoKing
Ruby, 33 40 bytes
->a,b{[a,b]+[*a..b,*a.downto(b)][1..-2]}
Temporary fix, trying to find a better idea
Jelly, 4 bytes
,œ|r
How it works
,œ|r Main link. Left argument: a. Right argument: b
, Pair; yield [a, b].
r Range; yield [a, ..., b].
œ| Perform multiset union.
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...
Perl 6, 26 22 bytes
{|@_,|[...^](@_).skip}
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]]]
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)]
Python 2, 58 45 bytes
lambda a,b:[a,b]+range(a+1,b)+range(a-1,b,-1)
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):[]);
>= 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
Ÿ¦¨«
Explanation
Ÿ # inclusive range [a ... b]
¦¨ # remove the first and last element
« # append to input