Update my Blog with some C Programming

Ok, to busy in live, and i don’t have time to update my blog 🙁
So, today i got some exam with C Programming and turn out bad

here some code i work on in the exam, a little bit messy code 🙂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>

void main()
{
    int xn, yn, i, j, x[4], y[4], done = 0, jalan, gerakan[100], jml = 0, temp;
    scanf("%d %d", &xn, &yn);
    int papan[xn][yn];
    for(i = 0; i < 4;i++)
    {
        scanf("%d %d", &x[i], &y[i]);
    }
    scanf("%d", &jalan);
    i = 0;
    while(jalan > 0)
    {
        temp = (jalan/10)*10;
        gerakan[i] = jalan - temp;
        jalan = temp/10;
        jml++;
        i++;
    }
   
    for(i = 0;i < yn;i++ )
    {
        for(j = 0; j < xn; j++)
        {
            papan[j][i] = 0;
        }
    }

    for(i = jml-1; i >= 0;i--)
    {
        if(gerakan[i] == 1)
        {
            if((x[0] + 1) < xn)
            {
                x[3] = x[2];
                x[2] = x[1];
                x[1] = x[0];
                y[3] = y[2];
                y[2] = y[1];
                y[1] = y[0];
                x[0]++;
            }
        }
        else if(gerakan[i] == 2)
        {
            if((y[0] + 1) < yn)
            {
                x[3] = x[2];
                x[2] = x[1];
                x[1] = x[0];
                y[3] = y[2];
                y[2] = y[1];
                y[1] = y[0];
                y[0]++;            
            }
        }
        else if(gerakan[i] == 3)
        {
            if((x[0] - 1) >= 0)
            {
                x[3] = x[2];
                x[2] = x[1];
                x[1] = x[0];
                y[3] = y[2];
                y[2] = y[1];
                y[1] = y[0];
                x[0]--;            
            }
        }
        else if(gerakan[i] == 4)
        {
            if((y[0] - 1) >= 0)
            {
                x[3] = x[2];
                x[2] = x[1];
                x[1] = x[0];
                y[3] = y[2];
                y[2] = y[1];
                y[1] = y[0];
                y[0]--;            
            }
        }
    }

    printf("\n");
    for(i = 0; i < 4; i++)
    {
        papan[x[i]][y[i]] = 1;
    }
   
    for(i = 0;i < yn;i++ )
    {
        for(j = 0; j < xn; j++)
        {
            printf("%d ", papan[j][i]);
        }
        printf("\n");
    }
   
}

Ok here’s the screenshot :

So first input the size of the matrix x X y
and then put the snake coordinate x y
put the snake body coordinate
and the last one is for the tail
and then put some integer value from 1 to 4
the rule is 1 to go right, 2 to go down, 3 to go left, and 4 to go up

I hope this helpful to who ever read this 😀

Convert Decimal to Roman with MSSQL

Today I got assignment to make ms sql function to convert decimal to roman numeral
here’s the code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Function DecToRom
(
    @InputNumber as varchar(MAX)
)
RETURNS varchar(MAX)
AS
BEGIN
  DECLARE @Hasil varchar(MAX), @RomanLetter varchar(7), @InputTemp bigint, @Posisi int, @Mod bigint
 
  SET @Hasil = ''
  SET @RomanLetter = 'IVXLCDM'

  IF @InputNumber = 0
        SET @Hasil = '0'
  ELSE
  BEGIN
    SELECT @Posisi = 1, @InputTemp = ABS(@InputNumber)
   
    WHILE(@Posisi <= 5)
    BEGIN
        SET @Mod = @InputTemp % 10
        SET @InputTemp = @InputTemp / 10
       
        SELECT @Hasil = CASE
         WHEN @Mod IN (0,1,2,3) THEN        
           Replicate( SubString( @RomanLetter, @Posisi, 1 ), @Mod ) + @Hasil
         WHEN @Mod IN (4) THEN
           SubString( @RomanLetter, @Posisi, 2 ) + @Hasil
         WHEN @Mod IN (5,6,7,8) THEN
           SubString( @RomanLetter, @Posisi + 1, 1 ) +
           Replicate( SubString( @RomanLetter, @Posisi, 1 ), @Mod - 5 ) + @Hasil
         WHEN @Mod IN (9) THEN
           SubString( @RomanLetter, @Posisi, 1 ) + SubString( @RomanLetter, @Posisi + 2, 1 ) + @Hasil
        END
         
        SET @Posisi = @Posisi + 2
    END
   
    SET @Hasil = Replicate('M', @InputTemp) + @Hasil
   
    IF @InputNumber < 0
        SET @Hasil = '-' + @Hasil
       
   END

   RETURN @Hasil
END
GO

credit to sql-bi-dev

WordPress Permalink With IIS 6 Using IIRF

Previously i’m using Isapi_Writer 3.0 from HeliconTech to use permalink for WordPress but sadly it not goes smoothly, i got problem with the permalink, it turn off randomly and get another 404 page, so i try another method, now i try using IIRF (can be download it here) and use this in IIRF.ini :

1
2
3
4
5
6
7
8
9
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d                                
RewriteRule ^/sitemap.xml$   - [L]

RewriteRule ^wp-(.*)$ /wp-$1 [L]
RewriteRule ^xmlrpc(.*)$ /xmlrpc$1 [L]

RewriteRule ^(index.php)*(.*)$ index.php/$2 [NC,L]

Now it’s really fixed, i hope 😀

Update : Again i got another 404 Page
so i change the RewriteRule to

1
RewriteRule ^(index.php)*(.*)$ index.php/$1 [NC,L]