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

  • SEARCH
  • Home
  • 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 130795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:00:15+00:00 2026-05-11T06:00:15+00:00

As a fun side-project for myself to help in learning yet another PHP MVC

  • 0

As a fun side-project for myself to help in learning yet another PHP MVC framework, I’ve been writing Reversi / Othello as a PHP & Ajax application, mostly straightforward stuff. I decided against using a multidimensional array for a number of reasons and instead have a linear array ( in this case 64 elements long ) and a couple methods to convert from the coordinates to integers.

So I was curious, is there any other, possibly faster algorithms for converting an integer to a coordinate point?

function int2coord($i){     $x = (int)($i/8);     $y = $i - ($x*8);           return array($x, $y); }  //Not a surprise but this is .003 MS slower on average function int2coord_2($i){     $b = base_convert($i, 10, 8);     $x =  (int) ($b != 0 ? $b/8 : 0); // could also be $b < 8 for condition     $y = $b % 10;     return array($x, $y); } 

And for posterity sake, the method I wrote for coord2int

function coord2int($x, $y){    return ($x*8)+$y; } 

Update:
So in the land of the weird, the results were not what I was expecting but using a pre-computed lookup table has predominantly shown to be the fastest, guess trading memory for speed is always a winner?

  • There was a table with times here but I cut it due to styling issues with SO.
  • 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. 2026-05-11T06:00:16+00:00Added an answer on May 11, 2026 at 6:00 am

    I don’t have the time to measure this myself right now, but I would suspect that a pre-computed lookup table would beat your solution in speed. The code would look something like this:

    class Converter  {     private $_table;      function __construct()      {         $this->_table = array();         for ($i=0; $i<64; $i++) {             $this->_table[$i] = array( (int)($i/8), (int)($i%8) );          }     }      function int2coord( $i )     {         return $this->_table[$i];     } }  $conv = new Converter();  $coord = $conv->int2coord( 42 ); 

    Of course, this does add a lot of over-head so in practice you would only bother to pre-compute all coordinates if you conversion code was called very often.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This works out of the box. However, if you are… May 11, 2026 at 9:05 pm
  • Editorial Team
    Editorial Team added an answer split takes a regular expression, so you can do: String[]… May 11, 2026 at 9:05 pm
  • Editorial Team
    Editorial Team added an answer In general, there is no efficient ways to remove specific… May 11, 2026 at 9:05 pm

Related Questions

As a side project, for fun, I'm rewriting my blog and CMS in Flex
I admit the linux network system is somewhat foreign to me, I know enough
I'm looking to build a VM into a game and was wondering if anyone
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.