$100 Laptops
"The MIT Media Lab has launched a new research initiative to develop a
$100 laptop-- a technology that could revolutionize how we educate the
world's children. One Laptop Per Child (OLPC) was announced by Nicholas
Negroponte, Lab chairman and co-founder, at the World Economic Forum at
Davos, Switzerland in January 2005."
Read more on this at <http://laptop.media.mit.edu/>.
Love ko to
Thank God for McDonalds. With my present job as a programmer, I find myself waking in odd hours because my body clock is already used to it. Because I don't know how to cook my own meal, I have to rely on restaurants and cafeterias to supply my body with much-needed energy. The restaurants are already closed at this hour, so I had to sacrifice my hard-earned money just to eat. McDo is kindda expensive. I spend more than a hundred bucks, and I'm still not satisfied. The McDo crowd is different in the evening. I find myself surrounded by Med and Law students who are burning the midnight candle. Anyway, I'll just eat to my heart's content tommorrow.
Ten-digit Perfect Square Numbers
In one of the mailing lists that I've subscribed to, a question was
posed yesterday for finding a ten-digit number consisting of distinct
digits that is a perfect square. Wikipedia defines a perfect square as "a positive integer which is the square of some other integer, i.e. can be written in the form n^2 for some integer n."
I wanted to code my solution using C/C++, but not all of us have
compilers. Thus, I coded my solution using JavaScript. To
see the results, just copy and paste the code below and save it to a
file with .html as its filename extension. Then, run it in your
browser.
Some of the Answers
1026753849 (lowest value)
9814072356 (highest value)
There are 87 possible answers.
Solution
<script type="text/javascript">
function isUnique(n) {
var str = new String(n);
var tmp = new Array(10);
for(var i = 0; i < 10; i++) {
tmp[i] = null;
}
for(var i = 0; i < 10; i++) {
if(tmp[str.charAt(i)] == null) {
tmp[str.charAt(i)] = str.charAt(i);
} else {
return false;
}
}
return true;
}
function main() {
var lbound = 31992;
var ubound = 99380;
var count = 0;
for(var i = lbound; i <= ubound; i++) {
if(isUnique(i * i)) {
document.write((i * i) + "<br />");
count++;
}
}
document.write("There are " + count + " possible answers.");
}
main();
</script>
Discussion
The lowest possible solution is 1023456789, and the highest
possible solution is 9876543210. Although 0123456789 is the
lowest possible number that can be constructed using 10 distinct
digits, I leave you to find out why we can't use it as a lower bound
(duh). :)
The square root of 1023456789 is aprox. 31991.51. We round it
off to 31992, and start finding the solution here. The square
root of 9876543210 is aprox. 99380.80. We round it off to 99381,
and stop finding the solution here. The script then calculates
the square of every number from 31992 to 99381, and displays it if the
result consists of distinct digits.
Posted by: simoncpu in: With Logic and Chaos
Modified on July 15, 2005 at 8:17 PM
Dreams
It's been years since I've last remembered my dreams. I don't know why, but it seems that I have lost my ability to recall them as I grew older. When I was a 3-year old kid, I often had this dream, which seems very real, about wandering around our neighborhood accompanied by my guardian spirits (I sometimes see Satan, but he can't hurt me nor can my guardian spirits hurt him). Today, I'll try to bring back that "skill" because I could just imagine the many possibilities I can do in my dreams. I'm no longer a 3-year old kid, so my motivations *ehem* are no longer innocent. Hehe.
Coldfusion's isNumeric(): A different approach
My friend, Aldwin, has a different approach in solving the isNumeric()
problem mentioned in my previous post. Here is his solution for
the module that he's working on (I've slightly modified it to remove
sensitive information):
<cfset acceptonly = "1,2,3,4,5,6,7,8,9,0,.,-">
<cfif listfind(acceptonly, str, ",") gt 0>
This is not a valid number.
<cfelse>
This is a valid number.
</cfif>
Please note that this is only applicable for certain (preferrably pre-validated) inputs. This will not flag an error for inputs such as "8.-.16-" or "...32.256"
Work-around for Coldfusion's isNumeric() function
Problem: You need to
determine whether a given input is a number or not.
Unfortunately, Coldfusion's isNumeric() function only checks whether a
number can be treated as a number internally. Therefore, the
following strings (without the quotation marks) would cause the
function to return a true value:
"16d"
"128f"
"32e256"
Although this is fine for many applications, this is often not the desired behaviour such as when you need to validate them before passing it to a MySQL query.
Solution: A solution I've found so far is to use Regular Expressions. We use REFind to search for the following regex pattern:
Example:
This is a vaild number.
<cfelse>
This is not a valid number.
</cfif>
Please note that this is also applicable to other programming languages that support Regular Expressions (i.e.: either built-in or through a library), although this may no longer be necessary for more elegant languages such as PHP (sorry, I'm biased).
Generating RTF
I'm making a web-based payroll system right now. Since we need to
generate print-outs of the data, I opted to format it using Microsoft's
proprietary (?!) Rich Text Format (RTF). I didn't choose PDF
because it's a bit complicated, and because we are on a tight deadline
(was it a correct decision?). I have no formal training on this
whatsoever, so I had to rely on samples to deduce some of the rules
that make up this document language.
The text that MSWord generates is so horrible. I had to examine lengthy sequences such as this:
This is fun! :)
The Tao of Programming
When I was a kid, I used to find The Tao of Programming rather boring
and confusing. Now that I'm older (but still a kid, nevertheless), I
now find it very funny because I can now relate.
Read more about the Tao of Programming here.
Wala Lang
Yikes. This blog is supposed to be a venue where I can discuss problems, solutions, and ideas
relating to Computer Science and Information and Communication
Technology. I don't know why I can't bring myself into the mood
for serious thinking right now. I've been waiting for it to come,
but it seems that I can only sustain my concentration for a couple
of hours each day.
Anyway, this post shall mark the end of my posting inane remarks in this blog.
deleted
*poof* This entry is now null and void.