My Coding Quiz #53

avatar

My Coding Quiz #53 👨‍💻🛠️🧩

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...




Quiz
By @eniolw


What's your choice?

Solution to the previous quiz: '8/KppppPPk/8/8/8/8/8/8'. As always, let's analyze the script line by line. First we define a string fen with the value "8/KPPppppppk/8/8/8/8/8/8/8/8/8/8 w - - 0 1" and you may wonder, what the hell is this? Well, although it doesn't look like it, it's a representation of a chess position. It is not a diagram, but it is a format that is readable by a chess program and contains all the essential elements that describe a chess position.

These elements are extracted from the FEN in the following line p, t, r1, r2, o, m = fen.split(). Here we have used the split method and then unpacked the content in the variables p (piece arrangement), t (turn), r1 (castling possibilities), r2 (square for the en passant pawn; I should have named this variable differently), o (number of half moves to apply the fifty move rule) and m (number of full moves since the game started).

These are all attributes of a chess position, but for this script we are only interested in the first one, p, that is, the piece arrangement itself.

What we basically do is to apply the replace method to replace the characters "P" in the string with the character "p", but by specifying the third numerical argument of replace, we are telling it to do the replacement only for that number of characters. Since in this case we said 2, only two "P" characters will be replaced. That explains why the value of new is '8/KppppPPPPk/8/8/8/8/8/8/8/8/8/8'.

I know, it might be annoying for a human to read that string, but it's not impossible. By the way, the capital P stands for white pawn, while the small p stands for black pawn, so with this operation what we did was to replace two white pawns by two black ones.


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 and others.


Mi Quiz de Programación #53 👨‍💻🛠️🧩

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...




Quiz
Por @eniolw


¿Cuál es tu elección?

Solución al quiz anterior: '8/KppppPPk/8/8/8/8/8/8'. Como siempre, analicemos el script línea por línea. Primero definimos la cadena fen con el valor "8/KPPppppppk/8/8/8/8/8/8/8/8/8/8 w - - 0 1" y te preguntarás, ¿qué carajos es esto? Pues aunque no lo parezca, es una representación de una posición de ajedrez. No es un diagrama, pero es un formato que es legible por un programa de ajedrez y contiene todos los elementos esenciales que describen una posición de ajedrez.

Estos elementos son extraídos del FEN en la siguiente línea p, t, r1, r2, o, m = fen.split(). Aquí hemos utilizado el método split y luego descomprimimos el contenido en las variables p (disposición de piezas), t (turno), r1 (posibilidades de enroque), r2 (casilla para el peón al paso; debería haber nombrado esta variable de otra manera), o (número de medios movimientos para aplicar la regla de los cincuenta movimientos) y m (número de movimientos completos desde que comenzó la partida).

Todos estos son atributos de una posición de ajedrez, pero para este script sólo nos interesa el primero, p, es decir, la disposición de las piezas en sí.

Lo que básicamente hacemos es aplicar el método replace para reemplazar los caracteres "P" en la cadena con el carácter "p" , pero al especificar el tercer argumento numérico de replace, le estamos diciendo que reemplace solo esa cantidad de caracteres. Como en este caso dijimos 2, solo se reemplazarán dos caracteres "P". Eso explica por qué el valor de new es '8/KppppPPPPk/8/8/8/8/8/8/8/8/8/8'.

Lo sé, puede resultar molesto para un humano leer esa cadena, pero no es imposible. Por cierto, la P mayúscula representa un peón blanco, mientras que la p minúscula representa un peón negro, entonces con esta operación lo que hicimos fue sustituir dos peones blancos por dos negros.


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.



0
0
0.000
2 comments
avatar

This post has been manually curated by @bhattg from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.

Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.

image.png

100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @bhattg by upvoting this comment and support the community by voting the posts made by @indiaunited.

0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000