mirror of
https://github.com/golang/go
synced 2024-11-25 01:08:02 -07:00
gofmt -r 'α[β:len(α)] -> α[β:]' -w test/bench
except chameneosredux which i know is being edited require gofmt for test/bench R=r https://golang.org/cl/157110
This commit is contained in:
parent
7ada6018a7
commit
19dae0799b
@ -607,7 +607,7 @@ def RelativePath(path, cwd):
|
||||
|
||||
# Check that gofmt run on the list of files does not change them
|
||||
def CheckGofmt(ui, repo, files, just_warn=False):
|
||||
files = [f for f in files if f.startswith('src/') and f.endswith('.go')]
|
||||
files = [f for f in files if (f.startswith('src/') or f.startswith('test/bench/')) and f.endswith('.go')]
|
||||
if not files:
|
||||
return
|
||||
cwd = os.getcwd()
|
||||
@ -1082,6 +1082,7 @@ def sync(ui, repo, **opts):
|
||||
err = commands.postincoming(ui, repo, modheads, True, "tip")
|
||||
if err:
|
||||
return err
|
||||
commands.update(ui, repo)
|
||||
sync_changes(ui, repo)
|
||||
|
||||
def sync_note(msg):
|
||||
|
@ -49,7 +49,7 @@ type Node struct {
|
||||
}
|
||||
|
||||
type Arena struct {
|
||||
head *Node
|
||||
head *Node;
|
||||
}
|
||||
|
||||
var arena Arena
|
||||
@ -69,7 +69,7 @@ func (a *Arena) New(item int, left, right *Node) *Node {
|
||||
if a.head == nil {
|
||||
nodes := make([]Node, 3<<uint(*n));
|
||||
for i := 0; i < len(nodes)-1; i++ {
|
||||
nodes[i].left = &nodes[i+1];
|
||||
nodes[i].left = &nodes[i+1]
|
||||
}
|
||||
a.head = &nodes[0];
|
||||
}
|
||||
@ -85,7 +85,7 @@ func bottomUpTree(item, depth int) *Node {
|
||||
if depth <= 0 {
|
||||
return arena.New(item, nil, nil)
|
||||
}
|
||||
return arena.New(item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1))
|
||||
return arena.New(item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1));
|
||||
}
|
||||
|
||||
func (n *Node) itemCheck() int {
|
||||
@ -95,7 +95,7 @@ func (n *Node) itemCheck() int {
|
||||
return n.item + n.left.itemCheck() - n.right.itemCheck();
|
||||
}
|
||||
|
||||
const minDepth = 4;
|
||||
const minDepth = 4
|
||||
|
||||
func main() {
|
||||
flag.Parse();
|
||||
|
@ -52,7 +52,7 @@ func bottomUpTree(item, depth int) *Node {
|
||||
if depth <= 0 {
|
||||
return &Node{item: item}
|
||||
}
|
||||
return &Node{ item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1) }
|
||||
return &Node{item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1)};
|
||||
}
|
||||
|
||||
func (n *Node) itemCheck() int {
|
||||
@ -62,7 +62,7 @@ func (n *Node) itemCheck() int {
|
||||
return n.item + n.left.itemCheck() - n.right.itemCheck();
|
||||
}
|
||||
|
||||
const minDepth = 4;
|
||||
const minDepth = 4
|
||||
|
||||
func main() {
|
||||
flag.Parse();
|
||||
|
@ -46,7 +46,7 @@ var n = flag.Int("n", 7, "count")
|
||||
|
||||
func fannkuch(n int) int {
|
||||
if n < 1 {
|
||||
return 0;
|
||||
return 0
|
||||
}
|
||||
|
||||
n1 := n - 1;
|
||||
@ -55,7 +55,7 @@ func fannkuch(n int) int {
|
||||
count := make([]int, n);
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
perm1[i] = i; // initial (trivial) permutation
|
||||
perm1[i] = i // initial (trivial) permutation
|
||||
}
|
||||
|
||||
r := n;
|
||||
@ -64,34 +64,36 @@ func fannkuch(n int) int {
|
||||
for {
|
||||
if didpr < 30 {
|
||||
for i := 0; i < n; i++ {
|
||||
fmt.Printf("%d", 1+perm1[i]);
|
||||
fmt.Printf("%d", 1+perm1[i])
|
||||
}
|
||||
fmt.Printf("\n");
|
||||
didpr++;
|
||||
}
|
||||
for ; r != 1; r-- {
|
||||
count[r-1] = r;
|
||||
count[r-1] = r
|
||||
}
|
||||
|
||||
if perm1[0] != 0 && perm1[n1] != n1 {
|
||||
flips := 0;
|
||||
for i := 1; i < n; i++ { // perm = perm1
|
||||
perm[i] = perm1[i];
|
||||
perm[i] = perm1[i]
|
||||
}
|
||||
k := perm1[0]; // cache perm[0] in k
|
||||
for { // k!=0 ==> k>0
|
||||
for i, j := 1, k-1; i < j; i, j = i+1, j-1 {
|
||||
perm[i], perm[j] = perm[j], perm[i];
|
||||
perm[i], perm[j] = perm[j], perm[i]
|
||||
}
|
||||
flips++;
|
||||
// Now exchange k (caching perm[0]) and perm[k]... with care!
|
||||
j := perm[k]; perm[k] = k; k = j;
|
||||
j := perm[k];
|
||||
perm[k] = k;
|
||||
k = j;
|
||||
if k == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if flipsMax < flips {
|
||||
flipsMax = flips;
|
||||
flipsMax = flips
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,19 +101,19 @@ func fannkuch(n int) int {
|
||||
// rotate down perm[0..r] by one
|
||||
perm0 := perm1[0];
|
||||
for i := 0; i < r; i++ {
|
||||
perm1[i] = perm1[i+1];
|
||||
perm1[i] = perm1[i+1]
|
||||
}
|
||||
perm1[r] = perm0;
|
||||
count[r]--;
|
||||
if count[r] > 0 {
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
if r == n {
|
||||
return flipsMax;
|
||||
return flipsMax
|
||||
}
|
||||
}
|
||||
return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -91,7 +91,7 @@ func RepeatFasta(s []byte, count int) {
|
||||
pos := 0;
|
||||
s2 := make([]byte, len(s)+WIDTH);
|
||||
copy(s2, s);
|
||||
copy(s2[len(s):len(s2)], s);
|
||||
copy(s2[len(s):], s);
|
||||
for count > 0 {
|
||||
line := min(WIDTH, count);
|
||||
out.Write(s2[pos : pos+line]);
|
||||
|
@ -58,7 +58,7 @@ func count(data string, n int) map[string] int {
|
||||
counts[s] = 1
|
||||
}
|
||||
}
|
||||
return counts
|
||||
return counts;
|
||||
}
|
||||
|
||||
func countOne(data string, s string) int {
|
||||
@ -66,7 +66,7 @@ func countOne(data string, s string) int {
|
||||
if i, ok := counts[s]; ok {
|
||||
return i
|
||||
}
|
||||
return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ func (kn kNucArray) Less(i, j int) bool {
|
||||
if kn[i].count == kn[j].count {
|
||||
return kn[i].name > kn[j].name // sort down
|
||||
}
|
||||
return kn[i].count > kn[j].count
|
||||
return kn[i].count > kn[j].count;
|
||||
}
|
||||
|
||||
func sortedArray(m map[string]int) kNucArray {
|
||||
@ -102,10 +102,10 @@ func print(m map[string] int) {
|
||||
a := sortedArray(m);
|
||||
sum := 0;
|
||||
for _, kn := range a {
|
||||
sum += kn.count;
|
||||
sum += kn.count
|
||||
}
|
||||
for _, kn := range a {
|
||||
fmt.Printf("%s %.3f\n", kn.name, 100*float64(kn.count)/float64(sum));
|
||||
fmt.Printf("%s %.3f\n", kn.name, 100*float64(kn.count)/float64(sum))
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ func main() {
|
||||
os.Exit(2);
|
||||
}
|
||||
if line[0] == '>' && bytes.Equal(line[0:len(three)], three) {
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
data, err := io.ReadAll(in);
|
||||
@ -132,7 +132,7 @@ func main() {
|
||||
for i := 0; i < len(data); i++ {
|
||||
if data[i] != '\n' {
|
||||
data[j] = data[i] &^ ' '; // upper case
|
||||
j++
|
||||
j++;
|
||||
}
|
||||
}
|
||||
str := string(data[0:j]);
|
||||
@ -145,6 +145,6 @@ func main() {
|
||||
|
||||
interests := []string{"GGT", "GGTA", "GGTATT", "GGTATTTTAATT", "GGTATTTTAATTTATAGT"};
|
||||
for _, s := range interests {
|
||||
fmt.Printf("%d %s\n", countOne(str, s), s);
|
||||
fmt.Printf("%d %s\n", countOne(str, s), s)
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func main() {
|
||||
|
||||
byte_acc <<= 1;
|
||||
if Tr+Ti <= Limit*Limit {
|
||||
byte_acc |= 0x01;
|
||||
byte_acc |= 0x01
|
||||
}
|
||||
|
||||
bit_num++;
|
||||
|
@ -48,7 +48,7 @@ func boolInt(b bool) int8 {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The board is a 50 cell hexagonal pattern. For . . . . .
|
||||
@ -112,7 +112,7 @@ var piece_def = [10][4]int8 {
|
||||
[4]int8{E, SE, SE, NE},
|
||||
[4]int8{E, SE, SE, W},
|
||||
[4]int8{E, SE, E, E},
|
||||
[4]int8{ E, E, E, SW}
|
||||
[4]int8{E, E, E, SW},
|
||||
}
|
||||
|
||||
|
||||
@ -133,14 +133,10 @@ var (
|
||||
)
|
||||
|
||||
/* Returns the direction rotated 60 degrees clockwise */
|
||||
func rotate(dir int8) int8 {
|
||||
return (dir + 2) % PIVOT;
|
||||
}
|
||||
func rotate(dir int8) int8 { return (dir + 2) % PIVOT }
|
||||
|
||||
/* Returns the direction flipped on the horizontal axis */
|
||||
func flip(dir int8) int8 {
|
||||
return (PIVOT - dir) % PIVOT;
|
||||
}
|
||||
func flip(dir int8) int8 { return (PIVOT - dir) % PIVOT }
|
||||
|
||||
|
||||
/* Returns the new cell index from the specified cell in the
|
||||
@ -151,60 +147,60 @@ func flip(dir int8) int8 {
|
||||
func shift(cell, dir int8) int8 {
|
||||
switch dir {
|
||||
case E:
|
||||
return cell + 1;
|
||||
return cell + 1
|
||||
case ESE:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell + 7;
|
||||
return cell + 7
|
||||
} else {
|
||||
return cell + 6;
|
||||
return cell + 6
|
||||
}
|
||||
case SE:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell + 6;
|
||||
return cell + 6
|
||||
} else {
|
||||
return cell + 5;
|
||||
return cell + 5
|
||||
}
|
||||
case S:
|
||||
return cell + 10;
|
||||
return cell + 10
|
||||
case SW:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell + 5;
|
||||
return cell + 5
|
||||
} else {
|
||||
return cell + 4;
|
||||
return cell + 4
|
||||
}
|
||||
case WSW:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell + 4;
|
||||
return cell + 4
|
||||
} else {
|
||||
return cell + 3;
|
||||
return cell + 3
|
||||
}
|
||||
case W:
|
||||
return cell - 1;
|
||||
return cell - 1
|
||||
case WNW:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell - 6;
|
||||
return cell - 6
|
||||
} else {
|
||||
return cell - 7;
|
||||
return cell - 7
|
||||
}
|
||||
case NW:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell - 5;
|
||||
return cell - 5
|
||||
} else {
|
||||
return cell - 6;
|
||||
return cell - 6
|
||||
}
|
||||
case N:
|
||||
return cell - 10;
|
||||
return cell - 10
|
||||
case NE:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell - 4;
|
||||
return cell - 4
|
||||
} else {
|
||||
return cell - 5;
|
||||
return cell - 5
|
||||
}
|
||||
case ENE:
|
||||
if ((cell / 5) % 2) != 0 {
|
||||
return cell - 3;
|
||||
return cell - 3
|
||||
} else {
|
||||
return cell - 4;
|
||||
return cell - 4
|
||||
}
|
||||
}
|
||||
return cell;
|
||||
@ -215,32 +211,32 @@ func shift(cell, dir int8) int8 {
|
||||
* location or not.
|
||||
*/
|
||||
func out_of_bounds(cell, dir int8) bool {
|
||||
switch(dir) {
|
||||
switch dir {
|
||||
case E:
|
||||
return cell % 5 == 4;
|
||||
return cell%5 == 4
|
||||
case ESE:
|
||||
i := cell % 10;
|
||||
return i == 4 || i == 8 || i == 9 || cell >= 45;
|
||||
case SE:
|
||||
return cell % 10 == 9 || cell >= 45;
|
||||
return cell%10 == 9 || cell >= 45
|
||||
case S:
|
||||
return cell >= 40;
|
||||
return cell >= 40
|
||||
case SW:
|
||||
return cell % 10 == 0 || cell >= 45;
|
||||
return cell%10 == 0 || cell >= 45
|
||||
case WSW:
|
||||
i := cell % 10;
|
||||
return i == 0 || i == 1 || i == 5 || cell >= 45;
|
||||
case W:
|
||||
return cell % 5 == 0;
|
||||
return cell%5 == 0
|
||||
case WNW:
|
||||
i := cell % 10;
|
||||
return i == 0 || i == 1 || i == 5 || cell < 5;
|
||||
case NW:
|
||||
return cell % 10 == 0 || cell < 5;
|
||||
return cell%10 == 0 || cell < 5
|
||||
case N:
|
||||
return cell < 10;
|
||||
return cell < 10
|
||||
case NE:
|
||||
return cell % 10 == 9 || cell < 5;
|
||||
return cell%10 == 9 || cell < 5
|
||||
case ENE:
|
||||
i := cell % 10;
|
||||
return i == 4 || i == 8 || i == 9 || cell < 5;
|
||||
@ -251,14 +247,14 @@ func out_of_bounds(cell, dir int8) bool {
|
||||
/* Rotate a piece 60 degrees clockwise */
|
||||
func rotate_piece(piece int) {
|
||||
for i := 0; i < 4; i++ {
|
||||
piece_def[piece][i] = rotate(piece_def[piece][i]);
|
||||
piece_def[piece][i] = rotate(piece_def[piece][i])
|
||||
}
|
||||
}
|
||||
|
||||
/* Flip a piece along the horizontal axis */
|
||||
func flip_piece(piece int) {
|
||||
for i := 0; i < 4; i++ {
|
||||
piece_def[piece][i] = flip(piece_def[piece][i]);
|
||||
piece_def[piece][i] = flip(piece_def[piece][i])
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,7 +262,7 @@ func flip_piece(piece int) {
|
||||
func calc_cell_indices(cell []int8, piece int, index int8) {
|
||||
cell[0] = index;
|
||||
for i := 1; i < 5; i++ {
|
||||
cell[i] = shift(cell[i-1], piece_def[piece][i-1]);
|
||||
cell[i] = shift(cell[i-1], piece_def[piece][i-1])
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,7 +271,7 @@ func cells_fit_on_board(cell []int8, piece int) bool {
|
||||
return !out_of_bounds(cell[0], piece_def[piece][0]) &&
|
||||
!out_of_bounds(cell[1], piece_def[piece][1]) &&
|
||||
!out_of_bounds(cell[2], piece_def[piece][2]) &&
|
||||
!out_of_bounds(cell[3], piece_def[piece][3]);
|
||||
!out_of_bounds(cell[3], piece_def[piece][3])
|
||||
}
|
||||
|
||||
/* Returns the lowest index of the cells of a piece.
|
||||
@ -301,7 +297,7 @@ func first_empty_cell(cell []int8, minimum int8) int8 {
|
||||
for first_empty == cell[0] || first_empty == cell[1] ||
|
||||
first_empty == cell[2] || first_empty == cell[3] ||
|
||||
first_empty == cell[4] {
|
||||
first_empty++;
|
||||
first_empty++
|
||||
}
|
||||
return first_empty;
|
||||
}
|
||||
@ -312,7 +308,7 @@ func first_empty_cell(cell []int8, minimum int8) int8 {
|
||||
func bitmask_from_cells(cell []int8) uint64 {
|
||||
var piece_mask uint64;
|
||||
for i := 0; i < 5; i++ {
|
||||
piece_mask |= 1 << uint(cell[i]);
|
||||
piece_mask |= 1 << uint(cell[i])
|
||||
}
|
||||
return piece_mask;
|
||||
}
|
||||
@ -332,26 +328,26 @@ func record_piece(piece int, minimum int8, first_empty int8, piece_mask uint64)
|
||||
*/
|
||||
func fill_contiguous_space(board []int8, index int8) {
|
||||
if board[index] == 1 {
|
||||
return;
|
||||
return
|
||||
}
|
||||
board[index] = 1;
|
||||
if !out_of_bounds(index, E) {
|
||||
fill_contiguous_space(board, shift(index, E));
|
||||
fill_contiguous_space(board, shift(index, E))
|
||||
}
|
||||
if !out_of_bounds(index, SE) {
|
||||
fill_contiguous_space(board, shift(index, SE));
|
||||
fill_contiguous_space(board, shift(index, SE))
|
||||
}
|
||||
if !out_of_bounds(index, SW) {
|
||||
fill_contiguous_space(board, shift(index, SW));
|
||||
fill_contiguous_space(board, shift(index, SW))
|
||||
}
|
||||
if !out_of_bounds(index, W) {
|
||||
fill_contiguous_space(board, shift(index, W));
|
||||
fill_contiguous_space(board, shift(index, W))
|
||||
}
|
||||
if !out_of_bounds(index, NW) {
|
||||
fill_contiguous_space(board, shift(index, NW));
|
||||
fill_contiguous_space(board, shift(index, NW))
|
||||
}
|
||||
if !out_of_bounds(index, NE) {
|
||||
fill_contiguous_space(board, shift(index, NE));
|
||||
fill_contiguous_space(board, shift(index, NE))
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,22 +362,22 @@ func has_island(cell []int8, piece int) bool {
|
||||
temp_board := make([]int8, 50);
|
||||
var i int;
|
||||
for i = 0; i < 5; i++ {
|
||||
temp_board[cell[i]] = 1;
|
||||
temp_board[cell[i]] = 1
|
||||
}
|
||||
i = 49;
|
||||
for temp_board[i] == 1 {
|
||||
i--;
|
||||
i--
|
||||
}
|
||||
fill_contiguous_space(temp_board, int8(i));
|
||||
c := 0;
|
||||
for i = 0; i < 50; i++ {
|
||||
if temp_board[i] == 0 {
|
||||
c++;
|
||||
c++
|
||||
}
|
||||
}
|
||||
if c == 0 || (c == 5 && piece == 8) || (c == 40 && piece == 8) ||
|
||||
(c%5 == 0 && piece == 0) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -422,7 +418,6 @@ func calc_pieces() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Calculate all 32 possible states for a 5-bit row and all rows that will
|
||||
* create islands that follow any of the 32 possible rows. These pre-
|
||||
* calculated 5-bit rows will be used to find islands in a partially solved
|
||||
@ -432,9 +427,11 @@ func calc_pieces() {
|
||||
ROW_MASK = 0x1F;
|
||||
TRIPLE_MASK = 0x7FFF;
|
||||
)
|
||||
|
||||
var (
|
||||
all_rows = [32]int8{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};
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
};
|
||||
bad_even_rows [32][32]int8;
|
||||
bad_odd_rows [32][32]int8;
|
||||
bad_even_triple [32768]int8;
|
||||
@ -446,9 +443,9 @@ func rows_bad(row1, row2 int8, even bool) int8 {
|
||||
var row2_shift int8;
|
||||
/* Test for blockages at same index and shifted index */
|
||||
if even {
|
||||
row2_shift = ((row2 << 1) & ROW_MASK) | 0x01;
|
||||
row2_shift = ((row2 << 1) & ROW_MASK) | 0x01
|
||||
} else {
|
||||
row2_shift = (row2 >> 1) | 0x10;
|
||||
row2_shift = (row2 >> 1) | 0x10
|
||||
}
|
||||
block := ((row1 ^ row2) & row2) & ((row1 ^ row2_shift) & row2_shift);
|
||||
/* Test for groups of 0's */
|
||||
@ -458,22 +455,22 @@ func rows_bad(row1, row2 int8, even bool) int8 {
|
||||
if row1&(1<<i) != 0 {
|
||||
if in_zeroes {
|
||||
if !group_okay {
|
||||
return 1;
|
||||
return 1
|
||||
}
|
||||
in_zeroes = false;
|
||||
group_okay = false;
|
||||
}
|
||||
} else {
|
||||
if !in_zeroes {
|
||||
in_zeroes = true;
|
||||
in_zeroes = true
|
||||
}
|
||||
if (block & (1 << i)) == 0 {
|
||||
group_okay = true;
|
||||
group_okay = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if in_zeroes {
|
||||
return boolInt(!group_okay);
|
||||
return boolInt(!group_okay)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -492,7 +489,7 @@ func triple_is_okay(row1, row2, row3 int, even bool) bool {
|
||||
return ((row1 == 0x03) && (row2 == 0x0B) && ((row3 & 0x1C) == 0x0C)) ||
|
||||
((row1 == 0x01) && (row2 == 0x05) && (row3 == 0x06)) ||
|
||||
((row1 == 0x19) && (row2 == 0x11)) ||
|
||||
((row1 == 0x15) && (row2 == 0x11));
|
||||
((row1 == 0x15) && (row2 == 0x11))
|
||||
}
|
||||
/* There are two cases:
|
||||
* row1: 10011 10101
|
||||
@ -516,17 +513,17 @@ func calc_rows() {
|
||||
result1 := bad_even_rows[row1][row2];
|
||||
result2 := bad_odd_rows[row2][row3];
|
||||
if result1 == 0 && result2 != 0 && triple_is_okay(row1, row2, row3, true) {
|
||||
bad_even_triple[row1+(row2*32)+(row3*1024)] = 0;
|
||||
bad_even_triple[row1+(row2*32)+(row3*1024)] = 0
|
||||
} else {
|
||||
bad_even_triple[row1+(row2*32)+(row3*1024)] = boolInt(result1!=0 || result2!=0);
|
||||
bad_even_triple[row1+(row2*32)+(row3*1024)] = boolInt(result1 != 0 || result2 != 0)
|
||||
}
|
||||
|
||||
result1 = bad_odd_rows[row1][row2];
|
||||
result2 = bad_even_rows[row2][row3];
|
||||
if result1 == 0 && result2 != 0 && triple_is_okay(row1, row2, row3, false) {
|
||||
bad_odd_triple[row1+(row2*32)+(row3*1024)] = 0;
|
||||
bad_odd_triple[row1+(row2*32)+(row3*1024)] = 0
|
||||
} else {
|
||||
bad_odd_triple[row1+(row2*32)+(row3*1024)] = boolInt(result1!=0 || result2!=0);
|
||||
bad_odd_triple[row1+(row2*32)+(row3*1024)] = boolInt(result1 != 0 || result2 != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -534,17 +531,16 @@ func calc_rows() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Calculate islands while solving the board.
|
||||
*/
|
||||
func boardHasIslands(cell int8) int8 {
|
||||
/* Too low on board, don't bother checking */
|
||||
if cell >= 40 {
|
||||
return 0;
|
||||
return 0
|
||||
}
|
||||
current_triple := (board >> uint((cell/5)*5)) & TRIPLE_MASK;
|
||||
if (cell/5)%2 != 0 {
|
||||
return bad_odd_triple[current_triple];
|
||||
return bad_odd_triple[current_triple]
|
||||
}
|
||||
return bad_even_triple[current_triple];
|
||||
}
|
||||
@ -581,17 +577,17 @@ func record_solution() {
|
||||
|
||||
func solve(depth, cell int8) {
|
||||
if solution_count >= *max_solutions {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
for board&(1<<uint(cell)) != 0 {
|
||||
cell++;
|
||||
cell++
|
||||
}
|
||||
|
||||
for piece := int8(0); piece < 10; piece++ {
|
||||
var piece_no_mask uint16 = 1 << uint(piece);
|
||||
if avail&piece_no_mask == 0 {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
avail ^= piece_no_mask;
|
||||
max_rots := piece_counts[piece][cell];
|
||||
@ -608,7 +604,7 @@ func solve(depth, cell int8) {
|
||||
}
|
||||
board |= piece_mask[rotation];
|
||||
if boardHasIslands(next_cell[piece][cell][rotation]) == 0 {
|
||||
solve(depth + 1, next_cell[piece][cell][rotation]);
|
||||
solve(depth+1, next_cell[piece][cell][rotation])
|
||||
}
|
||||
board ^= piece_mask[rotation];
|
||||
}
|
||||
@ -622,7 +618,7 @@ func pretty(b *[50]int8) {
|
||||
for i := 0; i < 50; i += 10 {
|
||||
fmt.Printf("%c %c %c %c %c \n %c %c %c %c %c \n", b[i]+'0', b[i+1]+'0',
|
||||
b[i+2]+'0', b[i+3]+'0', b[i+4]+'0', b[i+5]+'0', b[i+6]+'0',
|
||||
b[i+7]+'0', b[i+8]+'0', b[i+9]+'0');
|
||||
b[i+7]+'0', b[i+8]+'0', b[i+9]+'0')
|
||||
}
|
||||
fmt.Printf("\n");
|
||||
}
|
||||
@ -639,7 +635,7 @@ func smallest_largest() (smallest, largest *[50]int8) {
|
||||
continue
|
||||
}
|
||||
if c < s {
|
||||
smallest = candidate;
|
||||
smallest = candidate
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -649,7 +645,7 @@ func smallest_largest() (smallest, largest *[50]int8) {
|
||||
continue
|
||||
}
|
||||
if c > s {
|
||||
largest = candidate;
|
||||
largest = candidate
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ import (
|
||||
var n = flag.Int("n", 1000, "number of iterations")
|
||||
|
||||
type Body struct {
|
||||
x, y, z, vx, vy, vz, mass float64
|
||||
x, y, z, vx, vy, vz, mass float64;
|
||||
}
|
||||
|
||||
const (
|
||||
@ -161,8 +161,8 @@ var (
|
||||
mass: 5.15138902046611451e-05 * solarMass,
|
||||
};
|
||||
sun = Body{
|
||||
mass: solarMass
|
||||
}
|
||||
mass: solarMass,
|
||||
};
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -43,8 +43,8 @@ import (
|
||||
"fmt";
|
||||
)
|
||||
|
||||
var n = flag.Int("n", 27, "number of digits");
|
||||
var silent = flag.Bool("s", false, "don't print result");
|
||||
var n = flag.Int("n", 27, "number of digits")
|
||||
var silent = flag.Bool("s", false, "don't print result")
|
||||
|
||||
var (
|
||||
tmp1 *bignum.Integer;
|
||||
@ -56,7 +56,7 @@ var (
|
||||
|
||||
func extract_digit() int64 {
|
||||
if numer.Cmp(accum) > 0 {
|
||||
return -1;
|
||||
return -1
|
||||
}
|
||||
|
||||
// Compute (numer * 3 + accum) / denom
|
||||
@ -70,7 +70,7 @@ func extract_digit() int64 {
|
||||
|
||||
// ... is normalized, then the two divisions have the same result.
|
||||
if tmp2.Cmp(denom) >= 0 {
|
||||
return -1;
|
||||
return -1
|
||||
}
|
||||
|
||||
return tmp1.Value();
|
||||
@ -94,7 +94,7 @@ func eliminate_digit(d int64) {
|
||||
|
||||
func printf(s string, arg ...) {
|
||||
if !*silent {
|
||||
fmt.Printf(s, arg);
|
||||
fmt.Printf(s, arg)
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,15 +115,15 @@ func main() {
|
||||
i++;
|
||||
m = i % 10;
|
||||
if m == 0 {
|
||||
printf("\t:%d\n", i);
|
||||
printf("\t:%d\n", i)
|
||||
}
|
||||
if i >= *n {
|
||||
break;
|
||||
break
|
||||
}
|
||||
eliminate_digit(d);
|
||||
}
|
||||
|
||||
if m > 0 {
|
||||
printf("%s\t:%d\n", " "[m : 10], *n);
|
||||
printf("%s\t:%d\n", " "[m:10], *n)
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ var variants = []string {
|
||||
}
|
||||
|
||||
type Subst struct {
|
||||
pat, repl string
|
||||
pat, repl string;
|
||||
}
|
||||
|
||||
var substs = []Subst{
|
||||
@ -79,10 +79,10 @@ func countMatches(pat string, bytes []byte) int {
|
||||
for {
|
||||
e := re.Execute(bytes);
|
||||
if len(e) == 0 {
|
||||
break;
|
||||
break
|
||||
}
|
||||
n++;
|
||||
bytes = bytes[e[1]:len(bytes)];
|
||||
bytes = bytes[e[1]:];
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@ -98,10 +98,10 @@ func main() {
|
||||
bytes = regexp.MustCompile("(>[^\n]+)?\n").ReplaceAll(bytes, []byte{});
|
||||
clen := len(bytes);
|
||||
for _, s := range variants {
|
||||
fmt.Printf("%s %d\n", s, countMatches(s, bytes));
|
||||
fmt.Printf("%s %d\n", s, countMatches(s, bytes))
|
||||
}
|
||||
for _, sub := range substs {
|
||||
bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl));
|
||||
bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl))
|
||||
}
|
||||
fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(bytes));
|
||||
}
|
||||
|
@ -103,13 +103,13 @@ func main() {
|
||||
for {
|
||||
line, err = in.ReadSlice('\n');
|
||||
if err != nil || line[0] == '>' {
|
||||
break;
|
||||
break
|
||||
}
|
||||
line = line[0 : len(line)-1];
|
||||
nchar += len(line);
|
||||
if len(line)+nchar/60+128 >= w {
|
||||
nbuf := make([]byte, len(buf)*5);
|
||||
copy(nbuf[len(nbuf)-len(buf):len(nbuf)], buf);
|
||||
copy(nbuf[len(nbuf)-len(buf):], buf);
|
||||
w += len(nbuf) - len(buf);
|
||||
buf = nbuf;
|
||||
}
|
||||
@ -123,7 +123,7 @@ func main() {
|
||||
// The loop left room for the newlines and 128 bytes of padding.
|
||||
i := 0;
|
||||
for j := w; j < len(buf); j += 60 {
|
||||
n := copy(buf[i:i+60], buf[j:len(buf)]);
|
||||
n := copy(buf[i:i+60], buf[j:]);
|
||||
buf[i+n] = '\n';
|
||||
i += n + 1;
|
||||
}
|
||||
|
@ -46,9 +46,7 @@ import (
|
||||
var n = flag.Int("n", 2000, "count")
|
||||
var nCPU = flag.Int("ncpu", 4, "number of cpus")
|
||||
|
||||
func evalA(i, j int) float64 {
|
||||
return 1 / float64(((i + j)*(i + j + 1)/2 + i + 1));
|
||||
}
|
||||
func evalA(i, j int) float64 { return 1 / float64(((i+j)*(i+j+1)/2 + i + 1)) }
|
||||
|
||||
type Vec []float64
|
||||
|
||||
@ -56,7 +54,7 @@ func (v Vec) Times(i, n int, u Vec, c chan int) {
|
||||
for ; i < n; i++ {
|
||||
v[i] = 0;
|
||||
for j := 0; j < len(u); j++ {
|
||||
v[i] += evalA(i, j)*u[j];
|
||||
v[i] += evalA(i, j) * u[j]
|
||||
}
|
||||
}
|
||||
c <- 1;
|
||||
@ -66,7 +64,7 @@ func (v Vec) TimesTransp(i, n int, u Vec, c chan int) {
|
||||
for ; i < n; i++ {
|
||||
v[i] = 0;
|
||||
for j := 0; j < len(u); j++ {
|
||||
v[i] += evalA(j, i)*u[j];
|
||||
v[i] += evalA(j, i) * u[j]
|
||||
}
|
||||
}
|
||||
c <- 1;
|
||||
@ -82,11 +80,11 @@ func (v Vec) ATimesTransp(u Vec) {
|
||||
x := make(Vec, len(u));
|
||||
c := make(chan int, *nCPU);
|
||||
for i := 0; i < *nCPU; i++ {
|
||||
go x.Times(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, u, c);
|
||||
go x.Times(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, u, c)
|
||||
}
|
||||
wait(c);
|
||||
for i := 0; i < *nCPU; i++ {
|
||||
go v.TimesTransp(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, x, c);
|
||||
go v.TimesTransp(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, x, c)
|
||||
}
|
||||
wait(c);
|
||||
}
|
||||
@ -97,7 +95,7 @@ func main() {
|
||||
N := *n;
|
||||
u := make(Vec, N);
|
||||
for i := 0; i < N; i++ {
|
||||
u[i] = 1;
|
||||
u[i] = 1
|
||||
}
|
||||
v := make(Vec, N);
|
||||
for i := 0; i < 10; i++ {
|
||||
|
@ -44,9 +44,7 @@ import (
|
||||
|
||||
var n = flag.Int("n", 2000, "count")
|
||||
|
||||
func evalA(i, j int) float64 {
|
||||
return 1 / float64(((i + j)*(i + j + 1)/2+ i + 1));
|
||||
}
|
||||
func evalA(i, j int) float64 { return 1 / float64(((i+j)*(i+j+1)/2 + i + 1)) }
|
||||
|
||||
type Vec []float64
|
||||
|
||||
@ -54,7 +52,7 @@ func (v Vec) Times(u Vec) {
|
||||
for i := 0; i < len(v); i++ {
|
||||
v[i] = 0;
|
||||
for j := 0; j < len(u); j++ {
|
||||
v[i] += evalA(i, j)*u[j];
|
||||
v[i] += evalA(i, j) * u[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,7 +61,7 @@ func (v Vec) TimesTransp(u Vec) {
|
||||
for i := 0; i < len(v); i++ {
|
||||
v[i] = 0;
|
||||
for j := 0; j < len(u); j++ {
|
||||
v[i] += evalA(j, i)*u[j];
|
||||
v[i] += evalA(j, i) * u[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,7 +77,7 @@ func main() {
|
||||
N := *n;
|
||||
u := make(Vec, N);
|
||||
for i := 0; i < N; i++ {
|
||||
u[i] = 1;
|
||||
u[i] = 1
|
||||
}
|
||||
v := make(Vec, N);
|
||||
for i := 0; i < 10; i++ {
|
||||
|
@ -52,7 +52,7 @@ func f(i int, in <-chan int, out chan<- int) {
|
||||
fmt.Printf("%d\n", i);
|
||||
os.Exit(0);
|
||||
}
|
||||
out <- n - 1
|
||||
out <- n-1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user