问:
RecyclerView strange adapter and rows behaviour
My RecyclerView have two problems :

The first problem is when i am finished working with its activity and press back button it creates the same activity again but after removing some row (Mostly from the end) ,, I don't know if the problem is it  creates the view on multiple phases or what .

The second problem is when i press some button(Like button for example) it recreates the activity with the new result at each time it is pressed .

here is my Adapter

```<code>    package com.example.agh.grad.Adapters;

import android.Manifest; import android.app.Activity; import
android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.support.v4.app.ActivityCompat; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import com.example.agh.grad.ItemClickListner; import com.example.agh.grad.Models.Services; import com.example.agh.grad.R; import com.example.agh.grad.SearchServices; import com.example.agh.grad.ServiceDetail; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import org.parceler.Parcels; import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; /** * Created by cz on 17/06/17. */ public class recylerServiceAdapter extends RecyclerView.Adapter<recylerServiceAdapter.ViewHolder> { ArrayList<Services> service; Context context; ItemClickListner clickListner; public recylerServiceAdapter(ArrayList<Services> service, Context context) { this.service = service; this.context = context; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_recyler_services, parent, false); ViewHolder viewHolder = new ViewHolder(v); context= parent.getContext(); return viewHolder; }

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.tvServiceName.setText(service.get(position).getName());
    holder.tvServiceDisrption.setText(service.get(position).getServiceShortDesrption());
    holder.tvServiceProvider.setText(service.get(position).getServiceProvider());
    holder.tvLikeCounter.setText(String.valueOf(service.get(position).getLikes()));
    holder.tvDislikeCounter.setText(String.valueOf(service.get(position).getDislikes()));
    holder.tvLocationDescrption.setText(service.get(position).getLocationAddress());

    holder.tvServiceName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

    /*   Intent myIntent=   new Intent(context,SearchServices.class);
    context.startActivity(myIntent);*/
}
 });

       holder.btnLike.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final FirebaseDatabase firedatabase = FirebaseDatabase.getInstance();
            DatabaseReference ref = firedatabase.getReference("Services");
            DatabaseReference wantedService =    ref.child(String.valueOf(service.get(holder.getAdapterPosition()).getName()));
     final  Long uplikes=    service.get(holder.getAdapterPosition()).getLikes()+1;

            wantedService.child("likes").setValue(uplikes, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    holder.tvLikeCounter.setText(String.valueOf(uplikes));
                }
            });
         // TODO: 11/10/17  update on the database

            //// TODO: 05/12/17  Check state of buttons and act upon it

            holder.btnLike.setClickable(false);//// TODO: 05/12/17 set a clicked icon
            holder.btnDislike.setClickable(false);
        }
    });
    holder.btnDislike.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final FirebaseDatabase firedatabase = FirebaseDatabase.getInstance();
            DatabaseReference ref = firedatabase.getReference("Services");
            DatabaseReference wantedService =    ref.child(String.valueOf(service.get(holder.getAdapterPosition()).getName()));
            final  Long dislikes=    service.get(holder.getAdapterPosition()).getLikes()-1;

            wantedService.child("likes").setValue(dislikes, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    holder.tvLikeCounter.setText(String.valueOf(dislikes));
                }
            });
        }
    });
    holder.btnCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + service.get(holder.getAdapterPosition()).getPhoneNumber()));

            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Ask for permission
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            context.startActivity(callIntent);
        }
    });

    holder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent myIntent=   new Intent(context,ServiceDetail.class);

            myIntent.putExtra(SearchServices.PARCELER_TAG, Parcels.wrap(service.get(holder.getAdapterPosition()) ));
            context.startActivity(myIntent);

            ((Activity)context).finish();
        }
    });

}

@Override
public int getItemCount() {
    return service.size();
}

public void setClickListener(ItemClickListner itemClickListener) {
    this.clickListner = itemClickListener;
}

public class ViewHolder extends RecyclerView.ViewHolder  {
    @BindView (R.id.serviceName) TextView tvServiceName;
    @BindView (R.id.serviceProvider)TextView tvServiceProvider;
    @BindView (R.id.serviceShortDescrption)TextView tvServiceDisrption;
    @BindView (R.id.tvLikeCounter)TextView tvLikeCounter;
    @BindView (R.id.tvDislikeCounter)TextView tvDislikeCounter ;
    @BindView (R.id.locationDescrption)TextView tvLocationDescrption;

    @BindView (R.id.btnLike) Button btnLike;
    @BindView (R.id.btnDislike)  Button btnDislike;
    @BindView (R.id.btnCall) Button btnCall;
    @BindView (R.id.serviceCard) CardView cardView;

    public ViewHolder(View itemView) {
        super(itemView);
        itemView.setTag(itemView);

        ButterKnife.bind(this, itemView);

    }

}
}
</code>```

and here is my activity

```<code>            public class MainActivity extends AppCompatActivity  {

List<String> arrayServices = new ArrayList<>();

RecyclerView recyclerViewServices;
recylerServiceAdapter recylerServiceAdapter;
 ArrayList<Services> newServices;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = this.getIntent();
  //  arrayServices= intent.getStringArrayListExtra("newServices");
 //   System.out.println(arrayServices.size());
   newServices = Parcels.unwrap(intent.getParcelableExtra(SearchServices.PARCELER_TAG)) ;

Log.e( "onCreate: ",newServices.toString() );
    recyclerViewServices = (RecyclerView) findViewById(R.id.recylerViewServiceDetail);
    recyclerViewServices.setLayoutManager(new LinearLayoutManager(this));
    recylerServiceAdapter = new recylerServiceAdapter(newServices, getApplicationContext());
    recyclerViewServices.setAdapter(recylerServiceAdapter);

   }
      }
</code>```

and my activity_main.xml

```<code>        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightPrimary"
tools:context="com.example.agh.grad.MainActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recylerViewServiceDetail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteX="5dp"
    tools:layout_editor_absoluteY="5dp" />
  </RelativeLayout>
</code>```

答:
instead of using this </p>

```<code> holder.tvServiceName.setText(service.get(position).getName());
</code>```

<p>use </p>

```<code>     holder.tvServiceName.setText(service.get(getAdapterPosition())
    .getName());
</code>```

Body:
My RecyclerView have two problems :

