Advertisement
sluchaynayakotya

gus 1

Jun 30th, 2020
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // inits list of [1..n] w\o random number in it (ans)
  2. const n = 42;
  3. let a;
  4. {
  5.   const ans = Math.random()*n+1|0;
  6.   let flg = false;
  7.   a = Array(n).fill().map((_,i) => (flg|=(i+1)===ans)?i+2:i+1);
  8.   console.log('expected', ans);
  9. }
  10. // finds exculed number
  11. function find_exculed_number(a, n) {
  12.   let buf = a[0];
  13.   for (let i=1; i<=n; ++i) if ((a[i]||n)-buf>1) return buf+1; else buf=a[i];
  14.   throw Error();
  15. }
  16. // profit
  17. console.log('result', find_exculed_number(a, n));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement