summary refs log tree commit diff stats
path: root/tinyc/examples/ex2.c
blob: d415e39d7c4ff4c886544bb968904eed5def939d (plain) (blame)
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
#include <stdlib.h>
#include <stdio.h>

#define N 20

int nb_num;
int tab[N];
int stack_ptr;
int stack_op[N];
int stack_res[60];
int result;

int find(int n, int i1, int a, int b, int op)
{
    int i, j;
    int c;

    if (stack_ptr >= 0) {
        stack_res[3*stack_ptr] = a;
        stack_op[stack_ptr] = op;
        stack_res[3*stack_ptr+1] = b;
        stack_res[3*stack_ptr+2] = n;
        if (n == result)
            return 1;
        tab[i1] = n;
    }

    for(i=0;i<nb_num;i++) {
        for(j=i+1;j<nb_num;j++) {
            a = tab[i];
            b = tab[j];
            if (a != 0 && b != 0) {

                tab[j] = 0;
                stack_ptr++;

                if (find(a + b, i, a, b, '+'))
                    return 1;
                if (find(a - b, i, a, b, '-'))
                    return 1;
                if (find(b - a, i, b, a, '-'))
                    return 1;
                if (find(a * b, i, a, b, '*'))
                    return 1;
                if (b != 0) {
                    c = a / b;
                    if (find(c, i, a, b, '/'))
                        return 1;
                }

                if (a != 0) {
                    c = b / a;
                    if (find(c, i, b, a, '/'))
                        return 1;
                }

                stack_ptr--;
                tab[i] = a;
                tab[j] = b;
            }
        }
    }

    return 0;
}

int main(int argc, char **argv)
{
    int i, res, p;

    if (argc < 3) {
        printf("usage: %s: result numbers...\n"
               "Try to find result from numbers with the 4 basic operations.\n", argv[0]);
        exit(1);
    }

    p = 1;
    result = atoi(argv[p]);
    printf("result=%d\n", result);
    nb_num = 0;
    for(i=p+1;i<argc;i++) {
        tab[nb_num++] = atoi(argv[i]);
    }

    stack_ptr = -1;
    res = find(0, 0, 0, 0, ' ');
    if (res) {
        for(i=0;i<=stack_ptr;i++) {
            printf("%d %c %d = %d\n",
                   stack_res[3*i], stack_op[i],
                   stack_res[3*i+1], stack_res[3*i+2]);
        }
        return 0;
    } else {
        printf("Impossible\n");
        return 1;
    }
}
on https://example3.com/twtxt.txt 2019-02-26T11:06:44.000Z @<foo https://example.com/twtxt.txt> Did you eat my lunch? ``` ### Query tweets by mention URL ``` $ curl 'https://twtxt.tilde.institute/api/plain/mentions?url=https://foobarrington.co.uk/twtxt.txt' foo https://example.com/twtxt.txt 2019-02-26T11:06:44.000Z @<foo_barrington https://foobarrington.co.uk/twtxt.txt> Hey!! Are you still working on that project?e ``` ### Get all Tags ``` $ curl 'https://twtxt.example.com/api/plain/tags' foo https://example.com/twtxt.txt 2019-03-01T09:33:04.000Z No, seriously, I need #help foo https://example.com/twtxt.txt 2019-03-01T09:32:12.000Z Seriously, I love #programming! foo https://example.com/twtxt.txt 2019-03-01T09:31:02.000Z I love #programming! ``` ### Query by Tag ``` $ curl 'https://twtxt.example.com/api/plain/tags/programming' foo https://example.com/twtxt.txt 2019-03-01T09:31:02.000Z I love #programming! ``` ## Benchmarks * [bombardier](https://github.com/codesenberg/bombardier) ``` $ bombardier -c 100 -n 200000 http://localhost:9001/api/plain/tweets Bombarding http://localhost:9001/api/plain/tweets with 200000 request(s) using 100 connection(s) 200000 / 200000 [=============================================================] 100.00% 19574/s 10s Done! Statistics Avg Stdev Max Reqs/sec 19905.42 3597.45 27879.77 Latency 5.02ms 3.43ms 80.11ms HTTP codes: 1xx - 0, 2xx - 200000, 3xx - 0, 4xx - 0, 5xx - 0 others - 0 Throughput: 34.56MB/s ``` ## Other Documentation In addition to what is provided here, additional information, particularly regarding the configuration file, may be found by running getwtxt with the `-m` or `--manual` flags. You will likely want to pipe the output to `less` as it is quite long. ``` $ ./getwtxt -m | less $ ./getwtxt --manual | less ``` If you need to remove getwtxt from your system, navigate to the source directory you acquired using `git` during the installation process and run the appropriate `make` hook: ``` $ sudo make uninstall ``` ## Notes twtxt Information * [twtxt.readthedocs.io](https://twtxt.readthedocs.io) twtxt Client Repo * [buckket/twtxt](https://github.com/buckket/twtxt) (Includes links to additional related projects. See `Contributions`) Registry Specification * [twtxt.readthedocs.io/.../registry.html](https://twtxt.readthedocs.io/en/latest/user/registry.html)