Parity Sequence
Your code should output the numbers from 1 to 100, inclusive. When only the even-indexed characters of your code are run (in other words, the odd-indexed characters are removed), it should output the even numbers from 1 to 100, inclusive. When only the odd-indexed characters of your code are run, it should output the odd numbers from 1 to 100, inclusive.
Judge
(async function*(context: Context): Challenge { yield (await context.run()).assertEquals("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100").setName("Full source output"); // Method for splitting string into Unicode characters sourced from https://stackoverflow.com/a/73802453 const sourceChars = Array.from(new Intl.Segmenter("en", {granularity: 'grapheme'}).segment(context.code), ({segment}) => segment); yield (await context.runCode(sourceChars.filter((b,idx) => idx%2).join(""))).assertEquals("1\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99").setName("Odd-indexed bytes output"); yield (await context.runCode(sourceChars.filter((b,idx) => !(idx%2)).join(""))).assertEquals("2\n4\n6\n8\n10\n12\n14\n16\n18\n20\n22\n24\n26\n28\n30\n32\n34\n36\n38\n40\n42\n44\n46\n48\n50\n52\n54\n56\n58\n60\n62\n64\n66\n68\n70\n72\n74\n76\n78\n80\n82\n84\n86\n88\n90\n92\n94\n96\n98\n100").setName("Even-indexed bytes output"); return context.noFailures(); })
Example Code
``;; for(let i=1;i<101;i++)console.log(i); ``;; `f_o_r_(_l_e_t_ _i_=_2_;_i_<_1_0_1_;_i_+_=_2_)_c_o_n_s_o_l_e_._l_o_g_(_i_)_;`;; `f_o_r_(_l_e_t_ _i_=_1_;_i_<_1_0_1_;_i_+_=_2_)_c_o_n_s_o_l_e_._l_o_g_(_i_)_;`;;