INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Pattern problem.

Pattern problem.

(OP)
I notice that this forum has been dead for almost a year.

Today I was thinking (yeah, I know, DANGEROUS) about a simple test that could be given to prospective coders to determine how well they can visualize and code on the fly. The following is what I think would separate real coders from the rest of the pack.

Let's see some code for the following problem:

0123456789
9876543210
1234567890

Using the above three lines as a pattern, write code that will output the above lines and all following lines until the pattern repeats. Hint: This pattern will repeat starting with the 21st line.

Everything you need to know is posted above. There should be no reason for me to answer any questions. And, yes, this is deliberately minimal to test two things. First, how well a coder can recognize patterns. And, second, how well a coder can write code to output those patterns.

I spent about 10 minutes before I could visualize how to code this. Then I spent 20 more minutes writing/debugging C++ code to solve this problem. I am a FoxPro programmer, but chose C++ because I have about 3 HOURS total experience in C++ coding. I did not try FoxPro, but I assume that the time would be comparable.

Later I will post my C++ code for comparison purposes. I may even give stars to code that I think is exceptional (assuming that I understand your coding language).

mmerlinn

http://mmerlinn.com

Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

RE: Pattern problem.

Um - about 2 seconds to see the pattern, and about 1 minute to write the code ...

Hidden:

Public Sub main()
Dim strDigits As String

strDigits = "0123456789"
Do
Debug.Print strDigits
strDigits = StrReverse(strDigits)
Debug.Print strDigits
strDigits = StrReverse(Left(strDigits, 9)) & Right(strDigits, 1)
Loop Until strDigits = "0123456789"
End Sub

Note that the HIDE tag rather spoils the layout of the code ...

RE: Pattern problem.

And upon reflection, I can simplify it slightly:

Hidden:

Public Sub main2()
Dim strDigits As String

strDigits = "0123456789"
Do
Debug.Print strDigits & vbCrLf & StrReverse(strDigits)
strDigits = Right(strDigits, 9) & Left(strDigits, 1)
Loop Until strDigits = "0123456789"
End Sub

RE: Pattern problem.

(OP)
Dang, not exactly the way I had envisioned it.

I never thought of assigning the "0123456789" to a variable. So, my instructions were not clear.

My intent was that the pattern would be generated one digit at a time entirely by the code without assigning any part of the pattern to a string variable.

So, let me try again.

0123456789
9876543210
1234567890

Using the above three lines as a pattern, write code that will output the above lines and all following lines until the pattern repeats.

Rules: The results must be generated by your code one digit at a time. String variables, if needed, are only permitted to build and output the results. No part of the input pattern may be assigned to a variable, although it is obvious that the intermediary and output results must be assigned to one or more variables. In other words, the results must be entirely generated by the code, one digit at a time, without starting with any fixed variable(s). Note that string variables are not even needed in some languages like C++.

Hint: This pattern will repeat starting with the 21st line.

Also, an explanation of how the code works might help. It took me a bit to figure out how the code submitted by strongm above works since I am not familiar with his language.

Now let's see whether my revised instructions are still as clear as mud.

mmerlinn

http://mmerlinn.com

Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

RE: Pattern problem.

Ok
(language is VBA, by the way)

Hidden:

Public Sub Main3()
Dim lp1 As Long
Dim lp2 As Long
Dim lp3 As Long

For lp3 = 0 To 9
For lp1 = 0 To 9
Debug.Print Trim((lp1 + lp3) Mod 10);
Next
Debug.Print
For lp2 = 9 To 0 Step -1
Debug.Print Trim((lp2 + lp3) Mod 10);
Next
Debug.Print
Next
End Sub

RE: Pattern problem.

@mmerlinn

In my opinion, you have not provided enough information to establish a reasonable pattern.

Based on assumptions any of the following would be valid for the next value.

9876543210
8765432109
0987654321

If it is pattern recognition you are looking for, then you would have to accept any of those as valid (and others IMO less valid)

The clue of repeating at line 21 is valid for all of those.

For the record, I would have chose 876543210

**********************************************
What's most important is that you realise ... There is no spoon.

RE: Pattern problem.

Fair point (and I can make miniscule modifications of my code to deal with all of those smile ). But as a test, the whole premise now seems flawed to me anyway. The OP stated that it was to "determine how well they can visualize and code on the fly", but by then changing the parameters of the question because the first solution didn't fit the OPs idea of how it should be solved, this goal is immediately undermined since we are no longer allowed to solve it any way we like.

