Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream> // For outputting shit, obvsly.
- #include<stdlib.h> // So I can end with a fuck you.
- #include<stdio.h> // Actually, screw cout.
- #include<math.h> // For the better is_even function.
- #include<assert.h> // Asserting stuff.
- using namespace std; //Fuck typing std:: everywhere, seriously.
- void ex41a(){
- unsigned int n = 2; // I don't want to be prompted every time I run this shit.
- //cin >> n;
- unsigned int x = 1;
- if (n > 0) {
- unsigned int k = 0;
- bool e = true;
- do {
- if (++k == n) { e = false; }
- x *= 2;
- }
- while(e);
- }
- printf("[ex41a] f(%d): %d\n", n, x);
- }
- void ex41d(){ //Time to make a non-fucked version, yay.
- unsigned int n = 2;
- unsigned int x = 1;
- for(unsigned int i=0;i<n;++i){ x*=2;} //Single line because it's basically one statement. Fuck you.
- printf("[ex41d] f(%d): %d\n", n, x);
- }
- void ex44a(){
- double n = 0; //Changed from float to double. DUH.
- while (n < 100000000) {
- ++n;
- }
- printf("[ex44a] f(): %d\n", n);
- }
- void ex44b(){
- float x = 5000;
- float y = 4999;
- float res = (double)(x) * x - (double)(y) * y; //Casting to doubles to momentarily have double precision calculations.
- printf("[ex44b] f(%f,%f): %f\n", x,y, res);
- }
- bool is_even (const double i){ //Biggest possible data type is probably best here.
- //if (i % 2 == 0) return true;
- return (fmod(i,2) == 0); //Fuck you.
- }
- void ex51a(){
- int n = -21;
- printf("[ex51a] f(%d): %d\n", n, is_even(n));
- }
- double invert (double x){
- return (x == 0)? 0 : 1/x;
- }
- void ex51b(){
- double n = 20;
- printf("[ex51b] f(%f): %f\n", n, invert(n));
- }
- int min2(int a, int b){
- return (a<=b)? a : b; // This is fucking kindergarden shit.
- }
- void ex52a(){
- int n = 20, m = 0;
- printf("[ex52a] f(%d,%d): %d\n", n,m, min2(n,m));
- n = -10; m = 20;
- printf("[ex52a] f(%d,%d): %d\n", n,m, min2(n,m));
- }
- int min4(int a, int b, int c, int d){
- return min2(min2(a,b),min2(c,d));
- }
- void ex52b(){
- int a=4, b=2, c=1, d=3;
- printf("[ex52b] f(%d,%d,%d,%d): %d\n", a,b,c,d, min4(a,b,c,d));
- }
- //Not entirely accurate, but Good Enough(TM)
- bool is_leap_year(int year){
- return ((fmod(year,4) == 0 && fmod(year,100) != 0) || fmod(year,400) == 0);
- }
- //Holy shiet, this really needed a function.
- bool is_valid_month(int month){
- return (month<=12 && month>=1);
- }
- //Used twice, so validation got split off.
- //Ugly switch, but whatever.
- int days_in_month(int year, int month){
- switch(month){
- case 1: // January
- case 3: // March
- case 5: // May
- case 7: // July
- case 8: // August
- case 10: // October
- case 12: // december
- return 31;
- break;
- case 2: // February
- return(is_leap_year(year))? 29 : 28;
- break;
- default: //Rest
- return 30;
- break;
- }
- }
- bool is_valid_day(int year, int month, int day){
- return (day>=1 && day<=days_in_month(year, month));
- }
- int day_of_week(int year, int month, int day){
- assert (is_valid_month(month));
- assert (is_valid_day(year, month, day));
- //We use here that January 1st 2006 was a Sunday. Hence the +1 at the end there, to wrap around to monday.
- int refyear = 2006;
- //Calculate all the days in the months gone by.
- int days_of_months = 0;
- for(int i=1;i<month;i++){
- days_of_months+=days_in_month(year, i);
- }
- //Normally I'd push this all into the return but fuck it.
- int days_total = ((is_leap_year(year))? 366 : 366)*(year-refyear)+days_of_months+day;
- //Mod7 gives us the day of week. YEA.
- return fmod(days_total+1, 7);
- }
- int c_day_of_week(int y, int m, int d){
- return (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7; // C fun times.
- // Actually really nifty and still relatively easy to read.
- // Taken from: http://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
- }
- void ex53(){
- int year = 2013;
- int month = 10;
- int day = 22;
- printf("[ex53] f(%d,%d,%d): %d\n", year,month,day, day_of_week(year,month,day));
- printf("[ex53] c_f(%d,%d,%d): %d\n", year,month,day, c_day_of_week(year,month,day));
- }
- // Stupid fucking main function to call everything else.
- int main (){
- ex41a();
- ex41d();
- ex44a();
- ex44b();
- ex51a();
- ex51b();
- ex52a();
- ex52b();
- ex53();
- return atoi("Fuck You.");
- }
- //I want my REPL back.
- //WTFs encountered:
- //You can't have varags in any sane manner.
- //You can't concatenate things into strings in any easy manner.
- //There's to_string() in C++11, but it can't be passed to printf?
- //Everything
- //TRWTF is C++
- //No local functions. I think they added lambdas (fucked) in 11 though??
- //Silent failings in general.
- //I can't abstract away the printfs without an immense amount of wtf, no matter how I try
- //Teaching something like C++ as a first.
- //Good things:
- //I can return "Fuck you" as exit value.
- //I don't have to work with this for my own projects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement