Is the bus load legal?

15

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]

Adám

Posted 2018-08-05T17:05:40.080

Reputation: 37 779

Am I misunderstanding this challenge or can [30,31,0] be [1, 1, 1] because it's covered by max3? – Okx – 2018-08-05T17:47:15.887

Is swapping truth values allowed? (e.g. any truthy value in place of 0 and any falsy one in place of 1?) – Mr. Xcoder – 2018-08-05T17:48:24.287

@Okx You're misunderstanding something. [x,31,z] rules out max1 and max2 because they don't allow 31 standees. – Adám – 2018-08-05T17:50:42.930

@Mr.Xcoder Is that usually allowed in challenges like this? – Adám – 2018-08-05T17:52:03.523

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.

– Mr. Xcoder – 2018-08-05T17:56:30.277

@Mr.Xcoder I think I'll leave it like this for now (several answers are already in), but I'll try to keep it in mind for next time. – Adám – 2018-08-05T18:06:52.517

@Mr.Xcoder To my understanding: If you are using the same truthy value / falsy value (always use 1 for thuthy, 0 for falsy), they are "two unique values" which is allowed by this post; If your truthy value / falsy value variance between testcases (sometime use 0 for falsy, but sometime use false for falsy), they are not allowed. – tsh – 2018-08-06T06:37:32.627

@tsh Right, that's correct with the current formulation of the OP. – Adám – 2018-08-06T07:42:27.230

I think Okx's misunderstanding could be avoided if the example matrix wasn't square. – JiK – 2018-08-06T17:03:04.120

@JiK Right. That's why I included the other test matrix as well. – Adám – 2018-08-06T17:26:32.217

Answers

8

jslip

Posted 2018-08-05T17:05:40.080

Reputation: 721

2∧.≤ – Adám – 2018-08-06T07:47:21.160

Thanks @Adám. Don't know how I missed that. – jslip – 2018-08-06T10:22:48.117

6It looks like emoji. ^_^ >,< @.@ – tsh – 2018-08-07T02:25:27.553

6

Haskell, 22 20 bytes

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!

nimi

Posted 2018-08-05T17:05:40.080

Reputation: 34 639

Flipping true and false in the output results in a shorter solution. – user202729 – 2018-08-17T06:23:57.050

4

Octave, 15 bytes

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

Try it online!

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

tsh

Posted 2018-08-05T17:05:40.080

Reputation: 13 072

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!

– sundar - Reinstate Monica – 2018-08-06T10:24:42.060

3

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.

sundar - Reinstate Monica

Posted 2018-08-05T17:05:40.080

Reputation: 5 296

3

R, 32 30 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.

Kirill L.

Posted 2018-08-05T17:05:40.080

Reputation: 6 693

2Save 2 bytes with a function body apply(x>=y,2,all) – mnel – 2018-08-06T12:16:49.543

1save 4 bytes – JayCe – 2018-08-06T13:59:33.410

2

Jelly, 3 bytes

<Ẹ€

Try it online!

0 = True, 1 = False.

Erik the Outgolfer

Posted 2018-08-05T17:05:40.080

Reputation: 38 134

If the values needn't be distinct, would work – Mr. Xcoder – 2018-08-05T17:38:22.250

@Mr.Xcoder I don't think that option is given here. I guess I'll wait and see. – Erik the Outgolfer – 2018-08-05T17:38:54.303

It is allowed. – Mr. Xcoder – 2018-08-05T17:41:35.363

1@Mr.Xcoder Hm, it looks like isn't exactly "truthy-falsy" but rather "falsy-truthy", which, unfortunately, isn't what the challenge asks for. – Erik the Outgolfer – 2018-08-05T17:42:36.957

@Mr.Xcoder Jelly needs . – Adám – 2018-08-05T17:47:23.723

2

Ohm v2, 3 bytes

>Σy

Try it online!

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

Mr. Xcoder

Posted 2018-08-05T17:05:40.080

Reputation: 39 774

2

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!

Arnauld

Posted 2018-08-05T17:05:40.080

Reputation: 111 334

2

Japt, 6 5 bytes

-1 bytes from @Shaggy

eȨVv

Try it online!

Luis felipe De jesus Munoz

Posted 2018-08-05T17:05:40.080

Reputation: 9 639

VgY -> Vv to save a byte. – Shaggy – 2018-08-06T07:42:45.370

2

Haskell, 30 bytes

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

Try it online!

ovs

Posted 2018-08-05T17:05:40.080

Reputation: 21 408

2

Retina 0.8.2, 57 bytes

\d+
$*
;(?=.*;(.*))
;$1¶
%(+`,1*(1*)(;.*),\1$
$2
(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.

Neil

Posted 2018-08-05T17:05:40.080

Reputation: 95 035

1

Python 2, 38 bytes

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

Try it online!

ovs

Posted 2018-08-05T17:05:40.080

Reputation: 21 408

1

05AB1E, 5 bytes

εs<›P

Try it online or verify all test cases.

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

Kevin Cruijssen

Posted 2018-08-05T17:05:40.080

Reputation: 67 575

1

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

wastl

Posted 2018-08-05T17:05:40.080

Reputation: 3 089

1

Brachylog, 14 bytes

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

Try it online!

sundar - Reinstate Monica

Posted 2018-08-05T17:05:40.080

Reputation: 5 296

0

Wolfram Language (Mathematica), 18 bytes

Inner[Less,##,Or]&

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

Try it online!

alephalpha

Posted 2018-08-05T17:05:40.080

Reputation: 23 988