# Is the bus load legal?

I was in the bus today, and noticed this sign:

      seated    standing    wheelchairs
max1    37         30            00
max2    36         26            01
max3    34         32            00


The number of seated passengers, standees, and wheelchairs all have to be no larger than some row in the table. (See chat for details.)

For the purposes of this challenge we will generalise this idea: Given a non-negative integer list of a strictly positive length N (number of passenger types) and a non-negative integer matrix of strictly positive dimensions (N columns and one row per configuration, or the transpose of this), return a list of indices/truthy-falsies/two-unique-values indicating which configurations limits are fulfilled.

E.g. with the above matrix:
30,25,1[1] (0-indexed) [2] (1-indexed) or [false,true,false] (Boolean) or ["Abe","Bob","Abe"] (two unique values) etc.

The following test cases use the above matrix and the 0/1 for false/true:
[30,30,0][1,0,1]
[30,31,0][0,0,1]
[35,30,0][1,0,0]
[0,0,1][0,1,0]
[0,0,0][1,1,1]
[1,2,3][0,0,0]

The following test cases use the following matrix:
1 2 0 4
2 3 0 2

[1,2,1,2][0,0]
[1,3,0,1][0,1]
[1,2,0,3][1,0]
[1,2,0,1][1,1]

• Am I misunderstanding this challenge or can [30,31,0] be [1, 1, 1] because it's covered by max3?
– Okx
Commented Aug 5, 2018 at 17:47
• Is swapping truth values allowed? (e.g. any truthy value in place of 0 and any falsy one in place of 1?) Commented Aug 5, 2018 at 17:48
• @Okx You're misunderstanding something. [x,31,z] rules out max1 and max2 because they don't allow 31 standees.
Commented Aug 5, 2018 at 17:50
• @Mr.Xcoder Is that usually allowed in challenges like this?
Commented Aug 5, 2018 at 17:52
• I used to think (see (2)) (also see Martin's comment) this is allowed by default, but I haven't found a meta consensus. I have proceeded by posting this meta question, whose conclusion that the OP should be asked first. I usually allow it, I don't see the reason why they shouldn't be swapped. Commented Aug 5, 2018 at 17:56

# APL (Dyalog Unicode), 5 3 bytes

∧.≤


Try it online!

• ∧.≤
Commented Aug 6, 2018 at 7:47
• Thanks @Adám. Don't know how I missed that. Commented Aug 6, 2018 at 10:22
• It looks like emoji. ^_^ >,< @.@
– tsh
Commented Aug 7, 2018 at 2:25

map.(or.).zipWith(>)


Returns False if legal and True if not.

Try it online!

Flipping True/False as return values saves 2 bytes (thanks @user202729!). With True for legal it's map.(and.).zipWith(<=) (22 bytes). Try it online!

• Flipping true and false in the output results in a shorter solution. Commented Aug 17, 2018 at 6:23

# Octave, 15 bytes

@(a,b)all(a>=b)


Try it online!

As per sundar's comment, omitting the transpose saves 2 bytes.

• OP allows taking the matrix as the transpose of what's shown in the question, and you can take b as a column vector instead of a row vector (since it's just specified as a list), saving 2 bytes: Try it online! Commented Aug 6, 2018 at 10:24

# Jelly, 3 bytes

<Ẹ€


Try it online!

0 = True, 1 = False.

• If the values needn't be distinct, <§ would work Commented Aug 5, 2018 at 17:38
• @Mr.Xcoder I don't think that option is given here. I guess I'll wait and see. Commented Aug 5, 2018 at 17:38
• Commented Aug 5, 2018 at 17:41
• @Mr.Xcoder Hm, it looks like <§ isn't exactly "truthy-falsy" but rather "falsy-truthy", which, unfortunately, isn't what the challenge asks for. Commented Aug 5, 2018 at 17:42
• @Mr.Xcoder Jelly needs ≥.
Commented Aug 5, 2018 at 17:47

# Ohm v2, 3 bytes

>Σy


Try it online!

Algorithm: vectorized > (greater than), Σ sum each, y sign.

# MATL, 3 bytes

<~A


Try it online!

Takes the input matrix as a transpose of the format in the question (as allowed by OP), with one column per configuration. Outputs boolean 0 and 1 for false and true.

# R, 3230 26 bytes

function(x,y)!colSums(x<y)


Try it online!

Accepts the matrix in transposed form as x, test config as y. Returns a vector of booleans.

Initial -2 bytes thanks to mnel, and further -4 by JayCe.

• Save 2 bytes with a function body apply(x>=y,2,all)
– mnel
Commented Aug 6, 2018 at 12:16
• save 4 bytes Commented Aug 6, 2018 at 13:59

# JavaScript (ES6), 38 bytes

Takes input as (matrix)(vector). Returns a Boolean array.

m=>v=>m.map(r=>!r.some((t,x)=>v[x]>t))


Try it online!

map.((.).(==)<*>(zipWith min))


Try it online!

# Retina 0.8.2, 57 bytes

\d+
$* ;(?=.*;(.*)) ;$1¶
%(+,1*(1*)(;.*),\12
(1*);\1$ Try it online! Link includes test cases, but the output is all run together. Explanation: \d+$*


Convert to unary.

;(?=.*;(.*))
;$1¶  Give each row of the matrix its own copy of the list. %(  Operate separately on each row of the matrix. +,1*(1*)(;.*),\1$
$2  Repeatedly remove the last number of the row and list while the last number of the row is at least as big as that of the list. (1*);\1$


There should then be one number left in the list and the number in the row should be at least as big as that.

# Japt, 6 5 bytes

-1 bytes from @Shaggy

eÈ¨Vv


Try it online!

• VgY -> Vv to save a byte. Commented Aug 6, 2018 at 7:42

# Python 2, 38 bytes

lambda m,l:[l==map(min,l,r)for r in m]


Try it online!

# 05AB1E, 5 bytes

εs<›P


Explanation:

Unfortunately 05AB1E v1 doesn't have a 1-char builtin for ≤ or ≥, so I decrease each value instead before using ›. 05AB1E v2 which is currently in development will have these builtins.

ε        # For-each row of the (implicitly input) matrix:
s       #  Swap, so the (implicitly input) list is at the top of the stack
<      #  Decrease every value in the input-list by 1
#   i.e. [30,25,1] → [29,24,0]
›     #  Check for each value in the matrix-row if they're larger
#  than the input-list value at the same index
#   i.e. [37,30,0] and [29,24,0] → [1,1,0]
P    #  Then take the product of these checks
#   i.e. [1,1,0] → 0


# Stax, 8 bytes

â ╤┘µrφî


Run and debug it

Explanation:

mx\{:vm|A Full program, unpacked, implicit input
m         Map over rows of the matrix:
x\         Zip with input array
{  m     Map over result:
:v        Check if non-increasing, i.e. matrix element greater than or equal to array element
|A   All.
Implicit output


# Brachylog, 14 bytes

zzᵐ{≥₁ᵐ∧1|∧0}ᵐ


Try it online!

# Wolfram Language (Mathematica), 18 bytes

Inner[Less,##,Or]&


Returns a list of two unique values: True means falsy, False means truthy.

Try it online!