Minic

From Esolang
Jump to navigation Jump to search

Minic is a variation of C that looks a lot like C that is invented by User:A. It maintains the goals of Keg as much as possible. Its primary purpose is used for golfing. However, it will only do good on complex problems, as simple problems(like the Hello, world! program) will result in a long program in Minic.

Differences

You should note that the parameters of main is used to declare variables, and you can declare them elsewhere. However, declaring them in the main parameters significantly golfs programs.

Example:

main(x=1,y='2',z[12]="3") {}

This defines x as 1, y as 2, and an array z with length 12 as the string 13. Of course you don't have to set them into values:

main(x,y,z[12]) {

}

Other than that, the differences are so tiny that they are barely noticable.

Examples

Calculate the Pyramid problem

Several balls are in a pyramid.
On the first row, there is 1 ball.
On the second row, there are 3 balls.
On the third row, there are 6 balls.
On the fourth row, there are 10 balls.
...
If there are 100 rows, how many balls are there? (It should print 171700) (55 bytes)

main(s,t,i=1){for(;i<101;++i)s+=t+=i;printf("%d\n",s);}

Hello, world! program (32 bytes)

main(){puts("Hello, world!");}

Enumerate how many 'A' 's are on a line of input (64 bytes)

main(i,c){for(;(c=getchar())!=-1;c==65?++i:0);printf("%d",--i);}

Make a function w evaluating what weekday is on a specified year, month, and day. (71 bytes)

w(y,m,d){if(m<3)m+=12,--y;return(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;}

Enter a string.

Enter a string. Change all characters in the alphabet to the next character in the alphabet without changing other characters. The next charater of Z is A, and the next character of z is a. (83 bytes)

main(c){for(;(c=getchar())!=-1;isalpha(c)?++c:0,c==91||c==123?c-=26:0,putchar(c));}

99 bottles of beer program(164 bytes)

main(b=99){for(;(printf("%d bottles of beer on the wall, %d bottles of beer.\nTake one down, pass it around, %d bottles of beer on the wall.\n",b,b,b-1),b>1);--b);}