Hope this helps.
it would help a lot if i could understand it...lol....i have only ever made simple programs so i don't understand anything you just said
Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver
camman977 wrote:Hope this helps.
it would help a lot if i could understand it...lol....i have only ever made simple programs so i don't understand anything you just said


Stewsburntmonkey wrote:Well, who's fault it that?
I do think people should understand that some languages are better for certain tasks than others. Languages have their niches and I think it is a good idea to know and understand those. I know it makes my life a lot easier.

einstein wrote:my programming/scripting ability is very very weak...
If i need to do something i'll learn how to do it then and there... my general knowledge of the language is therefore terrible...
Perfect example being by knowledge of PHP. I can happily make a website which relies solely on PHP, and it's interface with mySQL (the downlink challenge being an example)... but in order to do this challenge i had to basically "learn" the php functions required by reading php.net and then applying them...
I am not, nor do i claim to be, a programmer/scripter but when it is required that i code/script something... i can answer then call!
Code: Select all
# happy.tcl - Calculates whether a number is happy or not
# By coolsi (coolsi@crazie.co.uk), 2004
#
# !happy <number>
bind pub - !happy happy
# [squares] will take the digits of a number, square them and sum them. How kind!
proc squares { numchars number } {
set square 0
for { set i 0 } { $i < $numchars } { incr i } {
set num [string index $number $i]
set square [expr [expr $square + [expr $num * $num]]]
}
return $square
}
# happy is called by !happy...original, huh?
proc happy { nick host hand chan text } {
set number [lindex $text 0]
if { $number < 1 } {
putquick "PRIVMSG $chan ::|"
} else {
set numchars [string length $number]
set squared [squares $numchars $number]
while { $squared != 1 } {
set squared [squares [string length $squared] $squared]
if { $squared == 4 } { break }
}
if { $squared == 1 } {
putquick "PRIVMSG $chan :$number is a happy number!"
} elseif { $squared == 4 } {
putquick "PRIVMSG $chan :$number is an unhappy number :("
}
}
}
Code: Select all
<?PHP
$randomoruser = $_POST['randusr'];
$setoverall = 100; // Set a limit, in case of error and infinite loops
$overalltries = $setoverall;
if($randomoruser == "random"){
$intro = "Random number chosen";
$randint = rand(1,10000); //Generate a random number between 1 and 10000
} elseif($randomoruser == "user"){
$randint = $_POST['submitnumber'];
$intro = "User chosen number";
} else {
echo "
<form action='' method='post'>
<input type='hidden' value='random' name='randusr'>Generate random number: <input type='submit' value='Click'>
</form>
<br />
<form action='' method='post'>
<input type='hidden' value='user' name='randusr'><input type='text' value='Insert own number' name='submitnumber'><input type='submit' value='Click'>
</form>
";
exit;
}
echo "<b>$intro:</b> $randint<br />";
for($overalltries = $setoverall; $overalltries > 0; $overalltries--){
$lengthint = strlen($randint); //get random integer length
$pool = 0;
$runtimesone = 0;
echo "Trying number: $randint - ";
for($runtimesone == 0; $runtimesone < $lengthint; $runtimesone++){
$secondaryrun = $runtimesone + 1;
$dgts['$runtimesone'] = substr($randint, $runtimesone, 1); // Put each character into $dgts array
echo "(" . $dgts['$runtimesone'] . ") ";
if($dgts['$runtimesone'] == 0){
$dgts['$runtimesone'] = "0";
}
$squared = $dgts['$runtimesone'] * $dgts['$runtimesone']; // Square each digit
$pool = $pool + $squared; // Add the squared numbers
}
echo "--- Sqaured and added = $pool<br />";
if(($pool == 1) || ($pool == 4) || ($pool == 0)){
if($pool == 4){
$floop = 1;
} else {
$floop = "invalid";
}
break; // Halt the loop if it adds up to 1, or a 4 loop
}
$randint = $pool;
}
if($pool == 1){
echo "<br />We got ourselves a happy number!";
} else {
if($floop == 1){
echo "<br />Unhappy '4-loop' detected, not a happy number";
} elseif($floop == "invalid") {
echo "<br />Number supplied was 0, or not a number";
}
}
?>
Users browsing this forum: No registered users and 19 guests