Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:46:41+00:00 2026-05-23T15:46:41+00:00

I am searching for someone who could write me a script to output the

  • 0

I am searching for someone who could write me a script to output the following pattern:

http://img84.imageshack.us/img84/3038/82351644.png

its starting with 0 in the center, then 1 to the left, 2 down, 3 right…you get the idea. – its always 0 to 9 and starting over again…

i found this topic , but it is clearly different from my request.
since i have no good understanding of php and the “pros” are here,
i am asking nicely if someone would spend some time doing this for me.
That would be great! Also if I could set in a variable how many “rounds” the script is performing, that would be awesome! – Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:46:42+00:00Added an answer on May 23, 2026 at 3:46 pm

    Just because I had nothing better to do and I always like a challenge:

    <?php
    
    // A few constants.
    define('DOWN', 0);
    define('LEFT', 3);
    define('RIGHT', 1);
    define('UP', 2);
    
    // Dictates the size of the spiral.
    $size = 11;
    
    // The initial number.
    $number = 0;
    
    // The initial direction.
    $direction = RIGHT;
    
    // The distance and number of points remaining before switching direction.
    $remain = $distance = 1;
    
    // The initial "x" and "y" point.
    $y = $x = round($size / 2);
    
    // The dimension of the spiral.
    $dimension = $size * $size;
    
    // Loop
    for ( $count = 0; $count < $dimension; $count++ )
    {
      // Add the current number to the "x" and "y" coordinates.
      $spiral[$x][$y] = $number;
    
      // Depending on the direction, set the "x" or "y" value.
      switch ( $direction )
      {
        case LEFT: $y--; break;
        case UP: $x--; break;
        case DOWN: $x++; break;
        case RIGHT: $y++; break;
      }
    
      // If the distance remaining is "0", switch direction.
      if ( --$remain == 0 )
      {
        switch ( $direction )
        {
          case DOWN:
            $direction = LEFT;
            $distance++;
    
            break;
          case UP:
            $distance++;
    
          default:
            $direction--;
    
            break;
        }
    
        // Reset the distance remaining.
        $remain = $distance;
      }
    
      // Increment the number or reset it to 0 if the number is 9.
      if ( $number < 9 )
        $number++;
      else
        $number = 0;
    }
    
    // Sort by "x" numerically.
    ksort($spiral, SORT_NUMERIC);
    
    foreach ( $spiral as &$x )
    {
      // Sort by "y" numerically.
      ksort($x, SORT_NUMERIC);
    
      foreach ( $x as $ykey => $y )
        // Output the number.
        echo $y . ' ';
    
      // Skip a line.
      echo PHP_EOL;
    }
    

    Outputs:

    0 1 2 3 4 5 6 7 8 9 0 
    9 2 3 4 5 6 7 8 9 0 1 
    8 1 2 3 4 5 6 7 8 9 2 
    7 0 1 0 1 2 3 4 5 0 3 
    6 9 0 9 6 7 8 9 6 1 4 
    5 8 9 8 5 0 1 0 7 2 5 
    4 7 8 7 4 3 2 1 8 3 6 
    3 6 7 6 5 4 3 2 9 4 7 
    2 5 6 5 4 3 2 1 0 5 8 
    1 4 3 2 1 0 9 8 7 6 9 
    0 9 8 7 6 5 4 3 2 1 0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone write this literally for me so I can understand how the casting
Ok, quick points for someone who is better at searching than I am... I
Searching online, I have found the following routine for calculating the sign of a
So I tried searching SO hoping someone had a good explanation of this, with
I'm searching ways to identify scores, when someone is playing i.e. guitar. How can
Can someone shed some light on how searching is done on web-sites like del.icio.us?
Can someone please help. I have been searching and encountered/modified this code I am
Could someone give me a link, a tutorial or an already made css template
I have been searching around for a solution for quite some time, hoping someone
I am using the following url to stream twitter data. http://stream.twitter.com/1/statuses/filter.json?count=-150&follow=16256661&track=indiana Without the count

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.