11
7
The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism!
The Challenge
Your challenge is to implement a program that will map some genes using cross-over frequencies, in as many programming languages as possible. You are allowed to use any sort of standard library function that your language has, since this is mostly a language showcase.
What is "gene mapping?"
Gene mapping is the process of locating the relative position of genes on chromosomes. This is done by measuring the crossing-over frequency of pairs of genes, equal to the percent of offspring in which that the pair is not inherited together. Distance is measured in map units with one map unit equal to one percent of crossing over. For example, if genes C & D have a crossing-over frequency of 11%, then gene C is a distance of 11 map units away from gene D.
Gene mapping is performed with multiple pairs of genes to determine their relative order. For example, the data (A,B,12) (D,B,7) (A,D,5) (D,H,2) (H,B,9) produces the following map:
A..H.D......B
You may have noticed that B......D.H..A is also a valid map. This is true, because it is not possible to distinguish between mirror opposites. Your program can pick which one to output. Although the input may not include every possible pair, there will always be enough information to reconstruct the entire map (so there will never be more than 2 valid outputs). In addition, the numbers will always work out (unlike actual biology), meaning that you won't have stuff like (A,B,3) (B,C,4) (A,C,13).
Input
Input will begin with a number n followed by a list of genes (uppercase letters). There will then be n triplets of data. Each set will consist of a pair of genes and their crossing over frequency (distance).
3,P,H,I
P,H,3
H,I,1
P,I,4
7,A,B,G,Q,U
B,Q,4
A,B,10
G,U,13
Q,U,10
A,G,9
G,Q,3
A,Q,6
Input is not rigidly defined, because different languages may have restrictions on what is feasible. For example, you may change the delimiters to something other than commas and newlines. Input formatting is largely up to you.
Output
Output will be a rendition of the gene map. It will consist of the genes (capital letters) spaced out by periods such that the distances are accurately portrayed. Here are the outputs for the above examples.
P..HI *or* IH..P
BG..Q.....A...U *or* U...A.....Q..GB
This also isn't a completely rigid requirement. For example you could use something other than periods, like commas or spaces.
The Objective Winning Criterion
As for an objective winning criterion, here it is: Each language is a separate competition as to who can write the shortest entry, but the overall winner would be the person who wins the most of these sub-competitions. This means that a person who answers in many uncommon languages can gain an advantage. Code-golf is mostly a tiebreaker for when there is more than one solution in a language: the person with the shortest program gets credit for that language.
Rules, Restrictions, and Notes
Your program can be written in any language that existed prior to December 20th, 2013. I will also have to rely on the community to validate some responses written in some of the more uncommon/esoteric languages, since I am unlikely to be able to test them.
Current Leaderboard
This section will be periodically updated to show the number of languages and who is leading in each.
- AutoHotkey (632) - Avi
- dj (579) - rubik
Current User Rankings
- Avi (1): AutoHotkey (632)
- rubik (1): dj (579)
Should we include code to read the input? Or should we just assume input is passed as first argument of the function? – Shoe – 2013-12-31T10:32:55.363
@Jefffrey I suppose either one is fine. – PhiNotPi – 2013-12-31T15:05:30.627
.. the leaderboard ? :-) – Avi – 2014-01-02T07:49:12.237
1What are the input bounds? Not so much
n, but primarily the bounds for the crossing over frequency (distance). Can we assume it will always be, say, less than1000? – rubik – 2014-03-11T19:20:44.223@PhiNotPi: can you provide a couple more test cases? I've almost finished mine and I'd like to test it more. – rubik – 2014-03-13T16:09:46.030
@PhiNotPi I added my solution, the leaderboard should be edited. – rubik – 2014-03-16T20:25:45.373
Sorry for the delay, I've been extremely busy lately. I've updated it. – PhiNotPi – 2014-03-16T20:31:44.293