chrislo-sourceclassifier 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +325 -0
- data/README.textile +51 -0
- data/Rakefile +64 -0
- data/examples/example.rb +22 -0
- data/lib/sourceclassifier.rb +22 -0
- data/lib/trainer.rb +51 -0
- data/sourceclassifier.gemspec +35 -0
- data/sources/gcc/ackermann.gcc-2.gcc +93 -0
- data/sources/gcc/ackermann.gcc-3.gcc +20 -0
- data/sources/gcc/ary.gcc +40 -0
- data/sources/gcc/binarytrees.gcc +136 -0
- data/sources/gcc/binarytrees.gcc-2.gcc +140 -0
- data/sources/gcc/binarytrees.gcc-3.gcc +134 -0
- data/sources/gcc/chameneos.gcc +117 -0
- data/sources/gcc/chameneos.gcc-2.gcc +134 -0
- data/sources/gcc/chameneos.gcc-3.gcc +120 -0
- data/sources/gcc/chameneosredux.gcc +306 -0
- data/sources/gcc/echo.gcc +144 -0
- data/sources/gcc/except.gcc +52 -0
- data/sources/gcc/fannkuch.gcc +105 -0
- data/sources/gcc/fannkuch.gcc-2.gcc +94 -0
- data/sources/gcc/fasta.gcc +158 -0
- data/sources/gcc/fasta.gcc-2.gcc +132 -0
- data/sources/gcc/fasta.gcc-3.gcc +145 -0
- data/sources/gcc/fasta.gcc-4.gcc +141 -0
- data/sources/gcc/fibo.gcc +20 -0
- data/sources/gcc/harmonic.gcc +22 -0
- data/sources/gcc/hash.gcc +31 -0
- data/sources/gcc/hash2.gcc +38 -0
- data/sources/gcc/heapsort.gcc +72 -0
- data/sources/gcc/hello.gcc-2.gcc +12 -0
- data/sources/gcc/hello.gcc-3.gcc +20 -0
- data/sources/gcc/knucleotide.gcc +173 -0
- data/sources/gcc/knucleotide.gcc-2.gcc +168 -0
- data/sources/gcc/lists.gcc +226 -0
- data/sources/gcc/magicsquares.gcc +378 -0
- data/sources/gcc/mandelbrot.gcc +84 -0
- data/sources/gcc/mandelbrot.gcc-2.gcc +63 -0
- data/sources/gcc/mandelbrot.gcc-3.gcc +91 -0
- data/sources/gcc/mandelbrot.gcc-4.gcc +78 -0
- data/sources/gcc/matrix.gcc +66 -0
- data/sources/gcc/message.gcc-2.gcc +72 -0
- data/sources/gcc/message.gcc-3.gcc +64 -0
- data/sources/gcc/methcall.gcc +89 -0
- data/sources/gcc/moments.gcc +120 -0
- data/sources/gcc/nbody.gcc +142 -0
- data/sources/gcc/nbody.gcc-2.gcc +143 -0
- data/sources/gcc/nbody.gcc-3.gcc +142 -0
- data/sources/gcc/nestedloop.gcc +25 -0
- data/sources/gcc/nsieve.gcc +35 -0
- data/sources/gcc/nsievebits.gcc-2.gcc +37 -0
- data/sources/gcc/nsievebits.gcc-3.gcc +53 -0
- data/sources/gcc/objinst.gcc +95 -0
- data/sources/gcc/partialsums.gcc +86 -0
- data/sources/gcc/partialsums.gcc-3.gcc +81 -0
- data/sources/gcc/partialsums.gcc-4.gcc +68 -0
- data/sources/gcc/pidigits.gcc +105 -0
- data/sources/gcc/primes.gcc +75 -0
- data/sources/gcc/prodcons.gcc +86 -0
- data/sources/gcc/random.gcc +29 -0
- data/sources/gcc/raytracer.gcc +125 -0
- data/sources/gcc/raytracer.gcc-2.gcc +181 -0
- data/sources/gcc/recursive.gcc +68 -0
- data/sources/gcc/recursive.gcc-2.gcc +55 -0
- data/sources/gcc/regexdna.gcc-2.gcc +126 -0
- data/sources/gcc/regexmatch.gcc +136 -0
- data/sources/gcc/revcomp.gcc +85 -0
- data/sources/gcc/revcomp.gcc-2.gcc +88 -0
- data/sources/gcc/revcomp.gcc-4.gcc +71 -0
- data/sources/gcc/reversefile.gcc +103 -0
- data/sources/gcc/reversefile.gcc-2.gcc +56 -0
- data/sources/gcc/sieve.gcc +34 -0
- data/sources/gcc/spectralnorm.gcc +54 -0
- data/sources/gcc/spellcheck.gcc +72 -0
- data/sources/gcc/spellcheck.gcc-2.gcc +61 -0
- data/sources/gcc/strcat.gcc +38 -0
- data/sources/gcc/sumcol.gcc-2.gcc +98 -0
- data/sources/gcc/sumcol.gcc-3.gcc +22 -0
- data/sources/gcc/sumcol.gcc-4.gcc +18 -0
- data/sources/gcc/sumcol.gcc-5.gcc +32 -0
- data/sources/gcc/takfp.gcc +23 -0
- data/sources/gcc/tcp-stream.gcc +122 -0
- data/sources/gcc/tcpecho.gcc +122 -0
- data/sources/gcc/tcpecho.gcc-2.gcc +136 -0
- data/sources/gcc/tcprequest.gcc +122 -0
- data/sources/gcc/threadring.gcc +73 -0
- data/sources/gcc/wc.gcc +52 -0
- data/sources/gcc/wc.gcc-2.gcc +40 -0
- data/sources/gcc/wc.gcc-3.gcc +46 -0
- data/sources/gcc/wordfreq.gcc-2.gcc +85 -0
- data/sources/perl/ackermann.perl +28 -0
- data/sources/perl/ackermann.perl-2.perl +25 -0
- data/sources/perl/ackermann.perl-3.perl +20 -0
- data/sources/perl/ackermann.perl-4.perl +18 -0
- data/sources/perl/ary.perl +25 -0
- data/sources/perl/ary.perl-2.perl +23 -0
- data/sources/perl/binarytrees.perl +66 -0
- data/sources/perl/binarytrees.perl-2.perl +71 -0
- data/sources/perl/chameneos.perl +67 -0
- data/sources/perl/echo.perl +81 -0
- data/sources/perl/except.perl +73 -0
- data/sources/perl/fannkuch.perl +44 -0
- data/sources/perl/fannkuch.perl-2.perl +38 -0
- data/sources/perl/fasta.perl +112 -0
- data/sources/perl/fasta.perl-2.perl +135 -0
- data/sources/perl/fasta.perl-4.perl +122 -0
- data/sources/perl/fibo.perl +15 -0
- data/sources/perl/fibo.perl-2.perl +0 -0
- data/sources/perl/fibo.perl-3.perl +0 -0
- data/sources/perl/harmonic.perl +7 -0
- data/sources/perl/hash.perl +23 -0
- data/sources/perl/hash.perl-2.perl +17 -0
- data/sources/perl/hash.perl-3.perl +24 -0
- data/sources/perl/hash2.perl +16 -0
- data/sources/perl/heapsort.perl +65 -0
- data/sources/perl/heapsort.perl-2.perl +0 -0
- data/sources/perl/hello.perl +5 -0
- data/sources/perl/knucleotide.perl-2.perl +30 -0
- data/sources/perl/lists.perl +48 -0
- data/sources/perl/mandelbrot.perl-2.perl +32 -0
- data/sources/perl/matrix.perl +59 -0
- data/sources/perl/matrix.perl-2.perl +0 -0
- data/sources/perl/matrix.perl-3.perl +0 -0
- data/sources/perl/message.perl +27 -0
- data/sources/perl/methcall.perl +66 -0
- data/sources/perl/moments.perl +44 -0
- data/sources/perl/nbody.perl +108 -0
- data/sources/perl/nestedloop.perl +28 -0
- data/sources/perl/nsieve.perl-2.perl +41 -0
- data/sources/perl/nsieve.perl-4.perl +43 -0
- data/sources/perl/nsievebits.perl +37 -0
- data/sources/perl/objinst.perl +73 -0
- data/sources/perl/partialsums.perl-3.perl +31 -0
- data/sources/perl/pidigits.perl +52 -0
- data/sources/perl/pidigits.perl-2.perl +47 -0
- data/sources/perl/process.perl +50 -0
- data/sources/perl/prodcons.perl +47 -0
- data/sources/perl/random.perl-4.perl +17 -0
- data/sources/perl/recursive.perl-2.perl +57 -0
- data/sources/perl/regexdna.perl +48 -0
- data/sources/perl/regexdna.perl-2.perl +43 -0
- data/sources/perl/regexdna.perl-3.perl +50 -0
- data/sources/perl/regexdna.perl-4.perl +49 -0
- data/sources/perl/regexdna.perl-5.perl +42 -0
- data/sources/perl/regexdna.perl-6.perl +43 -0
- data/sources/perl/regexmatch.perl +35 -0
- data/sources/perl/revcomp.perl-2.perl +34 -0
- data/sources/perl/reversefile.perl +8 -0
- data/sources/perl/reversefile.perl-2.perl +0 -0
- data/sources/perl/reversefile.perl-3.perl +0 -0
- data/sources/perl/sieve.perl +23 -0
- data/sources/perl/spectralnorm.perl-2.perl +54 -0
- data/sources/perl/spellcheck.perl +24 -0
- data/sources/perl/strcat.perl +13 -0
- data/sources/perl/strcat.perl-2.perl +0 -0
- data/sources/perl/sumcol.perl +8 -0
- data/sources/perl/takfp.perl +23 -0
- data/sources/perl/takfp.perl-3.perl +20 -0
- data/sources/perl/tcpecho.perl +61 -0
- data/sources/perl/tcprequest.perl +61 -0
- data/sources/perl/tcpstream.perl +61 -0
- data/sources/perl/threadring.perl +55 -0
- data/sources/perl/threadring.perl-2.perl +43 -0
- data/sources/perl/wc.perl +20 -0
- data/sources/perl/wc.perl-2.perl +14 -0
- data/sources/perl/wordfreq.perl +22 -0
- data/sources/perl/wordfreq.perl-3.perl +0 -0
- data/sources/perl/wordfreq.perl3.perl +0 -0
- data/sources/python/ackermann.python +21 -0
- data/sources/python/ary.python +19 -0
- data/sources/python/binarytrees.python +39 -0
- data/sources/python/binarytrees.python-3.python +44 -0
- data/sources/python/chameneos.python-6.python +73 -0
- data/sources/python/chameneosredux.python +126 -0
- data/sources/python/chameneosredux.python-2.python +122 -0
- data/sources/python/dispatch.python +176 -0
- data/sources/python/dispatch.python-2.python +136 -0
- data/sources/python/echo.python +64 -0
- data/sources/python/except.python +62 -0
- data/sources/python/fannkuch.python +50 -0
- data/sources/python/fannkuch.python-2.python +54 -0
- data/sources/python/fasta.python-2.python +79 -0
- data/sources/python/fibo.python +17 -0
- data/sources/python/fibo.python-2.python +0 -0
- data/sources/python/fibo.python-3.python +0 -0
- data/sources/python/harmonic.python-2.python +9 -0
- data/sources/python/hash.python +21 -0
- data/sources/python/hash.python-2.python +0 -0
- data/sources/python/hash2.python +30 -0
- data/sources/python/heapsort.python-3.python +66 -0
- data/sources/python/hello.python +5 -0
- data/sources/python/implicitode.python +231 -0
- data/sources/python/knucleotide.python +55 -0
- data/sources/python/lists.python +44 -0
- data/sources/python/magicsquares.python +145 -0
- data/sources/python/mandelbrot.python +44 -0
- data/sources/python/mandelbrot.python-2.python +35 -0
- data/sources/python/mandelbrot.python-3.python +46 -0
- data/sources/python/matrix.python +34 -0
- data/sources/python/matrix.python-2.python +23 -0
- data/sources/python/message.python +24 -0
- data/sources/python/message.python-2.python +20 -0
- data/sources/python/message.python-3.python +19 -0
- data/sources/python/meteor.python +210 -0
- data/sources/python/meteor.python-2.python +192 -0
- data/sources/python/methcall.python +51 -0
- data/sources/python/moments.python +65 -0
- data/sources/python/nbody.python +123 -0
- data/sources/python/nbody.python-2.python +120 -0
- data/sources/python/nestedloop.python +24 -0
- data/sources/python/nsieve.python +27 -0
- data/sources/python/nsieve.python-2.python +23 -0
- data/sources/python/nsieve.python-4.python +25 -0
- data/sources/python/nsievebits.python +27 -0
- data/sources/python/nsievebits.python-2.python +43 -0
- data/sources/python/objinst.python +53 -0
- data/sources/python/partialsums.python +37 -0
- data/sources/python/partialsums.python-2.python +35 -0
- data/sources/python/partialsums.python-3.python +48 -0
- data/sources/python/pidigits.python +38 -0
- data/sources/python/pidigits.python-3.python +63 -0
- data/sources/python/pidigits.python-4.python +24 -0
- data/sources/python/process.python +51 -0
- data/sources/python/process.python-2.python +133 -0
- data/sources/python/prodcons.python +51 -0
- data/sources/python/prodcons.python-2.python +0 -0
- data/sources/python/random.python +27 -0
- data/sources/python/raytracer.python +203 -0
- data/sources/python/recursive.python +35 -0
- data/sources/python/regexdna.python +39 -0
- data/sources/python/regexdna.python-2.python +34 -0
- data/sources/python/regexmatch.python +36 -0
- data/sources/python/revcomp.python-3.python +31 -0
- data/sources/python/reversefile.python +13 -0
- data/sources/python/reversefile.python-2.python +0 -0
- data/sources/python/reversefile.python-3.python +0 -0
- data/sources/python/sieve.python +50 -0
- data/sources/python/spectralnorm.python-2.python +36 -0
- data/sources/python/spellcheck.python +17 -0
- data/sources/python/strcat.python +35 -0
- data/sources/python/strcat.python-2.python +0 -0
- data/sources/python/sumcol.python-2.python +0 -0
- data/sources/python/sumcol.python-3.python +0 -0
- data/sources/python/takfp.python +19 -0
- data/sources/python/tcpecho.python +67 -0
- data/sources/python/tcprequest.python +67 -0
- data/sources/python/tcpstream.python +67 -0
- data/sources/python/threadring.python +47 -0
- data/sources/python/threadring.python-2.python +40 -0
- data/sources/python/threadring.python-3.python +34 -0
- data/sources/python/wc.python-2.python +19 -0
- data/sources/python/wordfreq.python +43 -0
- data/sources/python/wordfreq.python-2.python +0 -0
- data/sources/python/wordfreq.python-3.python +28 -0
- data/sources/python/wordfreq.python-4.python +38 -0
- data/sources/python/wordfreq.python-5.python +39 -0
- data/sources/ruby/ackermann.ruby +17 -0
- data/sources/ruby/ackermann.ruby-5.ruby +153 -0
- data/sources/ruby/ary.ruby +22 -0
- data/sources/ruby/binarytrees.ruby-2.ruby +55 -0
- data/sources/ruby/chameneos.ruby-2.ruby +71 -0
- data/sources/ruby/dispatch.ruby +114 -0
- data/sources/ruby/echo.ruby +41 -0
- data/sources/ruby/except.ruby +61 -0
- data/sources/ruby/except.ruby-2.ruby +61 -0
- data/sources/ruby/fannkuch.ruby +42 -0
- data/sources/ruby/fasta.ruby +81 -0
- data/sources/ruby/fibo.ruby +15 -0
- data/sources/ruby/harmonic.ruby-2.ruby +15 -0
- data/sources/ruby/hash.ruby +19 -0
- data/sources/ruby/hash2.ruby +23 -0
- data/sources/ruby/heapsort.ruby +55 -0
- data/sources/ruby/hello.ruby +6 -0
- data/sources/ruby/knucleotide.ruby-2.ruby +44 -0
- data/sources/ruby/lists.ruby +46 -0
- data/sources/ruby/mandelbrot.ruby-3.ruby +63 -0
- data/sources/ruby/matrix.ruby +40 -0
- data/sources/ruby/matrix.ruby-2.ruby +30 -0
- data/sources/ruby/message.ruby +29 -0
- data/sources/ruby/message.ruby-2.ruby +24 -0
- data/sources/ruby/meteor.ruby +386 -0
- data/sources/ruby/meteor.ruby-2.ruby +561 -0
- data/sources/ruby/methcall.ruby +58 -0
- data/sources/ruby/methcall.ruby-2.ruby +54 -0
- data/sources/ruby/moments.ruby +64 -0
- data/sources/ruby/nbody.ruby-2.ruby +145 -0
- data/sources/ruby/nestedloop.ruby +22 -0
- data/sources/ruby/nsieve.ruby +36 -0
- data/sources/ruby/nsieve.ruby-2.ruby +25 -0
- data/sources/ruby/nsievebits.ruby-2.ruby +42 -0
- data/sources/ruby/objinst.ruby +58 -0
- data/sources/ruby/partialsums.ruby +39 -0
- data/sources/ruby/pidigits.ruby +92 -0
- data/sources/ruby/pidigits.ruby-2.ruby +109 -0
- data/sources/ruby/prodcons.ruby +41 -0
- data/sources/ruby/random.ruby +17 -0
- data/sources/ruby/recursive.ruby-2.ruby +53 -0
- data/sources/ruby/regexdna.ruby +32 -0
- data/sources/ruby/regexdna.ruby-2.ruby +38 -0
- data/sources/ruby/regexmatch.ruby +33 -0
- data/sources/ruby/revcomp.ruby +28 -0
- data/sources/ruby/reversefile.ruby +7 -0
- data/sources/ruby/sieve.ruby +30 -0
- data/sources/ruby/spectralnorm.ruby +48 -0
- data/sources/ruby/spellcheck.ruby +18 -0
- data/sources/ruby/spellcheck.ruby-2.ruby +0 -0
- data/sources/ruby/strcat.ruby +12 -0
- data/sources/ruby/strcat.ruby-2.ruby +12 -0
- data/sources/ruby/sumcol.ruby +12 -0
- data/sources/ruby/sumcol.ruby-2.ruby +5 -0
- data/sources/ruby/takfp.ruby +15 -0
- data/sources/ruby/tcpecho.ruby +45 -0
- data/sources/ruby/tcprequest.ruby +45 -0
- data/sources/ruby/tcpstream.ruby +45 -0
- data/sources/ruby/threadring.ruby +61 -0
- data/sources/ruby/threadring.ruby-2.ruby +33 -0
- data/sources/ruby/wc.ruby +15 -0
- data/sources/ruby/wordfreq.ruby +17 -0
- data/sources/ruby/wordfreq.ruby2.ruby +0 -0
- data/test/fixtures/sources/gcc/ackermann.gcc-2.gcc +93 -0
- data/test/fixtures/sources/python/ackermann.python +21 -0
- data/test/fixtures/sources/ruby/ackermann.ruby +17 -0
- data/test/test_source_classifier.rb +40 -0
- data/test/test_trainer.rb +34 -0
- data/trainer.bin +1193 -0
- metadata +393 -0
@@ -0,0 +1,378 @@
|
|
1
|
+
/* The Computer Language Benchmarks Game
|
2
|
+
http://shootout.alioth.debian.org/
|
3
|
+
|
4
|
+
contributed contributed by Charlie Brej
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <stdlib.h>
|
9
|
+
|
10
|
+
int n=0;
|
11
|
+
int mn=0;
|
12
|
+
|
13
|
+
typedef struct FfmCache {
|
14
|
+
int x;
|
15
|
+
int y;
|
16
|
+
int pm_count;
|
17
|
+
int pm[];
|
18
|
+
}FfmCache, *PtrFfmCache;
|
19
|
+
|
20
|
+
typedef struct Square {
|
21
|
+
struct Square* next;
|
22
|
+
PtrFfmCache ffm;
|
23
|
+
int priority;
|
24
|
+
int *grid;
|
25
|
+
int *unused;
|
26
|
+
}Square, *PtrSquare;
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
void SquarePrint(PtrSquare square)
|
31
|
+
{
|
32
|
+
int x;
|
33
|
+
int y;
|
34
|
+
for (y=0; y<n; y++){
|
35
|
+
for (x=0; x<n; x++){
|
36
|
+
printf("%d ", square->grid[x+y*n]);
|
37
|
+
}
|
38
|
+
printf("\n");
|
39
|
+
}
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
PtrSquare SquareNew(void)
|
46
|
+
{
|
47
|
+
PtrSquare new_square = malloc(sizeof(Square));
|
48
|
+
new_square->grid = malloc(n * n * sizeof(int));
|
49
|
+
new_square->unused = malloc(n * n * sizeof(int));
|
50
|
+
new_square->next=NULL;
|
51
|
+
new_square->ffm=NULL;
|
52
|
+
new_square->priority=0;
|
53
|
+
return new_square;
|
54
|
+
}
|
55
|
+
|
56
|
+
PtrSquare SquareNewEmpty(void)
|
57
|
+
{
|
58
|
+
int i;
|
59
|
+
PtrSquare new_square = SquareNew();
|
60
|
+
for (i=0; i<n*n; i++){
|
61
|
+
new_square->grid[i]=0;
|
62
|
+
new_square->unused[i]=1;
|
63
|
+
}
|
64
|
+
return new_square;
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
PtrSquare SquareNewCopy(PtrSquare old_square)
|
69
|
+
{
|
70
|
+
int i;
|
71
|
+
PtrSquare new_square = SquareNew();
|
72
|
+
for (i=0; i<n*n; i++){
|
73
|
+
new_square->grid[i]=old_square->grid[i];
|
74
|
+
new_square->unused[i]=old_square->unused[i];
|
75
|
+
}
|
76
|
+
return new_square;
|
77
|
+
}
|
78
|
+
|
79
|
+
void SquareFree(PtrSquare square)
|
80
|
+
{
|
81
|
+
free(square->ffm);
|
82
|
+
free(square->unused);
|
83
|
+
free(square);
|
84
|
+
return ;
|
85
|
+
}
|
86
|
+
|
87
|
+
void SquareGetRow(PtrSquare square, int row, int* out_array)
|
88
|
+
{
|
89
|
+
int i;
|
90
|
+
for (i=0; i<n; i++){
|
91
|
+
out_array[i] = square->grid[row*n+i];
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
void SquareGetColumn(PtrSquare square, int column, int* out_array)
|
96
|
+
{
|
97
|
+
int i;
|
98
|
+
for (i=0; i<n; i++){
|
99
|
+
out_array[i] = square->grid[n*i+column];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
int IntArraySum(int* data)
|
104
|
+
{
|
105
|
+
int i;
|
106
|
+
int sum = 0;
|
107
|
+
for (i=0; i<n; i++){
|
108
|
+
sum += data[i];
|
109
|
+
}
|
110
|
+
return sum;
|
111
|
+
}
|
112
|
+
|
113
|
+
int IntArrayCount0s(int* data)
|
114
|
+
{
|
115
|
+
int i;
|
116
|
+
int count = 0;
|
117
|
+
for (i=0; i<n; i++)
|
118
|
+
if(data[i]==0)
|
119
|
+
count++;
|
120
|
+
return count;
|
121
|
+
}
|
122
|
+
|
123
|
+
int SquareNumberPresent(PtrSquare square, int number)
|
124
|
+
{
|
125
|
+
int i;
|
126
|
+
for (i=0; i<n*n; i++){
|
127
|
+
if (square->grid[i] == number) return 1;
|
128
|
+
}
|
129
|
+
return 0;
|
130
|
+
}
|
131
|
+
|
132
|
+
int SquareEmptyCount(PtrSquare square)
|
133
|
+
{
|
134
|
+
int i;
|
135
|
+
int count=0;
|
136
|
+
for (i=0; i<n*n; i++){
|
137
|
+
if (square->grid[i] == 0) count++;
|
138
|
+
}
|
139
|
+
return count;
|
140
|
+
}
|
141
|
+
|
142
|
+
void SquareGetPossibleMoves(PtrSquare square, int x, int y, int* ret_pm, int* ret_pm_count)
|
143
|
+
{
|
144
|
+
int cell_groups[4][n];
|
145
|
+
int cell_group_count=2;
|
146
|
+
int group;
|
147
|
+
int i, i2;
|
148
|
+
int cur_acc;
|
149
|
+
int highest_candidate = n*n;
|
150
|
+
int lowest_candidate = 1;
|
151
|
+
|
152
|
+
int one_possible = 0;
|
153
|
+
|
154
|
+
|
155
|
+
SquareGetRow(square, y, cell_groups[0]);
|
156
|
+
SquareGetColumn(square, x, cell_groups[1]);
|
157
|
+
|
158
|
+
*ret_pm_count = 0;
|
159
|
+
if (x==y) {
|
160
|
+
for (i=0; i<n; i++)
|
161
|
+
cell_groups[cell_group_count][i] = square->grid[n*i+i];
|
162
|
+
cell_group_count++;
|
163
|
+
}
|
164
|
+
if (x + y == n - 1) {
|
165
|
+
for (i=0; i<n; i++)
|
166
|
+
cell_groups[cell_group_count][i] = square->grid[i + (n - 1 - i) * n];
|
167
|
+
cell_group_count++;
|
168
|
+
}
|
169
|
+
|
170
|
+
for (group=0; group<cell_group_count; group++){
|
171
|
+
int count = 0;
|
172
|
+
for (i=0; i<n; i++){
|
173
|
+
if (cell_groups[group][i] == 0){
|
174
|
+
if (count++) break;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
if (count==1){
|
178
|
+
int new_one_possible = mn - IntArraySum(cell_groups[group]);
|
179
|
+
if (one_possible==0){
|
180
|
+
one_possible = new_one_possible;
|
181
|
+
if (one_possible<1 || one_possible>n*n || SquareNumberPresent(square, one_possible)) return;
|
182
|
+
}
|
183
|
+
if (one_possible != new_one_possible) return;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
if (one_possible){
|
187
|
+
ret_pm[0] = one_possible;
|
188
|
+
*ret_pm_count = 1;
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
int local_pm_count = 0;
|
194
|
+
int zeros[cell_group_count];
|
195
|
+
int highest_zero_count=0;
|
196
|
+
for (i=0; i<cell_group_count; i++){
|
197
|
+
int zero_count = IntArrayCount0s(cell_groups[i])-1;
|
198
|
+
zeros[i] = zero_count;
|
199
|
+
if (highest_zero_count < zero_count) highest_zero_count = zero_count;
|
200
|
+
}
|
201
|
+
|
202
|
+
int lows[highest_zero_count];
|
203
|
+
int higs[highest_zero_count];
|
204
|
+
|
205
|
+
i2=0;
|
206
|
+
cur_acc=0;
|
207
|
+
for (i=0; i2<highest_zero_count; i++){
|
208
|
+
if(square->unused[i]){
|
209
|
+
cur_acc+=(i+1);
|
210
|
+
lows[i2]=cur_acc;
|
211
|
+
i2++;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
i2=0;
|
216
|
+
cur_acc=0;
|
217
|
+
for (i=n*n-1; i2<highest_zero_count; i--){
|
218
|
+
if(square->unused[i]){
|
219
|
+
cur_acc+=(i+1);
|
220
|
+
higs[i2]=cur_acc;
|
221
|
+
i2++;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
for (group=0; group<cell_group_count; group++){
|
226
|
+
int lft = mn - IntArraySum(cell_groups[group]);
|
227
|
+
int k = zeros[group];
|
228
|
+
int temp_highest_candidate = lft - lows[k-1];
|
229
|
+
int temp_lowest_candidate = lft - higs[k-1];
|
230
|
+
if (temp_highest_candidate<highest_candidate) highest_candidate = temp_highest_candidate;
|
231
|
+
if (temp_lowest_candidate>lowest_candidate) lowest_candidate = temp_lowest_candidate;
|
232
|
+
}
|
233
|
+
|
234
|
+
for (i=lowest_candidate; i<=highest_candidate; i++){
|
235
|
+
if(square->unused[i-1]){
|
236
|
+
ret_pm[local_pm_count++]=i;
|
237
|
+
|
238
|
+
}
|
239
|
+
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
*ret_pm_count = local_pm_count;
|
244
|
+
return;
|
245
|
+
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
PtrFfmCache SquareGetFewestMoves(PtrSquare square)
|
251
|
+
{
|
252
|
+
int x,y;
|
253
|
+
int i;
|
254
|
+
if (square->ffm){
|
255
|
+
return square->ffm;
|
256
|
+
}
|
257
|
+
square->ffm = malloc(sizeof(FfmCache)+sizeof(int)*n*n);
|
258
|
+
square->ffm->pm_count=n*n+1;
|
259
|
+
|
260
|
+
for (y=0; y<n; y++)
|
261
|
+
for (x=0; x<n; x++){
|
262
|
+
int index = x + y * n;
|
263
|
+
if (square->grid[index] == 0){
|
264
|
+
int temp_list[n*n];
|
265
|
+
int temp_list_count;
|
266
|
+
SquareGetPossibleMoves(square,x,y,temp_list,&temp_list_count);
|
267
|
+
if (temp_list_count<square->ffm->pm_count){
|
268
|
+
square->ffm->pm_count = temp_list_count;
|
269
|
+
square->ffm->x = x;
|
270
|
+
square->ffm->y = y;
|
271
|
+
for (i=0; i<square->ffm->pm_count; i++) square->ffm->pm[i] = temp_list[i];
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
|
277
|
+
if (square->ffm->pm_count>n*n) square->ffm->pm_count=0;
|
278
|
+
return square->ffm;
|
279
|
+
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
int SquareGetPriority(PtrSquare square)
|
285
|
+
{
|
286
|
+
int priority;
|
287
|
+
if (square->priority) return square->priority;
|
288
|
+
PtrFfmCache ffm = SquareGetFewestMoves(square);
|
289
|
+
priority = ffm->pm_count + SquareEmptyCount(square);
|
290
|
+
square->priority = priority;
|
291
|
+
return priority;
|
292
|
+
}
|
293
|
+
|
294
|
+
int SquareCompare(PtrSquare square1, PtrSquare square2)
|
295
|
+
{
|
296
|
+
int c = SquareGetPriority(square1) - SquareGetPriority(square2);
|
297
|
+
if (c==0){
|
298
|
+
int i;
|
299
|
+
for (i=0; c==0 && i<n*n; i++){
|
300
|
+
c = square1->grid[i] - square2->grid[i];
|
301
|
+
}
|
302
|
+
}
|
303
|
+
return c;
|
304
|
+
}
|
305
|
+
|
306
|
+
PtrSquare SquareQueueMerge(PtrSquare queue1, PtrSquare queue2)
|
307
|
+
{
|
308
|
+
if (!queue1) return queue2;
|
309
|
+
if (!queue2) return queue1;
|
310
|
+
|
311
|
+
PtrSquare new_queue = NULL;
|
312
|
+
PtrSquare* cur_ptr = &new_queue;
|
313
|
+
|
314
|
+
while (1){
|
315
|
+
if (SquareCompare(queue1, queue2)<0){
|
316
|
+
*cur_ptr = queue1;
|
317
|
+
cur_ptr = &queue1->next;
|
318
|
+
queue1 = queue1->next;
|
319
|
+
if (!queue1){
|
320
|
+
*cur_ptr = queue2;
|
321
|
+
return new_queue;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
else {
|
325
|
+
*cur_ptr = queue2;
|
326
|
+
cur_ptr = &queue2->next;
|
327
|
+
queue2 = queue2->next;
|
328
|
+
if (!queue2){
|
329
|
+
*cur_ptr = queue1;
|
330
|
+
return new_queue;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
PtrSquare SquareGetSuccessorNodes(PtrSquare square)
|
337
|
+
{
|
338
|
+
int i;
|
339
|
+
PtrSquare square_queue = NULL;
|
340
|
+
PtrFfmCache ffm = SquareGetFewestMoves(square);
|
341
|
+
|
342
|
+
for (i=0; i<ffm->pm_count; i++){
|
343
|
+
PtrSquare new_square = SquareNewCopy(square);
|
344
|
+
new_square->grid[ffm->x+ffm->y*n] = ffm->pm[i];
|
345
|
+
new_square->unused[ffm->pm[i]-1]=0;
|
346
|
+
square_queue = SquareQueueMerge(square_queue, new_square);
|
347
|
+
}
|
348
|
+
return square_queue;
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
int main(int argc, char **argv)
|
354
|
+
{
|
355
|
+
|
356
|
+
if (argv[1]) n = atoi(argv[1]);
|
357
|
+
else n = 5;
|
358
|
+
mn = n * (1 + n * n) / 2;
|
359
|
+
|
360
|
+
PtrSquare queue = SquareNewEmpty();
|
361
|
+
PtrSquare cur_square;
|
362
|
+
|
363
|
+
while (queue){
|
364
|
+
cur_square = queue;
|
365
|
+
queue = queue->next;
|
366
|
+
|
367
|
+
int priority = SquareGetPriority(cur_square);
|
368
|
+
if (!priority) break;
|
369
|
+
|
370
|
+
|
371
|
+
PtrSquare successor_nodes = SquareGetSuccessorNodes(cur_square);
|
372
|
+
queue = SquareQueueMerge(queue, successor_nodes);
|
373
|
+
SquareFree(cur_square);
|
374
|
+
}
|
375
|
+
|
376
|
+
SquarePrint(cur_square);
|
377
|
+
return 0;
|
378
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/* The Computer Language Benchmarks Game
|
2
|
+
http://shootout.alioth.debian.org/
|
3
|
+
|
4
|
+
contributed by Greg Buchholz (original iterative version)
|
5
|
+
modified by Yannick Gingras (made tail recursive)
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include<stdio.h>
|
9
|
+
#include<stdlib.h>
|
10
|
+
|
11
|
+
#define _ISOC99_SOURCE
|
12
|
+
|
13
|
+
__attribute__((pure, const, nothrow, sseregparm, hot))
|
14
|
+
int iterate(double Zr, double Zi,
|
15
|
+
double Tr, double Ti,
|
16
|
+
double Cr, double Ci,
|
17
|
+
int iter)
|
18
|
+
{
|
19
|
+
|
20
|
+
if (iter == 0)
|
21
|
+
return 1;
|
22
|
+
|
23
|
+
Zi = 2.0 * Zr * Zi + Ci;
|
24
|
+
Zr = Tr - Ti + Cr;
|
25
|
+
Tr = Zr * Zr;
|
26
|
+
Ti = Zi * Zi;
|
27
|
+
|
28
|
+
if (Tr + Ti > 4.0)
|
29
|
+
return 0;
|
30
|
+
|
31
|
+
return iterate (Zr, Zi, Tr, Ti, Cr, Ci, iter - 1);
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
int main (int argc, char **argv)
|
37
|
+
{
|
38
|
+
int w, h, buflen, bit_num = 0;
|
39
|
+
char byte_acc = 0;
|
40
|
+
char *buf, *pbuf;
|
41
|
+
double x, y, wrat, hrat;
|
42
|
+
double Cr, Ci;
|
43
|
+
|
44
|
+
w = h = atoi (argv[1]);
|
45
|
+
wrat = 2.0 / w;
|
46
|
+
hrat = 2.0 / h;
|
47
|
+
buflen = (w / 8 + (w % 8 ? 1 : 0)) * h;
|
48
|
+
buf = (char *) malloc (buflen);
|
49
|
+
pbuf = buf;
|
50
|
+
|
51
|
+
printf ("P4\n%d %d\n", w, h);
|
52
|
+
|
53
|
+
|
54
|
+
for (y = 0; y < h; ++y)
|
55
|
+
{
|
56
|
+
Ci = y * hrat - 1.0;
|
57
|
+
|
58
|
+
for (x = 0; x < w; ++x)
|
59
|
+
{
|
60
|
+
Cr = x * wrat - 1.5;
|
61
|
+
|
62
|
+
byte_acc <<= 1;
|
63
|
+
if (iterate (0.0, 0.0, 0.0, 0.0, Cr, Ci, 50))
|
64
|
+
byte_acc |= 0x01;
|
65
|
+
|
66
|
+
if (++bit_num == 8)
|
67
|
+
{
|
68
|
+
*(pbuf++) = byte_acc;
|
69
|
+
bit_num = byte_acc = 0;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
if (bit_num)
|
74
|
+
{
|
75
|
+
byte_acc <<= (8 - w % 8);
|
76
|
+
|
77
|
+
*(pbuf++) = byte_acc;
|
78
|
+
bit_num = byte_acc = 0;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
fwrite (buf, buflen, 1, stdout);
|
83
|
+
return 0;
|
84
|
+
}
|