Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

541
Views
¿Cómo se traduce to_s(2) de Ruby a python?

Así que he estado tratando de reescribir un fragmento de código de Ruby en Python, y no he podido hacerlo funcionar. Vuelvo a leer todo para asegurarme de que lo hice bien, pero sigue sin funcionar. Supongo que el problema radica en esta "traducción":

 def multiply(k, point = $G) current = point binary = k.to_s(2) binary.split("").drop(1).each do |char| current = double(current) current = add(current, point) if char == "1" end current end

Esta es mi versión traducida de Python:

 def multiply(k, point = G): current = point binary = bin(k) for i in binary[3:]: current = double(current) if i == "1": current = add(current, point) return current

Creo que no entendí muy bien los conceptos de to_s(2) y/o .drop(1) de Ruby . ¿Alguien podría decirme cuál es la mejor manera de traducir este código de Ruby a Python?

EDITAR Entonces, elaboraré tal como sugirió @Michael Butscher:

Tengo este código de Ruby, que traté de traducir a este código de Python. Y aunque la salida debe ser

044aeaf55040fa16de37303d13ca1dde85f4ca9baa36e2963a27a1c0c1165fe2b11511a626b232de4ed05b204bd9eccaf1b79f5752e14dd1e847aa2f4db6a5

arroja un error. ¿Por qué?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El problema no está en la función que has mostrado, sino en tu función inverse . / entre enteros en Ruby se traduce como // en Python 3:

Rubí:

 3 / 2 # => 1 3.0 / 2 # => 1.5

Pitón 3:

 3 / 2 # => 1.5 3 // 2 # => 1
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!