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: October 11, 2025, 9:06 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My maturity test
#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



Messages In This Thread
My maturity test - by FlatAssembler - January 9, 2018 at 2:08 pm
RE: My maturity test - by rado84 - January 9, 2018 at 8:59 pm
RE: My maturity test - by RoadRunner79 - January 9, 2018 at 9:18 pm
RE: My maturity test - by polymath257 - January 9, 2018 at 9:23 pm
RE: My maturity test - by SteelCurtain - January 9, 2018 at 10:27 pm
RE: My maturity test - by chimp3 - January 9, 2018 at 10:37 pm
RE: My maturity test - by FlatAssembler - January 10, 2018 at 12:13 am
RE: My maturity test - by SteelCurtain - January 10, 2018 at 8:43 am
RE: My maturity test - by Grandizer - January 10, 2018 at 9:19 am
RE: My maturity test - by polymath257 - January 10, 2018 at 12:43 am
RE: My maturity test - by Brian37 - January 10, 2018 at 8:59 am
RE: My maturity test - by FlatAssembler - January 10, 2018 at 9:12 am
RE: My maturity test - by polymath257 - January 10, 2018 at 10:13 am
RE: My maturity test - by I_am_not_mafia - January 10, 2018 at 10:01 am
RE: My maturity test - by SteelCurtain - January 10, 2018 at 3:05 pm

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Serious] Anyone here use ECU Test? Jehanne 2 1005 September 1, 2022 at 7:20 pm
Last Post: Jehanne
  Test if a ZIP is infected FlatAssembler 21 4124 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 3699 August 14, 2015 at 12:05 pm
Last Post: Longhorn
  Broadband speed test Darwinian 3 2174 April 18, 2014 at 6:23 am
Last Post: Sejanus
  Can anyone help beta test my webcam app? Tiberius 2 2028 April 26, 2013 at 9:20 am
Last Post: panda bear
  Hypercube Beta Test Darwinian 16 6981 June 24, 2012 at 6:50 am
Last Post: Darwinian
  Reliable internet speed test? Oldandeasilyconfused 8 5927 April 17, 2012 at 11:30 am
Last Post: venmalathy



Users browsing this thread: 1 Guest(s)