| Bytes | Lang | Time | Link |
|---|---|---|---|
| 060 | Wolfram Language Mathematica | 220109T224841Z | att |
| 147 | R | 220110T070032Z | pajonk |
| 012 | 05AB1E | 220109T213403Z | Kevin Cr |
| 015 | Jelly | 220109T182954Z | Jonathan |
| 070 | Haskell | 220109T082232Z | Madison |
| 085 | Ruby | 220109T101515Z | G B |
| 079 | JavaScript ES6 | 220109T091456Z | Arnauld |
| 021 | Charcoal | 220109T083231Z | Neil |
| 093 | Python | 220109T071111Z | pxeger |
Wolfram Language (Mathematica), 62 60 bytes
#/.(i#⋂##&@@#~Select~MemberQ@ii||i->Set@$)/@Join@@#&
⋂ are \[Function]\[Intersection]\[VectorLessEqual].
(i )/@Join@@# for all i in input
#/. i->Set@$ remove i if
#⋂##&@@ intersection of
#~Select~MemberQ@i lists containing i
i|| not all ≤i
R, 167 163 159 157 147 bytes
Or R>= 4.1, 126 bytes by replacing three function occurrences with \s.
Edit: -2 bytes thanks to @Giuseppe and -10 bytes thanks to @Dominic van Essen.
function(x,b=combn(c(0,sort(unique(unlist(x)))),2))lapply(x,setdiff,b[1,apply(b,2,function(y,`+`=function(k)sapply(x,match,x=y[k],0))all(!+1|+2))])
That turned out long...
Straightforward approach:
- Create all pairs of values from input list (leading zeros to fix issues with 1-length inputs).
uniqueandsorttake care of the "first element is smaller" requirement. - Define a helper function
+to look for a value in nested list. - Which pairs are dependent? (Uses \$\lnot p \lor q\$ for implication.) Extract first elements from them.
setdiffthose from all sublists.
05AB1E, 14 12 bytes
εʒδåÏ.«Ãy›O_
Try it online or verify all test cases.
Explanation:
ε # Map over each inner list of the (implicit) input list of lists:
ʒ # Filter this inner list by:
δ # Map over each list of the (implicit) input list of lists:
å # Check if it contains the current integer
Ï # Only keep those lists from the (implicit) input list of lists
.« # Reduce the remaining list of lists by:
à # Keep the values which are present in both lists
y› # Then check which remaining values are larger than the current integer
O # Sum to get the amount of values for which this is truthy
_ # Check if this sum is 0
# (after which the modified list of lists is output implicitly as result)
Jelly, 15 bytes
ċƇf/>Ƈ⁹ȧ
çⱮFḟ@Ɱ
A monadic Link accepting a list of lists of strictly positive integers that yields a list of lists of strictly positive integers.
Try it online! (The footer calls the Link for each and formats the output)
How?
ċƇf/>Ƈ⁹ȧ - Helper Link: list of lists, A; integer, I
Ƈ - filter keep those lists in A for which:
ċ - count occurrences of I - truthy if the list contains I
/ - reduce this list of lists that contain I by:
f - filter keep
- gets us a list of those values appearing in all of them
⁹ - use I as the right argument of:
Ƈ - filter keep those for which:
> - greater than I?
ȧ - logical AND I (non-vectorising)
- i.e. I if it is a consistently dependent smaller integer, else 0
çⱮFḟ@Ɱ - Link: list of lists, A
F - flatten A
Ɱ - map across each integer I in that with:
ç - call the Helper Link as a dyad - f(A, I)
Ɱ - map across each list in A with:
@ - with swapped arguments:
ḟ - filter discard
Haskell, 80 70 bytes
f l=filter(\n->all(\m->m<=n||any((&&).elem n<*>all(/=m))l)$l>>=id)<$>l
-10 bytes thanks to Wheat Wizard
Ruby, 85 bytes
->l{l.map{|a|a-l.flatten.select{|x|l.select{|c|c&[x]!=[]}.reduce(&:&).any?{|y|y>x}}}}
JavaScript (ES6), 79 bytes
Expects an array of sets.
a=>a.map(([...b])=>b.filter(p=>!b.some(q=>q>p&a.every(b=>b.has(q)|!b.has(p)))))
Charcoal, 21 bytes
IEθΦι⬤ι∨¬›νλ⊙θ‹№πν№πλ
Try it online! Link is to verbose version of code. Explanation:
θ Input array
E Map over subarrays
ι Current subarray
Φ Filtered where
ι Current subarray
⬤ All elements satisfy
ν Innermost element
¬› Not greater than
λ Inner element
∨ Logical Or
θ Input array
⊙ Any subarray satisfies
№ Count of
ν Innermost element
π In innermost subarray
‹ Is less than
№ Count of
λ Inner element
π In innermost subarray
I Cast to string
Implicitly print
Python, 104 93 bytes
lambda i:[[x for x in a if~-any(x<c>0<all(c in d for d in i if x in d)for c in a)]for a in i]
Stupid naïve iterative solution which I'm really not happy with. A recursive solution will be shorter.
-11 bytes thanks to a hint from xnor.
for a in z for b in a for c in b for d in c for e in d for f in e for g in f for h in g for i in h for j in i for k in j for l in j for m in l for n in m for o in n for p in o for q in p for r in q for s in r for t in s for u in t for v in u for w in v for x in w for y in x for z in y please kill me why is python's syntax so whitespace and keyword heavy