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: March 28, 2024, 7:53 am

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My maturity test
#1
My maturity test
Hey, guys! I am from Croatia, and, when I finish my high school, which will be in around 6 months, I will have to go to the maturity test. I have to choose the subjects I will take with respect to the university I am planning to attend. I am planning to study informatics, so I have to take informatics at my maturity test. However, I didn't have informatics as a subject at all in my high-school. In the maturity test in informatics, there are some tasks about programming, but they have little to do with what I happen to know about programming.

Here is an example from the last-year maturity test in informatics:
25. What will the following program (in pseudocode) output if a=14 and b=17?
Code:
m := 0;
p := 0;
for i := a to b do
{
    t := i;
    s := 0;
    while t > 0 do
    {
        z := t mod 2;
        s := s + z;
        t := t div 2;
    }
    if s > m then
    {
        m := s;
        p := i;
    }

}
print (p);

Do you have any idea how to solve that task? I don't. Last year, there were around ten of such tasks (plus the tasks from Word, Excel and the binary-system-related things) and they had only 90 minutes to solve that all.

Can you please explain me how to solve that task (and similar ones) in reasonable time? Calculators aren't allowed (and, as far as I can see, wouldn't help much).
Reply
#2
RE: My maturity test
I can't understand anything of your code. At first I thought it was C++ but I don't remember being taught about an assigning operator with semicolon in it. Aside from the contents of m and p the rest looks like gibberish - without any reference what to do with m and p you can't have a "for" loop. There should be any kind of equasion to tell the computer how to use these values outside of the loop, otherwise it will just jump to the loop in most cases.

If you wanna do programming, I'd recommend you choose C# (C Sharp) because it's a lot easier than C or C++. These two are about half a second faster in executing than C# but they're a lot harder to learn and kinda getting obsolete. Nowadays a lot of sotware is being written in C#, like Windows 10, for instance - a lot of its code, if not all of it, was written in C#.
Why I think C# is easier? In C or C++ you have a line like this to tell the computer to display a message: print or printf("Your message"). While in C# even a non-programmer can recognize the message command: WriteLine("Your message"); Or Console.WriteLine("your message"); if you're writing a program for the command prompt.
[Image: OAsWbDZ.png]
Reply
#3
RE: My maturity test
Do you know how the loops work? Step through it logically (perhaps mark down some notes).

Learning logic is a lot more important to programming than learning code. The language is secondary. Most programming works basically the same, but being able to work the logic, will be invaluable even if you decide to go into something else.

Do you have a particular question? Can you guess what parts you don’t quite know; are doing from your other programming experience? If your stuck on how something works ask; but us doing your homework doesn’t help that much.
It is said that an argument is what convinces reasonable men and a proof is what it takes to convince even an unreasonable man.  - Alexander Vilenkin
If I am shown my error, I will be the first to throw my books into the fire.  - Martin Luther
Reply
#4
RE: My maturity test
(January 9, 2018 at 2:08 pm)FlatAssembler Wrote: Hey, guys! I am from Croatia, and, when I finish my high school, which will be in around 6 months, I will have to go to the maturity test. I have to choose the subjects I will take with respect to the university I am planning to attend. I am planning to study informatics, so I have to take informatics at my maturity test. However, I didn't have informatics as a subject at all in my high-school. In the maturity test in informatics, there are some tasks about programming, but they have little to do with what I happen to know about programming.

Here is an example from the last-year maturity test in informatics:
25. What will the following program (in pseudocode) output if a=14 and b=17?
Code:
m := 0;
p := 0;
for i := a to b do
{
    t := i;
    s := 0;
    while t > 0 do
    {
        z := t mod 2;
        s := s + z;
        t := t div 2;
    }
    if s > m then
    {
        m := s;
        p := i;
    }

}
print (p);

Do you have any idea how to solve that task? I don't. Last year, there were around ten of such tasks (plus the tasks from Word, Excel and the binary-system-related things) and they had only 90 minutes to solve that all.

Can you please explain me how to solve that task (and similar ones) in reasonable time? Calculators aren't allowed (and, as far as I can see, wouldn't help much).

The output of this will depend on the specifics of the rules in your pseudocode. Since a=14 and b=1, the for statement will either 1. not run at all (since a>b) or run with i starting at 14 and decreasing down to b=1. My guess is that the first is intended. If so, then the whole for loop is skipped, leaving p=0, which is printed.

Otherwise, the internal while loop counts the number of initial 1s in the binary representation of i and the following if statement finds the number with the largest such sequence. The number with that sequence (between 14 and 1) is 7, so p=7, which is printed.

So, the answer depends on the grammar for your for statements.
Reply
#5
RE: My maturity test
Looks like the Tiger programming language, but with curly braces.

The first step in solving tasks such as these is to make sure you understand basic control structures in programming languages. For loops, while loops, if-then, if-then-else. Once you understand how these work, then stepping through small programs such as this becomes an exercise in maintaining your place as you step through.

For this program, we start off by initializing two variables, m and p, to zero.

The we go into a for loop that encompasses the rest of the code, except for a print statement at the end. We initialize a loop variable, i, which acts as a counter for the for loop, it starts at a (14) and increments by one for every iteration of the for loop until it reaches 17.

So, t is initialized to i, 14, in the first iteration. s is initialized to 0. Now we enter into the while loop, with a test condition that the loop will continue until t > 0 gets evaluated to false. Right now, 14 > 0, so we enter into the while loop.
1) 14 % 2 gets evaluated and assigned to z, so z is initialized to 0. (if you're not familiar with the modulo operator, read about it here)
2) 0 + 0 gets evaluated and assigned to s, so s still equals 0
3) t / 2 is evaluated and assigned to t, so t now equals 7.

7 is still > 0, so we're still in the while loop.
1) z = 7 % 2 = 1
2) s = 0 + 1 = 1
3) t = 7 / 2 (integer division in programming) = 3

3 > 0, still in while loop
1) z = 3 % 2 = 1
2) s = 1 + 1 = 2
3) t = 3 / 2 = 1

1 > 0, still in while loop
1) 1 % 2 = 1
2) s = 2 + 1 = 3
3) t = 1 / 2 = 0

0 > 0 is false, so we're finally out of the while loop.

Now we get to the if statement. If the test condition 's > m' is evaluated to true, then the entire block will get executed.
In this iteration of the for loop, s is now 3, and m is unchanged, zero. So, we enter the block, and assign s to m, so m is now 3, and we assign the loop variable i to p, so p is now 14.

That is how to step through an iteration of the for loop. You can repeat that the three more times necessary in order to determine the value of p after the for loop returns control to the main block.

The final answer is:

"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
#6
RE: My maturity test
Flatassembler: I have no idea what the hell your asking. I wish you the best on your exams regardless!
God thinks it's fun to confuse primates. Larsen's God!






Reply
#7
RE: My maturity test
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.
Reply
#8
RE: My maturity test
Ooops, I read the b as 1 and not 17. So yes, 15 is the answer.
Reply
#9
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.

My point was a quick study in the basic control structures common to programming languages and how arithmetic is done by a computer should be sufficient to step through problems like these with relative ease.

I merely used a sheet of paper to keep track of the variables as I stepped through each line.

Which part of this problem specifically is confusing to you? Maybe that's a better place to start.
"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
#10
RE: My maturity test
I can write code.....

"Code" <----- SEE, I did it! Big Grin

I was poking fun of myself. I couldn't program to save my life.
Reply



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



Users browsing this thread: 1 Guest(s)