RE: Pattern problem.

It struck me as odd that the method mattered at all.

I would see more value in seeing various methods as this would give insights into a persons thought processes. If this is a programming hiring test then how people think is as important as how they perform a given task.

**********************************************
What's most important is that you realise ... There is no spoon.

RE: Pattern problem.

(OP)
It is obvious that I did not think this all the way through as well as not being clear in the presentation.

As for the other possible patterns, I fail to see how two of the three given are possible.

9876543210 >> is already used so how could it be next?
8765432109 >> when I look at this one, it seems to break the pattern, but then I may be missing something obvious
0987654321 >> this is the only one that "looks" to me to fit the pattern

How about showing the full set (all 20) using these options so I can see how they fit the pattern that you see?

Anyhow, since I have garbled this problem, here is the solution that I came up with.

Spoiler:

CODE --> C++

#include <iostream>

int main();

    for (int i = 10; i < 20; i++)
    {
        for (int j = i - 10; j < i; j++)
        {
            cout << j % 10;
        }
        cout << endl;

        for (int k = i - 1; k > i - 11; k--)
        {
            cout << k % 10;
        }
        cout << endl;
    }
    return 0;
}

0123456789
9876543210
1234567890
0987654321
2345678901
1098765432
3456789012
2109876543
4567890123
3210987654
5678901234
4321098765
6789012345
5432109876
7890123456
6543210987
8901234567
7654321098
9012345678
8765432109 

There may be a better way.

Anyhow, the solutions I see posted here are the type of solutions I would expect a real coder to use to solve this kind of problem.

As you probably have noticed, there are some coders visiting these forums that would have used dozens and dozens of conditional statements often mixed in with loops to solve a simple problem like this. The code used by those coders drives me batty trying to figure out what they are doing especially when they are asking for help as to why their spaghetti code does not work as expected.

mmerlinn

http://mmerlinn.com

Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

RE: Pattern problem.

All of kwbMitel's options are valid (although perhaps slightly less obvious) continuations of the pattern sample you provided in the OP. I'll allow them to explain.

RE: Pattern problem.

9876543210 >> is already used so how could it be next?
It can be next because you have not established that it needs to change at all. The first and 3rd numbers change but there is no requirement of the second number to change. On the 1st and 3rd numbers, you have not actually established a pattern either. 2 instances are not enough for a pattern. The next value could simply toggle back to the first or skip 2 numbers or 3 or 4. Modifying by 1 meets the 21 step requirement however so it is reasonable to use this value. There are probably other patterns that would meet that requirement but I try to apply Occams Razor when I can.

8765432109 >> when I look at this one, it seems to break the pattern, but then I may be missing something obvious
There are 2 equally valid reasons to apply this pattern. The first is that if the numbers that are counting up are shifting one position up, then the numbers that are counting down should shift one number down. The second is that number in the first position is shifted to the end. This is the pattern I would choose. Additionally, when paired with the the other sequence, adding the two together results in the number 9999999999 which is aesthetically pleasing to me.

0987654321 >> this is the only one that "looks" to me to fit the pattern
I think you would have difficulty justifying this pattern over either of the other 2 with the information that you provided which was exactly my point. I believe all 3 are roughly equal and I have stated my preference (which does not match yours obviously).

"So what we have here, is a failure to communicate" ~ From:Cool Hand Luke

Lets say you received Strongm's first solution, my solution, and PHV's as results for your hiring process. Who is the stronger candidate? (I know I did not submit code but imagine I did something like yours but with the second number sequenced my way)

**********************************************
What's most important is that you realise ... There is no spoon.

RE: Pattern problem.

I already read the rephrased problem, but can't withstand the urge to irregardless post a solution in Foxpro using the inital line "0123456789" in a string variable transformed by code to give a very straight forward solution, which comes to an end as the 21st value will arrive at the start value.

Spoiler:

CODE --> Foxpro

cLine = "0123456789"
For i = 1 to 10
  ? cLine
  cLine = Chrtran(cLine,"0123456789","9876543210") && invert digits
  ? cLine
  cLine = Chrtran(cLine,"9876543210","1234567890") && shift digits
EndFor i
* ? cLine && uncomment this line to see cLine having the initial value after 10 invert and 10 shift operations
* For those not speaking Foxpro, Chrtran takes the first parameter, looks for any charr given in the second parameter and replaces it with the char at the same position in the third parameter, so chrtran is a doing as many single char string replacements as you want in one step. Eg the first chrtran does replace each 0 with a 9, each 1 with an 8, each 2 with a 7, and so on.

