SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help me to write a code

    somebody please write a code in php for me

    I have a six digit value 958469, i want to create other values similar to this value by changing every digit from 0-9 of every position which will result 54 unique similar value of this. I know how to do it in excel but want a code in php to print the result.

    Result should be like this:

    Value : 958469

    result

    058469
    158469
    258469
    358469
    458469
    558469
    658469
    758469
    858469
    958469
    908469
    918469
    928469
    938469
    948469
    958469
    968469
    978469
    988469
    998469
    950469
    951469
    952469
    953469
    954469
    955469
    956469
    957469
    959469
    958069
    958169
    958269
    958369
    958469
    958569
    958669
    958769
    958869
    958969
    958409
    958419
    958429
    958439
    958449
    958459
    958469
    958479
    958489
    958499
    958460
    958461
    958462
    958463
    958464
    958465
    958466
    958467
    958468
    958469

  2. #2
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    689
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    This will get you started:

    PHP Code:
    // Break 958469 into digits
    $p1 9$p2 5$p3 8$p4 4$p5 6$p6 9;

    for(
    $p 0$p 10$p++) echo sprintf("%d%d%d%d%d%d\n",$p$p2,$p3,$p4,$p5,$p6);
    for(
    $p 0$p 10$p++) echo sprintf("%d%d%d%d%d%d\n",$p1,$p$p3,$p4,$p5,$p6);
    for(
    $p 0$p 10$p++) echo sprintf("%d%d%d%d%d%d\n",$p1,$p2,$p$p4,$p5,$p6);
    for(
    $p 0$p 10$p++) echo sprintf("%d%d%d%d%d%d\n",$p1,$p2,$p3,$p$p5,$p6);
    for(
    $p 0$p 10$p++) echo sprintf("%d%d%d%d%d%d\n",$p1,$p2,$p3,$p4,$p$p6);
    for(
    $p 0$p 10$p++) echo sprintf("%d%d%d%d%d%d\n",$p1,$p2,$p3,$p4,$p5,$p ); 
    You can generalize it and wrap it in a function.

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,835
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by ahundiak View Post
    ...
    You can generalize it and wrap it in a function.
    Challenge accepted

    PHP Code:
    $x 958469;
    xx($x);
    function 
    xx($x 958469)
    {
      
    $x = (string) $x;
      
    $y str_split($x);

      echo 
    '<br />';
      foreach(
    $y as $id => $val)
      {
        echo 
    '<br />'// .$id, ', ' .$val;
        
    for($i3=0$i3<10$i3++)
        {
          if(
    $id 0// Miss the first item
          
    {
              echo 
    substr($x0$id);
          }    
          echo 
    $i3 .substr($x1+$id);
         echo (
    $i3 9) ? ', &nbsp;  ' NULL;
        }
      }

    Output
    058469, 158469, 258469, 358469, 458469, 558469, 658469, 758469, 858469, 958469
    908469, 918469, 928469, 938469, 948469, 958469, 968469, 978469, 988469, 998469
    950469, 951469, 952469, 953469, 954469, 955469, 956469, 957469, 958469, 959469
    958069, 958169, 958269, 958369, 958469, 958569, 958669, 958769, 958869, 958969
    958409, 958419, 958429, 958439, 958449, 958459, 958469, 958479, 958489, 958499
    958460, 958461, 958462, 958463, 958464, 958465, 958466, 958467, 958468, 958469
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  4. #4
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mr. John_Betong

    Thanks for the reply, your code is very much near what i wanted. But your code prints 60 values in which 5 values are duplicate and one principal value for which we are generating similar number. In the result there should be 54 unique value excluding the main value.

    I will be grateful if you can help me to create code to get this result.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,172
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    If we are to "help" you and not "do it for you" you can help us by showing what you have tried and are having trouble with and don't understand.
    I love homework problems as much as the next guy, but my school days have long past.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •