Festive code

Pages: 12
Couldn't think of anything special, so I made this little code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include  <iostream>

            signed
          bar(signed
        u){unsigned i=1;
          for(unsigned
        s=0;s<u;s++)i*=2;
       return i;}void foo(
         const char*c){
      int i(0);for(unsigned u
    =0;u<=6;u++) i+=(c[u]=='1')
   *bar(6-u);std::cout << char(i);
       }int main(){foo("1001"
      "101");foo("1000101");foo
   ("1010010");foo("1010010");foo
 ("1011001");foo("0100000");foo("10"
"11000");foo("1001101");foo("1000001")
          ;foo("101001"
         "1");return 0;}
The binary thing was really cool.
Heh, thanks. :P

Besides, what does your code print? I haven't got a Perl interpreter or anything of the like at hand.
I've come to the conclusion that only programmers would get into an arguement about whether to use tabs or spaces... spaces all the way.
@Kyon
That's fun :) And chrisname's is cool, it has colours and singing :P everything you could want from a festive perl script.
@Kyon,
It prints the n days of Christmas in random colours. It does the 12 days of Christmas, and then starts again, but keeps incrementing n, so the 13th day of Christmas is the same as the 1st.
chrisname wrote:
I tried making another one, it was going to be a quine with the source formatted to say "MERRY XMAS" so that the program would print "MERRY XMAS" in code
I made one: obfuscated Xmas tree quine
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
#include <iostream>
#include <string>
                    std
                    ::
                  string
               escape(const
             std:: string&s){
               std:: string
             r;;;for(unsigned
          i=0;i<s.size();i++){if
              (s[i]==10){r+=
           "\\n\\\n";continue;
         }if((s[i]=='"')||(s[i]==
             '\\')) r+='\\';r
          +=s[i];}return r;}void
       print(const std:: string&s){
    for(unsigned i=0;i<s.size();i++)if
            (s[i]=='^'&& i!=s.
         size()-1&& s[i+1]=='^'){
      std::cout<<'"'<<escape(s)<<'"'
   ;i=i+1+0;}else std::cout<<s[i];;}int
                main(){
                print (
                "#include <iostream>\n\
#include <string>\n\
                    std\n\
                    ::\n\
                  string\n\
               escape(const\n\
             std:: string&s){\n\
               std:: string\n\
             r;;;for(unsigned\n\
          i=0;i<s.size();i++){if\n\
              (s[i]==10){r+=\n\
           \"\\\\n\\\\\\n\";continue;\n\
         }if((s[i]=='\"')||(s[i]==\n\
             '\\\\')) r+='\\\\';r\n\
          +=s[i];}return r;}void\n\
       print(const std:: string&s){\n\
    for(unsigned i=0;i<s.size();i++)if\n\
            (s[i]=='^'&& i!=s.\n\
         size()-1&& s[i+1]=='^'){\n\
      std::cout<<'\"'<<escape(s)<<'\"'\n\
   ;i=i+1+0;}else std::cout<<s[i];;}int\n\
                main(){\n\
                print (\n\
                ^^);;;;\n\
                return \n\
                0;}");;;;
                return
                0;}
#include <iostream>
#include <string>
                    std
                    ::
                  string
               escape(const
             std:: string&s){
               std:: string
             r;;;for(unsigned
          i=0;i<s.size();i++){if
              (s[i]==10){r+=
           "\\n\\\n";continue;
         }if((s[i]=='"')||(s[i]==
             '\\')) r+='\\';r
          +=s[i];}return r;}void
       print(const std:: string&s){
    for(unsigned i=0;i<s.size();i++)if
            (s[i]=='^'&& i!=s.
         size()-1&& s[i+1]=='^'){
      std::cout<<'"'<<escape(s)<<'"'
   ;i=i+1+0;}else std::cout<<s[i];;}int
                main(){
                print (
                "#include <iostream>\n\
#include <string>\n\
                    std\n\
                    ::\n\
                  string\n\
               escape(const\n\
             std:: string&s){\n\
               std:: string\n\
             r;;;for(unsigned\n\
          i=0;i<s.size();i++){if\n\
              (s[i]==10){r+=\n\
           \"\\\\n\\\\\\n\";continue;\n\
         }if((s[i]=='\"')||(s[i]==\n\
             '\\\\')) r+='\\\\';r\n\
          +=s[i];}return r;}void\n\
       print(const std:: string&s){\n\
    for(unsigned i=0;i<s.size();i++)if\n\
            (s[i]=='^'&& i!=s.\n\
         size()-1&& s[i+1]=='^'){\n\
      std::cout<<'\"'<<escape(s)<<'\"'\n\
   ;i=i+1+0;}else std::cout<<s[i];;}int\n\
                main(){\n\
                print (\n\
                ^^);;;;\n\
                return \n\
                0;}");;;;
                return
                0;}
