create account

My Coding Quiz #3 by eniolw

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

<center><h2>My Coding Quiz #3 👨‍💻🛠️🧩</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/DQmSRModJQdKgco5MQkFqJyNjX71TepeqzMwDptZoTYtoPw/quiz_img_en.png" alt="Quiz"></center>

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

<p><b>Solution to the <a href='/@eniolw/my-coding-quiz-2'>previous quiz</a>:</b> <b>1</b>. This is a bit tricky in that we are dealing with an array of string elements, not numeric elements, which is what is declared in line 1. Then in line 2 we create a <code>b</code> identifier that references the identifier <code>a</code>, so <code>a</code> points to the same memory address as <code>b</code>. However, in line 3, <code>b</code> changes reference and now points to a new object, but doesn't overwrite what it previously pointed to. The references issue could be considered a red herring, although if you had any doubts when analyzing this, it means you should probably brush up on it!</p>

<p>Now this is the tricky part, because the object returned in line 3 is an ordered array of strings. This is: <b>['-0', '-1', '1', '2']</b>. String ordering is lexicographical, so it does not behave the same as numeric ordering. To understand this, imagine that you are asked to sort this array <code>["Shanon", "Turing", "Church"]</code>. Surely you will know how to order it by comparing each position of a string with its equivalent in the others (this one is rather easy).</p>

<p>By applying this to the original <code>['2', '1', '-1', '-0']</code> array, we'll figure out the trick. It is important to know that the character <code>'-'</code> is less than the characters <code>'1'</code> and <code>'2'</code>, so it is sorted first. Then, to break a tie between <code>'-0'</code> and <code>'-1'</code>, the second position of both strings is compared. It turns out that <code>'0'</code> is less than <code>'1'</code>, so it is sorted first. Hence, <b>['-0', '-1', '1', '2']</b> is the final result of the lexicographical ordering.</p>

<p>Finally, in line 4 the conversions are made to integer values and we have: <b>2 + -1</b>, which is <b>2 - 1</b> which is <b>1</b>. This one managed to trick all the participants this time!</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-196387">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> and even <a href="/created/hive-153850">Hive Learners</a>.</p>

<hr>

<center><h2>Mi Quiz de Programación #3 👨‍💻🛠️🧩</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/DQmeXoP1dwubmFGSG5fBM6MARRkT6CwDkoTxpJ7nfVGdzhE/quiz_img_es.png" alt="Quiz"></center>

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

<p><b>Solución al <a href='/@eniolw/my-coding-quiz-2'>quiz anterior</a>:</b> <b>1</b>. Este es un poco engañoso por cuanto estamos lidiando con un arreglo de cadenas de caracteres, no de números, que es lo que se declara en la línea 1. Luego, en la línea 2 se crea un indentificador <code>b</code> que hace referencia al identificador <code>a</code>, de modo que <code>a</code> apunta a la misma dirección de memoria que <code>b</code>. Sin embargo, en la línea 3, <code>b</code> cambia de referencia y ahora apunta a un nuevo objeto, más no sobreescribe lo que anteriormente apuntaba. El asunto de las referencias podría ser considerado una pista falsa, aunque si tuviste dudas, significa que probablemente deberías repasar este asunto!</p>

<p>Ahora bien, esta es la parte complicada, pues el objeto retornado en la línea 3 es un arreglo de cadenas de caracteres ordenado. Este es: <b>['-0', '-1', '1', '2']</b>. El ordenamiento de caracteres es lexicográfico, por lo que no se comporta igual que el ordenamiento numérico. Para entender esto, imagina que se pide ordenar este arreglo <code>["Shanon", "Turing", "Church"]</code>. Seguro sabrás ordenarlo comparando cada posición de una cadena de caracteres con su equivalente en las demás (en realidad este ejemplo es muy fácil).</p>

<p>Aplicando esto al arreglo original <code>['2', '1', '-1', '-0']</code>, descubriremos el truco. Importa saber que el caracter <code>'-'</code> es menor que los caracteres <code>'1'</code> y <code>'2'</code>, por lo que se ordena de primero. Luego, para desempatar entre <code>'-0'</code> y <code>'-1'</code>, se compara la segunda posición de ambas cadenas. Resulta que <code>'0'</code> es menor que <code>'1'</code>, por lo que se ordena de primero. De allí que <b>['-0', '-1', '1', '2']</b> sea el resultado final del ordenamiento lexicográfico.</p>

<p>Finalmente, en la línea 4 se hacen las conversiones a valores enteros y se tiene: <b>2 + -1</b>, que es <b>2 - 1</b> que es <b>1</b>. Éste ha conseguido engañar a todos los participantes esta vez.</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-196387">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> e incluso <a href="/created/hive-153850">Hive Learners</a>.</p>

