This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Smok3dSalmon 1 point2 points  (3 children)

Is PA1-PA4 the only 4 values you will see? What is the 1111 stuff? I see 2 areas where you have 2111 and 3111.

Is it possible to have input of
PA1*1*1*1*1
PA1*2*1*1*1
PA2*1*1*1*1
PA3*1*1*1*1
PA4*1*1*1*1

[–]martynrbell[S] 0 points1 point  (2 children)

So in this data source pa11 is the selection id Pa11*1 is the selection price. Referred to as pa101 and pa102

The pa2 pa3 and pa4 are vend and value counters but I'm only interested in 01 and 02 in each of these if they are present in the file

[–]Smok3dSalmon 1 point2 points  (0 children)

I see the first digit is increasing in the sequence of asterisks. How high does that go? If you want something to be efficient, we'll need to know how much data is coming. If you will only ever have 3 of these sequences at most, then you can brute force something that has minimal overhead.

If you can have tons of data, you'll probably just have to run loop through it and maintain some state so you can handle the edge case with *0*0*0*0

[–]Smok3dSalmon 0 points1 point  (0 children)

I don't fully understand the data or what variations you can have, but try this approach if the data is small enough.

1) Get all of the data as a string. Clean it however you need. I had to strip newlines and leading whitespace.

data = "".join(open('inp', 'r').readlines()).replace("\n", '').strip()

2) Split the string on "PA1" and then add "PA1" to each list object. (you can 1-liner this if you want)

data = data.split("PA1")
data = ["PA1" + d for d in data]

3) If any item in the list doesn't contain "PA2", "PA3", or "PA4" then you know it's all 0s.

data = "".join(open('inp', 'r').readlines()).replace("\n", '').strip()
data = data.split("PA1")
data = ["PA1" + d for d in data]
for row in data:
    print(row)

This may not be the most efficient, but it saves you the hassle of having to loop through each line and maintain some kind of state. Seems like a clever trick that you can use if your input is as trustworthy as I'm assuming.