> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# 1, 2, 3, 4, 5, Shaggy - Programming Puzzles
- URL: https://developerinsider.co/1-2-3-4-5-shaggy-programming-puzzles/
- Published: 2016-11-15T06:19:50.000Z
- Updated: 2019-11-01T16:22:55.000Z
- Author: Vineet Choudhary
- Tags: Programming Puzzles, Puzzles

This is a game where you must count to number from 0 to 1000\. However, if the number has a 6 in it, or is divisible by 6, you don't say the number. Instead, you say "Shaggy".

**Rules:**

- You can't hard-code the numbers.
- The number only has to satisfy at least 1 of the following requirements  
  - Divisible by 6
  - Number contains a 6
- Some type of separator is mandatory (12345Shaggy7.. doesn't count)
- You must count exactly to 1000 from 1.
- The numbers must be output, but it doesn't matter how (e.g., stdout, writing to a text file, etc.).

# Solutions

**Jump to [C](#c), [Swift](#swift), [JavaScript](#javascript), [PHP](#php) Solution.**  
You can submit your own solution in [comment section](#comments) in same/different programming language. If your solution is better or in different language we'll add here.

## C

```c
#include <stdio.h>

int main()
{
    for(int i=1;i<=1000;++i)
    {
        if(i%6)
        {
            for(int m=i;(m>0);m/=10) if (m%10==6) goto l;
            printf("%d,",i);
            continue;
        }
        printf("Shaggy,");
    }
    return 0;
}

```

## Swift

```swift
import Foundation

for i in 1...1000 {
    print(i%6<1 || (String(i).range(of: "6") != nil) ? "Shaggy" : "\(i)")
}

```

## JavaScript

```js
<html>
<body>
    <p id="print"></p>
    <script>
        for(i=0;i++<1000;)
        document.getElementById('print').innerHTML += i%6<1|/6/.test(i)?'Shaggy\n':i+'\n';
    </script>
</body>
</html>

```

## PHP

```php
<?
for(;1000>$i++;)
    echo$i%6*!strpbrk($i,6)?$i:Shaggy,"\n";

```