create account

My Coding Quiz #5 by eniolw

View this thread on: hive.blogpeakd.comecency.com
· @eniolw · (edited)
$13.31
My Coding Quiz #5
<div class="text-justify">

<center><h2>My Coding Quiz #5 馃懆鈥嶐煉火煕狅笍馃З</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://files.peakd.com/file/peakd-hive/eniolw/23z7NJX3U18bZT5JwoCJc3Sv1fi5AP7Ah8ZT56LmMZPzdyAHRd5YJ5oaJ2H4ScA1jNN8p.png" alt="Quiz"></center>

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

<p><b>Solution to the <a href="/@eniolw/my-coding-quiz-4">previous quiz</a>:</b> <b>14</b>. Lines 1 and 2 define a pair of <code>lambda</code> functions. Lambda is a keyword in the Python language for creating short functions intended to be used in-line, which enriches the language with <i>functional programming</i>.</p>
    
<p>If you didn't know, the reason for naming these functions <i>Lambda</i> is in honor of the <a href="https://en.wikipedia.org/wiki/Lambda_calculus">Lambda Calculus</a>, which was invented by theoretical computer scientist <i>Alonzo Church</i> to mathematically ground the theory of computation, something <i>Alan Turing</i> would do as well, but using a totally different model known as <i>Turing machines</i>.</p>
    
<p>Let's go back to the solution. It all makes sense when these functions are called in line 3 in a slightly obscure way, which is evidently intentional: <code>res = f1(f2(-4), 8)</code>. From here, we first resolve the call to the function <code>f2</code>, defined in line 2. This receives <b>-4</b> and returns its square, that is, <b>16</b>.</p>
    