* The nice part about it is it simply takes the 3 given lines of the pattern as part of the code. 
* Change that given part of the pattern and input it here, you might only change the number of iterations needed to repeat, 
* but otherwise the code would not need to adapt to a new pattern. Given you have all digits in each line. 

This will output

Spoiler:


0123456789
9876543210
1234567890
8765432109
2345678901
7654321098
3456789012
6543210987
4567890123
5432109876
5678901234
4321098765
6789012345
3210987654
7890123456
2109876543
8901234567
1098765432
9012345678
0987654321

and would then continue with
0123456789

Bye, Olaf.

RE: Pattern problem.

I think all the pattern is doing is moving the current first number to the end. The second part of the pattern simply inverts the current pattern.

Without starting with the patterned number in a string, you can do something like this. Language is PHP.

Spoiler:


CODE --> PHP

<?php
$max=10;
$collector = array();

for($i=0;$i<=$max-1;$i++)
	{
			$collector[] = $i;
	}
	$string = implode('', $collector);
	echo $string . "<br>";
do
{
	$invString='';
	for($i=count($collector)-1;$i>=0;$i--)
	{
		$invString .= $collector[$i];	
	}
	echo $invString . "<br>";
	$moved = array_shift($collector);
	$newArr = array_push($collector, $moved);
	$string = implode('', $collector);
	
	echo $string . "<br>";
	
}while($collector[0]!=0)



?> 

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Pattern problem.

Trouble is, Phil, that your code is banned under the rules introduced by mmerlinn's second post, since your for loop essentially builds the same string that I wasn't allowed to use in my initial solution ...

RE: Pattern problem.

But it builds it on the fly, which is the requirement. mmerlin just did not want you to create a string with the numbers directly in it. And my code does not build a string., it builds an array, thumbsup which it then uses to loop.

How else would you dynamically build the string then?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Pattern problem.

I feel like I'm a little late to the party, but here's my solution in C.

The digits being output are a single stream of digits that just happen to get cut to a new line every 10 digits. In other words, the entire set of digits being output is just a single stream pattern. (Not sure if I'm saying that correctly). The pattern is a saw tooth that goes up 10, then down 10, increments by 1, then repeats.

The value of digit goes well above "9", but we only print its value mod 10, so we only get a single digit value.

CODE

#include <stdio.h>
#include <stdlib.h>

int main ( int argc, char ** argv )
{
        int     x;
        int     digit           = 0;
        int     direction       = 1;

        for ( x = 0; x < 200; ++x )
                {
                printf("%d", digit % 10);
                if (! ((x+1) % 10))
                        {
                        direction *= -1;
                        if ( direction < 0 ) digit += 1;
                        printf("\n");
                        }
                digit += direction;
                }
}

0123456789
9876543210
1234567890
0987654321
2345678901
1098765432
3456789012
2109876543
4567890123
3210987654
5678901234
4321098765
6789012345
5432109876
7890123456
6543210987
8901234567
7654321098
9012345678
8765432109 

RE: Pattern problem.

Sorry for not "Spoilerizing" my code. It seems unneeded this late in the thread. Apologies if I assumed incorrectly.

RE: Pattern problem.

Phil,

It's not me arguing the toss. I'm more than happy for a fixed or dynamic string or array to be used. But mmerlinn specifically states: "The results must be generated by your code one digit at a time", " No part of the input pattern may be assigned to a variable" and "without assigning any part of the pattern to a string variable.". Your code doesn't follow any of these rules ... perhaps you'd like to join those of us who think the rules are odd.

RE: Pattern problem.

I'm just trying to understand.


1. The results must be generated by your code one digit at a time: It generates the number one digit at a time in a loop. Once its fully generated there's no reason to generate it again. That would be silly.

2. No part of the input string is assigned to a variable. Technically the variable is dynamically generated. But if you can never have the built string stored anywhere, how do you use the pattern?

3. I only assign the pattern to a string when I need to output.

But o.k, lets try this on for size:

no more spoilers

CODE

$top = 10;
$pos=0;
do{
	
	$arrpos=0;
	$arr=array();
	
	for($i=$pos;$i<=($pos + $top)-1;$i++)
	{
		if($i>=10)
		{
			echo $i-10;
			$arr[$arrpos]=$i-10;
			
		}
		else
		{
			echo $i;
			$arr[$arrpos]=$i;
		}
		$arrpos++;
	}
	echo "<br>";
	$invString='';
	for($j=count($arr)-1;$j>=0;$j--)
	{
		$invString .= $arr[$j];	
	}
	echo $invString;
	$pos++;
	echo "<br>";	

}while ($pos<=10) 

But yes, the rules are quite odd indeed.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Pattern problem.

Ah - and now you'll see that you've pretty much come up with the exact same solution as the rest of us. Which comes as no surprise, since the restated rules give little opportunity for anything much different, and why I don't really think that this ended up being a test "to determine how well they can visualize and code on the fly"

I think it would be interesting to hear mmerlinn's response to kwbMitel's question of 4th May

RE: Pattern problem.

I think my solution is unique in it's approach from the others submitted. Every solution submitted either has two inner loops to deal with the reversed pattern, or there is a string reverse function called to print it.

My solution outputs a single stream of characters, each one calculated from only the previous character.

0123456789987654321012345678900987654321234567890110987...

But then inserts a return after every 10 characters, giving this...

0123456789
9876543210
1234567890
0987654321
2345678901
10987...


The pattern I see is a triangle wave that is increasing by 1 every cycle, passed through a mod 10 filter. The output grouping by 10 is just for readability.

RE: Pattern problem.

Indeed, SamBones - and should certainly score something for originality. Mind you it only really works as long as the pattern is not one of kwbMittel's legitimate alternatives. All of the looping solutions should be able to deal with those with very minor changes.

Still awaiting further feedback from mmerlinn

RE: Pattern problem.

Well, any time there's ambiguity in the specs, you have to either get clarification, or make assumptions.

This could also be the fourth number in the sequence: 8888888888

I have a sequence rule in mind where that would be a valid next value.

This reminds me of this: http://www.youtube.com/watch?v=vKA4w2O61Xo

RE: Pattern problem.

Well, that one was easy ...

RE: Pattern problem.

Okay then, tempted in by this forum appearing in the "top discussions" :) I thought I'd throw in a quick and sort of 'dirty' offering in Python.

