473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help Understanding Script?

I want to understand how exactly this script works. Basically, it returns every combination that is possible using '.' - for example:

sam
s.am
sa.m
s.a.m

Can you explain what exactly it is going through on each step? I understand some of it, but not others - like $combinations = 1 << ($strlength - 1);

Expand|Select|Wrap|Line Numbers
  1. sub isBitSet { if ($_[0] & (1 << ($_[1] - 1))) { return 1; } else { return 0; }}
  2.  
  3. sub possibilize {
  4.   $strlength = length($_[0]);
  5.   if ($strlength > 20) { return 0; }
  6.   $combinations = 1 << ($strlength - 1);
  7.   $strloc = 0; $str = "";
  8.   for ($x = 0; $x < $combinations; $x++) {
  9.     $strloc = 1; $str = $_[0];
  10.     for ($y = 1; $y < $strlength; $y++) {
  11.       $str = substr($str, 0, $strloc);
  12.       if (isBitSet($x, $y)) { $str.= "."; $strloc++; } 
  13.       $str.= substr($_[0], $y); $strloc++;
  14.     } $out.= $str.
  15.   } return $out;
  16. }
Jul 17 '07 #1
1 1009
Can anyone explain?
...
Jul 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Elmbrook | last post by:
Hi, I've been trying to figure out this javascript code used here (this code is used for supplying browser info to a tracking company): In particular I'm trying to understand this line:...
14
by: StumpY | last post by:
HI, I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in...
4
by: Gequina | last post by:
Something goes wrong in my script. I'm all new to it so i don't know much yet. I have a set of buttons. And when you click on either of them, the background image will change. Only it's not...
17
by: Phil McKraken | last post by:
I am having a problem putting together a shopping cart with the below script. Everything displays fine, adds totals fine, and works perfect EXCEPT if you choose the 9.95 item #5 BY ITSELF the total...
2
by: Polyhedron_12 | last post by:
I am having problems calling functions in general in VB. I keep getting alot of errors. Can anybody help me out with this? I put the error message on the same line that it says it is at. I believe...
1
by: hel | last post by:
Hi I have just adopted a PHP project and need some help understanding DB_DataObject. I've looked around on the web and can't find a simple explanation. Basically, my MySQL database has no...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
4
by: eBob.com | last post by:
I am trying to understand a bit of JavaScript from http://developer.yahoo.com/maps/simple/jspost.html (appended below). I'd appreciate help understanding two things it. The first is the...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.