Let's test ourselves: Talking in code.

Pages: 12
closed account (L6b7X9L8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using std::cout;

int main()
{
        cout << "My aim is for as many users as possible to create a program\n";
        cout << "that can reply to the post above it using a slightly harder\n";
        cout << "method of programming. I'm hoping to get as far as 5 replies\n";
        cout << "at least before I start getting lost in the code! Ib4 Disch :)\n";
        cout << "\nYou can only use the STL so no boost and the program must\n";
        cout << "compile! If it doesn't your post does not count, that's the rules.\n";
        cout << "I'm looking forward to how wacky people can make their code!\n";
        return 0;
}
closed account (L6b7X9L8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
using std::cout;
using std::string;

enum Jirachi { Squirtle, Wartortal, Blastoise, Charmander, Charmeleon, Charizard, Bulbasaur, Venasaur, Ivysaur, Pikachu, Raichu, Togepi };

string Celebi[Togepi] = { "Of", "The", "A", "Interesting", "Haha", "Include", "Define", "That", "This", "Use", "Better" };


int main()
{
        cout << Celebi[Charmander] << " " << Celebi[Pikachu] << " " << Celebi[Squirtle] << " " << Celebi[Bulbasaur] << "\n";
        return 0;
}
1
2
3
4
5
6
#include <iostream>

int main(){
    std::cout << "Why are you doing this?!" << std::endl;
    return 0;
}
Why are you doing this?!
Last edited on
1
2
import sys
sys.stdout.print("That is an interesting enum")
Last edited on
closed account (L6b7X9L8)
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
#include <iostream>
#include <string>

class Word
{
        public: void Set(std::string var); std::string Show();
        private: std::string word;
}w1, w2, w3, w4, w5, w6, w7;

void Word::Set(std::string var)
{
	word = var;
}

std::string Word::Show()
{
	return word;
}

int main()
{
	w1.Set("To "); w2.Set("show "); w3.Set("programming "); w4.Set("from "); w5.Set("the "); w6.Set("ground "); w7.Set("up!");
	std::cout << w1.Show() << w2.Show() << w3.Show() << w4.Show() << w5.Show() << w6.Show() << w7.Show();
	return 0;
}

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 <iostream>
#include <cstdlib>
#include <ctime>

using std::cout;

int main()
{
    srand(time(NULL));
    int total[3] = {0}, i = 0;
    char c[7] = {' '};
    c[0] = 114;
    bool flag = 0;
    while(flag == 0)
    {
        total[0] = 114;
        total[1] = 0;
        total[2] = 0;
        for(i = 1; i < 7; ++i)
        {
            c[i] = 101 + rand() % 15;
            total[0] = total[0] + c[i];
        }
        total[1] = c[0] - c[2];
        total[2] = c[0] + c[6];
        if(total[0] == 756 && total[1] == 2 && (c[6] - c[5]) == 14 && c[1] == c[5] && c[3] == c[4] + (c[6] - 112))
        {
            flag = 1;
        }
    }
    for(i = 0; i < 7; ++i)
    {
        cout << c[i];
    }
    return 0;
}
closed account (L6b7X9L8)
Welp.... shit.

Edit: Well it compiles and prints...but.... in Gods name how?

Edit 2: Can anyone even beat this? This is freaking insane.
Last edited on
Do you actually know the randomiser algorithm? Or is that maths on it's own enough to generate your letters (by eventually just losing the generated number)
I've not actually checked the operations you've done yet.

EDIT: Oh I seeeee.... You're basically regenerating the entire string until it says what you want it to say (and just testing for it in an unusual manor)
Last edited on
closed account (L6b7X9L8)
So that's why it took like 10 seconds...
It's more obfuscation than sophistication though. =/
Hopefully someone can find something a little more beautiful.
Although I do say it's quite a nice "trick" Mats
closed account (L6b7X9L8)
I think that's the best we are gonna get it unless Disch chrisname can pull something out of his arse. I mean you don't even use any letters how much more beautiful do you want to get it?

Edit: See SatsumaBenji, that's why I wanted to do this =]
Last edited on
[edit]: Requires C++11.
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <chrono>
#include <cstdlib>
#include <functional>
#include <future>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <vector>


class when {
public:
    template <class Predicate, class Callable, typename... Args>
    when(Predicate p, Callable c, Args... args)
    {
        std::thread thread(when_thread_entry<Predicate, Callable, Args...>(p, c, args...));
        thread.detach();
    }
private:
    template <class Predicate, class Callable, typename... Args>
    struct when_thread_entry {
        when_thread_entry(Predicate p, Callable c, Args... args) : predicate(p), function(c), tuple(args...)
        {
            // Do nothing.
        }
        
        void operator()()
        {
            while (!(predicate()))
                std::this_thread::yield();
            call_function();
        }
    private:
        template <int... Indices>
        struct index {};
        template <int N, int... Indices>
        struct gen_seq : gen_seq<N - 1, N - 1, Indices...> {};
        template <int... Indices>
        struct gen_seq<0, Indices...> : index<Indices...> {};

        Predicate predicate;
        Callable function;
        std::tuple<Args...> tuple;

        template <int... Indices>
        void call_function(index<Indices...>)
        {
            function(std::get<Indices>(tuple)...);
        }

        void call_function()
        {
            call_function(gen_seq<sizeof...(Args)>{});
        }
    };
};

struct timeout_predicate {
    timeout_predicate(std::time_t duration) : end(curtime() + duration)
    {
        // Do nothing.
    }

    bool operator()()
    {
        return (curtime() >= end);
    }
private:
    std::time_t end;

    std::time_t curtime()
    {
        return std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
    }
};

class after : public when {
public:
    template <class Callable, typename... Args>
    after(std::time_t timeout, Callable c, Args... args) : when(timeout_predicate(timeout), c, args...)
    {
        // Do nothing.
    }
};

struct string_printer {
    string_printer(std::ostream& stream) : m_stream(stream)
    {
        // Do nothing.
    }

    void operator()(const std::string& string)
    {
        m_stream << string;
    }
private:
    std::ostream& m_stream;
};

struct stream_flusher {
    stream_flusher(std::ostream& stream) : m_stream(stream)
    {
        // Do nothing.
    }

    void operator()()
    {
        m_stream << std::flush;
    }
private:
    std::ostream& m_stream;
};

struct program_exiter {
    void operator()(int exit_code = EXIT_SUCCESS)
    {
        std::exit(exit_code);
    }
};

int main()
{
    string_printer printer(std::cout);
    stream_flusher flusher(std::cout);
    program_exiter exiter;
    after( 9, flusher);
    after( 7, printer, "hello, world\n");
    after( 3, printer, "Message: ");
    after( 5, flusher);
    after(10, exiter, EXIT_SUCCESS);
    while (true)
        ;
}
Last edited on
closed account (L6b7X9L8)
The hell is that?

Compiled okay with the -std=c++11

But on run I got error:

terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted
That's strange, it works fine for me.

Were you running it on your own system? I tried to run it on IDEOne.com but you aren't allowed to create threads (seems reasonable) which may be related to why it's not working for you.

But I'm not going to explain the code >:)
closed account (L6b7X9L8)
Yeah I am running it on my laptop ( Apparently I am running and old version of G++ so maybe that? ) It compiled okay with the -std=c++11 switch :/

Come on walk me through it >:P
closed account (N36fSL3A)
Can someone compile and place the executable here? I'm lazy and I don't want to get gcc or make a new project.
Zorg wrote:
I mean you don't even use any letters how much more beautiful do you want to get it?

...
Well.... He does.... But he just uses numbers and/or arithmetic to match the ASCII values of the characters
Although still very nice.
@Zorg
I'm using g++ 4.8.2 on Cygwin on Windows 7.

I'm not explaining it because I want someone else to figure it out.

@Fredbill
You probably shouldn't run executables people upload here. Plus you might not have all the DLLs you need. It's best you compile it yourself.
Pages: 12