Jump to content

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/
Share on other sites

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 by one_der_ball
Link to comment
https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397903
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/271686-help-with-a-riddle/#findComment-1397965
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.