# Randomly Assign People to Tasks

The challenge is to assign people to tasks randomly~. From stdin you get 2 lines. Line one is a comma-separated list of names. Line 2 is a comma-separated list of jobs. The output required is one line per task person combo. The line should be formatted as Name:task. If there are not enough people for jobs or vice verse then they will not be output.

~ Randomly is defined as each run with the same input has a reasonably different output.

Example Input:

Bob,John,Susan,Josie,Kim,Tom
Bins,Floor,Windows


Example Output:

Bob:Windows
Susan:Bins
Kim:Floor

• Can there be only two possible outputs? – Leaky Nun May 20 '16 at 9:13
• Also, usually we don't like to restrict on the input format. – Leaky Nun May 20 '16 at 9:14
• @KennyLau what makes you think there could only be two possible outputs? – leumas95 May 20 '16 at 9:18
• @KennyLau Also, sorry about specifying the input format, I actually don't care just thought I should specify something. I am used to stack overflow being really precise about the details provide for questions assumed it might extend here :) – leumas95 May 20 '16 at 9:21
• I mean, can we randomly choose one from only 2 possible outputs? – Leaky Nun May 20 '16 at 9:28

## 05AB1E, 7 bytes

Code:

.r².r)ø


Try it online

Following the input/output spec strictly (16 bytes):

.r².r)øvyr?':?,


Explained:

.r                # radomize first input
².r             # randomize second input
)ø           # merge the lists to an array of pairs cutting out extras
vyr?':?,  # format output


Try it online

# Java 7, 240239 238 bytes

import java.util.*;class M{public static void main(String[]a){String[]p=a[0].split(",");List j=new ArrayList(Arrays.asList(a[1].split(",")));for(int i=0;j.size()>0;)System.out.println(p[i++]+":"+j.remove((int)(Math.random()*j.size())));}}


Can most likely be golfed more with some arrays magic, instead of List j=new ArrayList(Arrays.asList(a[1].split(",")));..

Ungolfed:

Try it here

import java.util.*;

class M{
public static void main(String[] a){
String[] p = a[0].split(",");
List j = new ArrayList(Arrays.asList(a[1].split(",")));
for(int i = 0; j.size() > 0;){
System.out.println(p[i++] + ":" + j.remove((int)(Math.random() * j.size())));
}
}
}


# Jelly, 13 bytes

Œ!€X€ZL’$ÐfŒṘ  Try it online! # Pyth, 6 bytes CmO.pd  Try it online! ### How it works: CmO.pd (implicitly) takes the evaluated input m d for each "line": .p generate all permutations O choose one randomly C truncating transpose  # Following strictly the input/output format: (16 bytes) jjL\:CmO.pcd\,.z  Try it online! ### How it works: jjL\:CmO.pcd\,.z .z takes all lines m d for each line: c \, split by "," .p generate all permutations O choose one randomly C truncating transpose jL\: join every pair by ":" j join all pairs by newlines  • Realy nice, I have only ever done golf in python, I should learn pyth – leumas95 May 20 '16 at 9:19 • The last edit seems to break the random on each run part. but still cool :), ohh you updated again nvm – leumas95 May 20 '16 at 9:26 • This edit should be random. – Leaky Nun May 20 '16 at 9:28 # Mathcad, [tbd] bytes csort(M,n) sorts matrix M on column n. augment joins two arrays columnwise. runif(n,a,b) returns a vector of n uniformly-distributed numbers over the range a..b. concat(a,b) concatenates strings a and b. With due apologies to Messrs Gilbert and Sullivan. Mathcad scoring system yet to be determined (must get round to posting something on Meta ...). However, this solution clearly wouldn't be a contender for anything other than a Programming Language specific leaderboard. Taking a rough keyboard equivalence, and noting that Mathcad uses keyboard shortcuts for entering programming and some other operators, it takes around 100 "bytes". ## Q, 38 Bytes t:{$[n:&/#:'x:{(-#x)?x}'x;+n#/:x;0N]}


NOTE.- input and output format not exactly as proposed (see test)

Test

."\\S ",$7h$.z.t    /To accomplish a random output we mofify seed based on internal clock
t(BobJohnSusanJosieKimTom; BinsFloorWindows)
/generates (SusanWindows;KimBins;JohnFloor) (a different result each run)


Explanation

(-seqLen)?seq Shuffles the sequence

x:{(-#x)?x}'x shuffles each sequence of x (argument with sequence of names and sequence of works) and reassign to x

n:&/#:'x Assigns to n the minimum over (&/) each sequence lengths (#:'x)

\$[n;+n#/:x;0N] If n (if n is not 0), executes flip n take of each seq, Else returns null

# Ruby, 69 bytes

n=gets.split(/,|\n/).shuffle;puts gets.split(',').map{|j|n.pop+':'+j}


Ungolfed:

names = gets.split(/,|\n/).shuffle
jobs = gets.split(',')
jobs.each do |job|
name = names.pop
puts "#{name}:#{job}"
end


## JavaScript (Firefox 30-57), 82 bytes

(a,b,s=a=>a.sort(_=>Math.random()-.5),c=s(b))=>[for(x of s(a))if(c[0])[x,c.pop()]]


Uses bogus sort to shuffle. Version which accepts two string parameters of comma-separated names and returns lines of colon-separated matchups for 110 bytes, where \n represents the literal newline character:

(a,b,s=a=>a.sort(_=>Math.random()-.5),c=s(b.split,))=>[for(x of s(a.split,))if(c[0])x+':'+c.pop()].join\n
`