fork download
  1. const questions = [
  2. {
  3. question: "Which method is used to add a new element at the end of an array?",
  4. options: ["push()", "shift()", "unshift()", "add()"],
  5. answer: "push()"
  6. },
  7. {
  8. question: "What does the typeof operator return for the null value?",
  9. options: ["undefined", "null", "object", "NAN"],
  10. answer: "object"
  11. },
  12. {
  13. question: "Which statement is used to skip the current iteration of a loop ?",
  14. options: ["continue", "break", "resume", "exit"],
  15. answer: "continue"
  16. },
  17. {
  18. question: "Which method is used to select the HTML element by their class in JavaScript ?",
  19. options: ["document.getElementsByClassName", "document.getElementsbyClassName", "document.getelementsByClassName", "document.getElementByClassName"],
  20. answer: "document.getElementsByClassName"
  21. }
  22. ]
  23.  
  24. const quizContainer = document.querySelector('.quiz-container');
  25. const timeLeft = document.querySelector('.time-left');
  26. const heading = document.querySelector('.heading');
  27. const question = document.querySelector('.question');
  28. const options = document.querySelector('.options');
  29. const resultContainer = document.querySelector('.quiz-container');
  30. const score = document.querySelector('.score');
  31. const correctAnswersContent = document.querySelector('.correct-answers-content');
  32. const allAnswers = document.querySelector('.correct-answers')
  33. const correctAnswers = [ "push()","object", "continue","document.getElementsByClassName"];
  34. const userCorrectAnswers = []
  35. let currentIndex = 0
  36.  
  37. function displayQuestion(){
  38. const currentQuestion = questions[currentIndex];
  39. question.innerHTML = currentQuestion.question;
  40. options.innerHTML = "";
  41. currentQuestion.options.forEach((option) => {
  42. const button = document.createElement('button');
  43. button.innerHTML = option;
  44. button.onclick = () => checkAnswer(option)
  45. options.appendChild(button);
  46. })
  47. }
  48. function checkAnswer(userSelectedOption){
  49. const currentQuestion = questions[currentIndex];
  50. if(userSelectedOption === currentQuestion.answer){
  51. userCorrectAnswers.push(userSelectedOption)
  52. }
  53. if(currentIndex < questions.length){
  54. currentIndex++;
  55. displayQuestion()
  56. }
  57. else{
  58. displayResult()
  59. }
  60. }
  61.  
  62. function displayResult(){
  63. question.innerHTML = ""
  64. options.innerHTML = ""
  65. score.innerHTML = `You scored ${userCorrectAnswers.length} out of 4`;
  66. resultContainer.innerHTML = score.innerHTML
  67. }
  68. displayQuestion() for this why i am getting this error quiz.js:39 Uncaught TypeError: Cannot read properties of undefined (reading 'question')
  69. at displayQuestion (quiz.js:39:42)
  70. at checkAnswer (quiz.js:55:9)
  71. at button.onclick (quiz.js:44:32)
  72. /* package whatever; // don't place package name! */
  73. /*
  74.  
  75.   This source code accompanies the article, "Using The Golay Error Detection And
  76.   Correction Code", by Hank Wallace. This program demonstrates use of the Golay
  77.   code.
  78.   Usage: G DATA Encode/Correct/Verify/Test
  79.   where DATA is the data to be encoded, codeword to be corrected,
  80.   or codeword to be checked for errors. DATA is hexadecimal.
  81.   Examples:
  82.   G 555 E encodes information value 555 and prints a codeword
  83.   G ABC123 C corrects codeword ABC123
  84.   G ABC123 V checks codeword ABC123 for errors
  85.   G ABC123 T tests routines, ABC123 is a dummy parameter
  86.   This program may be freely incorporated into your programs as needed. It
  87.   compiles under Borland's Turbo C 2.0. No warranty of any kind is granted.
  88.   */
  89. #include "stdio.h"
  90. #include "conio.h"
  91. #define POLY 0xAE3 /* or use the other polynomial, 0xC75 */
  92.  
  93. /* ====================================================== */
  94.  
  95. unsigned long golay(unsigned long cw)
  96. /* This function calculates [23,12] Golay codewords.
  97.   The format of the returned longint is
  98.   [checkbits(11),data(12)]. */
  99. {
  100. int i;
  101. unsigned long c;
  102. cw&=0xfffl;
  103. c=cw; /* save original codeword */
  104. for (i=1; i<=12; i++) /* examine each data bit */
  105. {
  106. if (cw & 1) /* test data bit */
  107. cw^=POLY; /* XOR polynomial */
  108. cw>>=1; /* shift intermediate result */
  109. }
  110. return((cw<<12)|c); /* assemble codeword */
  111. }
  112.  
  113. /* ====================================================== */
  114.  
  115. int parity(unsigned long cw)
  116. /* This function checks the overall parity of codeword cw.
  117.   If parity is even, 0 is returned, else 1. */
  118. {
  119. unsigned char p;
  120.  
  121. /* XOR the bytes of the codeword */
  122. p=*(unsigned char*)&cw;
  123. p^=*((unsigned char*)&cw+1);
  124. p^=*((unsigned char*)&cw+2);
  125.  
  126. /* XOR the halves of the intermediate result */
  127. p=p ^ (p>>4);
  128. p=p ^ (p>>2);
  129. p=p ^ (p>>1);
  130.  
  131. /* return the parity result */
  132. return(p & 1);
  133. }
  134.  
  135. /* ====================================================== */
  136.  
  137. unsigned long syndrome(unsigned long cw)
  138. /* This function calculates and returns the syndrome
  139.   of a [23,12] Golay codeword. */
  140. {
  141. int i;
  142. cw&=0x7fffffl;
  143. for (i=1; i<=12; i++) /* examine each data bit */
  144. {
  145. if (cw & 1) /* test data bit */
  146. cw^=POLY; /* XOR polynomial */
  147. cw>>=1; /* shift intermediate result */
  148. }
  149. return(cw<<12); /* value pairs with upper bits of cw */
  150. }
  151.  
  152. /* ====================================================== */
  153.  
  154. int weight(unsigned long cw)
  155. /* This function calculates the weight of
  156.   23 bit codeword cw. */
  157. {
  158. int bits,k;
  159.  
  160. /* nibble weight table */
  161. const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
  162.  
  163. bits=0; /* bit counter */
  164. k=0;
  165. /* do all bits, six nibbles max */
  166. while ((k<6) && (cw))
  167. {
  168. bits=bits+wgt[cw & 0xf];
  169. cw>>=4;
  170. k++;
  171. }
  172.  
  173. return(bits);
  174. }
  175.  
  176. /* ====================================================== */
  177.  
  178. unsigned long rotate_left(unsigned long cw, int n)
  179. /* This function rotates 23 bit codeword cw left by n bits. */
  180. {
  181. int i;
  182.  
  183. if (n != 0)
  184. {
  185. for (i=1; i<=n; i++)
  186. {
  187. if ((cw & 0x400000l) != 0)
  188. cw=(cw << 1) | 1;
  189. else
  190. cw<<=1;
  191. }
  192. }
  193.  
  194. return(cw & 0x7fffffl);
  195. }
  196.  
  197. /* ====================================================== */
  198.  
  199. unsigned long rotate_right(unsigned long cw, int n)
  200. /* This function rotates 23 bit codeword cw right by n bits. */
  201. {
  202. int i;
  203.  
  204. if (n != 0)
  205. {
  206. for (i=1; i<=n; i++)
  207. {
  208. if ((cw & 1) != 0)
  209. cw=(cw >> 1) | 0x400000l;
  210. else
  211. cw>>=1;
  212. }
  213. }
  214.  
  215. return(cw & 0x7fffffl);
  216. }
  217.  
  218. /* ====================================================== */
  219.  
  220. unsigned long correct(unsigned long cw, int *errs)
  221. /* This function corrects Golay [23,12] codeword cw, returning the
  222.   corrected codeword. This function will produce the corrected codeword
  223.   for three or fewer errors. It will produce some other valid Golay
  224.   codeword for four or more errors, possibly not the intended
  225.   one. *errs is set to the number of bit errors corrected. */
  226. {
  227. unsigned char
  228. w; /* current syndrome limit weight, 2 or 3 */
  229. unsigned long
  230. mask; /* mask for bit flipping */
  231. int
  232. i,j; /* index */
  233. unsigned long
  234. s, /* calculated syndrome */
  235. cwsaver; /* saves initial value of cw */
  236.  
  237. cwsaver=cw; /* save */
  238. *errs=0;
  239. w=3; /* initial syndrome weight threshold */
  240. j=-1; /* -1 = no trial bit flipping on first pass */
  241. mask=1;
  242. while (j<23) /* flip each trial bit */
  243. {
  244. if (j != -1) /* toggle a trial bit */
  245. {
  246. if (j>0) /* restore last trial bit */
  247. {
  248. cw=cwsaver ^ mask;
  249. mask+=mask; /* point to next bit */
  250. }
  251. cw=cwsaver ^ mask; /* flip next trial bit */
  252. w=2; /* lower the threshold while bit diddling */
  253. }
  254.  
  255. s=syndrome(cw); /* look for errors */
  256. if (s) /* errors exist */
  257. {
  258. for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
  259. {
  260. if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
  261. {
  262. cw=cw ^ s; /* remove errors */
  263. cw=rotate_right(cw,i); /* unrotate data */
  264. return(s=cw);
  265. }
  266. else
  267. {
  268. cw=rotate_left(cw,1); /* rotate to next pattern */
  269. s=syndrome(cw); /* calc new syndrome */
  270. }
  271. }
  272. j++; /* toggle next trial bit */
  273. }
  274. else
  275. return(cw); /* return corrected codeword */
  276. }
  277.  
  278. return(cwsaver); /* return original if no corrections */
  279. } /* correct */
  280.  
  281. /* ====================================================== */
  282.  
  283. int decode(int correct_mode, int *errs, unsigned long *cw)
  284. /* This function decodes codeword *cw in one of two modes. If correct_mode
  285.   is nonzero, error correction is attempted, with *errs set to the number of
  286.   bits corrected, and returning 0 if no errors exist, or 1 if parity errors
  287.   exist. If correct_mode is zero, error detection is performed on *cw,
  288.   returning 0 if no errors exist, 1 if an overall parity error exists, and
  289.   2 if a codeword error exists. */
  290. {
  291. unsigned long parity_bit;
  292.  
  293. if (correct_mode) /* correct errors */
  294. {
  295. parity_bit=*cw & 0x800000l; /* save parity bit */
  296. *cw&=~0x800000l; /* remove parity bit for correction */
  297.  
  298. *cw=correct(*cw, errs); /* correct up to three bits */
  299. *cw|=parity_bit; /* restore parity bit */
  300.  
  301. /* check for 4 bit errors */
  302. if (parity(*cw)) /* odd parity is an error */
  303. return(1);
  304. return(0); /* no errors */
  305. }
  306. else /* detect errors only */
  307. {
  308. *errs=0;
  309. if (parity(*cw)) /* odd parity is an error */
  310. {
  311. *errs=1;
  312. return(1);
  313. }
  314. if (syndrome(*cw))
  315. {
  316. *errs=1;
  317. return(2);
  318. }
  319. else
  320. return(0); /* no errors */
  321. }
  322. } /* decode */
  323.  
  324. /* ====================================================== */
  325.  
  326. void golay_test(void)
  327. /* This function tests the Golay routines for detection and correction
  328.   of various patterns of error_limit bit errors. The error_mask cycles
  329.   over all possible values, and error_limit selects the maximum number
  330.   of induced errors. */
  331. {
  332. unsigned long
  333. error_mask, /* bitwise mask for inducing errors */
  334. trashed_codeword, /* the codeword for trial correction */
  335. virgin_codeword; /* the original codeword without errors */
  336. unsigned char
  337. pass=1, /* assume test passes */
  338. error_limit=3; /* select number of induced bit errors here */
  339. int
  340. error_count; /* receives number of errors corrected */
  341.  
  342. virgin_codeword=golay(0x555); /* make a test codeword */
  343. if (parity(virgin_codeword))
  344. virgin_codeword^=0x800000l;
  345. for (error_mask=0; error_mask<0x800000l; error_mask++)
  346. {
  347. /* filter the mask for the selected number of bit errors */
  348. if (weight(error_mask) <= error_limit) /* you can make this faster! */
  349. {
  350. trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
  351.  
  352. decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
  353.  
  354. if (trashed_codeword ^ virgin_codeword)
  355. {
  356. printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
  357. weight(error_mask),error_mask);
  358. pass=0;
  359. }
  360.  
  361. if (kbhit()) /* look for user input */
  362. {
  363. if (getch() == 27) return; /* escape exits */
  364.  
  365. /* other key prints status */
  366. printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
  367. }
  368. }
  369. }
  370. printf("Golay test %s!\n",pass?"PASSED":"FAILED");
  371. }
  372.  
  373. /* ====================================================== */
  374.  
  375. void main(int argument_count, char *argument[])
  376. {
  377. int i,j;
  378. unsigned long l,g;
  379. const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
  380. " where DATA is the data to be encoded, codeword to be corrected,\n"
  381. " or codeword to be checked for errors. DATA is hexadecimal.\n\n"
  382. "Examples:\n\n"
  383. " G 555 E encodes information value 555 and prints a codeword\n"
  384. " G ABC123 C corrects codeword ABC123\n"
  385. " G ABC123 V checks codeword ABC123 for errors\n"
  386. " G ABC123 T tests routines, ABC123 is a dummy parameter\n\n";
  387.  
  388. if (argument_count != 3)
  389. {
  390. printf(errmsg);
  391. exit(0);
  392. }
  393.  
  394. if (sscanf(argument[1],"%lx",&l) != 1)
  395. {
  396. printf(errmsg);
  397. exit(0);
  398. }
  399.  
  400. switch (toupper(*argument[2]))
  401. {
  402. case 'E': /* encode */
  403. l&=0xfff;
  404. l=golay(l);
  405. if (parity(l)) l^=0x800000l;
  406. printf("Codeword = %lX\n",l);
  407. break;
  408.  
  409. case 'V': /* verify */
  410. if (decode(0,&i,&l))
  411. printf("Codeword %lX is not a Golay codeword.\n",l);
  412. else
  413. printf("Codeword %lX is a Golay codeword.\n",l);
  414. break;
  415.  
  416. case 'C': /* correct */
  417. g=l; /* save initial codeword */
  418. j=decode(1,&i,&l);
  419. if ((j) && (i))
  420. printf("Codeword %lX had %d bits corrected,\n"
  421. "resulting in codeword %lX with a parity error.\n",g,i,l);
  422. else
  423. if ((j == 0) && (i))
  424. printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
  425. else
  426. if ((j) && (i == 0))
  427. printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
  428. else
  429. if ((j == 0) && (i == 0))
  430. printf("Codeword %lX does not require correction.\n",g);
  431. break;
  432.  
  433. case 'T': /* test */
  434. printf("Press SPACE for status, ESC to exit test...\n");
  435. golay_test();
  436. break;
  437.  
  438. default:
  439. printf(errmsg);
  440. exit(0);
  441. }
  442. }
  443.  
  444. /* end of G.C */
  445.  
  446.  
  447. import java.util.*;
  448. import java.lang.*;
  449. import java.io.*;
  450.  
  451. /* Name of the class has to be "Main" only if the class is public. */
  452. class Ideone
  453. {
  454. public static void main (String[] args) throws java.lang.Exception
  455. {
  456. // your code goes here
  457. }
  458. }