CODE --> Python

#! /usr/bin/env python
SEED = "0123456789"
sfwd = SEED
done = 0
while True:
	srev = sfwd[::-1]
	print(sfwd)
	print(srev)
	s = sfwd[0]
	sfwd = sfwd[1:] + s
	if SEED == sfwd:
		print(sfwd)
		break

# quit() 


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Pattern problem.

@Sambones

Re:each one calculated from only the previous character

I like your solution but your description is not as simple as you make it out to be. Your pattern needs to track through 20 characters and then do a shift by not duplicating the previous number as you would after 10 characters. Basically you also have 2 loops, one keeping track of the character count and 1 generating a new number based on the previous number.

I've highlighted in Yellow where you duplicate and in Green where you dont

0123456789987654321012345678900987654321234567890110987

**********************************************
What's most important is that you realise ... There is no spoon.

RE: Pattern problem.

Quote:

Basically you also have 2 loops...

True, I may have simplified my description, but there is only one loop. Generating the next character is just incrementing or decrementing the previous character. The one keeping track of the character count decides (after every 10) whether to change direction, print a new line, and whether it needs to increment the number by one (which gives us our shift due to the digit being printed modulo 10).

I'm not sure what you're saying about duplicating or not. That looks correct to me and matched the other expected sequences (not taking into account the "alternate" sequences suggested). The duplication is the start of the reversal of the previous 10. The non-duplication is the start of the next character cycle where a character has been shifted. That matches what's displayed when only 10 characters are displayed per line.

I'm wondering if it could be generalized to a function that takes the offset into the sequence as an input, and outputs the digit at that position.

RE: Pattern problem.

Ok, I've generalized the formula for calculating any digit within the sequence, just based on it's offset.

CODE

#include <stdio.h>

int     thedigit(int);

int main ( int argc, char ** argv )
{
        int     x;

        for ( x = 0; x < 200; ++x )
                {
                printf("%d", thedigit(x));

                if (! ((x+1) % 10)) printf("\n");
                }
}

int thedigit( int offset )
{
        int     decade = (int) (offset / 10);

        return( decade % 2 ? ((9 + ((decade - 1)/2)) - (offset % 10)) % 10 : ((decade / 2) + (offset % 10)) % 10 );
} 

