Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: April 25, 2024, 1:58 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My maturity test
#11
RE: My maturity test
I simply don't understand what's that algorithm supposed to achieve on the high-level. I suppose it counts the number of ones in the binary representation of the numbers and searches for some kind of maximum. But such low numbers (from 14 to 17) can't have 15 ones in their binary representation, they are only 4-5 digits long in the binary system.
Reply
#12
RE: My maturity test
(January 10, 2018 at 12:13 am)FlatAssembler Wrote: Thanks, SteelCurtain. 15 is the correct answer.
And I agree with you that the tasks are very confusing. Pseudocode itself can be confusing, especially if you didn't go to a high school with informatics as a subject, where the same pseudocode as one on the maturity test is used. Looking at an algorithm you've never seen before and trying to guess what it's doing is very confusing.

Step by step is the key. Go slowly and carefully, bit by bit. Note down all relevant values that you may need to use or refer to again.
Reply
#13
RE: My maturity test
Welcome to the black hole of careers. Once you enter the event horizon (your first programming job) you won't be able to escape a career as a code monkey.

It's too late for me but you can still save yourself.
Reply
#14
RE: My maturity test
(January 10, 2018 at 9:12 am)FlatAssembler Wrote: I simply don't understand what's that algorithm supposed to achieve on the high-level. I suppose it counts the number of ones in the binary representation of the numbers and searches for some kind of maximum. But such low numbers (from  14 to 17) can't have 15 ones in their binary representation, they are only 4-5 digits long in the binary system.

Yes, it counts the number of 1s in the binary description. In the for loop, t starts out with the value of i. then, setting z=t mod 2 gets the last binary digit, which is added to the running total, s. Then t=t div 2 divides t by 2, discarding the remainder. This happens as long as t>0. At the end, s holds the number of 1s (actually, the total of the binary digits, which is the same thing).

Now, m keeps track of the largest number of 1s so far, and p keeps track of the corresponding number. If s is larger than m, we replace m by s and p by i.

At the end, p=15, which in binary is 1111 (and has four 1s, more than any other number in the for loop). So, m=4, but we only print p.
Reply
#15
RE: My maturity test
The point of these exercises usually isn't to figure out what the program does on the high level, but whether you can look at a code snippet and follow the logic through.

Unless the problem specifically asks you to give a description of what the code does, my suggestion is to always stick to what the problem asks.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great

PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  [Serious] Anyone here use ECU Test? Jehanne 2 519 September 1, 2022 at 7:20 pm
Last Post: Jehanne
  Test if a ZIP is infected FlatAssembler 21 2232 June 11, 2020 at 10:05 am
Last Post: FlatAssembler
  Google's Mobile-Friendly Test Driving Me Batty: What am I Doing Wrong? Rhondazvous 10 2816 August 14, 2015 at 12:05 pm
Last Post: Longhorn
  Broadband speed test Darwinian 3 1834 April 18, 2014 at 6:23 am
Last Post: Sejanus
  Can anyone help beta test my webcam app? Tiberius 2 1771 April 26, 2013 at 9:20 am
Last Post: panda bear
  Hypercube Beta Test Darwinian 16 5683 June 24, 2012 at 6:50 am
Last Post: Darwinian
  Reliable internet speed test? Oldandeasilyconfused 8 5304 April 17, 2012 at 11:30 am
Last Post: venmalathy



Users browsing this thread: 1 Guest(s)