The first problem is when i am finished working with its activity and press back button it creates the same activity again but after removing some row (Mostly from the end) ,, I don't know if the problem is it  creates the view on multiple phases or what .

The second problem is when i press some button(Like button for example) it recreates the activity with the new result at each time it is pressed .

here is my Adapter

    package com.example.agh.grad.Adapters;

import android.Manifest; import android.app.Activity; import
android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.support.v4.app.ActivityCompat; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import com.example.agh.grad.ItemClickListner; import com.example.agh.grad.Models.Services; import com.example.agh.grad.R; import com.example.agh.grad.SearchServices; import com.example.agh.grad.ServiceDetail; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import org.parceler.Parcels; import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; /** * Created by cz on 17/06/17. */ public class recylerServiceAdapter extends RecyclerView.Adapter<recylerServiceAdapter.ViewHolder> { ArrayList<Services> service; Context context; ItemClickListner clickListner; public recylerServiceAdapter(ArrayList<Services> service, Context context) { this.service = service; this.context = context; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_recyler_services, parent, false); ViewHolder viewHolder = new ViewHolder(v); context= parent.getContext(); return viewHolder; }

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.tvServiceName.setText(service.get(position).getName());
    holder.tvServiceDisrption.setText(service.get(position).getServiceShortDesrption());
    holder.tvServiceProvider.setText(service.get(position).getServiceProvider());
    holder.tvLikeCounter.setText(String.valueOf(service.get(position).getLikes()));
    holder.tvDislikeCounter.setText(String.valueOf(service.get(position).getDislikes()));
    holder.tvLocationDescrption.setText(service.get(position).getLocationAddress());

    holder.tvServiceName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

    /*   Intent myIntent=   new Intent(context,SearchServices.class);
    context.startActivity(myIntent);*/
}
 });

       holder.btnLike.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final FirebaseDatabase firedatabase = FirebaseDatabase.getInstance();
            DatabaseReference ref = firedatabase.getReference("Services");
            DatabaseReference wantedService =    ref.child(String.valueOf(service.get(holder.getAdapterPosition()).getName()));
     final  Long uplikes=    service.get(holder.getAdapterPosition()).getLikes()+1;

            wantedService.child("likes").setValue(uplikes, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    holder.tvLikeCounter.setText(String.valueOf(uplikes));
                }
            });
         // TODO: 11/10/17  update on the database

            //// TODO: 05/12/17  Check state of buttons and act upon it

            holder.btnLike.setClickable(false);//// TODO: 05/12/17 set a clicked icon
            holder.btnDislike.setClickable(false);
        }
    });
    holder.btnDislike.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final FirebaseDatabase firedatabase = FirebaseDatabase.getInstance();
            DatabaseReference ref = firedatabase.getReference("Services");
            DatabaseReference wantedService =    ref.child(String.valueOf(service.get(holder.getAdapterPosition()).getName()));
            final  Long dislikes=    service.get(holder.getAdapterPosition()).getLikes()-1;

            wantedService.child("likes").setValue(dislikes, new DatabaseReference.CompletionListener() {
                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    holder.tvLikeCounter.setText(String.valueOf(dislikes));
                }
            });
        }
    });
    holder.btnCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + service.get(holder.getAdapterPosition()).getPhoneNumber()));

            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Ask for permission
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            context.startActivity(callIntent);
        }
    });

    holder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent myIntent=   new Intent(context,ServiceDetail.class);

            myIntent.putExtra(SearchServices.PARCELER_TAG, Parcels.wrap(service.get(holder.getAdapterPosition()) ));
            context.startActivity(myIntent);

            ((Activity)context).finish();
        }
    });

}

@Override
public int getItemCount() {
    return service.size();
}

public void setClickListener(ItemClickListner itemClickListener) {
    this.clickListner = itemClickListener;
}

public class ViewHolder extends RecyclerView.ViewHolder  {
    @BindView (R.id.serviceName) TextView tvServiceName;
    @BindView (R.id.serviceProvider)TextView tvServiceProvider;
    @BindView (R.id.serviceShortDescrption)TextView tvServiceDisrption;
    @BindView (R.id.tvLikeCounter)TextView tvLikeCounter;
    @BindView (R.id.tvDislikeCounter)TextView tvDislikeCounter ;
    @BindView (R.id.locationDescrption)TextView tvLocationDescrption;

    @BindView (R.id.btnLike) Button btnLike;
    @BindView (R.id.btnDislike)  Button btnDislike;
    @BindView (R.id.btnCall) Button btnCall;
    @BindView (R.id.serviceCard) CardView cardView;

    public ViewHolder(View itemView) {
        super(itemView);
        itemView.setTag(itemView);

        ButterKnife.bind(this, itemView);

    }

}
}

and here is my activity

            public class MainActivity extends AppCompatActivity  {

List<String> arrayServices = new ArrayList<>();

RecyclerView recyclerViewServices;
recylerServiceAdapter recylerServiceAdapter;
 ArrayList<Services> newServices;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = this.getIntent();
  //  arrayServices= intent.getStringArrayListExtra("newServices");
 //   System.out.println(arrayServices.size());
   newServices = Parcels.unwrap(intent.getParcelableExtra(SearchServices.PARCELER_TAG)) ;

Log.e( "onCreate: ",newServices.toString() );
    recyclerViewServices = (RecyclerView) findViewById(R.id.recylerViewServiceDetail);
    recyclerViewServices.setLayoutManager(new LinearLayoutManager(this));
    recylerServiceAdapter = new recylerServiceAdapter(newServices, getApplicationContext());
    recyclerViewServices.setAdapter(recylerServiceAdapter);

   }
      }

and my activity_main.xml

        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightPrimary"
tools:context="com.example.agh.grad.MainActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recylerViewServiceDetail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteX="5dp"
    tools:layout_editor_absoluteY="5dp" />
  </RelativeLayout>

Body:
instead of using this

 holder.tvServiceName.setText(service.get(position).getName());

use

     holder.tvServiceName.setText(service.get(getAdapterPosition())
    .getName());


来源: stackexchange

