Please login or register.

Login with username, password and session length
Advanced search  


Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: [Beginner] Programming Challenges I  (Read 3878 times)


  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
[Beginner] Programming Challenges I
« on: July 22, 2010, 03:58:04 am »

Cool idea I saw at where beginner programmers are challenged with some situations.  

So, who wants to try the first one?

The Challenge:
Write a program, in any free language, that prints to the terminal the lyrics to this song, 99 Bottles of Beer.

If you copy anything from that site, it will be obvious, so don't try it, although you may find that site useful for seeing code of many different languages.

Obviously I would expect to see PHP and JS code from here...
« Last Edit: July 22, 2010, 04:01:17 am by nukpana »


  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [Beginner] Programming Challenges I
« Reply #1 on: July 22, 2010, 03:59:03 am »

Here is my (un-whatever) try:

Code: [Select]

descCount($num) {
for ($i $num$i 0$i--) {
$array[] = $i;
return $array;

$num descCount(99);
array_push($num'no more');

foreach($num as $n) :

// Decending number
$d $n != 
$n 1

// Last descender
$d $d == 0
'no more'

// Plural Code
$npl $n == 1
$dpl $d == 1

$secndStmnt $n == 0
'Go to the store and buy some more'
'Take one down and pass it around';


<?php echo ucfirst($n); ?> bottle<?php echo $npl?> of beer on the wall, <?php echo $n?> bottle<?php echo $npl?> of beer.
<?php echo $secndStmnt?>, <?php echo $d?> bottle<?php echo $dpl?> of beer on the wall.
<br />
<?php endforeach; ?>