CODE --> output

0123456789
9876543210
1234567890
0987654321
2345678901
1098765432
3456789012
2109876543
4567890123
3210987654
5678901234
4321098765
6789012345
5432109876
7890123456
6543210987
8901234567
7654321098
9012345678
8765432109 

RE: Pattern problem.

@Sambones, I can see were your going now but you can understand me questioning a number being "calculated from only the previous character".

The directionality of the change govenrns whether you repeat a digit after the line feed or change the digits. Directionality cannot be determined by only the previous character.

Assume for a moment that the actual pattern is to take the digit in the first position and shift it to the end. Can your method be modified to accomodate that sequence?

It would need to look like this.

012345678998765432101234567890876543210923456789017654321098

**********************************************
What's most important is that you realise ... There is no spoon.

RE: Pattern problem.

Quote:

Assume for a moment that the actual pattern is to take the digit in the first position and shift it to the end. Can your method be modified to accomodate that sequence?
So my python solution wasn't that 'dirty' after all :)

and if you would want it to repeat the sequences continuously (without line breaks).

CODE --> python

#! /usr/bin/env python
import sys

SEED = "0123456789"
sfwd = SEED
while True:
	srev = sfwd[::-1]
	sys.stdout.write(sfwd)
	sys.stdout.write(srev)
	s = sfwd[0]
	sfwd = sfwd[1:] + s 

Sample output

CODE --> console

01234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789009876543212345678901109876543234567890122109876543456789012332109876545678901234432109876567890123455432109876789012345665432109878901234567765432109890123456788765432109012345678998765432101234567890098765432123456789011098765432345678901221098765434567890123321098765456789012344321098765678901234554321098767890123456654321098789012345677654321098901234567887654321090123456789987654321012345678900987654321234567890110987654323456789012210987654345678901233210987654567890123443210987656789012345543210987678901234566543210987890123456776543210989012345678876543210901234567899876543210123456789 

I'll let somebody else count the iterations :)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Pattern problem.

>So my python solution wasn't that 'dirty' after all :)

Nope - pretty much the same as my initial solution, but deemed illegal given the revised conditions provided by mmerlinn smile

Unfortunately

SEED = "0123456789"

breaches

>No part of the input pattern may be assigned to a variable
>results must be entirely generated by the code, one digit at a time, without starting with any fixed variable(s).


RE: Pattern problem.

That's no big deal :)

Python password generator for you. :)

CODE --> python

import string
import random
SEED = ''.join(random.choice(string.letters + string.digits) for _ in range(10)) 

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Pattern problem.

kwbMitel, I agree with you completely. I should never use absolutes like "only". bigsmile

My statement about only calculating from the previous character was incorrect. It was actually using three things, previous character, offset into sequence, and current direction. But I have now shown that you can calculate any character based solely on it's position within the sequence.

So, the rules are...

Quote (mmerlinn)


Rules: The results must be generated by your code one digit at a time. String variables, if needed, are only permitted to build and output the results. No part of the input pattern may be assigned to a variable, although it is obvious that the intermediary and output results must be assigned to one or more variables. In other words, the results must be entirely generated by the code, one digit at a time, without starting with any fixed variable(s). Note that string variables are not even needed in some languages like C++.

  1. One digit at a time, check!
  2. String variables only for output. I don't use any, so check!
  3. No part of the input pattern may be assigned to a variable. I don't use an "input pattern", so check!
  4. Results must be generated one digit at a time. Definitely! Check!
  5. ...without starting with any fixed variables. Definitely! Check!
I think I hit them all! bigsmile

RE: Pattern problem.

I think we've scared them off

RE: Pattern problem.

So, rather than post my code for my solution (which would be archaic for those here) I will instead post my logic that could easily be converted into code

Using the 3 lines provided for reference

Reference line 3
Line 4 = subtract line 3 from 9999999999
Line 5 = Increment each digit of line 3 by 1 and Truncate left digit if >=10
Repeat until line 21 = 01234567890

Now would you like to see that using basic? I'm sure I could dig out my manual.

**********************************************
What's most important is that you realise ... There is no spoon.

RE: Pattern problem.

I'm also late to the party, but I'm going to have a moan.

