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: February 22, 2025, 10:14 pm

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



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 668 September 1, 2022 at 7:20 pm
Last Post: Jehanne
  Test if a ZIP is infected FlatAssembler 21 3166 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 3253 August 14, 2015 at 12:05 pm
Last Post: Longhorn
  Broadband speed test Darwinian 3 1985 April 18, 2014 at 6:23 am
Last Post: Sejanus
  Can anyone help beta test my webcam app? Tiberius 2 1903 April 26, 2013 at 9:20 am
Last Post: panda bear
  Hypercube Beta Test Darwinian 16 6261 June 24, 2012 at 6:50 am
Last Post: Darwinian
  Reliable internet speed test? Oldandeasilyconfused 8 5613 April 17, 2012 at 11:30 am
Last Post: venmalathy



Users browsing this thread: 1 Guest(s)