one_der_ball Posted December 6, 2012 Share Posted December 6, 2012 First off hello every one this is my first post (since i just started learning php a week ago!) and to help me learn i have been finding php riddles to solve and i came across one that I am lost on how to go about solving ? wondering if i could get a nug in the right direction? anyway this is the question: Given a sequence, write a program to detect cycles within it. A file containing a sequence of numbers (space delimited). The file can have multiple such lines. Ensure to account for numbers that have more than one digit eg. 12. If there is no sequence, ignore that line. Print to stdout the first sequence you find in each line. Ensure that there are no trailing empty spaces on each line you print. I don't want to say it but this is scary to me right now but i don't want to give up on it either ? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/ Share on other sites More sharing options...
Maq Posted December 6, 2012 Share Posted December 6, 2012 1) This sounds like it could be some sort of homework. 2) Have you attempted doing this yourself? You'll never learn if you don't try. 3) Do you have any sample data? 4) What exactly are you stuck on? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397900 Share on other sites More sharing options...
one_der_ball Posted December 6, 2012 Author Share Posted December 6, 2012 (edited) 1) This sounds like it could be some sort of homework. 2) Have you attempted doing this yourself? You'll never learn if you don't try. 3) Do you have any sample data? 4) What exactly are you stuck on? I have been trying to do it myself but i dont know were tobegin varry new to php. as far as home work, it is not just a question i found on the internet to push myself into learing more about php, and sad to say there was no sample data all i want is some insight on what to lookinto to find the ancers for myself but i dont know were to start on this Edited December 6, 2012 by one_der_ball Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397903 Share on other sites More sharing options...
requinix Posted December 6, 2012 Share Posted December 6, 2012 What is a "cycle"? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397904 Share on other sites More sharing options...
one_der_ball Posted December 6, 2012 Author Share Posted December 6, 2012 What is a "cycle"? a cycle? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397907 Share on other sites More sharing options...
salathe Posted December 6, 2012 Share Posted December 6, 2012 … Given a sequence, write a program to detect cycles within it. … Print to stdout the first sequence you find in each line. … a cycle? A cycle! Or is that sequence? I'm confused too! Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397912 Share on other sites More sharing options...
one_der_ball Posted December 6, 2012 Author Share Posted December 6, 2012 A cycle! Or is that sequence? I'm confused too! I don't know ether Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397917 Share on other sites More sharing options...
requinix Posted December 6, 2012 Share Posted December 6, 2012 If you don't know what a "cycle" or "sequence" is then how are you supposed to solve the problem? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397919 Share on other sites More sharing options...
one_der_ball Posted December 6, 2012 Author Share Posted December 6, 2012 If you don't know what a "cycle" or "sequence" is then how are you supposed to solve the problem? well now i know what to start learning about to solve the problem Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397920 Share on other sites More sharing options...
one_der_ball Posted December 6, 2012 Author Share Posted December 6, 2012 ok so what I have got so far sequence = 4,8,12,5,6,4,8,12,9 (numbers or laters) the cycle is a funchion that will look for the maching sequence's and out put 4,8,12 i think im getting it this sound like im on the right track to any one? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397924 Share on other sites More sharing options...
Christian F. Posted December 6, 2012 Share Posted December 6, 2012 The sequence sounds correctly applied, yes. Though, the cycle sounds more like it should have been described as a loop. Where did you find that challenge? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397952 Share on other sites More sharing options...
salathe Posted December 6, 2012 Share Posted December 6, 2012 Source: www.codeeval.com/browse/5/ Detecting Cycles Challenge Description Given a sequence, write a program to detect cycles within it. Input A file containing a sequence of numbers (space delimited). The file can have multiple such lines. e.g 2 0 6 3 1 6 3 1 6 3 1 Ensure to account for numbers that have more than one digit eg. 12. If there is no sequence, ignore that line. Output Print to stdout the first sequence you find in each line. Ensure that there are no trailing empty spaces on each line you print. e.g. 6 3 1 So, by "cycle" what is really meant is adjacent occurrences of a sequence of numbers. Now that that's clear, what have you tried so far, if anything? Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397965 Share on other sites More sharing options...
Christian F. Posted December 6, 2012 Share Posted December 6, 2012 Ah, repeating patterns. That made a whole lot more sense, yes. Quote Link to comment https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.