My Coding Quiz #40 馃懆鈥嶐煉火煕狅笍馃З
Welcome to the new installment of my series of Coding Quizzes, in which you will be able to test your knowledge and skills about programming and software development in a simple and fun way. If you want to learn more about it visit my blog here on Hive and the first post where I introduced it.
Without further ado, here's the riddle...

By @eniolw
What's your choice? Can you figure out any feedback to the developers from this?
Solution to the previous quiz: a1,b2,c3,d4. First of all, we define the string files
with the hardcoded value 'abcd'
and the range ranks
that goes from 1 to 5 (6 is not counted, since the limit of the range is exclusive).
Next, we create a sq
object using the built-in zip
function. This function allows you to loop over two or more iterables simultaneously and make a new iterable of tuples with the matching elements of each iterable. We can see how this works in the following table:
Index | 0 | 1 | 2 | 3 |
files | a | b | c | d |
ranks | 1 | 2 | 3 | 4 |
zip | a1 | b2 | c3 | d4 |
Interestingly, it seems that there is no mathematical function that describes this operation, since the Catersian product of sets differs in that it creates all possible pair of elements. According to this page, the diagonal product is a close approximation to the zip
function.
Regardless, this function is very useful in programming and has many applications. In this case, I used it to combine the files
and ranks
to create sq
, which stands for squares. If you pay attention, these are names of squares on a chess board: a1, b2, c3 and d4.
Now, you may have also noticed that ranks
had elements from 1 to 5, so what happened to 5? It was ignored because zip
only pairs or combines iterables that have the same length. The moment the size of an iterable is longer than the others, zip
will stop and the resulting iterable will have the same length as the shortest given iterable.
Finally, the iterable is executed using the well-known join
function, obtaining a convenient string labels
.
If you want to blog about computer science and programming content, I invite you to join Hive and participate in its communities, such as STEM-social, Develop Spanish, Programming & Dev
Mi Quiz de Programaci贸n #40 馃懆鈥嶐煉火煕狅笍馃З
Bienvenido a mi nueva serie de Quizzes de Programaci贸n, en la cual podr谩s poner a prueba tus conocimientos y habilidades sobre programaci贸n y desarrollo de software de una manera sencilla y divertida. Si quieres aprender m谩s sobre ella visita mi blog aqu铆 en Hive y el primer post donde la present茅.
Sin m谩s pre谩mbulos, he aqu铆 el acertijo...

Por @eniolw
驴Cu谩l es tu elecci贸n? 驴Puedes deducir alg煤n feedback a los desarrolladores a partir de esto?
Soluci贸n al quiz anterior: a1,b2,c3,d4. En primer lugar, definimos la cadena files
con el valor codificado 'abcd'
y el rango ranks
que va del 1 al 5 (6 es no contabilizado, ya que el l铆mite del rango es excluyente).
A continuaci贸n, creamos un objeto sq
usando la funci贸n zip
incorporada. Esta funci贸n le permite recorrer dos o m谩s iterables simult谩neamente y crear un nuevo iterable de tuplas con los elementos coincidentes de cada iterable. Podemos ver c贸mo funciona esto en la siguiente tabla:
脥ndice | 0 | 1 | 2 | 3 |
files | a | b | c | d |
ranks | 1 | 2 | 3 | 4 |
zip | a1 | b2 | c3 | d4 |
Curiosamente, no parece que exista alguna funci贸n matem谩tica que describa esta operaci贸n, ya que el producto catersiano de conjuntos se diferencia en que crea todos los pares de elementos posibles. Seg煤n esta p谩gina , el producto diagonal es una aproximaci贸n cercana a la funci贸n zip
.
De todos modos, esta funci贸n es muy 煤til en programaci贸n y tiene muchas aplicaciones. En este caso, lo us茅 para combinar los files
y los ranks
para crear sq
, que significa casillas (squares en ingl茅s). Si prestas atenci贸n, estos son los nombres de las casillas de un tablero de ajedrez: a1, b2, c3 y d4.
Ahora, tambi茅n habr谩s notado que ranks
ten铆a elementos del 1 al 5, entonces, 驴qu茅 pas贸 con 5? Se ignor贸 porque zip
solo empareja o combina iterables que tienen la misma longitud. En el momento en que el tama帽o de un iterable sea m谩s largo que los dem谩s, zip
se detendr谩 y el iterable resultante tendr谩 la misma longitud que el iterable m谩s corto dado.
Finalmente, el iterable se ejecuta utilizando la conocida funci贸n join
, obteniendo una conveniente cadena labels
.
Si quieres bloguear sobre contenido inform谩tico y de programaci贸n, te invito a unirte a Hive y participar en sus comunidades, tales como STEM-social, Develop Spanish, Programming & Dev y otras.