</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 657 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-3
categoryhive-153850
json_metadata"{"image": ["https://images.ecency.com/DQmSRModJQdKgco5MQkFqJyNjX71TepeqzMwDptZoTYtoPw/quiz_img_en.png", "https://images.ecency.com/DQmeXoP1dwubmFGSG5fBM6MARRkT6CwDkoTxpJ7nfVGdzhE/quiz_img_es.png"], "thumbnails": ["https://images.ecency.com/DQmSRModJQdKgco5MQkFqJyNjX71TepeqzMwDptZoTYtoPw/quiz_img_en.png", "https://images.ecency.com/DQmeXoP1dwubmFGSG5fBM6MARRkT6CwDkoTxpJ7nfVGdzhE/quiz_img_es.png"], "tags": ["hive-153850", "programming", "coding", "software", "python", "neoxian", "stem", "creativecoin", "technology", "proofofbrain"], "description": "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.", "app": "ecency/3.0.32-vision", "format": "markdown+html"}"
created2023-06-24 09:17:54
last_update2023-06-24 09:17:54
depth0
children7
last_payout2023-07-01 09:17:54
cashout_time1969-12-31 23:59:59
total_payout_value8.238 HBD
curator_payout_value8.122 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,126
author_reputation253,484,293,384,648
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,731,526
net_rshares37,815,424,897,250
author_curate_reward""
vote details (721)
@jsalvage ·
The last time I checked, I found coding to be a difficult task to perform. Lol but I see how you're playing with the codes here. Quite interesting 
👍  ,
properties (23)
authorjsalvage
permlinkre-eniolw-2023625t1141119z
categoryhive-153850
json_metadata{"tags":["hive-153850","programming","coding","software","python","neoxian","stem","creativecoin","technology","proofofbrain"],"app":"ecency/3.0.39-mobile","format":"markdown+html"}
created2023-06-25 10:04:00
last_update2023-06-25 10:04:00
depth1
children2
last_payout2023-07-02 10:04:00
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_length147
author_reputation127,414,184,262,562
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,758,183
net_rshares160,702,235
author_curate_reward""
vote details (2)
@eniolw ·
Thank you! Try to solve it if you want.
properties (22)
authoreniolw
permlinkre-jsalvage-2023625t212123603z
categoryhive-153850
json_metadata{"tags":["hive-153850","programming","coding","software","python","neoxian","stem","creativecoin","technology","proofofbrain"],"app":"ecency/3.0.32-vision","format":"markdown+html"}
created2023-06-26 01:21:24
last_update2023-06-26 01:21:24
depth2
children1
last_payout2023-07-03 01:21:24
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_length39
author_reputation253,484,293,384,648
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,775,919
net_rshares0
@jsalvage ·
Smile, time is no longer on my side, maybe I'll try that when I graduate from college 
properties (22)
authorjsalvage
permlinkre-eniolw-rx0x33
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"peakd/2023.6.5"}
created2023-06-29 16:42:42
last_update2023-06-29 16:42:42
depth3
children0
last_payout2023-07-06 16:42: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_length86
author_reputation127,414,184,262,562
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,887,731
net_rshares0
@stemsocial ·
re-eniolw-my-coding-quiz-3-20230625t045802099z
<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-3-20230625t045802099z
categoryhive-153850
json_metadata{"app":"STEMsocial"}
created2023-06-25 04:58:00
last_update2023-06-25 04:58:00
depth1
children0
last_payout2023-07-02 04:58:00
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,903,711,652,468
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,753,862
net_rshares0
@visualblock ·
<center>

![](https://images.ecency.com/DQmeUXCY8732hkoJpZcnSxQD7NbHUbhe9d8wKYmqN3rN56e/testigo_hispapro.png)

<sup>
Has sido curado por @visualblock / You've been curated by @visualblock 
Bienvenidas delegaciones / Delegations welcome
 [Encuentra nuestra comunidad aquí / Find our community here](https://discord.gg/tGuctbfYKN) 
[Trail de Curación / Curation Trail](https://hive.vote/dash.php?trail=visualblock&i=1)

[Vota por nuestro Testigo aliado - @hispapro](https://vote.hive.uno/@hispapro) / [Vote for our allied Witness - @hispapro](https://vote.hive.uno/@hispapro) 
[Más información sobre el testigo aquí](https://ecency.com/hive-111111/@hispapro/witness-announcement-descubre-el-nuevo) / [More information about the witness here](https://ecency.com/hive-111111/@hispapro/witness-announcement-descubre-el-nuevo)

</sup>

</center>
properties (22)
authorvisualblock
permlinkre-eniolw-2023624t15359575z
categoryhive-153850
json_metadata{"tags":["hive-153850","programming","coding","software","python","neoxian","stem","creativecoin","technology","proofofbrain"],"app":"ecency/3.0.32-vision","format":"markdown+html"}
created2023-06-24 13:35:09
last_update2023-06-24 13:35:09
depth1
children2
last_payout2023-07-01 13:35:09
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_length839
author_reputation152,603,008,711,740
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,736,086
net_rshares0
@eniolw ·
Gracias.
properties (22)
authoreniolw
permlinkre-visualblock-2023625t11336743z
categoryhive-153850
json_metadata{"tags":["hive-153850","programming","coding","software","python","neoxian","stem","creativecoin","technology","proofofbrain"],"app":"ecency/3.0.32-vision","format":"markdown+html"}
created2023-06-25 05:13:36
last_update2023-06-25 05:13:36
depth2
children1
last_payout2023-07-02 05:13:36
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_length8
author_reputation253,484,293,384,648
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,754,069
net_rshares0
@visualblock ·
A ti por el buen trabajo que compartiste. 🤗
👍  ,
properties (23)
authorvisualblock
permlinkre-eniolw-2023625t155311458z
categoryhive-153850
json_metadata{"tags":["hive-153850","programming","coding","software","python","neoxian","stem","creativecoin","technology","proofofbrain"],"app":"ecency/3.0.32-vision","format":"markdown+html"}
created2023-06-25 13:53:12
last_update2023-06-25 13:53:12
depth3
children0
last_payout2023-07-02 13:53:12
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_length43
author_reputation152,603,008,711,740
root_title"My Coding Quiz #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,761,957
net_rshares160,450,880
author_curate_reward""
vote details (2)