It's a nice puzzle, but I'm worried that puzzles like this won't recruit the best and most creative staff (well, depending on the job, at least). What the question really asks is "Who thinks most like me?". If you want a problem-solver, it's best to make sure that the constraints are only real ones, not artificial ones. If someone can solve your problem in a way you didn't expect, and which is more elegant than your thought, employ them quickly! They may outshine you sometimes, but they'll make your product better than you could!

Of course there are real constraints in the real world that are actually annoyingly rubbish. If the boss insists on Fortran, that is a constraint. If the database only accepts files with the extension .hiThere and written in binary spelled out as text, backwards, then even though it's utterly stupid, the good employee must do the task (possibly hinting that it's ripe for an overhaul).

I'm also worried about next-number-in-the-sequence problems. These were certainly very popular in IQ tests when I was little, but that was before the online encyclopedia of integer series. If you take a typical IQ test of 30 years ago and enter the numers in OEIS, it frequently comes up with huge numbers of logical continuations. The problem with this sort of puzzle is that it tests the IQ of the tester, as much as the testee: it tests how far they can find a series that, with their limitations, appears to have only one continuation. An infinitely intelligent life-form from outer-space will always fail because there are an infinte number of continuations.

There is also a comment from Michael Abrash, I think, complaining that true coders leap in to a problem far too fast, realising they can see a solution, and often missing a much better solution that requires a more detailed think.

Sorry to be a grumpy old man, but I think recruitment is soooo important that it's vital to be careful how it is done. And thanks for the puzzle anyway!

RE: Pattern problem.

What I would look for in a coder when dealing with this problem is that they should challenge this statement:

Quote:

Everything you need to know is posted above. There should be no reason for me to answer any questions
If all they're given is a minimal list of desired outputs and no real guidance as to how those outputs have been produced, they should be demanding a proper spec - rather than guessing at what might be wanted and rushing to provide it.

If the required functionality isn't explicitly laid out in the spec, how will anyody test it to make sure it's working?

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd

RE: Pattern problem.

Yes, ChrisHunt. Misunderstandings are at the root of nearly all disasters. I would bet half a Mars-bar that nearly all big IT catastrophes that end up costing the public sector millions and get on the front page of newspapers (and probably also the private sector equivalents) are because someone didn't specify what was needed exactly enough, leading to a realisation mid-project that different people had different specifications in mind, and some people's aims were not going to fulfil what the project was actually supposed to do (in Layman's terms), leading to sudden "changes" in specification mid-project, which in turn leads to escalating costs as different teams find that they've been working at cross-purposes and now need to re-do old things, and develop work-arounds to deal with differences of opinion that they didn't expect, and also need to tackle whole new problems of which they hadn't been aware...

Having seen a few database developers in action, the best ones (I think) are the ones who keep on calmly asking what the point of the database is, what the users are trying to do, and how they currently do it, until both sides have agreed expectations. This often involves the users learning quite a lot about their own job, and realising that their data and working practices are quite different to what they thought! It takes considerable interpersonal skills as well as a good ability to combine overview of a complex problem with understanding of its nitty-gritty detail; an ability to observe and understand current approaches, but not be limited by them unnecessarily. I don't think many people can do it.

RE: Pattern problem.

Quote:

Having seen a few database developers in action, the best ones (I think) are the ones who keep on calmly asking what the point of the database is, what the users are trying to do, and how they currently do it, until both sides have agreed expectations. This often involves the users learning quite a lot about their own job, and realising that their data and working practices are quite different to what they thought! It takes considerable interpersonal skills as well as a good ability to combine overview of a complex problem with understanding of its nitty-gritty detail; an ability to observe and understand current approaches, but not be limited by them unnecessarily. I don't think many people can do it.

You know I couldn't agree more, and not just with database design. I've lost track of how many jobs that were totally different to how the managers described it once you get to understand what the users are actually doing.

And most user do not know WHAT they are doing, they just know how it's done from their perspective and what they need it to do for them.

One hour of asking the right questions is often worth several days of rewriting code.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Pattern problem.

As a telecoms engineer I can agree fully with all of that
often you get given requests for operation that are not the best way for the new system to operate.
The jsutification from the customer is always "Thats the way the old system did it". Often they have forgioten how much that complained obout that particular method of operation when the old system was installed smile

The goal should always be give the customer what they really want, not necessarily what they ask for. This can only be achieved by talking with them to find out what the end result should & then confirm the new process before starting.

Once the receptionist learns she can do her job faster with less effort the battle is won smile

A Maintenance contract is essential, not a Luxury.
Do things on the cheap & it will cost you dear

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close