#Quicker way to figure this out?

48 messages · Page 1 of 1 (latest)

vagrant idol
fallow nymphBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

edgy burrow
#

quicker than what?

vagrant idol
edgy burrow
#

you could write the program yourself and see what it outputs

#

for this small of a program the biggest speed improvement would be to print the pseudocode and use a pen to record the state

vagrant idol
edgy burrow
#

for even more speed™️ you could use a laminate sheet and a whiteboard pen

#

no, it's quite small

vagrant idol
edgy burrow
#

i dont wanna work it out

vagrant idol
#

and I should do it in 7 mins for an exam

edgy burrow
#

if you do a quick readthrough of the code it should take less than 30 sec

#

because you don't need to figure out what it actually prints

#

it's enough to figure out which answers it doesn't print

vagrant idol
edgy burrow
#

no, it is not A uuh my bad

vagrant idol
#

Yes...

edgy burrow
#

i am dum dum

#

just to be sure that i understand the syntax they use here:
does for i <- 1, n mean the same thing as for(auto i = 1; i < n; i++)

edgy burrow
#

and they don't use zero based numbering notlikethis

#

so p and value are passed around as references, right?

#

what about i?

vagrant idol
#

this could make everything even more confusing

edgy burrow
#

if p is modified in an inner scope that affects p from where that function was called, right?

#

otherwise there would be no point in changing the value of p at the end of the algorithm

vagrant idol
#

Ok! I did it on paper (without the p referenced) and A answer is on line 9, not 10

edgy burrow
#

assuming no shenanigans you can figure out the order of k values that afisare is called at

vagrant idol
#
10000
12000
12300
12340
12345 - afisare
12340
12300
12304
12354 - afisare
12304
12300
12000
12030
12430
12435 - afisare
12030
12034
12534 - afisare
12034
12030
12000
12003
12403
12453 - afisare
12403
12003
12043
12543 - afisare
12043
12003
12000
10000
10200
13200
13240
13245 - afisare
13240
13200
13204
13254 - afisare
13204
13200
10200
10230
10234
15234 - afisare
#

@edgy burrow 😦

#

@oblique rain do you have any idea?

vagrant idol
vagrant idol
edgy burrow
#

👍

oblique rain
#

oh wait, one-based indexing

#

holy shit

edgy burrow
#

not only that, they mix if they pass by value or reference

#
1 2 3 5!4 
1 2 4 3 5!
1 2 5!3 4 
1 2 4 5!3 
1 2 5!4 3 
1 3 2 4 5!
1 3 2 5!4 
1 4 2 3 5!
1 5!2 3 4 ```
here you can see the pattern I mentioned more clearly
#

1 + 2 + 3 + 4 = 10

#

so you know where it will be when it will print

#

and you can figure out which way it took there

vagrant idol