Giter Site home page Giter Site logo

Comments (4)

abrassel avatar abrassel commented on May 25, 2024 1

Thank you Manvi!

from quantumkatas.

Manvi-Agrawal avatar Manvi-Agrawal commented on May 25, 2024

@abrassel , seems there are three things at play here: efficiency of current algorithm, correctness of existing solution and passing of your solution with and without +1.

  • Efficiency: I agree that your solution is slightly more efficient. I think it would be a good idea to have it as an alternative solution in workbook
  • Correctness of existing solution: The existing solution is correct because BitSizeI function returns the minimum number of bits required to represent a number. BitSizeI function reference. To validate this, you can create an operation Demo_BitSizeI() operation in the jupyter notebook as follows:
open Microsoft.Quantum.Math;
operation Demo_BitSizeI() : Unit {
  let nBits = BitSizeI(8);
  Message($"Bits required to represent 8 {nBits}");
  }

And you can run above operation in jupyter notebook by executing the following code in a separate code cell. This gives 4 as the result

%simulate Demo_BitSizeI
  • Solution passing with/without +1: As explained in second point, BitSizeI function returns the minimum bits required to represent a number. In your case, you are generating random numbers in range [0, max-min+1] both inclusive and then filtering out extra number max-min+1 in until condition by specifying result<=max-min. Hence the test is passing.

For alternative solution, I have a minor suggestion to use let N= BitSizeI(range).

I hope this answers your query. @tcNickolas thoughts?

from quantumkatas.

tcNickolas avatar tcNickolas commented on May 25, 2024

I'm sorry for not answering this back in summer! I'm not sure how I've missed it, possibly I've read it and nodded along but got distracted before I actually commented?

I agree that it makes sense to use the more efficient approach you're describing, both as the main reference solution in the ReferenceImplementation.qs and in the workbook. Would you be interested in sending the pull request with the change? (I understand if you're not, it's been a couple months, which I'm terribly sorry about...)

from quantumkatas.

abrassel avatar abrassel commented on May 25, 2024

Hi Nickolas! I don't have the time at the moment to submit the PR, but you are welcome to copy and paste this solution yourself!

from quantumkatas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.