| Bytes | Lang | Time | Link |
|---|---|---|---|
| 012 | APL Dyalog Unicode | 201012T145559Z | Ven |
| 009 | Vyxal | 210809T093254Z | emanresu |
| 010 | Pyth | 210809T062721Z | Anders K |
| 011 | Vyxal | 210529T085504Z | Wasif |
| 063 | PowerShell | 210527T162654Z | mazzy |
| 083 | C gcc | 201011T230608Z | Noodle9 |
| 038 | Ruby | 201012T174106Z | ellcs |
| 064 | Scala | 201011T171953Z | Tomer Sh |
| 010 | 05AB1E | 201009T233220Z | Jonathan |
| 007 | Jelly | 201009T213917Z | Jonathan |
| 040 | Ruby | 201010T162354Z | Eric Dum |
| 049 | Perl 5 | 201010T220342Z | Kjetil S |
| 020 | APL+WIN | 201010T180550Z | Graham |
| 031 | R | 201010T122428Z | Dominic |
| 009 | Husk | 201010T040225Z | Razetime |
| 032 | Charcoal | 201009T214704Z | Neil |
| 065 | JavaScript ES6 | 201009T200037Z | Arnauld |
| 017 | 05AB1E | 201009T225551Z | lyxal |
| 043 | Python 3 | 201009T222651Z | Jonathan |
| 014 | Japt | 201009T212444Z | Shaggy |
| 053 | Python 3 | 201009T194655Z | hyper-ne |
APL (Dyalog Unicode), 13 12 bytesSBCS
1↓+/⌽(⌽⍳7)∘~
This is an atop of a train
1↓+/⌽(⌽⍳7)∘~
(⌽⍳7)∘~ ⍝ Right side of the atop
⍳7 ⍝ Range
⌽ ⍝ Reverse
∘ ⍝ Composed with...
~ ⍝ ...without (to remove our arguments)
⌽ ⍝ Rotated by...
+/ ⍝ ...the sum of the arguments
1↓ ⍝ Left side of the atop
1↓ ⍝ Drop leftmost (drop curried with 1)
Pyth, 10 bytes
>3-%R7t*5s
Takes input as a 3-element list of {0, …, 6}.
Try it online! Or see all 35 inputs.
How it works
sQ sum of input
*5 multiply by 5
t subtract 1
%R7 take each element of [0, that) mod 7
- Q remove elements present in input
>3 last 3 elements
It’s helpful to preserve symmetry under rotations modulo 7, since that leaves just five equivalence classes to consider. A good starting point is the “average” \$\frac{x + y + z}{3}\$, where division by 3 is the same as multiplication by 5 modulo 7. It happens that if we start walking down from the average minus 2, taking the first three numbers that aren’t in the input set, the five equivalence classes are conveniently mapped one-to-one:
- {0, 1, 6} ↦ {3, 4, 5} = {0, 1, 6} + 4
- {0, 2, 5} ↦ {1, 3, 4} = {3, 5, 6} + 5
- {0, 3, 4} ↦ {1, 2, 5} = {0, 3, 4} + 5
- {1, 2, 4} ↦ {0, 3, 5} = {0, 2, 5} + 5
- {3, 5, 6} ↦ {1, 2, 4} = {1, 2, 4} + 0
PowerShell, 35 63 bytes
based on the hyper-neutrino♦'s solution
+28 bytes thanks @DLosc
param($a)$b=1..7|?{$_-notin$a}
$b|%{$s+=$_}
$b|?{$_-ne$b[$s%4]}
C (gcc), 84 83 bytes
Saved a whopping 16 19 23 bytes thanks to the man himself ceilingcat!!!
Saved a byte thanks to Neil!!!
p;i;f(m){for(p=i=0;(L"ᨴᘬᤲᔪ"[p]>>i%7&m)-m;p+=++i%7<1);p=(64>>i%7)+m^127;}
Takes input as \$3\$ bits set in the least-significant-\$7\$-bits of an int and returns the three other numbers likewise.
Explanation (before some golfs)
f(m){ // function taking an integer with
// 3 bits set in its 7 lsb
// representing the 3 input numbers
for( // loop over
p=L"ᔪᘬᤲᨴ" // a sequence of 5 int values:
// 5418,5676,6450,6708,7224
// that are the 5 unique patterns of
// 3 set bits per 7 bits shifted and
// repeated over 13 bits so that their
// 7th bit is unset:
// 5418 = 1010100101010
// 5676 = 1011000101100
// 6450 = 1100100110010
// 6708 = 1101000110100
// 7224 = 1110000111000
;;++p) // no need to test for stopping
// since we must match one
for(i=7;i--;) // loop over shift values from 6 to 0
if((*p>>6-i&m)==m) // if a shifted 7-bit slice of one of
// our patterns matches m we've found
// the correct bit to exclude from m's
// 4 unset bits
return(1<<i)+m^127; // add that bit to m and flip the 7
// lsb so the 3 other unset bits are
// now set to represent the 3 return
// values
}
Ruby, 38 bytes
->s{n=s.sum;(([*1..7]-s)*9)[-n..-n+2]}
Stealing Eric's answer which based on Jonathan's answer. I would've commented to Eric, but i do not have enough reputation.
The actual difference: Using a range to get the three elemented slice.
05AB1E, 10 bytes
7LsKsO(._¨
How?
7LsKsO(._¨ - (push the input) e.g.: [2,4,7]
7 - push 7 7,[2,4,7]
L - range [1,2,3,4,5,6,7],[2,4,7]
s - swap top two of the stack [2,4,7],[1,2,3,4,5,6,7]
K - push a without bs [1,3,5,6]
s - swap top two of the stack [2,4,7],[1,3,5,6] (implicit input swapped in)
O - sum 13,[1,3,5,6]
( - negate -13,[1,3,5,6]
._ - rotate a left by b [6,1,3,5]
¨ - remove rightmost [6,1,3]
- implicit print top of stack [6,1,3]
Jelly, 9 8 7 bytes
7RṚḟṙSḊ
A monadic Link accepting a list of the three numbers, from \$[1,7]\$, in sorted order which yields a list of other numbers, from \$[1,7]\$, not necessarily sorted.
Try it online! Or see all 35 (I sorted the resulting values for easier comparison).
How?
7RṚḟṙSḊ - Link: list A e.g. [2,4,7]
7R - seven range [1,2,3,4,5,6,7]
Ṛ - reverse [7,6,5,4,3,2,1]
ḟ - filter discard (A) -> B [6,5,3,1]
S - sum (A) 13
ṙ - rotate (B) left by (that) [5,3,1,6]
Ḋ - remove the leftmost [3,1,6]
Perl 5, 49 bytes
sub{@c=grep!/[@_]/,0..6;splice@c,-sum(@_)%4,1;@c}
Just a translation of the python answer from HyperNeutrino.
APL+WIN, 20 bytes
Prompts for input of a vector of integers
3↑(-+/¯2↑n)⌽n←(⍳7)~⎕
R, 33 31 bytes
Edit: -2 bytes by using modulo -4 (which returns the negative of modulo 4)
(1:7)[v<--scan()][sum(v)%%-4-1]
Finds the 4 digits in 1..7 that aren't in the input, and excludes the one corresponding to the input sum (wrapping around).
TIO link tests that outputs are unique for each input, and shows output for every input.
(1:7) # vector of digits 1..7
[ ] # select elements
-scan() # excluding (negative indexes) input
v<- # and define v as (negative) input
# (so up to here we have the 4 elements that aren't in the input)
[ ] # from these, select elements
- # excluding (negative index)
(sum(v)%%4+1) # the sum of input, modulo 4, plus 1
Charcoal, 39 38 34 32 bytes
NθI⁻¹²⁷⁺θX²⊟Φ⁷№ETXdhp﹪×℅λX²ι¹²⁷θ
Try it online! Link is to verbose version of code. I/O is as a 7-bit integer 7..112. Explanation: The ordinals of the string TXdhp have five bit patterns which I have arbitrarily chosen to be such that the result excludes 1. They are then cyclically rotated until one matches the input, at which point I have determined the excluded bit. This bit is then added to the original input, and finally the difference between 127 and the sum is printed.
Nθ Cast input to integer
⁷ Literal 7
Φ Filter on implicit range
TXdhp Literal string `TXdhp`
E Map over characters
λ Current character
℅ Ordinal
× Multiplied by
² Literal 2
X Raised to power
ι Outer index
﹪ Modulo
¹²⁷ Literal 127
№ Count (i.e. contains)
θ Input
⊟ Pop matching value
² Literal 2
X Raised to that power
⁺ Added to
θ Input
⁻ Subtracted from
¹²⁷ Literal 127
I Cast to string
Implicitly print
I arbitrarily chose the following five bit patterns to exclude 1 but any five even cyclically distinct patterns would work.
T 1010100
X 1011000
d 1100100
h 1101000
p 1110000
JavaScript (ES6), 66 65 bytes
Takes input as a 3-digit string. Returns a string in the same format.
f=(n,k=i=0)=>++k<8?(~n.search(k)||n*43%399%4==i++?'':k)+f(n,k):''
05AB1E, 17 bytes
7LIм{3.$IO(._Dg<£
It's a much longer version of the Jelly answer, so go upvote that too.
Japt, 14 bytes
As previously advertised, I'm a wee bit tipsy so this could well be wrong and, even if right, could probably be golfed a little.
7õ kU k϶UxÍu4
Python 3, 53 bytes
def f(b):c=[*{*range(7)}-b];del c[-sum(b)%4];return c
-3 bytes thanks to FryAmTheEggman
-4 bytes by zero-indexing
-1 byte thanks to xnor