15
\$\begingroup\$

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]

\$\endgroup\$
10
  • \$\begingroup\$ Am I misunderstanding this challenge or can [30,31,0] be [1, 1, 1] because it's covered by max3? \$\endgroup\$
    – Okx
    Aug 5, 2018 at 17:47
  • \$\begingroup\$ Is swapping truth values allowed? (e.g. any truthy value in place of 0 and any falsy one in place of 1?) \$\endgroup\$
    – Mr. Xcoder
    Aug 5, 2018 at 17:48
  • \$\begingroup\$ @Okx You're misunderstanding something. [x,31,z] rules out max1 and max2 because they don't allow 31 standees. \$\endgroup\$
    – Adám
    Aug 5, 2018 at 17:50
  • \$\begingroup\$ @Mr.Xcoder Is that usually allowed in challenges like this? \$\endgroup\$
    – Adám
    Aug 5, 2018 at 17:52
  • \$\begingroup\$ 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. \$\endgroup\$
    – Mr. Xcoder
    Aug 5, 2018 at 17:56

16 Answers 16

8
\$\begingroup\$

APL (Dyalog Unicode), 5 3 bytes

∧.≤

Try it online!

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

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!

\$\endgroup\$
1
  • \$\begingroup\$ Flipping true and false in the output results in a shorter solution. \$\endgroup\$
    – DELETE_ME
    Aug 17, 2018 at 6:23
4
\$\begingroup\$

Octave, 15 bytes

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

Try it online!

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

\$\endgroup\$
1
  • \$\begingroup\$ 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! \$\endgroup\$
    – Sundar R
    Aug 6, 2018 at 10:24
3
\$\begingroup\$

Jelly, 3 bytes

<Ẹ€

Try it online!

0 = True, 1 = False.

\$\endgroup\$
5
  • \$\begingroup\$ If the values needn't be distinct, would work \$\endgroup\$
    – Mr. Xcoder
    Aug 5, 2018 at 17:38
  • \$\begingroup\$ @Mr.Xcoder I don't think that option is given here. I guess I'll wait and see. \$\endgroup\$ Aug 5, 2018 at 17:38
  • \$\begingroup\$ It is allowed. \$\endgroup\$
    – Mr. Xcoder
    Aug 5, 2018 at 17:41
  • 1
    \$\begingroup\$ @Mr.Xcoder Hm, it looks like isn't exactly "truthy-falsy" but rather "falsy-truthy", which, unfortunately, isn't what the challenge asks for. \$\endgroup\$ Aug 5, 2018 at 17:42
  • \$\begingroup\$ @Mr.Xcoder Jelly needs . \$\endgroup\$
    – Adám
    Aug 5, 2018 at 17:47
3
\$\begingroup\$

Ohm v2, 3 bytes

>Σy

Try it online!

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

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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.

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

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!

\$\endgroup\$
2
\$\begingroup\$

Haskell, 30 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Japt, 6 5 bytes

-1 bytes from @Shaggy

eȨVv

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ VgY -> Vv to save a byte. \$\endgroup\$
    – Shaggy
    Aug 6, 2018 at 7:42
1
\$\begingroup\$

Python 2, 38 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Brachylog, 14 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica), 18 bytes

Inner[Less,##,Or]&

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

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.