Success #stdin #stdout 0.04s 25692KB
stdin
Standard input is empty
stdout
const questions = [
    {
        question: "Which method is used to add a new element at the end of an array?",
        options: ["push()", "shift()", "unshift()", "add()"],
        answer: "push()"
      },
    {
        question: "What does the typeof operator return for the null value?",
        options: ["undefined", "null", "object", "NAN"],
        answer: "object"
      },
    {
        question: "Which statement is used to skip the current iteration of a loop ?",
        options: ["continue", "break", "resume", "exit"],
        answer: "continue"
      },
    {
          question: "Which method is used to select the HTML element by their class in JavaScript ?",
          options: ["document.getElementsByClassName", "document.getElementsbyClassName", "document.getelementsByClassName", "document.getElementByClassName"],
          answer: "document.getElementsByClassName"
      }
]

const quizContainer =  document.querySelector('.quiz-container');
const timeLeft = document.querySelector('.time-left');
const heading = document.querySelector('.heading');
const question = document.querySelector('.question');
const options = document.querySelector('.options');
const resultContainer = document.querySelector('.quiz-container');
const score = document.querySelector('.score');
const correctAnswersContent = document.querySelector('.correct-answers-content');
const allAnswers = document.querySelector('.correct-answers')
const correctAnswers = [ "push()","object", "continue","document.getElementsByClassName"];
const userCorrectAnswers = []
let currentIndex = 0

