πŸ“œ ⬆️ ⬇️

"Competition" for the best software implementation, displaying the number of "forty-two"

I understand that this article will certainly cause questions from the moderators (about the appropriateness of her stay on HabrΓ©), but where is it not here [ at Europe’s largest resource for IT specialists ] to raise the question of the answer to the main question from an IT point of view?

To begin with, I will briefly explain why this question is generally relevant.

 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘
 β–‘β–‘β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–ˆβ–ˆβ–“β–“β–ˆβ–ˆβ–“β–“β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–ˆβ–ˆβ–“β–“β–ˆβ–ˆβ–“β–“β–“β–“β–“β–“β–ˆβ–ˆβ–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–“β–“β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–“β–“β–“β–“β–ˆβ–ˆβ–“β–“β–ˆβ–ˆβ–“β–“β–“β–“β–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–“β–“β–“β–“β–ˆβ–ˆβ–“β–“β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–’β–’β–‘β–‘
 β–‘β–‘β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–‘β–‘
 β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘

Certainly, many of them paid attention to the abuse of the frequent encounter of the number '' forty-two '' on the web pages devoted to IT topics. Here are examples that I personally met:
Be careful, 16 great screenshots!







')
The remaining 9 screenshots










This fact brought me to the idea / idea that it is worth banning the use of the number 42 in the documentation for your projects. And since just hardcoding this number is not interesting, the idea arose to arrange such a "contest".

Leave your options [ in any programming language ] in the comments (if you want to be able to fix your code in the future, then let's link [ to gist in GitHub, to snippet to Bitbucket or to pastebin.com ] ).

"Competition" - indefinite, so you can take the time and think well.

Here is my implementation (requires Python 3.6 and higher)
import hashlib def calculate_sacred_number(): results = [] for hash_algorithm in hashlib.algorithms_available: # ||    - # \\ (    MD5, RIPEMD,  SHA  BLAKE,  β€” 32 ) if "shake" in hash_algorithm: #   SHAKE,        length  hexdigest() continue for uppercase in range(2): # ||     ,     for space in range(2): # ||         for n in range(10, 100): # ||     global numbers nw = numbers[n] # ||   ,      if uppercase: nw = nw.upper() if space: nw = nw.replace('-', ' ') ns = str(n) digest1 = hashlib.new(hash_algorithm, nw.encode()).hexdigest() # ||      , digest2 = hashlib.new(hash_algorithm, ns.encode()).hexdigest() # ||      ,    for i in range(2): # //   ,      if ( digest1[ 0] == ns[0] and digest2[ 0] == ns[0] # ||          ... and digest1[-1] == ns[1] and digest2[-1] == ns[1]): # || ...     . results += [ns] # //     digest1 = digest1[:len(digest1)//2] digest2 = digest2[:len(digest2)//2] assert(len(results) == 1) # ||     ""  return results[0] # ||    # // From [https://stackoverflow.com/a/8982279/2692494 'How do I tell Python to convert integers into words']: numbers = "zero one two three four five six seven eight nine".split() numbers.extend("ten eleven twelve thirteen fourteen fifteen sixteen".split()) numbers.extend("seventeen eighteen nineteen".split()) numbers.extend(tens if ones == "zero" else (tens + "-" + ones) for tens in "twenty thirty forty fifty sixty seventy eighty ninety".split() for ones in numbers[0:10]) print(calculate_sacred_number()) 
The code is richly seasoned with comments, so I do not accompany it with a verbal explanation.

PS Here is the source of this article (on the PC-markup ).

Source: https://habr.com/ru/post/349592/


All Articles