9
1
A while ago I purchased a new wallet which is able to hold 8 cards (4 on both side). However, I seem to have way more cards than that and I need to make choices on which ones I want to carry with me. Some cards I use more often than others, but the cards I prefer to carry with me are not necessarily the ones I use most.
The challenge
Given a stack of cards, return the layout of my wallet in the best way possible w.r.t. my preferences and restrictions. The layout should be as follows:
__ __ (row 1)
__ __ (row 2)
__ __ (row 3)
__ __ (row 4)
Currently I posess the following cards - stacks will always consist of a selection from these:
- 1 identity card (ID)
- 1 driver's license (DL)
- 2 credit cards (CC)
- 5 debit cards (DC)
- 1 public transport card (PC)
- 1 gym access card (GC)
- 9 membership cards from random stores and warehouses (MC)
I have some preferences and restrictions:
- Cards sorted by priority: ID, DL, CC, DC, PC, GC, MC
- Cards sorted by usage frequency: CC, DC, PC, GC, MC, ID, DL
- For safety reasons, the total number of debit cards and credit cards in my wallet can be at most 1 more than the sum of all other cards that will go in my wallet ( NDC+NCC ≤ NID+NDL+NPC+NGC+NMC+1 ).
- If present, my identity card and driver's licence should always go in row 1. This does not mean that other cards may not occupy spots in row 1.
- The most frequently used cards from the stack should always go in row 4.
Rules
- No 2 cards can occupy the same spot.
- Higher priority cards are always prefered over lower priority ones, unless the DC/CC restriction kicks in.
- ID/DL at row 1 overrules the frequency rule: if only ID is provided, it will go in row 1 and row 4 will be empty!
- Input formatting can be done in any way you like, as long as the order of the input stack is retained. e.g.
ID,CC,PC,MC,MC,MC,DL
may also be supplied as e.g.1ID 1CC 1PC 3MC 1DL 0DC 0GC
orID CC PC MC MC MC DL
. Output formatting does have a few restrictions: rows must all start at a new line, columns must be delimited in some way. Empty spots may be presented any way you like, as long as it does not mess up the 4x2 layout.
There can be more than one solution/order, it's up to you which one you provide as output.
- You may assume that cards of the same type will always be grouped at input.
- Apart from the above, standard code-golf rules and loopholes apply.
Bonus
You are allowed to remove 15% of your bytecount if you also return any cards that did not go in the wallet. Print "It fits!" in case of no remaining cards. This additional output should be clearly separated from the returend layout.
Examples
Input:
ID, DL, CC, GC, MC
2 possible outputs:
ID DL DL ID
__ __ or __ MC
MC __ __ __
CC GC GC CC
optional: It fits!
Input:
ID, CC, DC, PC, GC, MC, MC, MC, MC, MC
2 possible outputs:
ID MC GC ID
MC MC or MC PC
PC GC MC MC
CC DC DC CC
optional: e.g. (MC, MC) or (2MC)
Input:
DC, DC, CC, CC, GC, DL
2 possible outputs:
DL __ GC DL
__ __ or DC __
GC DC __ __
CC CC CC CC
optional: e.g. (DC) or (1DC)
Input:
CC, DC, DC, DC
2 possible outputs:
__ __ __ __
__ __ or __ __
__ __ __ __
CC __ __ CC
optional: e.g. (DC, DC, DC) or (3DC)
Input:
CC, CC, MC, MC, MC, MC, MC, MC, PC, DC, DC, DC, DC, DC, GC
2 possible outputs:
MC MC MC DC
PC GC or DC GC
DC DC PC MC
CC CC CC CC
optional: e.g. (DC, DC, DC, MC, MC, MC, MC) or (3DC, 4MC)
Input:
MC, MC, MC, MC, MC, MC, MC
2 possible outputs:
__ MC MC MC
MC MC or MC MC
MC MC MC __
MC MC MC MC
optional: It fits!
Input:
ID, CC
2 possible outputs:
ID __ __ ID
__ __ or __ __
__ __ __ __
CC __ CC __
optional: It fits!
This is code-golf, so the shortest code (in bytes) wins.
You forgot some important cards. ;) – Sleafar – 2016-01-16T08:12:24.357