function displayQuestion(){
    const currentQuestion = questions[currentIndex];
    question.innerHTML = currentQuestion.question;
    options.innerHTML = "";
    currentQuestion.options.forEach((option) => {
        const button = document.createElement('button');
        button.innerHTML = option; 
        button.onclick = () => checkAnswer(option)
        options.appendChild(button);
    })
}
function checkAnswer(userSelectedOption){
    const currentQuestion = questions[currentIndex];
    if(userSelectedOption === currentQuestion.answer){
        userCorrectAnswers.push(userSelectedOption)
    }
    if(currentIndex < questions.length){
        currentIndex++;
        displayQuestion()
    }
    else{
        displayResult()
    }
}

function displayResult(){
    question.innerHTML = ""
    options.innerHTML = ""
    score.innerHTML = `You scored ${userCorrectAnswers.length} out of 4`;
    resultContainer.innerHTML = score.innerHTML
}
displayQuestion() for this why i am getting this error quiz.js:39 Uncaught TypeError: Cannot read properties of undefined (reading 'question')
    at displayQuestion (quiz.js:39:42)
    at checkAnswer (quiz.js:55:9)
    at button.onclick (quiz.js:44:32)
    /* package whatever; // don't place package name! */
/*
    
    This source code accompanies the article, "Using The Golay Error Detection And
    Correction Code", by Hank Wallace. This program demonstrates use of the Golay
    code.
      Usage: G DATA Encode/Correct/Verify/Test
        where DATA is the data to be encoded, codeword to be corrected,
        or codeword to be checked for errors. DATA is hexadecimal.
      Examples:
        G 555 E      encodes information value 555 and prints a codeword
        G ABC123 C   corrects codeword ABC123
        G ABC123 V   checks codeword ABC123 for errors
        G ABC123 T   tests routines, ABC123 is a dummy parameter
    This program may be freely incorporated into your programs as needed. It
    compiles under Borland's Turbo C 2.0. No warranty of any kind is granted.
    */
    #include "stdio.h"
    #include "conio.h"
    #define POLY  0xAE3  /* or use the other polynomial, 0xC75 */
    
    /* ====================================================== */
    
    unsigned long golay(unsigned long cw)
    /* This function calculates [23,12] Golay codewords.
      The format of the returned longint is
      [checkbits(11),data(12)]. */
    {
      int i;
      unsigned long c;
      cw&=0xfffl;
      c=cw; /* save original codeword */
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return((cw<<12)|c);    /* assemble codeword */
    }
    
    /* ====================================================== */
    
    int parity(unsigned long cw)
    /* This function checks the overall parity of codeword cw.
      If parity is even, 0 is returned, else 1. */
    {
      unsigned char p;
    
      /* XOR the bytes of the codeword */
      p=*(unsigned char*)&cw;
      p^=*((unsigned char*)&cw+1);
      p^=*((unsigned char*)&cw+2);
    
      /* XOR the halves of the intermediate result */
      p=p ^ (p>>4);
      p=p ^ (p>>2);
      p=p ^ (p>>1);
    
      /* return the parity result */
      return(p & 1);
    }
    
    /* ====================================================== */
    
    unsigned long syndrome(unsigned long cw)
    /* This function calculates and returns the syndrome
      of a [23,12] Golay codeword. */
    {
      int i;
      cw&=0x7fffffl;
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return(cw<<12);        /* value pairs with upper bits of cw */
    }
    
    /* ====================================================== */
    
    int weight(unsigned long cw)
    /* This function calculates the weight of
      23 bit codeword cw. */
    {
      int bits,k;
    
      /* nibble weight table */
      const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
    
      bits=0; /* bit counter */
      k=0;
      /* do all bits, six nibbles max */
      while ((k<6) && (cw))
        {
          bits=bits+wgt[cw & 0xf];
          cw>>=4;
          k++;
        }
    
      return(bits);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_left(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw left by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 0x400000l) != 0)
                cw=(cw << 1) | 1;
              else
                cw<<=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_right(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw right by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 1) != 0)
                cw=(cw >> 1) | 0x400000l;
              else
                cw>>=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long correct(unsigned long cw, int *errs)
    /* This function corrects Golay [23,12] codeword cw, returning the
      corrected codeword. This function will produce the corrected codeword
      for three or fewer errors. It will produce some other valid Golay
      codeword for four or more errors, possibly not the intended
      one. *errs is set to the number of bit errors corrected. */
    {
      unsigned char
        w;                /* current syndrome limit weight, 2 or 3 */
      unsigned long
        mask;             /* mask for bit flipping */
      int
        i,j;              /* index */
      unsigned long
        s,                /* calculated syndrome */
        cwsaver;          /* saves initial value of cw */
    
      cwsaver=cw;         /* save */
      *errs=0;
      w=3;                /* initial syndrome weight threshold */
      j=-1;               /* -1 = no trial bit flipping on first pass */
      mask=1;
      while (j<23) /* flip each trial bit */
        {
          if (j != -1) /* toggle a trial bit */
            {
              if (j>0) /* restore last trial bit */
                {
                  cw=cwsaver ^ mask;
                  mask+=mask; /* point to next bit */
                }
              cw=cwsaver ^ mask; /* flip next trial bit */
              w=2; /* lower the threshold while bit diddling */
            }
    
          s=syndrome(cw); /* look for errors */
          if (s) /* errors exist */
            {
              for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
                {
                  if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
                    {
                      cw=cw ^ s;              /* remove errors */
                      cw=rotate_right(cw,i);  /* unrotate data */
                      return(s=cw);
                    }
                  else
                    {
                      cw=rotate_left(cw,1);   /* rotate to next pattern */
                      s=syndrome(cw);         /* calc new syndrome */
                    }
                }
              j++; /* toggle next trial bit */
            }
          else
            return(cw); /* return corrected codeword */
        }
    
      return(cwsaver); /* return original if no corrections */
    } /* correct */
    
    /* ====================================================== */
    
    int decode(int correct_mode, int *errs, unsigned long *cw)
    /* This function decodes codeword *cw in one of two modes. If correct_mode
      is nonzero, error correction is attempted, with *errs set to the number of
      bits corrected, and returning 0 if no errors exist, or 1 if parity errors
      exist. If correct_mode is zero, error detection is performed on *cw,
      returning 0 if no errors exist, 1 if an overall parity error exists, and
      2 if a codeword error exists. */
    {
      unsigned long parity_bit;
    
      if (correct_mode)               /* correct errors */
        {
          parity_bit=*cw & 0x800000l; /* save parity bit */
          *cw&=~0x800000l;            /* remove parity bit for correction */
    
          *cw=correct(*cw, errs);     /* correct up to three bits */
          *cw|=parity_bit;            /* restore parity bit */
    
          /* check for 4 bit errors */
          if (parity(*cw))            /* odd parity is an error */
            return(1);
          return(0); /* no errors */
        }
      else /* detect errors only */
        {
          *errs=0;
          if (parity(*cw)) /* odd parity is an error */
            {
              *errs=1;
              return(1);
            }
          if (syndrome(*cw))
            {
              *errs=1;
              return(2);
            }
          else
            return(0); /* no errors */
        }
    } /* decode */
    
    /* ====================================================== */
    
    void golay_test(void)
    /* This function tests the Golay routines for detection and correction
      of various patterns of error_limit bit errors. The error_mask cycles
      over all possible values, and error_limit selects the maximum number
      of induced errors. */
    {
      unsigned long
        error_mask,         /* bitwise mask for inducing errors */
        trashed_codeword,   /* the codeword for trial correction */
        virgin_codeword;    /* the original codeword without errors */
      unsigned char
        pass=1,             /* assume test passes */
        error_limit=3;      /* select number of induced bit errors here */
      int
        error_count;        /* receives number of errors corrected */
    
      virgin_codeword=golay(0x555); /* make a test codeword */
      if (parity(virgin_codeword))
        virgin_codeword^=0x800000l;
      for (error_mask=0; error_mask<0x800000l; error_mask++)
        {
          /* filter the mask for the selected number of bit errors */
          if (weight(error_mask) <= error_limit) /* you can make this faster! */
            {
              trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
    
              decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
    
              if (trashed_codeword ^ virgin_codeword)
                {
                  printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
                    weight(error_mask),error_mask);
                  pass=0;
                }
    
              if (kbhit()) /* look for user input */
                {
                  if (getch() == 27) return; /* escape exits */
    
                  /* other key prints status */
                  printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
                }
            }
        }
      printf("Golay test %s!\n",pass?"PASSED":"FAILED");
    }
    
    /* ====================================================== */
    
    void main(int argument_count, char *argument[])
    {
      int i,j;
      unsigned long l,g;
      const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
                 "  where DATA is the data to be encoded, codeword to be corrected,\n"
                 "  or codeword to be checked for errors. DATA is hexadecimal.\n\n"
                 "Examples:\n\n"
                 "  G 555 E      encodes information value 555 and prints a codeword\n"
                 "  G ABC123 C   corrects codeword ABC123\n"
                 "  G ABC123 V   checks codeword ABC123 for errors\n"
                 "  G ABC123 T   tests routines, ABC123 is a dummy parameter\n\n";
    
      if (argument_count != 3)
        {
          printf(errmsg);
          exit(0);
        }
    
      if (sscanf(argument[1],"%lx",&l) != 1)
        {
          printf(errmsg);
          exit(0);
        }
    
      switch (toupper(*argument[2]))
        {
          case 'E': /* encode */
            l&=0xfff;
            l=golay(l);
            if (parity(l)) l^=0x800000l;
            printf("Codeword = %lX\n",l);
            break;
    
          case 'V': /* verify */
            if (decode(0,&i,&l))
              printf("Codeword %lX is not a Golay codeword.\n",l);
            else
              printf("Codeword %lX is a Golay codeword.\n",l);
            break;
    
          case 'C': /* correct */
            g=l; /* save initial codeword */
            j=decode(1,&i,&l);
            if ((j) && (i))
              printf("Codeword %lX had %d bits corrected,\n"
                     "resulting in codeword %lX with a parity error.\n",g,i,l);
            else
              if ((j == 0) && (i))
                printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
              else
                if ((j) && (i == 0))
                  printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
                else
                  if ((j == 0) && (i == 0))
                    printf("Codeword %lX does not require correction.\n",g);
            break;
    
          case 'T': /* test */
            printf("Press SPACE for status, ESC to exit test...\n");
            golay_test();
            break;
    
          default:
            printf(errmsg);
            exit(0);
        }
    }
    
    /* end of G.C */


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
	}
}