Lol nice!
Here's my try:
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
#include <iostream>
#include <map>
#include <ctime>
#include <cstring>
#include <utility>
using namespace std;
#define ___  make_pair
                                              int
                                           _[][ 32]=
                                         {{0x00000000},
                                       {0x48617070,0x79204368,
                                   0x72697374,0x6d617320,0x457665,
                                 0},{0x4d657272,0x79204368,0x72697374,
                              0x6d6173},{0x48617070,0x7920686f,0x6c696461
                            ,0x7973},{0x48617070,0x79204e65,0x77205965,0x6172
                        },{0x48617070,0x79206269,0x72746864,0x61792c20,0x4e756c6c
                      },{0x4e6f2066, 0x75636b69, 0x6e672061,0x726d6167,0x6564646f,
                   0x6e20746f,0x64617921},{0x2066726f,0x6d204e75,0x6c6c21},{ 0x00000000
                } };void K(char _){uint32_t ___=clock(); while(true) { if( ( (long double)
              (clock()-___)/CLOCKS_PER_SEC)>0.1) break;}if(_==0) return; cout <<_; } void I (
           int ___, short ____ ){ }void I(int ___,bool ____){___==0?exit(666):I(8,(short)2);char
        *p=(char*)&_[___];for(int i=0;i<strlen(p);i+=4)for(int k=3;k>=0;k--) K(p[i+k]);____ ? I(7
     ,false): I(8,(short)2);}int J(){time_t _____;tm *_;time(&_____);_=localtime(&_____);map<pair<int,
  pair<int,int> >,int> __;__[___(0,___(11,24))]=1;__[___(0,___(11,25))]=2;__[___(0,___(11,26))]=2;__[___
(0,___(11,31))]=4;__[___(2012,___(11,21))]=6;__[___(0,___(9,23))]=5;for(int i=26;i<31; i++)__[___(0,___(11,i))]=3;
                        return __[___(_->tm_year+((986*2)-72)==2012 ? 2012:
                                       0,___ ( _-> tm_mon,
                                       _->tm_mday) ) ] ;}
                                       int main( ){ I(J()
                                      ,J()>4?false:true);}
                   /////////////////////////////////////////////////////////////////////
             ///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
That was cool, Null. Very... verbose.
Last edited on
Awesome shit here guys :D
A rather late festive 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
                             #include\
                            < vector >
                             #include\
                           < iostream >
                             template
                          <class T>bool
                        move(std::vector<T>&
                    x,std::vector<T>& y){return
                         (!x.empty()&&(y.
                      empty()||x[x.size()-1]<y
                    [y.size()-1]))?(y.push_back(x
                [x.size()-1]),x.pop_back(),true):false;
            }void print(std::ostream& os,const std::vector
                    <unsigned>& v){for(unsigned
                i=0;i<v.size();i++)os<<" "<<v[i];os
             <<"\n";}int main(){std::vector<std::vector<
           unsigned>*> Game;for(unsigned u=0;u<3;u++)Game.
       push_back(new std::vector<unsigned>);for(unsigned u=4;
              u>0;u--)Game[0]->push_back(u);unsigned
        input1(0),input2(0);std::cout<<"0: ";print(std::
    cout,*Game[0]);std::cout<<"1: ";print(std::cout,*Game[1])
;std::cout<<"2: ";print(std::cout,*Game[2]);do{std::cout<<"From:"
       " ";std::cin>>input1;if(input1>=3)break;std::cout<<
    "To:   ";std::cin>>input2;if(input2>=3)break;system("cls");
  move<unsigned>(*Game[input1],*Game[input2]);std::cout << "0: ";
print(std::cout,*Game[0]);std::cout<<"1: ";print(std::cout,*Game[1])
                      ;std::cout<<"2: ";print
                      (std::cout,*Game[2]);}
                      while(true);while(!Game
                      .empty()){delete Game[
                       Game.size()-1];Game.
                      pop_back();}return 0;}


Gratz to he who figures out what this does.

EDIT:
I forgot to apologize for the use of a system() call in that code, so here goes;
Sorry.
Last edited on
I can't understand what it's doing at all...
It's a puzzle (use inputs from 0 to 2).
I got that far, I just can't figure out what I'm aiming to do.
http://en.wikipedia.org/wiki/Tower_of_Hanoi

Although there is no check to determine whether you moved the entire stack to a different pin.
I forgot they were supposed to go on a different stack so they ended up exactly the same as they were at the start...
This one actually checks whether you solved the puzzle.
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
#include <vector>
#include <iostream>
#include <string>

                        template
                     <class T> bool
                  move(std::vector<T>&
               x,std::vector<T>& y){return
                   (!x.empty()&&(y.empty
                 ()||x[x.size() - 1]<y[y.
              size()-1]))?(y.push_back(x[x.                                 size()
                 -1]),x.pop_back(),true                                    ):false;}
               void print(std::ostream& os                               ,const std::
            vector<unsigned>& v){for(unsigned                          i=0;i<v.size();i
         ++)os<<" "<<v[i];os<<"\n";} int main(){                         std::vector
             <std::vector<unsigned>*> Game;                           for(unsigned u=0;
          u<3;u++)Game.push_back(new std::vector                   <unsigned>);for(unsigned
        u=4;u>0;u--)Game[0]->push_back(u);unsigned                   input1(0),input2(0);
     std::cout<<"0: ";print(std::cout,*Game[0]);std::              cout<<"1: ";print(std::
  cout,*Game[1]);std::cout<<"2: ";print(std::cout,*Game          [2]);do{std::cout<<"From: "
                  ;std::cin>>input1;                                      if(input1
                  >=3)break; std::                                        cout<<"To"
                  ":   ";std::cin>>                                       input2;if

(input2          >=3)break;
system(        "cls");move
<unsigned    >(*Game
[input1],*Game[input2
]);if(Game[1]               ->size()      ==4||           Game[2]->size           ()==4)        {std::
cout << "Yo"                 "u win!"   "\nPre"           "ss"     " <"           "any key"     "> fo"
"llowed by an e"               "nter.";std::             string    foo(           "");std::cin  >>foo;
break;}     else{                  std::                  cout     <<"0"           ": ";   print(std::
cout,*       Game[0]);             std::                  cout     <<"1"           ": ";     print(std
::cout        ,*Game[1]            );std                  ::cout<<"2: ";           print        (std::

cout,*Game[2]);}}while(true);while(!Game.empty()){delete Game[Game.size()-1];Game.pop_back();return 0;}
Cool!
Happy Christmas!
Topic archived. No new replies allowed.
Pages: 12