Postagens

Mostrando postagens de outubro, 2022

The Weekly Challenge: Week 186

 The Weekly Challenge is a site that delivers two challenges each week. This was originally for just Perl and Raku (Raku is Perl 6), but in week 18 someone submitted a Python solution, and now you can submit any language. Note that solutions for week 186 are open until 10/16/2022. You can contribute by solving and putting the solution on  GitHub . Now I will show you my solutions. Task 1  Task 1 is as follows: You are given two list @a and @b of same size. Create a subroutine sub zip(@a, @b)  that merge the two list as shown in the example below. Example Input:  @a = qw/1 2 3/; @b = qw/a b c/; Output: zip(@a, @b) should return qw/1 a 2 b 3 c/;         zip(@b, @a) should return qw/a 1 b 2 c 3/; Using list comprehensions in Python makes this quite easy: def z(a, b): # note the different name to avoid recursion     return [j for i in zip(a, b) for j in i] JavaScript requires map, but if the arrays are not the same size, array b will be ignored, or if a is larger, the indices without b v