how can I find the path of consecutive numbers in a file with python?How do I check whether a file exists without exceptions?How do I copy a file in Python?Finding the index of an item given a list containing it in PythonHow can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How do I get the number of elements in a list?How do I list all files of a directory?Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missingImage Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition
Is this cheap "air conditioner" able to cool a room?
Why can I log in to my Facebook account with a misspelled email/password?
What does Fisher mean by this quote?
Colleagues speaking another language and it impacts work
What was the first multiprocessor x86 motherboard?
If there were no space agencies, could a person go to space?
Does this put me at risk for identity theft?
Do other countries guarantee freedoms that the United States does not have?
Looking for a new job because of relocation - is it okay to tell the real reason?
Where to pee in London?
Japanese equivalent of a brain fart
Finish the Mastermind
Sparse matrix processing: flip sign of top-left entries of the matrix
Why couldn't soldiers sight their own weapons without officers' orders?
Why is there a need to prevent a racist, sexist, or otherwise bigoted vendor from discriminating who they sell to?
Are certificates without DNS fundamentally flawed?
Was there ever a difference between 'volo' and 'volo'?
Is Odin inconsistent about the powers of Mjolnir?
What word can be used to describe a bug in a movie?
ESTA declined to the US
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
Did silent film actors actually say their lines or did they simply improvise “dialogue” while being filmed?
4-dimensional Knight's Tour
Short story about a teenager who has his brain replaced with a microchip (Psychological Horror)
how can I find the path of consecutive numbers in a file with python?
How do I check whether a file exists without exceptions?How do I copy a file in Python?Finding the index of an item given a list containing it in PythonHow can I safely create a nested directory?How to get the current time in PythonHow can I make a time delay in Python?How do I get the number of elements in a list?How do I list all files of a directory?Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missingImage Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a file of 4000,000 data. I'm starting programming in python. I want to find a path to arrive of 7 to 1. But I have some conditionals:
1.- The path must be descending for example: 7, 6, 5....1 (hoping to be consecutive), but can be 7,6,3,1. The principal goal is descending (second column). Imagine that the substrate between lines must be = 1 to identify them
2.- The path mustn't go up. For example: If i'm in 7, 6, 5..and then 6 is not correct. The next number of 5 must be the number 4, or other lower but no higer. I Imagine that the substrate between lines must be -1 to identify them
3.- Could reapeat the numbers. For example if i'm in 7 , I could have some lines in 7 before to pass 6 and it would be ok. Remember, the principal goal is no go up, is descending. I imagine the result will be constant 0 or 1 .
4.- If one of this conditionals are false, so:
a) start again but no in the first line where is a 7. I mean, start in the next line where is a 7 (second 7 in the file)
if there is not a path starting in 7, take then line with 6, and so on, until to find the path to arrive to 1.
b) or start from the last line where the process is broken. (I don't know if this option is eficient)
In resume, I want to find the path eficient to go from 7 to 1, in a descending way, and don't go up.
input file is:
1 6
2 6
3 6
4 7
5 7
6 3
7 3
8 5
9 7
10 6
...so etc.
Out file:
45 7
46 7
47 7
48 7
49 6
50 6
51 5
52 5
53 4
54 3
55 2
56 1
or
50 7
51 6
52 5
53 4
54 3
55 2
56 1
So, could you guide me how can I do this process?
Thanks a lot.
python algorithm path numbers conditional
add a comment |
I have a file of 4000,000 data. I'm starting programming in python. I want to find a path to arrive of 7 to 1. But I have some conditionals:
1.- The path must be descending for example: 7, 6, 5....1 (hoping to be consecutive), but can be 7,6,3,1. The principal goal is descending (second column). Imagine that the substrate between lines must be = 1 to identify them
2.- The path mustn't go up. For example: If i'm in 7, 6, 5..and then 6 is not correct. The next number of 5 must be the number 4, or other lower but no higer. I Imagine that the substrate between lines must be -1 to identify them
3.- Could reapeat the numbers. For example if i'm in 7 , I could have some lines in 7 before to pass 6 and it would be ok. Remember, the principal goal is no go up, is descending. I imagine the result will be constant 0 or 1 .
4.- If one of this conditionals are false, so:
a) start again but no in the first line where is a 7. I mean, start in the next line where is a 7 (second 7 in the file)
if there is not a path starting in 7, take then line with 6, and so on, until to find the path to arrive to 1.
b) or start from the last line where the process is broken. (I don't know if this option is eficient)
In resume, I want to find the path eficient to go from 7 to 1, in a descending way, and don't go up.
input file is:
1 6
2 6
3 6
4 7
5 7
6 3
7 3
8 5
9 7
10 6
...so etc.
Out file:
45 7
46 7
47 7
48 7
49 6
50 6
51 5
52 5
53 4
54 3
55 2
56 1
or
50 7
51 6
52 5
53 4
54 3
55 2
56 1
So, could you guide me how can I do this process?
Thanks a lot.
python algorithm path numbers conditional
What have you tried to get this done?
– DirtyBit
Mar 27 at 6:08
Well, I tried to find a way easy to do this, but I don't have idea what modules of python could help me. Do you have some idea?
– Hdez
Mar 27 at 6:11
better to addalgorithms
tag. This will be more useful.
– Maged Saeed
Mar 27 at 6:13
1
It is indeed an interesting question, but some of us will be reluctant to post an answer if you do not show your current research. In addition, it would be useless to post an algorithm that you already use or a less efficient one. Long story short, you should really add your current attempt.
– Serge Ballesta
Mar 27 at 8:47
Longest increasing subsequence problem, if I am not mistaken (you want it decreasing, but makes no difference).
– user58697
Mar 27 at 20:20
add a comment |
I have a file of 4000,000 data. I'm starting programming in python. I want to find a path to arrive of 7 to 1. But I have some conditionals:
1.- The path must be descending for example: 7, 6, 5....1 (hoping to be consecutive), but can be 7,6,3,1. The principal goal is descending (second column). Imagine that the substrate between lines must be = 1 to identify them
2.- The path mustn't go up. For example: If i'm in 7, 6, 5..and then 6 is not correct. The next number of 5 must be the number 4, or other lower but no higer. I Imagine that the substrate between lines must be -1 to identify them
3.- Could reapeat the numbers. For example if i'm in 7 , I could have some lines in 7 before to pass 6 and it would be ok. Remember, the principal goal is no go up, is descending. I imagine the result will be constant 0 or 1 .
4.- If one of this conditionals are false, so:
a) start again but no in the first line where is a 7. I mean, start in the next line where is a 7 (second 7 in the file)
if there is not a path starting in 7, take then line with 6, and so on, until to find the path to arrive to 1.
b) or start from the last line where the process is broken. (I don't know if this option is eficient)
In resume, I want to find the path eficient to go from 7 to 1, in a descending way, and don't go up.
input file is:
1 6
2 6
3 6
4 7
5 7
6 3
7 3
8 5
9 7
10 6
...so etc.
Out file:
45 7
46 7
47 7
48 7
49 6
50 6
51 5
52 5
53 4
54 3
55 2
56 1
or
50 7
51 6
52 5
53 4
54 3
55 2
56 1
So, could you guide me how can I do this process?
Thanks a lot.
python algorithm path numbers conditional
I have a file of 4000,000 data. I'm starting programming in python. I want to find a path to arrive of 7 to 1. But I have some conditionals:
1.- The path must be descending for example: 7, 6, 5....1 (hoping to be consecutive), but can be 7,6,3,1. The principal goal is descending (second column). Imagine that the substrate between lines must be = 1 to identify them
2.- The path mustn't go up. For example: If i'm in 7, 6, 5..and then 6 is not correct. The next number of 5 must be the number 4, or other lower but no higer. I Imagine that the substrate between lines must be -1 to identify them
3.- Could reapeat the numbers. For example if i'm in 7 , I could have some lines in 7 before to pass 6 and it would be ok. Remember, the principal goal is no go up, is descending. I imagine the result will be constant 0 or 1 .
4.- If one of this conditionals are false, so:
a) start again but no in the first line where is a 7. I mean, start in the next line where is a 7 (second 7 in the file)
if there is not a path starting in 7, take then line with 6, and so on, until to find the path to arrive to 1.
b) or start from the last line where the process is broken. (I don't know if this option is eficient)
In resume, I want to find the path eficient to go from 7 to 1, in a descending way, and don't go up.
input file is:
1 6
2 6
3 6
4 7
5 7
6 3
7 3
8 5
9 7
10 6
...so etc.
Out file:
45 7
46 7
47 7
48 7
49 6
50 6
51 5
52 5
53 4
54 3
55 2
56 1
or
50 7
51 6
52 5
53 4
54 3
55 2
56 1
So, could you guide me how can I do this process?
Thanks a lot.
python algorithm path numbers conditional
python algorithm path numbers conditional
edited Mar 27 at 6:24
Maged Saeed
9411 gold badge11 silver badges28 bronze badges
9411 gold badge11 silver badges28 bronze badges
asked Mar 27 at 6:06
HdezHdez
385 bronze badges
385 bronze badges
What have you tried to get this done?
– DirtyBit
Mar 27 at 6:08
Well, I tried to find a way easy to do this, but I don't have idea what modules of python could help me. Do you have some idea?
– Hdez
Mar 27 at 6:11
better to addalgorithms
tag. This will be more useful.
– Maged Saeed
Mar 27 at 6:13
1
It is indeed an interesting question, but some of us will be reluctant to post an answer if you do not show your current research. In addition, it would be useless to post an algorithm that you already use or a less efficient one. Long story short, you should really add your current attempt.
– Serge Ballesta
Mar 27 at 8:47
Longest increasing subsequence problem, if I am not mistaken (you want it decreasing, but makes no difference).
– user58697
Mar 27 at 20:20
add a comment |
What have you tried to get this done?
– DirtyBit
Mar 27 at 6:08
Well, I tried to find a way easy to do this, but I don't have idea what modules of python could help me. Do you have some idea?
– Hdez
Mar 27 at 6:11
better to addalgorithms
tag. This will be more useful.
– Maged Saeed
Mar 27 at 6:13
1
It is indeed an interesting question, but some of us will be reluctant to post an answer if you do not show your current research. In addition, it would be useless to post an algorithm that you already use or a less efficient one. Long story short, you should really add your current attempt.
– Serge Ballesta
Mar 27 at 8:47
Longest increasing subsequence problem, if I am not mistaken (you want it decreasing, but makes no difference).
– user58697
Mar 27 at 20:20
What have you tried to get this done?
– DirtyBit
Mar 27 at 6:08
What have you tried to get this done?
– DirtyBit
Mar 27 at 6:08
Well, I tried to find a way easy to do this, but I don't have idea what modules of python could help me. Do you have some idea?
– Hdez
Mar 27 at 6:11
Well, I tried to find a way easy to do this, but I don't have idea what modules of python could help me. Do you have some idea?
– Hdez
Mar 27 at 6:11
better to add
algorithms
tag. This will be more useful.– Maged Saeed
Mar 27 at 6:13
better to add
algorithms
tag. This will be more useful.– Maged Saeed
Mar 27 at 6:13
1
1
It is indeed an interesting question, but some of us will be reluctant to post an answer if you do not show your current research. In addition, it would be useless to post an algorithm that you already use or a less efficient one. Long story short, you should really add your current attempt.
– Serge Ballesta
Mar 27 at 8:47
It is indeed an interesting question, but some of us will be reluctant to post an answer if you do not show your current research. In addition, it would be useless to post an algorithm that you already use or a less efficient one. Long story short, you should really add your current attempt.
– Serge Ballesta
Mar 27 at 8:47
Longest increasing subsequence problem, if I am not mistaken (you want it decreasing, but makes no difference).
– user58697
Mar 27 at 20:20
Longest increasing subsequence problem, if I am not mistaken (you want it decreasing, but makes no difference).
– user58697
Mar 27 at 20:20
add a comment |
1 Answer
1
active
oldest
votes
I would create a finite-state machine with a state for each number (7 states, 1 to 7). At each line:
- If the number on the current line is 7: create a new instance of the machine (it would be a class) and push it to a list of "alive" automata.
- Call
.add_number(parsed_number)
on all the machines. This function remembers the number and returns one of three possible results:- 0 - I don't accept the number, toss me away (you have to model all state transitions which is basically any transition from larger to smaller number).
- 1 - I have accepted the number, do nothing.
- 2 - I have accepted the number and the number is 1: print what I have accumulated and toss me away.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370786%2fhow-can-i-find-the-path-of-consecutive-numbers-in-a-file-with-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would create a finite-state machine with a state for each number (7 states, 1 to 7). At each line:
- If the number on the current line is 7: create a new instance of the machine (it would be a class) and push it to a list of "alive" automata.
- Call
.add_number(parsed_number)
on all the machines. This function remembers the number and returns one of three possible results:- 0 - I don't accept the number, toss me away (you have to model all state transitions which is basically any transition from larger to smaller number).
- 1 - I have accepted the number, do nothing.
- 2 - I have accepted the number and the number is 1: print what I have accumulated and toss me away.
add a comment |
I would create a finite-state machine with a state for each number (7 states, 1 to 7). At each line:
- If the number on the current line is 7: create a new instance of the machine (it would be a class) and push it to a list of "alive" automata.
- Call
.add_number(parsed_number)
on all the machines. This function remembers the number and returns one of three possible results:- 0 - I don't accept the number, toss me away (you have to model all state transitions which is basically any transition from larger to smaller number).
- 1 - I have accepted the number, do nothing.
- 2 - I have accepted the number and the number is 1: print what I have accumulated and toss me away.
add a comment |
I would create a finite-state machine with a state for each number (7 states, 1 to 7). At each line:
- If the number on the current line is 7: create a new instance of the machine (it would be a class) and push it to a list of "alive" automata.
- Call
.add_number(parsed_number)
on all the machines. This function remembers the number and returns one of three possible results:- 0 - I don't accept the number, toss me away (you have to model all state transitions which is basically any transition from larger to smaller number).
- 1 - I have accepted the number, do nothing.
- 2 - I have accepted the number and the number is 1: print what I have accumulated and toss me away.
I would create a finite-state machine with a state for each number (7 states, 1 to 7). At each line:
- If the number on the current line is 7: create a new instance of the machine (it would be a class) and push it to a list of "alive" automata.
- Call
.add_number(parsed_number)
on all the machines. This function remembers the number and returns one of three possible results:- 0 - I don't accept the number, toss me away (you have to model all state transitions which is basically any transition from larger to smaller number).
- 1 - I have accepted the number, do nothing.
- 2 - I have accepted the number and the number is 1: print what I have accumulated and toss me away.
answered Mar 27 at 8:28
Martin IndraMartin Indra
1164 bronze badges
1164 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370786%2fhow-can-i-find-the-path-of-consecutive-numbers-in-a-file-with-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What have you tried to get this done?
– DirtyBit
Mar 27 at 6:08
Well, I tried to find a way easy to do this, but I don't have idea what modules of python could help me. Do you have some idea?
– Hdez
Mar 27 at 6:11
better to add
algorithms
tag. This will be more useful.– Maged Saeed
Mar 27 at 6:13
1
It is indeed an interesting question, but some of us will be reluctant to post an answer if you do not show your current research. In addition, it would be useless to post an algorithm that you already use or a less efficient one. Long story short, you should really add your current attempt.
– Serge Ballesta
Mar 27 at 8:47
Longest increasing subsequence problem, if I am not mistaken (you want it decreasing, but makes no difference).
– user58697
Mar 27 at 20:20