last day (15 days later) » 

01:37
-5
Q: How can i reduce this function code down to, maximum 25 lines?

MazeoI for a reason need to reduce the length of my function down to maximum 25 lines. I can only use the write function I can't use for I can't do multiple stuff at the same line (example a[0] = 0;a[1] = 1;a[2] = 2;) I can't delete current newlines I can't declare and assign a var in the same li...

can you do a[0] = 0, a[1] = 1, a[2] = 2; ?
Or int a[]={0,1,2};.
also a[2] = a[2] + 1; can be written as a[2]++;
What this code is supposed to do anyway?
@EugeneSh. Nope I can't
@dangee1705 i know, for the increment, i just forgot, thanks for the reminder. But what you proposed is not allowed
01:37
Is this a homework assignment? I'd like to talk to your tutor ;). Readability is more important than number of lines.
Anyway, this code has a predetermined output. You can simply run it as is, get this output and write another program printing it without any calculations.
This is homework yeah, but it's done on purpose, it's the standard of the school, done in purpose to make it harder
@EugeneSh. I have to upload a single function to do the whole job
@WumpusQ.Wumbley I guess a can be defined as char. Then all the writes can be squashed into one.
@EugeneSh.could you give me the write sentence to do so ? please
"All the different combinations of numbers" is an infinite set, is it not?
01:37
The requirements are moot. "int a[]={0,1,2}; - I can't" Why? Which rule prevents that? "I can't delete current newlines" What do you mean?
@HolyBlackCat Sorry i forgot to mention that I can't declare and assign a var in the same line... corrected it
@Mazeo I hope that the purpose of the assignment is a demonstration of how focusing on arbitrary rules can lead to worse code.
What Is it supposed to do?
Before we talk about minifying the code, are you sure it works as intended? I see a bunch of commas in the output, and that's all.
never have I missed for loops so much
01:37
All combinations of numbers is infinite.
Assignments like these are the pedagogical equivalent of hazing.
@AndrewHenle: Stop with rants about how code ought to be written. The assignment is not teaching students to write this way. And it says not to cram operations onto one line, so you misread it. There is a purpose to introducing artificial constraints on exercises, not code for deployment. It is the same reason humans do weight training on machines even though those exercises are not real-world work, and the reason why children learning to write practice repetitious or arbitrary sequences of letters even though nobody wants a document with those sequences.
Nobody learns a skill fully formed. Human brains learn by practicing parts (as part of a regime that includes more comprehensive exercises over time). We practice elementary physics questions before tackling systems. Introducing artificial constraints forces a student to think about things in ways they might not have previously, thus giving them mental exercise they might not have gotten another way and forming more connections. There is nothing unreasonable about posing exercises with constraints that are not suitable for deployed software.
Thanks ! @EricPostpischil
@AndrewHenle: Comparing with a time constraint is a bad analogy. That forces a person to use existing skill and knowledge—they do not have time to consider anything else. A length constraint is different. First, the student has time. That means they can ponder and research alternatives. Second, it forces the student to think: What alternative ways can I do this? What do I know about various operators? How can I use them differently than I used them previously? In order to have a worthwhile opinion on something, you need to actually understand it, not respond with knee-jerk reflexes.

last day (15 days later) »