Skip to main content
deleted 51 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 5647 bytes

\(e,d,l,m=c(d,l))m[order(!(m<e)-(e<d),(m-e)^2)]

Attempt This Online!

Approach copied from Jonah's answer - upvote that one!


Previously: R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses Uses the decreasing argument of sort to control sorting order:.

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: decreasing TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the decreasing argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: decreasing TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )

R, 47 bytes

\(e,d,l,m=c(d,l))m[order(!(m<e)-(e<d),(m-e)^2)]

Attempt This Online!

Approach copied from Jonah's answer - upvote that one!


Previously: R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

Uses the decreasing argument of sort to control sorting order.

edited body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the descendingdecreasing argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: descendingdecreasing TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the descending argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: descending TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the decreasing argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: decreasing TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )
added 597 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the descending argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: descending TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the descending argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: descending TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading