# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### Newcomers DBPro Corner / Test Your Coding Skills

Message
Posted: 19th Jul 2013 17:10 Edited at: 21st Jul 2013 01:09
I thought it might be fun to make some quick challenges for newbies to see how they are growing as problem-solvers. If you want to post your own solutions please put them in code tags.

Challenge 0 — Produce random numbers between 12 and 29, and demonstrate that your program works as required.
Solution:

[OUT OF ORDER: DO NOT ATTEMPT] Challenge 1 — This time, pretend you are working with a language that only produces random numbers from 0 to 0.99999, how are you going to create the same range from 12 to 29? Use this code for getting random numbers: n# = rnd(99999)/100000.0
Solution:

I will add more when I think of them. Please post your own challenges and corrections to mine, if there are any mistakes. But please, only post original challenges, not things like FizzBuzz that are widely known.
Posted: 19th Jul 2013 19:23
Challenge 2 - Rewrite the following code using no, if conditional testing.

Solution:
Posted: 20th Jul 2013 05:50 Edited at: 20th Jul 2013 05:52
Challenge 3 - Through code, list all prime numbers between 1 and 100.

Solution:

If anyone has a better solution, that would be interesting. I actually made myself think trying to answer my own challenge!

Posted: 20th Jul 2013 12:13 Edited at: 20th Jul 2013 12:21

Mathematical logic is certainly interesting and can be very useful, but I don't particularly like this example as it doesn't improve the code.

@thenerd - Here's my solution:

I don't have DB installed so I had to dry run the code to check it. I sort of had to develop my own notation in the process so I hope it is easy to follow, maybe useful:
Posted: 20th Jul 2013 18:16 Edited at: 20th Jul 2013 19:38
@OBese87 - The sample and solution function exactly the same.
Test:

Please explain to me how this is not an improvement?
Posted: 20th Jul 2013 23:16 Edited at: 20th Jul 2013 23:17
@Wicked
It's not quite the same, you'll get the same output but logically they are different. The mathematical method checks bounds before incrementing; the conditional method checks bounds after incrementing. This probably would have been clearer if I hadn't totally changed your code. This functions exactly the same as the mathematical method:

Quote: "Please explain to me how this is not an improvement?"

There seems to always be unnecessary calculations, it is always calculating for both keys whether one, both or neither are pressed. Have you run a speed test? I might be wrong, math logic can be surprisingly quick sometimes.

Here's another version:

Pretty amazing mow many different ways you can code the same thing.
Posted: 21st Jul 2013 00:07 Edited at: 21st Jul 2013 00:11
After running a speed test, you are correct it doesn’t perform as well. Your first snippet above is probably the best choice.

Quote: "Pretty amazing how many different ways you can code the same thing. "

Thats the reason I enjoy programming, there are always alternitive ways to code.

I have a question concerning your first challenge. The line you have commented is correct. The code that follows just prints a range of number from 12 to 29. The second challenge, 18 would have worked the same as 18.00017.

Thank you.
Posted: 21st Jul 2013 01:06
Quote: "The second challenge, 18 would have worked the same as 18.00017."

I seem to have made a mistake there. It was supposed to be an example of truncation causing bias. I'll have to look at that and change it. Thanks.
Posted: 21st Jul 2013 01:13
Quote: "I seem to have made a mistake there."

We all make them