create account

My Coding Quiz #53 by eniolw

View this thread on: hive.blogpeakd.comecency.com
· @eniolw ·
$10.89
My Coding Quiz #53
<div class="text-justify">

<center><h2>My Coding Quiz #53 👨‍💻🛠️🧩</h2></center>

<p>Welcome to the new installment of my series of <b>Coding Quizzes</b>, 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 <a href="/@eniolw">my blog</a> here on Hive and the <a href="/@eniolw/my-coding-quiz-1">first post</a> where I introduced it.</p>

<h3>Without further ado, here's the riddle...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmdy8VkxmfMERram9zEiNj1Yde8Wno4JEF4V9uTSNKUBPb/imagen.png" alt="Quiz">
<h6>By @eniolw</h6>
</center>

<br><center><h3>What's your choice?</h3></center>

<p><b>Solution to the <a href="/@eniolw/my-coding-quiz-52">previous quiz</a>:</b> <b>'8/KppppPPk/8/8/8/8/8/8'</b>. As always, let's analyze the script line by line. First we define a string <code>fen</code> with the value <code>"8/KPPppppppk/8/8/8/8/8/8/8/8/8/8 w - - 0 1"</code> and you may wonder, what the hell is this? Well, although it doesn't look like it, <i>it's a representation of a chess position</i>. It is not a diagram, but <a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation">it is a format</a> that is readable by a chess program and contains all the essential elements that describe a chess position.</p>

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

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

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

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

<hr>

<p>If you want to blog about computer science and programming content, I invite you to join <a href="/">Hive</a> and participate in its communities, such as <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> and others.</p>

<hr>

<center><h2>Mi Quiz de Programación #53 👨‍💻🛠️🧩</h2></center>

<p>Bienvenido a mi nueva serie de <b>Quizzes de Programación</b>, 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 <a href="/@eniolw">mi blog</a> aquí en Hive y el <a href="/@eniolw/my-coding-quiz-1">primer post</a> donde la presenté.</p>

<h3>Sin más preámbulos, he aquí el acertijo...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmSjqMk7QcXKuZepZ1Wf3chbCqLvmqoyLVuUWtGi7rcqUm/imagen.png" alt="Quiz">
<h6>Por @eniolw</h6>
</center>

<br><center><h3>¿Cuál es tu elección?</h3></center>

<p><b>Solución al <a href="/@eniolw/my-coding-quiz-52">quiz anterior</a>:</b> <b>'8/KppppPPk/8/8/8/8/8/8'</b>. Como siempre, analicemos el script línea por línea. Primero definimos la cadena <code>fen</code> con el valor <code>"8/KPPppppppk/8/8/8/8/8/8/8/8/8/8 w - - 0 1"</code> y te preguntarás, ¿qué carajos es esto? Pues aunque no lo parezca, <i>es una representación de una posición de ajedrez</i>. No es un diagrama, pero <a href="https://es.wikipedia.org/wiki/Notaci%C3%B3n_de_Forsyth-Edwards">es un formato</a> que es legible por un programa de ajedrez y contiene todos los elementos esenciales que describen una posición de ajedrez.</p>

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

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

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

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

<hr>

<p>Si quieres bloguear sobre contenido informático y de programación, te invito a unirte a <a href="/">Hive</a> y participar en sus comunidades, tales como <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> y otras.</p>

</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 540 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-53
categoryhive-197685
json_metadata"{"image":["https://images.ecency.com/DQmdy8VkxmfMERram9zEiNj1Yde8Wno4JEF4V9uTSNKUBPb/imagen.png","https://images.ecency.com/DQmSjqMk7QcXKuZepZ1Wf3chbCqLvmqoyLVuUWtGi7rcqUm/imagen.png"],"tags":["hive-197685","programming","coding","python","quiz","chess","neoxian","proofofbrain","waivio","creativecoin","spanish"],"description":"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 fun way.","app":"ecency/3.1.0-vision","format":"markdown+html","image_ratios":["1.3550","1.3550"]}"
created2024-03-20 00:13:33
last_update2024-03-20 00:13:33
depth0
children2
last_payout2024-03-27 00:13:33
cashout_time1969-12-31 23:59:59
total_payout_value5.504 HBD
curator_payout_value5.388 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,472
author_reputation253,650,633,664,455
root_title"My Coding Quiz #53"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id132,183,635
net_rshares21,528,018,794,175
author_curate_reward""
vote details (604)
@indiaunited ·
Indiaunited Curation 1710946662035
This post has been manually curated by @bhattg from Indiaunited community. Join us on our [Discord Server](https://discord.gg/bGmS2tE). 

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](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=173333.82586024754%20VESTS), [250HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=433334.5646506188%20VESTS), [500HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=866669.1293012376%20VESTS), [1000HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=1733338.2586024753%20VESTS). 

[![image.png](https://files.peakd.com/file/peakd-hive/bala41288/46eaz12N-image.png)](https://discord.gg/bGmS2tE) 

<sub>**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.**</sub>
properties (22)
authorindiaunited
permlinkindiaunited-1710946662035
categoryhive-197685
json_metadata{"app":"hiveblog/0.1","format":"markdown","tags":["hive-197685","programming","coding","python","quiz","chess","neoxian","proofofbrain","waivio","creativecoin","spanish"]}
created2024-03-20 14:57:42
last_update2024-03-20 14:57:42
depth1
children0
last_payout2024-03-27 14:57:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,328
author_reputation95,462,840,533,451
root_title"My Coding Quiz #53"
beneficiaries
0.
accountbhattg
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id132,198,689
net_rshares0
@stemsocial ·
re-eniolw-my-coding-quiz-53-20240321t013234523z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> 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.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-eniolw-my-coding-quiz-53-20240321t013234523z
categoryhive-197685
json_metadata{"app":"STEMsocial"}
created2024-03-21 01:32:33
last_update2024-03-21 01:32:33
depth1
children0
last_payout2024-03-28 01:32:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,905,425,648,299
root_title"My Coding Quiz #53"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id132,210,150
net_rshares0