int main (int argc, char **argv) { char data[512]; const char *login; const char *pass; const char *time; int i; openlog ("checkpassword-pg", 0, LOG_AUTHPRIV); setlogmask(LOG_UPTO(LOG_INFO)); read_data (data); login = data; i = find_zero (0, data) + 1; pass = data + i; i = find_zero (i, data) + 1; time = data + i; find_zero (i, data); if (argc < 2) { syslog (LOG_ERR, "no program to run"); return 2; } load_config(); argv[0] = argv[1]; return checkpassword_pg (login, pass, time, argv); }
IGL_INLINE void igl::min( const Eigen::SparseMatrix<AType> & A, const int dim, Eigen::PlainObjectBase<DerivedB> & B, Eigen::PlainObjectBase<DerivedI> & I) { const int n = A.cols(); const int m = A.rows(); B.resize(dim==1?n:m); B.setConstant(std::numeric_limits<typename DerivedB::Scalar>::max()); I.resize(dim==1?n:m); for_each(A,[&B,&I,&dim](int i, int j,const typename DerivedB::Scalar v) { if(dim == 2) { std::swap(i,j); } // Coded as if dim == 1, assuming swap for dim == 2 if(v < B(j)) { B(j) = v; I(j) = i; } }); Eigen::VectorXi Z; find_zero(A,dim,Z); for(int j = 0;j<I.size();j++) { if(Z(j) != (dim==1?m:n) && 0 < B(j)) { B(j) = 0; I(j) = Z(j); } } }
int main(int argc, char *argv[]) { int matrix[M][N] = { {3, 2, 1, 0, 4}, {1, 0, 1, 0, 4}, {1, 1, 3, 1, 3}, {1, 1, 2, 3, 2} }; int mask[M][N]; prepare_mask(matrix, mask); find_zero(matrix, mask); printf("BEFORE\n"); print_matrix(matrix); set_mask(matrix, mask); /* {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {1, 0, 3, 0, 3}, {1, 0, 2, 0, 2} */ printf("AFTER\n"); print_matrix(matrix); return 0; }
void Munkres::step4() { /* find an uncovered zero and prime it * if now starred zeros in row goto step 5 * else cover row and uncover colum of starred zero * * once no uncovered exist goto step 6. */ bool done = false; int i = 0; int j = 0; int a; while (!done) { if (find_zero(&i, &j)) { if (!is_covered(i, j)) { prime(i, j); a = starred_in_row(i); if (a == -1) // if no starred zeros { done = true; step5(i, j); } else { uncover_col(a); cover_row(i); } } } else { done = true; step6( min_uncovered()); } } }
fixed TaskMinTarget::search(const fixed tp) { if (!tm.has_targets()) // don't bother if nothing to adjust return tp; force_current = false; /// @todo if search fails, force current const fixed p = find_zero(tp); if (valid(p)) { return p; } else { force_current = true; return find_zero(tp); } }
/** * strscpy - Copy a C-string into a sized buffer * @dest: Where to copy the string to * @src: Where to copy the string from * @count: Size of destination buffer * * Copy the string, or as much of it as fits, into the dest buffer. * The routine returns the number of characters copied (not including * the trailing NUL) or -E2BIG if the destination buffer wasn't big enough. * The behavior is undefined if the string buffers overlap. * The destination buffer is always NUL terminated, unless it's zero-sized. * * Preferred to strlcpy() since the API doesn't require reading memory * from the src string beyond the specified "count" bytes, and since * the return value is easier to error-check than strlcpy()'s. * In addition, the implementation is robust to the string changing out * from underneath it, unlike the current strlcpy() implementation. * * Preferred to strncpy() since it always returns a valid string, and * doesn't unnecessarily force the tail of the destination buffer to be * zeroed. If the zeroing is desired, it's likely cleaner to use strscpy() * with an overflow test, then just memset() the tail of the dest buffer. */ ssize_t strscpy(char *dest, const char *src, size_t count) { const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; size_t max = count; long res = 0; if (count == 0) return -E2BIG; #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS /* * If src is unaligned, don't cross a page boundary, * since we don't know if the next page is mapped. */ if ((long)src & (sizeof(long) - 1)) { size_t limit = PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)); if (limit < max) max = limit; } #else /* If src or dest is unaligned, don't do word-at-a-time. */ if (((long) dest | (long) src) & (sizeof(long) - 1)) max = 0; #endif while (max >= sizeof(unsigned long)) { unsigned long c, data; c = read_word_at_a_time(src+res); if (has_zero(c, &data, &constants)) { data = prep_zero_mask(c, data, &constants); data = create_zero_mask(data); *(unsigned long *)(dest+res) = c & zero_bytemask(data); return res + find_zero(data); } *(unsigned long *)(dest+res) = c; res += sizeof(unsigned long); count -= sizeof(unsigned long); max -= sizeof(unsigned long); } while (count) { char c; c = src[res]; dest[res] = c; if (!c) return res; res++; count--; } /* Hit buffer length without finding a NUL; force NUL-termination. */ if (res) dest[res-1] = '\0'; return -E2BIG; }
fixed TaskSolveTravelled::search(const fixed ce) { #ifdef SOLVE_ZERO return find_zero(ce); #else return find_min(ce); #endif }
/* * Do a strncpy, return length of string without final '\0'. * 'count' is the user-supplied count (return 'count' if we * hit it), 'max' is the address space maximum (and we return * -EFAULT if we hit it). */ static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max) { static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; long res = 0; /* * Truncate 'max' to the user-specified limit, so that * we only have one limit we need to check in the loop */ if (max > count) max = count; if (IS_UNALIGNED(src, dst)) goto byte_at_a_time; while (max >= sizeof(unsigned long)) { unsigned long c, data; /* Fall back to byte-at-a-time if we get a page fault */ if (unlikely(__get_user(c,(unsigned long __user *)(src+res)))) break; *(unsigned long *)(dst+res) = c; if (has_zero(c, &data, &constants)) { data = prep_zero_mask(c, data, &constants); data = create_zero_mask(data); return res + find_zero(data); } res += sizeof(unsigned long); max -= sizeof(unsigned long); } byte_at_a_time: while (max) { char c; if (unlikely(__get_user(c,src+res))) return -EFAULT; dst[res] = c; if (!c) return res; res++; max--; } /* * Uhhuh. We hit 'max'. But was that the user-specified maximum * too? If so, that's ok - we got as much as the user asked for. */ if (res >= count) return res; /* * Nope: we hit the address space limit, and we still had more * characters the caller would have wanted. That's an EFAULT. */ return -EFAULT; }
double IsolineCrossingFinder::solve() { const auto sol = find_zero(Half(xmax + xmin)); if (valid(sol)) { return sol; } else { return -1; } }
/* * Do a strnlen, return length of string *with* final '\0'. * 'count' is the user-supplied count, while 'max' is the * address space maximum. * * Return 0 for exceptions (which includes hitting the address * space maximum), or 'count+1' if hitting the user-supplied * maximum count. * * NOTE! We can sometimes overshoot the user-supplied maximum * if it fits in a aligned 'long'. The caller needs to check * the return value against "> max". */ static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max) { const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; long align, res = 0; unsigned long c; /* * Truncate 'max' to the user-specified limit, so that * we only have one limit we need to check in the loop */ if (max > count) max = count; /* * Do everything aligned. But that means that we * need to also expand the maximum.. */ align = (sizeof(long) - 1) & (unsigned long)src; src -= align; max += align; if (unlikely(__get_user(c,(unsigned long __user *)src))) return 0; c |= aligned_byte_mask(align); for (;;) { unsigned long data; if (has_zero(c, &data, &constants)) { data = prep_zero_mask(c, data, &constants); data = create_zero_mask(data); return res + find_zero(data) + 1 - align; } res += sizeof(unsigned long); if (unlikely(max < sizeof(unsigned long))) break; max -= sizeof(unsigned long); if (unlikely(__get_user(c,(unsigned long __user *)(src+res)))) return 0; } res -= align; /* * Uhhuh. We hit 'max'. But was that the user-specified maximum * too? If so, return the marker for "too long". */ if (res >= count) return count+1; /* * Nope: we hit the address space limit, and we still had more * characters the caller would have wanted. That's 0. */ return 0; }
fixed TaskBestMc::search(const fixed mc) { // only search if mc zero is valid f(fixed(0)); if (valid(fixed(0))) { fixed a = find_zero(mc); if (valid(a)) return a; } return mc; }
bool TaskBestMc::search(const fixed mc, fixed &result) { // only search if mc zero is valid f(fixed(0)); if (valid(fixed(0))) { fixed a = find_zero(mc); if (valid(a)) { result = a; return true; } } result = mc; return false; }
void main() { int l,t; clrscr(); b=generate(); draw_screen(); for(l=0;l<=100;l++) { b=find_zero(); t=getkey(); if(t==1) exit(0); if(t==72) { if(b<12) { t=a[b]; a[b]=a[b+4]; a[b+4]=t; b=find_zero(); draw_screen(); } } if(t==80)//down { if(b>3) { t=a[b-4]; a[b-4]=a[b]; a[b]=t; b=find_zero(); draw_screen(); //drawscreen(); } } if(t==77)//right { if(b!=0 && b!=4 && b!=8 && b!=12) { t=a[b-1]; a[b-1]=a[b]; a[b]=t; b=find_zero(); draw_screen(); //awscreen(); } } if(t==75)//left { if(b!=3 && b!=7 && b!=11 && b!=15) { t=a[b+1]; a[b+1]=a[b]; a[b]=t; b=find_zero(); draw_screen(); //drawscreen(); } } e=win(); if(e==1) { gotoxy(25,28); printf("you won"); } if(l==100) { gotoxy(25,28); printf("Moves over"); break; } } getch(); }
double TaskGlideRequired::search(const double S) { auto a = find_zero(S); return a/res.v_opt; }
fixed TaskGlideRequired::search(const fixed S) { auto a = find_zero(S); return a/res.v_opt; }
fixed TaskGlideRequired::search(const fixed S) { fixed a = find_zero(S); return a/res.VOpt; }