<p>Then we solve the call to function <code>f1</code>, defined in line 1, which receives 16 and 8 as arguments. It executes the operation <code>16 - 8 / 4</code> which produces <b>14</b> (don't fall into the operator precedence trap, where <code>8 / 4</code> should be executed first because it is a division). An unnecessary rounding with <code>round</code> is applied to this value.</p>
    
<p>So <b>14</b> is the value assigned to <code>res</code> and printed at the end. It seems that only @zuerich managed to solve the quiz correctly this time. Congratulations!</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>,  <a href="/created/hive-153850">Hive Learners</a> and others.</p>

<hr>

<center><h2>Mi Quiz de Programaci贸n #5 馃懆鈥嶐煉火煕狅笍馃З</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://files.peakd.com/file/peakd-hive/eniolw/23z7NJX3U18bZT5VyfRpHwdozj6HQnouXjLU8ZMTx77G7LLFjrqA4NqLVuhsXeSJuJyqn.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-4">quiz anterior</a></b>: <b>14</b>. Las l铆neas 1 y 2 definen un par de funciones <code>lambda</code>. Lambda es una palabra clave en el lenguaje Python para crear funciones cortas destinadas a ser utilizadas de manera  in-line, lo que enriquece el lenguaje con <i>programaci贸n funcional</i>.</p>
    
<p>Si no lo sab铆as, la raz贸n para llamar a estas funciones <i>Lambda</i> es en honor al <a href="https://es.wikipedia.org/wiki/C%C3%A1lculo_lambda">C谩lculo lambda</a>, que fue inventado por el inform谩tico te贸rico <i>Alonzo Church</i> para fundamentar matem谩ticamente la teor铆a de la computaci贸n, algo que <i>Alan Turing</i> har铆a tambi茅n, pero usando un modelo totalmente diferente conocido como <i>m谩quinas de Turing</i>.</p>
    
<p>Volvamos a la soluci贸n. Todo tiene sentido cuando estas funciones se llaman en la l铆nea 3 de una manera un poco oscura, lo cual es evidentemente intencional: <code>res = f1(f2(-4), 8)</code>. A partir de aqu铆, primero resolvemos la llamada a la funci贸n <code>f2</code>, definida en la l铆nea 2. Esta recibe <b>-4</b> y devuelve su cuadrado, es decir, <b>16</b>.</p>
    
<p>Luego resolvemos la llamada a la funci贸n <code>f1</code>, definida en la l铆nea 1, que recibe 16 y 8 como argumentos. Ejecuta la operaci贸n <code>16 - 8 / 4</code> que produce <b>14</b> (no caigas en la trampa de precedencia de operadores, donde <code>8 / 4</code> se debe ejecutar primero porque es una divisi贸n). Se aplica un redondeo innecesario con <code>round</code> a este valor.</p>
    
<p>Entonces <b>14</b> es el valor asignado a <code>res</code> e impreso al final. Parece que solo @zuerich logr贸 resolver el cuestionario correctamente esta vez. 隆Felicidades!</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>, <a href="/created/hive-153850">Hive Learners</a> y otras.</p>

</div>
馃憤  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 704 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-5
categoryhive-153850
json_metadata"{"image":["https://files.peakd.com/file/peakd-hive/eniolw/23z7NJX3U18bZT5JwoCJc3Sv1fi5AP7Ah8ZT56LmMZPzdyAHRd5YJ5oaJ2H4ScA1jNN8p.png","https://files.peakd.com/file/peakd-hive/eniolw/23z7NJX3U18bZT5VyfRpHwdozj6HQnouXjLU8ZMTx77G7LLFjrqA4NqLVuhsXeSJuJyqn.png"],"thumbnails":["https://images.ecency.com/DQmNyLDw74txVF22QEEXbGPLZnpmgTgychT5GLmJZFBiGt5/quiz_img_en.png","https://images.ecency.com/DQmNPN547BAVvNw1KPWiuQ8AJtPSK4Rjp9Qb293kNyH1MiL/quiz_img_es.png"],"tags":["python","programming","coding","software","technology","neoxian","proofofbrain","creativecoin","spanish","hive-153850"],"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.33-vision","format":"markdown","users":["eniolw","zuerich"]}"
created2023-07-03 09:09:15
last_update2023-07-07 19:18:30
depth0
children7
last_payout2023-07-10 09:09:15
cashout_time1969-12-31 23:59:59
total_payout_value6.716 HBD
curator_payout_value6.594 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,625
author_reputation255,223,074,416,427
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,995,083
net_rshares30,701,642,383,644
author_curate_reward""
vote details (768)
@edb · (edited)
$0.03
I started running the code of your quizzes instead of guessing because they're harder than they look. But there's one important thing I learned about Python: while values have a type, variables don't. They're just references to a value object.

This is more logical and convenient than the variable types that other languages have, in my opinion. I didn't even know you could initialize variables with a type.
馃憤  , ,
properties (23)
authoredb
permlinkre-eniolw-rx7zqe
categoryhive-153850
json_metadata{"tags":"hive-153850"}
created2023-07-03 12:23:03
last_update2023-07-03 12:34:48
depth1
children1
last_payout2023-07-10 12:23:03
cashout_time1969-12-31 23:59:59
total_payout_value0.014 HBD
curator_payout_value0.014 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length409
author_reputation35,653,564,934,000
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,998,226
net_rshares70,093,095,570
author_curate_reward""
vote details (3)
@eniolw ·
It's great that it made you think and you're learning things. That's part of the point! I'll talk more about the type issue in the next quiz.
properties (22)
authoreniolw
permlinkre-edb-202373t114521864z
categoryhive-153850
json_metadata{"tags":"hive-153850","app":"ecency/3.0.33-vision","format":"markdown+html"}
created2023-07-03 15:45:21
last_update2023-07-03 15:45:21
depth2
children0
last_payout2023-07-10 15:45:21
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_length141
author_reputation255,223,074,416,427
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id125,002,820
net_rshares0
@rafaelaquino ·
Por aqu铆 mi respuesta:

-5.0 <class 'float'>
properties (22)
authorrafaelaquino
permlinkre-eniolw-rx8yqr
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"peakd/2023.6.5"}
created2023-07-04 00:59:15
last_update2023-07-04 00:59:15
depth1
children1
last_payout2023-07-11 00:59:15
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_length45
author_reputation110,423,639,605,208
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id125,016,352
net_rshares0
@eniolw ·
Ok, ya veremos!
properties (22)
authoreniolw
permlinkre-rafaelaquino-202374t01734147z
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"ecency/3.0.33-vision","format":"markdown+html"}
created2023-07-04 04:17:33
last_update2023-07-04 04:17:33
depth2
children0
last_payout2023-07-11 04:17: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_length15
author_reputation255,223,074,416,427
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id125,019,947
net_rshares0
@stemsocial ·
re-eniolw-my-coding-quiz-5-20230704t054352358z
<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-5-20230704t054352358z
categoryhive-153850
json_metadata{"app":"STEMsocial"}
created2023-07-04 05:43:51
last_update2023-07-04 05:43:51
depth1
children0
last_payout2023-07-11 05:43:51
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,918,229,493,305
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id125,021,717
net_rshares0
@zuerich ·
I would guess -5, class int
馃憤  ,
馃憥  , ,
properties (23)
authorzuerich
permlinkre-eniolw-rx7v06
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"peakd/2023.6.5"}
created2023-07-03 10:40:54
last_update2023-07-03 10:40:54
depth1
children1
last_payout2023-07-10 10:40:54
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_length27
author_reputation170,924,009,565,596
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id124,996,405
net_rshares-16,363,983,962
author_curate_reward""
vote details (5)
@eniolw ·
$0.08
Ok, we'll see ;)
馃憤  
properties (23)
authoreniolw
permlinkre-zuerich-202373t114539264z
categoryhive-153850
json_metadata{"tags":["hive-153850"],"app":"ecency/3.0.33-vision","format":"markdown+html"}
created2023-07-03 15:45:39
last_update2023-07-03 15:45:39
depth2
children0
last_payout2023-07-10 15:45:39
cashout_time1969-12-31 23:59:59
total_payout_value0.042 HBD
curator_payout_value0.042 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length16
author_reputation255,223,074,416,427
root_title"My Coding Quiz #5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id125,002,827
net_rshares192,713,525,661
author_curate_reward""
vote details (1)