JavaScript (ES6), 38 34 30 29 28 bytes
Takes input as any number of separate parameters. Returns 0
or 1
.
(a,b,c,d)=>!(d|(a^b^c)%7)^!c
Test cases
let f =
(a,b,c,d)=>!(d|(a^b^c)%7)^!c
console.log('[Truthy]')
console.log(f(6 ))
console.log(f(6, 2 ))
console.log(f(1, 3 ))
console.log(f(2, 1, 3))
console.log(f(3, 2, 6))
console.log('[Falsy]')
console.log(f(1, 6 ))
console.log(f(5, 4, 2 ))
console.log(f(3, 1, 4 ))
console.log(f(5, 4, 6, 2 ))
console.log(f(1, 2, 3, 4, 5, 6))
How?
Below are simplified versions of the main expression according to the number of parameters provided, undefined variables being coerced to either 0 or false:
# of param. | simplified expression | comment
------------+------------------------------+---------------------------------------------
1 | !(a % 7) ^ 1 | always true
2 | !((a ^ b) % 7) ^ 1 | false for (1,6), (2,5) and (3,4)
3 | !((a ^ b ^ c) % 7) | see the table below
4+ | !(d | (a ^ b ^ c) % 7) | always false
NB: The order of (a,b,c) doesn't matter because they're always XOR'd together.
The trickiest case is the 3rd one. Here is a table showing all possible combinations:
a | b | c | a^b^c | %7 | =0? | faces that sum to 7
--+---+---+-------+----+-----+--------------------
1 | 2 | 3 | 0 | 0 | Yes | none
1 | 2 | 4 | 7 | 0 | Yes | none
1 | 2 | 5 | 6 | 6 | No | 2 + 5
1 | 2 | 6 | 5 | 5 | No | 1 + 6
1 | 3 | 4 | 6 | 6 | No | 3 + 4
1 | 3 | 5 | 7 | 0 | Yes | none
1 | 3 | 6 | 4 | 4 | No | 1 + 6
1 | 4 | 5 | 0 | 0 | Yes | none
1 | 4 | 6 | 3 | 3 | No | 1 + 6
1 | 5 | 6 | 2 | 2 | No | 1 + 6
2 | 3 | 4 | 5 | 5 | No | 3 + 4
2 | 3 | 5 | 4 | 4 | No | 2 + 5
2 | 3 | 6 | 7 | 0 | Yes | none
2 | 4 | 5 | 3 | 3 | No | 2 + 5
2 | 4 | 6 | 0 | 0 | Yes | none
2 | 5 | 6 | 1 | 1 | No | 2 + 5
3 | 4 | 5 | 2 | 2 | No | 3 + 4
3 | 4 | 6 | 1 | 1 | No | 3 + 4
3 | 5 | 6 | 0 | 0 | Yes | none
4 | 5 | 6 | 7 | 0 | Yes | none
Alt. version #1, 32 bytes
Takes input as an array. Returns a boolean.
a=>a.every(x=>a.every(y=>x+y-7))
Test cases
let f =
a=>a.every(x=>a.every(y=>x+y-7))
console.log('[Truthy]')
console.log(f([6] ))
console.log(f([6, 2] ))
console.log(f([1, 3] ))
console.log(f([2, 1, 3]))
console.log(f([3, 2, 6]))
console.log('[Falsy]')
console.log(f([1, 6] ))
console.log(f([5, 4, 2] ))
console.log(f([3, 1, 4] ))
console.log(f([5, 4, 6, 2] ))
console.log(f([1, 2, 3, 4, 5, 6]))
Alt. version #2, Chrome/Firefox, 34 bytes
This one abuses the sort methods of Chrome and Firefox. It doesn't work with Edge.
Takes input as an array. Returns 0
or 1
.
a=>a.sort((a,b)=>k&=a+b!=7,k=1)&&k
Test cases
let f =
a=>a.sort((a,b)=>k&=a+b!=7,k=1)&&k
console.log('[Truthy]')
console.log(f([6] ))
console.log(f([6, 2] ))
console.log(f([1, 3] ))
console.log(f([2, 1, 3]))
console.log(f([3, 2, 6]))
console.log('[Falsy]')
console.log(f([1, 6] ))
console.log(f([5, 4, 2] ))
console.log(f([3, 1, 4] ))
console.log(f([5, 4, 6, 2] ))
console.log(f([1, 2, 3, 4, 5, 6]))
Related. – FlipTack – 2017-12-04T20:30:53.640
It seems that the last two falsey cases are superfluous as any list longer than 3 will contain opposing values, no? – Weckar E. – 2017-12-06T12:22:38.657
@WeckarE yes, obviously - if you have a look at the answers they all exploit this. It was just an easier explanation to write. – FlipTack – 2017-12-06T15:09:52.510
@FlipTack Actually you don't have to check the length at all, every list longer than 3 elements has at least one pair of opposite sides. – Erik the Outgolfer – 2017-12-07T18:12:54.640
@EriktheOutgolfer Yes, that's exactly the point I was making - of course I realised that when making the challenge, but it doesn't make my explanations for those test cases invalid. – FlipTack – 2017-12-07T18:37:17.073
1You can still see up to 5 faces from a single point if you bent the light waves with something heavy like a black hole – Ferrybig – 2017-12-14T06:46:23.190