问:
Find elements that share a common Voronoi boundary
I am trying to find the 'nearest neighbors' for the Voronoi graph elements, in other words, the elements which share a common boundary. Is there an implemented  way to do it in R. I tried follow the example from here (https://flowingdata.com/2016/04/12/voronoi-diagram-and-delaunay-triangulation-in-r/) and use the deldir package which helps with estabishing the boundaries:

```<code>set.seed(369)
x <- rnorm(50, 0, 1.5)
y <- rnorm(50, 0, 1)

library(deldir)

dta <- deldir(x, y)
plot(x, y, type = "n", asp=1)
points(x, y, pch = 20, col = "red", cex = 0.75)
plot(dta, wlines = "tess", wpoints = "none", number = FALSE, add = TRUE, lty = 1)
</code>```

How can I find the common boundary neighbours? I there a way to find second degree neighbours (elements that don't share a boundary, but do share a common neighbour)?

答:
Some helpers:

```<code>library(sp)
library(rgeos)
library(deldir)
library(hrbrthemes)
library(ggplot2)
</code>```

We can turn the deldir object into polygons with this function:

```<code>voroni_to_polys <- function(dd) {

  vor_desc <- tile.list(dd) # tile.list extracts the polygon data from the deldir computation

  # ^^ gets us the points for the polygons but we still have to close them, hence the need for the rbind

  lapply(1:(length(vor_desc)), function(i) {

    tmp <- cbind(vor_desc[[i]]$x, vor_desc[[i]]$y)
    tmp <- rbind(tmp, tmp[1,])

    Polygons(list(Polygon(tmp)), ID=i) # now we can make the Polygon(s)

  }) -> vor_polygons

  # dummy data frame that makes IDs easier
  xdf <- data.frame(id=sapply(slot(SpatialPolygons(vor_polygons), 'polygons'), slot, 'ID'))

  rownames(xdf) <- xdf$id

  SpatialPolygonsDataFrame(SpatialPolygons(vor_polygons), data=xdf)

}
</code>```

Your data:

```<code>set.seed(369)

data.frame(
  x = rnorm(50, 0, 1.5),
  y = rnorm(50, 0, 1)
) -> pts_df

dta <- deldir(pts_df$x, pts_df$y)
</code>```

Make the polygons:

```<code>vpoly <- voroni_to_polys(dta)
</code>```

We'll need this to show the ID #'s in the centroid position:

```<code>centers <- gCentroid(vpoly, byid=TRUE)
centers <- as.data.frame(centers)
centers$id <- 1:nrow(centers)

plot_df <- fortify(vpoly)
</code>```

Plot it for a visual reference:

```<code>ggplot() +
  geom_polygon(data=plot_df, aes(long, lat, group=group), color="#2b2b2b", fill="white") +
  geom_point(data=pts_df, aes(x, y), color="red") +
  geom_text(data=centers, aes(x, y, label=id), color="black", size=2) +
  theme_ipsum(grid="")
</code>```

Use gTouches() for ones that touch:

```<code>gTouches(vpoly, byid=TRUE)
##        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
## 1  FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 2  FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 3  FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 4  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 5  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 6  FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 7  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE
## 8   TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
## 9  FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 10 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 11 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 12 FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE
## 13 FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
## 14  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 15 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 16 FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 17 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE
## 18 FALSE FALSE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 19 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 20 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE  TRUE
## 21 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
## 22 FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE FALSE
## 23 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
## 24 FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 25 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 26 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 27 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 28  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
## 29 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
## 30 FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 31 FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 32  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 33 FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 34 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 35 FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 36 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
## 37 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 38 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE
## 39 FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 40 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE
## 41 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
## 42 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
## 43  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
## 44 FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE
## 45 FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
## 46 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 47 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 48 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 49 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
## 50 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
</code>```

You should be able to turn this into node pairs and use n-away graph algorithms for the second part of your question. Or, open a new question.

ContentLicense: CC BY-SA 3.0

Body:
I am trying to find the 'nearest neighbors' for the Voronoi graph elements, in other words, the elements which share a common boundary. Is there an implemented  way to do it in R. I tried follow the example from here (https://flowingdata.com/2016/04/12/voronoi-diagram-and-delaunay-triangulation-in-r/) and use the deldir package which helps with estabishing the boundaries:

set.seed(369)
x <- rnorm(50, 0, 1.5)
y <- rnorm(50, 0, 1)

library(deldir)

dta <- deldir(x, y)
plot(x, y, type = "n", asp=1)
points(x, y, pch = 20, col = "red", cex = 0.75)
plot(dta, wlines = "tess", wpoints = "none", number = FALSE, add = TRUE, lty = 1)

How can I find the common boundary neighbours? I there a way to find second degree neighbours (elements that don't share a boundary, but do share a common neighbour)?

Body:
Some helpers:

library(sp)
library(rgeos)
library(deldir)
library(hrbrthemes)
library(ggplot2)

We can turn the deldir object into polygons with this function:

voroni_to_polys <- function(dd) {

  vor_desc <- tile.list(dd) # tile.list extracts the polygon data from the deldir computation

  # ^^ gets us the points for the polygons but we still have to close them, hence the need for the rbind

  lapply(1:(length(vor_desc)), function(i) {

    tmp <- cbind(vor_desc[[i]]$x, vor_desc[[i]]$y)
    tmp <- rbind(tmp, tmp[1,])

    Polygons(list(Polygon(tmp)), ID=i) # now we can make the Polygon(s)

  }) -> vor_polygons

  # dummy data frame that makes IDs easier
  xdf <- data.frame(id=sapply(slot(SpatialPolygons(vor_polygons), 'polygons'), slot, 'ID'))

  rownames(xdf) <- xdf$id

  SpatialPolygonsDataFrame(SpatialPolygons(vor_polygons), data=xdf)

}

Your data:

set.seed(369)

data.frame(
  x = rnorm(50, 0, 1.5),
  y = rnorm(50, 0, 1)
) -> pts_df

dta <- deldir(pts_df$x, pts_df$y)

Make the polygons:

vpoly <- voroni_to_polys(dta)

We'll need this to show the ID #'s in the centroid position:

centers <- gCentroid(vpoly, byid=TRUE)
centers <- as.data.frame(centers)
centers$id <- 1:nrow(centers)

plot_df <- fortify(vpoly)

Plot it for a visual reference:

ggplot() +
  geom_polygon(data=plot_df, aes(long, lat, group=group), color="#2b2b2b", fill="white") +
  geom_point(data=pts_df, aes(x, y), color="red") +
  geom_text(data=centers, aes(x, y, label=id), color="black", size=2) +
  theme_ipsum(grid="")

Use gTouches() for ones that touch:

gTouches(vpoly, byid=TRUE)
##        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
## 1  FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 2  FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 3  FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 4  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 5  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 6  FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 7  FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE
## 8   TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
## 9  FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 10 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 11 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 12 FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE
## 13 FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
## 14  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 15 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 16 FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 17 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE
## 18 FALSE FALSE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 19 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 20 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE  TRUE
## 21 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
## 22 FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE FALSE
## 23 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
## 24 FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 25 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 26 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 27 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 28  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
## 29 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
## 30 FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 31 FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 32  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 33 FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 34 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 35 FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 36 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
## 37 FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 38 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE
## 39 FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 40 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE
## 41 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
## 42 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
## 43  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
## 44 FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE
## 45 FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
## 46 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 47 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## 48 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## 49 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
## 50 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE

You should be able to turn this into node pairs and use n-away graph algorithms for the second part of your question. Or, open a new question.


问:
copy elision of temporary object
CPP Refs states:

— when a temporary class object that has not been bound to a reference (12.2) would be copied/moved to a class object with the same cv-unqualified type, the copy/move operation can be omitted by constructing the temporary object directly into the target of the omitted copy/move

Let's say I have some test code:

```<code>#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class MyVector : public vector<T>
{
public:
    MyVector()
    {
        cout << "MyVector()" << endl;
    }

    MyVector(const MyVector& right):
        vector<T>(right)
    {
        cout << "MyVector(const MV&)" << endl;
    }

    MyVector(MyVector&& right) :
        vector<T>(right)
    {
        cout << "MyVector(MV&&)" << endl;
    }

};

class A
{
public:
    A() = default;
    A(MyVector<char> vec) :
        _vec(std::move(vec))
    {
        cout << "A(MyVec)" << endl;
    }
private:
    MyVector<char> _vec;
};

MyVector<char> funcElision()
{
    cout << "\nElision" << endl;
    MyVector<char> tmp;
    tmp.emplace_back('a');
    return tmp;
}

A funcElisionExternal()
{
    cout << "\nElision external test" << endl;
    return A(funcElision());
}

A funcElisionInternal()
{
    cout << "Elision internal test" << endl;
    MyVector<char> tmp;
    tmp.emplace_back('a');
    return A(tmp);
}

int main()
{
    auto a = funcElisionInternal();
    auto b = funcElisionExternal();
}
</code>```

The output of the test is:

```<code>Elision internal test
MyVector()
MyVector(const MV&)
MyVector(MV&&)
A(MyVec)

Elision external test

Elision
MyVector()
MyVector(MV&&)
A(MyVec)
 End
</code>```

The function elisionExternal does work as expected, but i don't know why the elisionInternal is doing the copy operation, since the MyVec is temporary object?

答:
```<code>return A(tmp);
</code>```

A's constructor that takes a MyVector takes it by value. Therefore, A's constructor parameter is initialized by copying from the glvalue. There is no possibility of elision here because tmp is not a prvalue; it is an lvalue.

You can only elide from an lvalue if it is being returned directly. That is, if you returned tmp, and the return type was decltype(tmp), then elision could take place (as you do with funcElision). But otherwise, no.

Title: copy elision of temporary object

Body:
CPP Refs states:

— when a temporary class object that has not been bound to a reference (12.2) would be copied/moved to a class object with the same cv-unqualified type, the copy/move operation can be omitted by constructing the temporary object directly into the target of the omitted copy/move

Let's say I have some test code:

#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class MyVector : public vector<T>
{
public:
    MyVector()
    {
        cout << "MyVector()" << endl;
    }

    MyVector(const MyVector& right):
        vector<T>(right)
    {
        cout << "MyVector(const MV&)" << endl;
    }

    MyVector(MyVector&& right) :
        vector<T>(right)
    {
        cout << "MyVector(MV&&)" << endl;
    }

};

class A
{
public:
    A() = default;
    A(MyVector<char> vec) :
        _vec(std::move(vec))
    {
        cout << "A(MyVec)" << endl;
    }
private:
    MyVector<char> _vec;
};

MyVector<char> funcElision()
{
    cout << "\nElision" << endl;
    MyVector<char> tmp;
    tmp.emplace_back('a');
    return tmp;
}

A funcElisionExternal()
{
    cout << "\nElision external test" << endl;
    return A(funcElision());
}

A funcElisionInternal()
{
    cout << "Elision internal test" << endl;
    MyVector<char> tmp;
    tmp.emplace_back('a');
    return A(tmp);
}

int main()
{
    auto a = funcElisionInternal();
    auto b = funcElisionExternal();
}

The output of the test is:

Elision internal test
MyVector()
MyVector(const MV&)
MyVector(MV&&)
A(MyVec)

Elision external test

Elision
MyVector()
MyVector(MV&&)
A(MyVec)
 End

The function elisionExternal does work as expected, but i don't know why the elisionInternal is doing the copy operation, since the MyVec is temporary object?

Body:
return A(tmp);

A's constructor that takes a MyVector takes it by value. Therefore, A's constructor parameter is initialized by copying from the glvalue. There is no possibility of elision here because tmp is not a prvalue; it is an lvalue.

You can only elide from an lvalue if it is being returned directly. That is, if you returned tmp, and the return type was decltype(tmp), then elision could take place (as you do with funcElision). But otherwise, no.


问:
Using ScheduledExecutorService, How to Start a Thread without waiting for other thread to complete at fixed interval?
I want to run a task at every particular interval of time regardless of completion of previous thread. And I've used ScheduledExecutorService with the schedule time at every one second. But the problem is, in my Runnable, If I make thread to sleep for 5 seconds, My ScheduledExecuterService also getting executed in every 5 seconds while it supposed to run each thread at 1 second.

It seems like it ScheduledExecuterService is waiting for previous thread to completion. But I want, The task to be triggered at every 1 second no matter what if job inside the task waits for longer time.

Here's is my code.

```<code>public class MyTask implements Runnable {

   public void run() {
       System.out.println("hi there at: "+ new java.util.Date());
       try {
           Thread.sleep(5000);
       } catch (InterruptedException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
   }
}
</code>```

And here's my ScheduledExecutorService Code.

```<code>public class JavaScheduledExecutorServiceExample {

   public static void main(String[] args) {
       ScheduledExecutorService execService = Executors.newScheduledThreadPool(5);
       execService.scheduleAtFixedRate(new MyTask(), 0, 1000, TimeUnit.MILLISECONDS);
   }
}
</code>```

Correct me If I'm doing something wrong. And If I'm wrong, is there any alternative to achieve the same? Providing Any best practices could be more helpful :)

答:
"If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute."  The behavior you are seeing is consistent with the javadocs

I believe this will perform the way you specified:

```<code>public class JavaScheduledExecutorServiceExample {
    private static ScheduledExecutorService execService = null;
    private static int timesAsleep = 0;

    public static class MyTask implements Runnable {

        public void run() {
            System.out.println("hi there at: "+ new java.util.Date());
            // schedule again
            execService.schedule(new MyTask(), 1000, TimeUnit.MILLISECONDS);
            try {
                int i = timesAsleep;
                timesAsleep++;
                System.out.println("asleep " + i + "----------------------");
                Thread.sleep(5000);
                System.out.println("awoke " + i + "----------------------");
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        execService = Executors.newScheduledThreadPool(5);
        execService.schedule(new MyTask(), 1000, TimeUnit.MILLISECONDS);
    }

}
</code>```

Notice the  use schedule() instead of scheduleAtFixedRate() on the ScheduledExecutorService instance. It also schedules the next task as soon as it starts the new task.

Body:
I want to run a task at every particular interval of time regardless of completion of previous thread. And I've used ScheduledExecutorService with the schedule time at every one second. But the problem is, in my Runnable, If I make thread to sleep for 5 seconds, My ScheduledExecuterService also getting executed in every 5 seconds while it supposed to run each thread at 1 second.

It seems like it ScheduledExecuterService is waiting for previous thread to completion. But I want, The task to be triggered at every 1 second no matter what if job inside the task waits for longer time.

Here's is my code.

public class MyTask implements Runnable {

   public void run() {
       System.out.println("hi there at: "+ new java.util.Date());
       try {
           Thread.sleep(5000);
       } catch (InterruptedException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
   }
}

And here's my ScheduledExecutorService Code.

public class JavaScheduledExecutorServiceExample {

   public static void main(String[] args) {
       ScheduledExecutorService execService = Executors.newScheduledThreadPool(5);
       execService.scheduleAtFixedRate(new MyTask(), 0, 1000, TimeUnit.MILLISECONDS);
   }
}

Correct me If I'm doing something wrong. And If I'm wrong, is there any alternative to achieve the same? Providing Any best practices could be more helpful :)

Body:
"If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute."  The behavior you are seeing is consistent with the javadocs

I believe this will perform the way you specified:

public class JavaScheduledExecutorServiceExample {
    private static ScheduledExecutorService execService = null;
    private static int timesAsleep = 0;

    public static class MyTask implements Runnable {

        public void run() {
            System.out.println("hi there at: "+ new java.util.Date());
            // schedule again
            execService.schedule(new MyTask(), 1000, TimeUnit.MILLISECONDS);
            try {
                int i = timesAsleep;
                timesAsleep++;
                System.out.println("asleep " + i + "----------------------");
                Thread.sleep(5000);
                System.out.println("awoke " + i + "----------------------");
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        execService = Executors.newScheduledThreadPool(5);
        execService.schedule(new MyTask(), 1000, TimeUnit.MILLISECONDS);
    }

}

Notice the  use schedule() instead of scheduleAtFixedRate() on the ScheduledExecutorService instance. It also schedules the next task as soon as it starts the new task.


问:
Extract only number between commas
I have a returned string like this from my code:  (<C1>, 4.297, %)
And I am trying to extract only the value 4.297 from this string using gsub command:

```<code>Fat<-gsub("\\D", "", stringV)
</code>```

However, this extracts not only 4.297 but also the number '1' in C1.
Is there a way to extract only 4.297 from this string, please can you help.

Thanks

答:
you can use  as.numeric convert no number string to NA.

```<code>ss <- as.numeric(unlist(strsplit(stringV, ',')))
ss[!is.na(ss)]
#[1] 4.297
</code>```

Title: Extract only number between commas

Body:
I have a returned string like this from my code:  (<C1>, 4.297, %)
And I am trying to extract only the value 4.297 from this string using gsub command:

Fat<-gsub("\\D", "", stringV)

However, this extracts not only 4.297 but also the number '1' in C1.
Is there a way to extract only 4.297 from this string, please can you help.

Thanks

Body:
you can use  as.numeric convert no number string to NA.

ss <- as.numeric(unlist(strsplit(stringV, ',')))
ss[!is.na(ss)]
#[1] 4.297


问:
How to add TextField to UIAlertController in Swift
I am trying to show a UIAlertController with a UITextView. When I add the line:

```<code>    //Add text field
    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
    }
</code>```

I get a Runtime error:

fatal error: unexpectedly found nil while unwrapping an Optional value

```<code>    let alertController: UIAlertController = UIAlertController(title: "Find image", message: "Search for image", preferredStyle: .Alert)

    //cancel button
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
        //cancel code
    }
    alertController.addAction(cancelAction)

    //Create an optional action
    let nextAction: UIAlertAction = UIAlertAction(title: "Search", style: .Default) { action -> Void in
        let text = (alertController.textFields?.first as! UITextField).text
        println("You entered \(text)")
    }
    alertController.addAction(nextAction)

    //Add text field
    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
        textField.textColor = UIColor.greenColor()
    }
    //Present the AlertController
    presentViewController(alertController, animated: true, completion: nil)
</code>```

This is presented inside my ViewController via an IBAction.

I have downloaded the code from here and it works fine. I copied and pasted that method into my code and it breaks. The presence of self on the last line has no impact.

答:
How to add textField to AlertView? Let's keep it short and simple.

This works for Swift 3.0 and above.

```<code>var nameField: UITextField?
let alertController = UIAlertController(title: "Add Number", message: nil, preferredStyle: .alert)
// Add textfield to alert view
alertController.addTextField { (textField) in
    nameField = textField
}
</code>```

First, you instantiate an object of UIAlertController and then you add a text field to it by accessing addTextField member of UIAlertController class.

ContentLicense: CC BY-SA 4.0

Body:
I am trying to show a UIAlertController with a UITextView. When I add the line:

    //Add text field
    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
    }

I get a Runtime error:

fatal error: unexpectedly found nil while unwrapping an Optional value

    let alertController: UIAlertController = UIAlertController(title: "Find image", message: "Search for image", preferredStyle: .Alert)

    //cancel button
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
        //cancel code
    }
    alertController.addAction(cancelAction)

    //Create an optional action
    let nextAction: UIAlertAction = UIAlertAction(title: "Search", style: .Default) { action -> Void in
        let text = (alertController.textFields?.first as! UITextField).text
        println("You entered \(text)")
    }
    alertController.addAction(nextAction)

    //Add text field
    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
        textField.textColor = UIColor.greenColor()
    }
    //Present the AlertController
    presentViewController(alertController, animated: true, completion: nil)

This is presented inside my ViewController via an IBAction.

I have downloaded the code from here and it works fine. I copied and pasted that method into my code and it breaks. The presence of self on the last line has no impact.

Body:
How to add textField to AlertView? Let's keep it short and simple.

This works for Swift 3.0 and above.

var nameField: UITextField?
let alertController = UIAlertController(title: "Add Number", message: nil, preferredStyle: .alert)
// Add textfield to alert view
alertController.addTextField { (textField) in
    nameField = textField
}

First, you instantiate an object of UIAlertController and then you add a text field to it by accessing addTextField member of UIAlertController class.


问:
devise - how to add validation to the users model
I'm using rails 3 w devise. How can I add a validation to devise for a extra column in my user's table, column: first_name

Any ideas?

Thanks

答:
```<code>class User < ActiveRecord::Base
  validates :first_name, :presence => true
end
</code>```

ContentLicense: CC BY-SA 2.5


问:
Why is my output equaling zero? (student)
I am a student in my first year of CIS courses, so I am a begineer. We are supposed to get input from a text file with an employee, the employee's department, hourly salary, and hours worked in given week, that looks like:

```<code>EID001, 1, 10.00, 40
EID002, 2, 10.50, 35
EID003, 3, 11.00, 30
EID004, 4, 11.50, 25
EID005, 5, 12.00, 20
EID006, 6, 12.50, 40
EID007, 7, 11.00, 25
.
.
.
(Employee ID, Department, Hourly Salary, Hours Worked)
</code>```

Then separate each field into elements of an array, validate each field, and calculate the total gross pay (Hourly Salary * Hours Worked) for each of the 7 departments.

My code:

```<code>    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Project_3_rev
{
    class Program
    {
        const int DEPARTMENTS = 7;
        const int FIELDS = 4;
        static void Main(string[] args)
        {
            FileStream fStream = new FileStream("project3data.txt", FileMode.Open, FileAccess.Read);
            StreamReader inFile = new StreamReader(fStream);
            string input = "";
            string[] fields = new string[FIELDS];
            string employee = "";
            int department = 0;
            double salary = 0.00;
            int hours = 0;

            double totalSalary = 0.00;
            int totalHours = 0;
            double[] grossPayArray = new double[DEPARTMENTS];

            input = inFile.ReadLine();
            while(input != null)
            {
                fields = input.Split(',');

                checkEmployee(input, fields, employee);
                checkDepartment(input, fields, department);

                for(int x = 1; x <= DEPARTMENTS; x++)
                {
                    totalSalary = 0.00;
                    totalHours = 0;
                    while (department == x)
                    {

                        checkSalary(input, fields, salary, department, totalSalary);
                        checkHours(input, fields, hours, department, totalHours);
                        grossPayArray[x - 1] = totalSalary * totalHours;
                    }
                }

                input = inFile.ReadLine();
            }

            displayOutput(grossPayArray);

        }

        static void checkEmployee(string inp, string[] fieldsArray, string emp)
        {
            if(fieldsArray[0] == null)
                Console.WriteLine("An Employee ID is invalid.");
        }

        static void checkDepartment(string inp, string[] fieldsArray, int dept)
        {
            if((!int.TryParse(fieldsArray[1], out dept)) || dept < 0 || dept > DEPARTMENTS)
            {
                Console.WriteLine("Department field is invalid: " + fieldsArray[1]);
            }

        }

        static void checkSalary(string inp, string[] fieldsArray, double sal, int dept, double totSal)
        {

                    if ((double.TryParse(fieldsArray[2], out sal)) && sal >= 10.00)
                        totSal = totSal * sal;
                    else
                        Console.WriteLine("Salary field is invalid: " + fieldsArray[2]);

        }

        static void checkHours(string inp, string[] fieldsArray, int hrs, int dept, int totHrs)
        {

                    if ((int.TryParse(fieldsArray[3], out hrs)) && hrs >= 0)
                        totHrs = totHrs * hrs;

                    else
                        Console.WriteLine("Hours field is invalid: " +  fieldsArray[3]);

        }

        static void displayOutput(double[] grossArray)
        {
            for(int x = 1; x <= DEPARTMENTS; x++)
            {
                Console.WriteLine("Department " + x + ": Gross Pay = " + grossArray[x-1]);
            }
        }

    }
}
</code>```

My output:

```<code>Department 1: Gross Pay = 0
Department 2: Gross Pay = 0
Department 3: Gross Pay = 0
Department 4: Gross Pay = 0
Department 5: Gross Pay = 0
Department 6: Gross Pay = 0
Department 7: Gross Pay = 0
</code>```

Why are the Gross Pays equaling zero?

Please keep in mind that I am in my first year of computer science. I am only allowed to use what we have learned and I only know the basics. Please cut me a little slack if this code is messy or my logic is way off. Thanks ahead of time.

答:
In these two lines of code:

```<code>totalSalary = 0.00;
totalHours = 0;
</code>```

you set the values to zero.  Multiplying them by anything later, will still be zero.  You need to make sure you either update these fields with the correct values before multiplying, or at the very least set them to 1.

Body:
I am a student in my first year of CIS courses, so I am a begineer. We are supposed to get input from a text file with an employee, the employee's department, hourly salary, and hours worked in given week, that looks like:

EID001, 1, 10.00, 40
EID002, 2, 10.50, 35
EID003, 3, 11.00, 30
EID004, 4, 11.50, 25
EID005, 5, 12.00, 20
EID006, 6, 12.50, 40
EID007, 7, 11.00, 25
.
.
.
(Employee ID, Department, Hourly Salary, Hours Worked)

Then separate each field into elements of an array, validate each field, and calculate the total gross pay (Hourly Salary * Hours Worked) for each of the 7 departments.

My code:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Project_3_rev
{
    class Program
    {
        const int DEPARTMENTS = 7;
        const int FIELDS = 4;
        static void Main(string[] args)
        {
            FileStream fStream = new FileStream("project3data.txt", FileMode.Open, FileAccess.Read);
            StreamReader inFile = new StreamReader(fStream);
            string input = "";
            string[] fields = new string[FIELDS];
            string employee = "";
            int department = 0;
            double salary = 0.00;
            int hours = 0;

            double totalSalary = 0.00;
            int totalHours = 0;
            double[] grossPayArray = new double[DEPARTMENTS];

            input = inFile.ReadLine();
            while(input != null)
            {
                fields = input.Split(',');

                checkEmployee(input, fields, employee);
                checkDepartment(input, fields, department);

                for(int x = 1; x <= DEPARTMENTS; x++)
                {
                    totalSalary = 0.00;
                    totalHours = 0;
                    while (department == x)
                    {

                        checkSalary(input, fields, salary, department, totalSalary);
                        checkHours(input, fields, hours, department, totalHours);
                        grossPayArray[x - 1] = totalSalary * totalHours;
                    }
                }

                input = inFile.ReadLine();
            }

            displayOutput(grossPayArray);

        }

        static void checkEmployee(string inp, string[] fieldsArray, string emp)
        {
            if(fieldsArray[0] == null)
                Console.WriteLine("An Employee ID is invalid.");
        }

        static void checkDepartment(string inp, string[] fieldsArray, int dept)
        {
            if((!int.TryParse(fieldsArray[1], out dept)) || dept < 0 || dept > DEPARTMENTS)
            {
                Console.WriteLine("Department field is invalid: " + fieldsArray[1]);
            }

        }

        static void checkSalary(string inp, string[] fieldsArray, double sal, int dept, double totSal)
        {

                    if ((double.TryParse(fieldsArray[2], out sal)) && sal >= 10.00)
                        totSal = totSal * sal;
                    else
                        Console.WriteLine("Salary field is invalid: " + fieldsArray[2]);

        }

        static void checkHours(string inp, string[] fieldsArray, int hrs, int dept, int totHrs)
        {

                    if ((int.TryParse(fieldsArray[3], out hrs)) && hrs >= 0)
                        totHrs = totHrs * hrs;

                    else
                        Console.WriteLine("Hours field is invalid: " +  fieldsArray[3]);

        }

        static void displayOutput(double[] grossArray)
        {
            for(int x = 1; x <= DEPARTMENTS; x++)
            {
                Console.WriteLine("Department " + x + ": Gross Pay = " + grossArray[x-1]);
            }
        }

    }
}

My output:

Department 1: Gross Pay = 0
Department 2: Gross Pay = 0
Department 3: Gross Pay = 0
Department 4: Gross Pay = 0
Department 5: Gross Pay = 0
Department 6: Gross Pay = 0
Department 7: Gross Pay = 0

Why are the Gross Pays equaling zero?

Please keep in mind that I am in my first year of computer science. I am only allowed to use what we have learned and I only know the basics. Please cut me a little slack if this code is messy or my logic is way off. Thanks ahead of time.

Body:
In these two lines of code:

totalSalary = 0.00;
totalHours = 0;

you set the values to zero.  Multiplying them by anything later, will still be zero.  You need to make sure you either update these fields with the correct values before multiplying, or at the very least set them to 1.


问:
Unable to run commands in docker container using docker-compose
EDITED - Added folder structure

I'm trying to run a node.js app in a docker container using docker-compose, however, the container fails to run the specified command and exits.

I'm running docker-for-mac, version 17.09.0-ce-mac35 (19611)

This is my folder structure:

```<code>.
├── docker-compose.yml
├── backend/
│  ├── Dockerfile
│  ├── package.json
│  ├── (source files)
├── frontend/
│  ├── Dockerfile
│  ├── package.json
│  ├── (source files)
</code>```

This is my docker-compose file:

```<code>version: "3"
services:
  ihm-backend:
    environment:
      - NODE_ENV=development
    build: ./backend
    volumes:
      - ./backend:/src
    ports:
      - "3000:3000"
      - "9222:9222"
    working_dir: /src
    command:
      - "./node_modules/.bin/nodemon --watch ./ --inspect=0.0.0.0:9222 --nolazy ./app.js"
</code>```

And this is my Dockerfile:

```<code>FROM node:6-alpine

COPY ./package.json src/
COPY ./npm-shrinkwrap.json src/

RUN cd /src && npm install

COPY . /src

WORKDIR /src

CMD ["./bin/www"]
</code>```

Notice that the docker-compose file overrides the command.

When I run it, I get the following error:

```<code>Cannot start service ihm-backend: oci runtime error: container_linux.go:265:
starting container process caused "exec: \"./node_modules/.bin/nodemon --watch
./ --inspect=0.0.0.0:9222 --nolazy ./app.js\": stat ./node_modules/.bin/nodemon
--watch ./ --inspect=0.0.0.0:9222 --nolazy ./app.js: no such file or directory"
</code>```

I tried to play with the command a bit - when changing it to ls or pwd I got the expected output. However, once I try to use npm or anything from the file-system like ls ./node_modules, I get the same error. Also, if I just start the container into a shell, I'm able to run any command I want, including npm scripts

答:
Not sure if this helps, but this is what I use for my node app and it works .

Dockerfile

```<code>FROM node:carbon

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install
RUN npm install nodemon -g

# Bundle app source
COPY . .
</code>```

docker-compose

```<code>web:
  build: .
  volumes:
    - ".:/src/app"
  ports:
    - "3000:3000"
  command:
      - "nodemon"
</code>```

Body:
EDITED - Added folder structure

I'm trying to run a node.js app in a docker container using docker-compose, however, the container fails to run the specified command and exits.

I'm running docker-for-mac, version 17.09.0-ce-mac35 (19611)

This is my folder structure:

.
├── docker-compose.yml
├── backend/
│  ├── Dockerfile
│  ├── package.json
│  ├── (source files)
├── frontend/
│  ├── Dockerfile
│  ├── package.json
│  ├── (source files)

This is my docker-compose file:

version: "3"
services:
  ihm-backend:
    environment:
      - NODE_ENV=development
    build: ./backend
    volumes:
      - ./backend:/src
    ports:
      - "3000:3000"
      - "9222:9222"
    working_dir: /src
    command:
      - "./node_modules/.bin/nodemon --watch ./ --inspect=0.0.0.0:9222 --nolazy ./app.js"

And this is my Dockerfile:

FROM node:6-alpine

COPY ./package.json src/
COPY ./npm-shrinkwrap.json src/

RUN cd /src && npm install

COPY . /src

WORKDIR /src

CMD ["./bin/www"]

Notice that the docker-compose file overrides the command.

When I run it, I get the following error:

Cannot start service ihm-backend: oci runtime error: container_linux.go:265:
starting container process caused "exec: \"./node_modules/.bin/nodemon --watch
./ --inspect=0.0.0.0:9222 --nolazy ./app.js\": stat ./node_modules/.bin/nodemon
--watch ./ --inspect=0.0.0.0:9222 --nolazy ./app.js: no such file or directory"

I tried to play with the command a bit - when changing it to ls or pwd I got the expected output. However, once I try to use npm or anything from the file-system like ls ./node_modules, I get the same error. Also, if I just start the container into a shell, I'm able to run any command I want, including npm scripts

Body:
Not sure if this helps, but this is what I use for my node app and it works .

Dockerfile

FROM node:carbon

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install
RUN npm install nodemon -g

# Bundle app source
COPY . .

docker-compose

web:
  build: .
  volumes:
    - ".:/src/app"
  ports:
    - "3000:3000"
  command:
      - "nodemon"


答:
The problem is here:

```<code>for(int x = 1; x <= DEPARTMENTS; x++)
{
    totalSalary = 0.00;
    totalHours = 0;
    while (department == x)
    {
        checkSalary(input, fields, salary, department, totalSalary);
        checkHours(input, fields, hours, department, totalHours);
        grossPayArray[x - 1] = totalSalary * totalHours;
    }
}
</code>```

Notice that you never change the variables totalSalary and totalHours.

What I suggest you do is redefine your functions to only validate the input salary:

```<code>static void validateSalary(string inp, string[] fieldsArray, double sal, int dept, double totSal)
{
    // you might want to rewrite this
    if !((double.TryParse(fieldsArray[2], out sal)) && sal >= 10.00)
        Console.WriteLine("Salary field is invalid: " + fieldsArray[2]);
}
</code>```

This way, the function actually only validates the salary, as it was named. See: Single Responsibility Principle

Then set your total salary within the loop itself:

```<code>    while (department == x)
    {
        checkSalary(input, fields, salary, department, totalSalary);
        checkHours(input, fields, hours, department, totalHours);

        totalSalary *= salary;
        totalHours += hours;

        grossPayArray[x - 1] = totalSalary * totalHours;
    }
</code>```

EDIT: Of course, this still has the problem that salary doesn't change within the loop.

Title: Why is my output equaling zero? (student)

Body:
The problem is here:

for(int x = 1; x <= DEPARTMENTS; x++)
{
    totalSalary = 0.00;
    totalHours = 0;
    while (department == x)
    {
        checkSalary(input, fields, salary, department, totalSalary);
        checkHours(input, fields, hours, department, totalHours);
        grossPayArray[x - 1] = totalSalary * totalHours;
    }
}

Notice that you never change the variables totalSalary and totalHours.

What I suggest you do is redefine your functions to only validate the input salary:

static void validateSalary(string inp, string[] fieldsArray, double sal, int dept, double totSal)
{
    // you might want to rewrite this
    if !((double.TryParse(fieldsArray[2], out sal)) && sal >= 10.00)
        Console.WriteLine("Salary field is invalid: " + fieldsArray[2]);
}

This way, the function actually only validates the salary, as it was named. See: Single Responsibility Principle

Then set your total salary within the loop itself:

    while (department == x)
    {
        checkSalary(input, fields, salary, department, totalSalary);
        checkHours(input, fields, hours, department, totalHours);

        totalSalary *= salary;
        totalHours += hours;

        grossPayArray[x - 1] = totalSalary * totalHours;
    }

EDIT: Of course, this still has the problem that salary doesn't change within the loop.


问:
angular is not defined, why?
The following angular piece doesn't work, it seems that in the immediately invoked function the code breaks where I create my module because angular syntax is not recognised.

```<code><!DOCTYPE html>
<html ng-app="MyModule">
 <head>
    <script data-require="angular.js@*" data-semver="4.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.17/angular2.min.js"></script>

  </head>
  <body ng-controller="MyCtrller">
    <h1>Hello!</h1>
    {{ cousin }}
  </body>

</html>

<script type="text/javascript">
(function() {
    var app = angular.module("MyModule", []);
    var MyCtrller = function($scope)          ///typo here in "MyCtrller"
    {
          $scope.cousin = "Karen";
    }
    app.controller("MyCtrller", ["$scope", MyCtrller]);
}());
</script>
</code>```

I expect the result to be Karen.

Instead, I see {{ cousin }}

The error I get in console is:

Uncaught ReferenceError: angular is not defined

on the line where I create my module:

var app = angular.module("MyModule", []);

答:
Just use the AngularJs script instead of Angular Script in your script like this</p>

```<code> <script src="https://code.angularjs.org/1.6.7/angular.js"></script>
</code>```

Title: angular is not defined, why?

Body:
The following angular piece doesn't work, it seems that in the immediately invoked function the code breaks where I create my module because angular syntax is not recognised.

<!DOCTYPE html>

Hello!

    {{ cousin }}

I expect the result to be Karen.

Instead, I see {{ cousin }}

The error I get in console is:

Uncaught ReferenceError: angular is not defined

on the line where I create my module:

var app = angular.module("MyModule", []);

Body:
Just use the AngularJs script instead of Angular Script in your script like this

 <script src="https://code.angularjs.org/1.6.7/angular.js"></script>


问:
PHP $_POST function with a table
I have a table, in a grid of 4x4. Assume they're all black boxes. I now have it so that when I hover, they turn grey.

However, how would I make it so that if you click on a table cell, it stays grey, and I can somehow pass that cell's coordinates to a $_POST function? I hope I am being descriptive enough.

答:
$_POST is generally used for form data, so you would need to populate (via javascript) a hidden <input> element on click with the data you want passed.  Depending on how you want to trigger the $_POST you could submit the form in the same click event, or by some other action.

The point is the only way to pass data through $_POST is normally through a form or through AJAX.

Title: PHP $_POST function with a table