BASKETBALL FRVR?
Answer :
JavaScript (ES6), 73 72 bytes
  Prints all unique, lexically sorted combinations.
f=(n,p=0,s='')=>n?n>1&&f(n-2,0,s+'S')&f(n-(p-9?p+=3:9),p,s+'V'):alert(s)   Test cases
In this snippet, alert() has been replaced by console.log() for user-friendliness.
f=(n,p=0,s='')=>n?n>1&&f(n-2,0,s+'S')&f(n-(p-9?p+=3:9),p,s+'V'):console.log(s)  ;[2, 3, 4, 12, 16] .forEach(n => { console.log('[' + n + ']'); f(n); }) Jelly, 30 bytes
o2,5ṁo8‘ Hṗ@€⁾VSẎðOḂŒgÇ€FS=ðÐf   A monadic link returning a list of the strings (lists of characters).
Try it online! - The footer calls the link and separates the entries by newlines since a full program's implicit output would smash them together.
How?
o2,5ṁo8‘ - Link 1, helper to form shot scores: list of shots grouped by type (S=1 and V=0)          -                                e.g. [[1,1],[0,0,0,0,0],[1,1],[0],[1,1]]  2,5     - 2 paired with 5 = [2,5] o        - logical or (vectorises)             [[1,1],[2,5,0,0,0],[1,1],[2,5],[1,1]]     ṁ    - mould like the input                [[1,1],[2,5,0,0,0],[1,1],[2],[1,1]]      o8  - logical or with 8                   [[1,1],[2,5,8,8,8],[1,1],[2],[1,1]]        ‘ - increment                           [[2,2],[3,6,9,9,9],[2,2],[3],[2,2]]  Hṗ@€⁾VSẎðOḂŒgÇ€FS=ðÐf - Link: number, total score, n H                     - halve n     ⁾VS               - literal ['V','S']  ṗ@€                  - Cartesian power with swapped @rguments for €ach                       -   ...i.e. for each in [1,2,...,floor(half n)]                       -   yielding all strings of Vs and Ss from length 1 to floor(half n)        Ẏ              - tighten (from a list of lists of lists to a list of lists)         ð         ðÐf - filter keep those entries for which this yields a truthy value:          O            -   cast to ordinals (S->83, V->86)           Ḃ           -   modulo 2         (S->1, V->0)            Œg         -   group equal runs (e.g. [0,0,1,1,0] -> [[0,0],[1,1],[0]])              Ç€       -   call the last link (1) as a monad for €ach (transform to scores)                F      -   flatten (make one list of scores)                 S     -   sum (calculate the total score of the string)                  =    -   equals right argument (n)?   The resulting order is actually lexicographical in reverse, to have it forward sorted just reverse it by appending Ṛ.
Python 3, 96 95 85 77 73 bytes
  -1 byte thanks to @notjagan
 -4 bytes thanks to @xnor
f=lambda x,s='',i=3:f(x-2,s+'S')+f(x-i,s+'V',3*(i<9)+i)if x>0 else[s]*-~x   Try it online!
Comments
Post a Comment