15
1
Instructions
Barry is a not so good backend developer in charge of a small API that should give you information about purchases made in a client's shop. However, he hasn't done a great job and your boss tells you to fix it client-side instead. Ideally you should receive comma-separated values such as 927,2,45,90
which correspond to something like item_id
,item_amount
,unit_price
,total
In this first puzzle we only care about item_id
and item_amount
but we need the other fields in place to present the problem. Barry sometimes gets things mixed up and returns noise as part of the output, he also gets the order wrong, returning noise
, noise
, unit_price
, total
, item_id
, item_amount
.
Your Task
You need to store in a map (or similar structure) the pairs of item_id
and item_amount
regardless of whether Barry returns them correctly or not and print each element in a new line in the least number of characters possible. (Storing is not mandatory, we just care about the output)
Sample input (mixed correct and messy formats)
103,2,50,100
106,1,900,900
459,40,150,300,67,2
4,20,30,6000
In other words input will be either a,b,x,x
or x,x,x,x,a,b
where what we care about is a
& b
. You need to provide code assuming we have a variable called G
(or any other name) with all the lines of csv.
Sample output
103,2
106,1
67,2 //This one was messy
4,20
Tolerance
There is a certain margin for tolerance when it comes to the answer. Answers in similar formats but adhering to the correct values, will also be accepted. Formats like [a,b]
,(a,b)
or {a,b}
are valid, but a,b
is preferred.
Although the first puzzle had mixed acceptance due to the fact that it was easy and fast to solve, I also felt that some people liked that too. So I'm going to continue making quickgolfs for now
Will input be always of the format
x,x,x,x
andx,x,x,x,x,x
wherex
denotes a number? – Spikatrix – 2015-05-18T13:40:16.930Yes, input will follow one of those two formats, let me clarify – Juan Cortés – 2015-05-18T13:40:54.243
Do we need to submit a program or a function or something else? Also, where all can inputs be taken from? – Spikatrix – 2015-05-18T13:42:33.710
Input will be available from a variable in your code
G
if possible, or similar depending on your language. – Juan Cortés – 2015-05-18T13:44:36.387Updated requirements to include the valid formats – Juan Cortés – 2015-05-18T14:05:56.810
What about an output like
["103" "2"]
? Would that be considered valid? – Dennis – 2015-05-18T14:16:49.360Sure, you are removing the noise and getting the values, I don't see why not – Juan Cortés – 2015-05-18T14:18:45.777
3
[tag:quick-golf] is essentially a difficulty tag. Consensus seems to be that we don't want those, so I'm removing that tag for now. If you want difficulty tags to be re-evaluated, please make a meta post for it. But that would be a massive retagging effort, which I think should happen in a coordinated manner, rather than individual users creating arbitrary new tags for it.
– Martin Ender – 2015-05-18T14:36:41.373I'll just stick to adding it in the title, if that's ok – Juan Cortés – 2015-05-18T14:48:22.353
I have a solution here, but it is too long(97 bytes). :(
– Spikatrix – 2015-05-18T15:25:27.597If our language has variables, do we have to assume the input is stored in one? My code would be shorter if I just read from STDIN. The Perl solution is doing this as well. – Dennis – 2015-05-18T15:51:28.057
I dont mind reading from STDIN or equivalent input, whatever is shortest – Juan Cortés – 2015-05-18T15:54:36.507
2@CoolGuy There is no such thing. You're not supposed to beat Pyth with C (because you're never going to). The joy is in beating other submissions in the same language or languages of similar verbosity. If there was already a 50 byte C submission I could understand not posting (although even then, I might post it if the approach is different and interesting). But since there isn't, please do post your answer. You're fairly close to JavaScript and Python, so it's definitely not excessively long for C. – Martin Ender – 2015-05-18T16:05:16.027
@MartinBüttner , Ok. I posted it.
– Spikatrix – 2015-05-20T08:20:07.070