Quick way to reverse an array
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; Array.Reverse(array1);
5293 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; Array.Reverse(array1);
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; int lastIndexOf14 = Array.FindLastIndex(array1, element => element == 14); Response.Write("<br/>Last Index of Element 14 is <b>" + lastIndexOf14 + "</b> in array.");
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; int indexOf11 = Array.FindIndex(array1, element => element == 11); Response.Write("<br/>Index of Element 11 is <b>" + indexOf11 + "</b> in array.");
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; Response.Write("<br/><br/><li>Check whether element 209 Exists in Array.</li>"); bool isExist = Array.Exists(array1, element => element == 209);
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; int[] array2 = Array.FindAll(array1, element => element == 11); Response.Write("<br/>There are <b>" + array2.Length + "</b> element in array which are equal to 11.");
int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31}; int[] array2 = Array.FindAll(array1, element => element <= 11); Response.Write("<br/>There are <b>" + array2.Length + "</b> element in array which are less than 11.");
function is_valid_email($email) { if(preg_match("/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) > 0) return true; else return false; }
function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval) { if(empty($mval)) $mval = date("m"); if(empty($dval)) $dval = date("d"); if(empty($yval)) $yval = date("Y"); $months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December"); $out = "<select name='$mid' id='$mid'>"; foreach($months as $val => $text) if($val == $mval) $out .= "<option value='$val' selected>$text</option>"; else $out .= "<option value='$val'>$text</option>"; $out .= "</select> "; $out .= "<select name='$did' id='$did'>"; for($i = 1; $i <= 31; $i++) if($i == $dval) $out .= "<option value='$i' selected>$i</option>"; else $out .= "<option value='$i'>$i</option>"; $out .= "</select> "; $out .= "<select name='$yid' id='$yid'>"; for($i = date("Y"); $i <= date("Y") + 2; $i++) if($i == $yval) $out.= "<option value='$i' selected>$i</option>"; else $out.= "<option value='$i'>$i</option>"; $out .= "</select>"; return $out; }
var shape; function initialize() { var mapDiv = document.getElementById('map-canvas'); var map = new google.maps.Map(mapDiv, { center: new google.maps.LatLng(24.886436490787712, -70.2685546875), zoom: 4, mapTypeId: google.maps.MapTypeId.ROADMAP }); shape = new google.maps.Polygon({ strokeColor: '#ff0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#ff0000', fillOpacity: 0.35 }); shape.setMap(map); google.maps.event.addListener(map, 'click', addPoint); } function addPoint(e) { var vertices = shape.getPath(); vertices.push(e.latLng); }
#include <iostream> #include <iomanip> #include <time.h> #include <math.h> using namespace std; //vars int GroupOfPeople[50]; //bool v = true; //funcs void Fill (int M); bool CheckDuplicates (int M); double T_Math(int M); int MaxSamples = 50000; int main(){ //srand ( time(NULL) ); srand(1);//for debug; static seed double ModelSum = 0; double Modelavg = 0; cout << setw(15) <<"Num in group" <<setw(17) << "\% Modeled" <<setw(15) << "\%Theoretical" <<setw(23)<< "Theoretical - Modeled"<<endl; for (int M=1; M<50; M++) {//this loop performs checks for groups of size M ModelSum=0; for (int ii=0; ii<MaxSamples; ii++) {//this loop perfroms checks on multiple samples Fill(M);//ensures a new sample each call if (CheckDuplicates(M)){ ModelSum++;}//endif }//end for Modelavg=ModelSum/MaxSamples; //printf("The Theoretical probability of duplicate birthdays in a group of %d is %f\n",M,T_Math(M)); //printf("The Modeled probability of duplicate birthdays in a group of %d is %f\n",M,Modelavg); double TP = T_Math(M); cout<<fixed<<setprecision(2); cout << setw(15) <<(M +1) <<setw(15) << (Modelavg*100)<<"\%" <<setw(15) << (TP*100) << "\%"; cout<<fixed<<setprecision(5) <<setw(15)<< (TP - Modelavg) << endl; }//end for }//end main void Fill(int M){ for (int i=1; i<M+1; i++) {//limited iterations by Max preventing wasted resources GroupOfPeople[i] = ((rand()%365)+1); }//end for }//end fill bool CheckDuplicates (int M){ //nested loop for self comparison, we don't need more memory(M$, take note!) for (int i=0; i< M; i++) { for (int ii=(i+1); ii<M; ii++) { if (GroupOfPeople[i]==GroupOfPeople[ii]) { return true; }//end if }//end for }//end for return false; }//end CheckDuplicates double T_Math(int M){ double a = ( 364 / (static_cast<double> ( 365 ) ) ); double e = ( ( M * ( M - 1 ) ) / (static_cast<double> ( 2 ) ) ); return 1 - pow(a, e); }//end T_Math