Creative Problem Solving

Coding is only one half of programming. Unfortunately with most programming classes only that half is being taught and the other half of programming never gets mentioned. As a result there are lots of programs written that work but which are extremely inefficient.

I have recently been looking at the sorts of questions being asked as homework for JavaScript classes and writing articles that highlight the difference between the historical JavaScript code that the teacher expects to be used for the answer and alternative ways the question could be answered using modern JavaScript. In my search for such questions I came across the following one which, rather than indicating that the JavaScript course was teaching outdated coding techniques, clearly demonstrates how the creative problem solving half of programming is being completely overlooked in many programming courses.

The question: was “Write a JavaScript program that accepts two numbers as input from the user and computes the sum of all integers between those two numbers including the two inputs.” and the person asking for help with that homework was asking what type of loop to use to do the calculation.

Of course a loop isn’t required to answer that question as the answer can be derived directly from the numbers at either end of the sequence.

sumRange = function(x, y) {return (y-x+1)/2*(x+y);}

Now of course this solution requires that x be less than or equal to y but so would any solution involving a loop. This solution is also more efficient for any case where the end points of the range are not equal.

Why that the creative problem solving half of programming is omitted from so many programming courses? Is it because teaching the creative half of programming is too difficult and so the courses concentrate on the easier part where strict rules apply? Can the creative problem solving part of programming actually be taught or is it a talent that tsome people are born with?

From my point of view, I agree that teaching concepts are well out of date and I too have seen examples that hail back to the 80’s.

With regards to teaching the creative side, this is something that IMHO has to evolve of its own accord, like teaching a dog new tricks, you have to have persistence in training and the same applies to programming where the student has to have persistence and to keep on learning.

The other side of the coin, some people are very adept at picking up new skills effortlessly and are more inclined to try things rather than ask if something is possible, they will try and then ask why something doesn’t work as they thought.

Given the right environment, people can be creative with creations, it does rely on your interests in the subject like art and artists, you have people who are creative artists and with coding you have coders that are creative with coding.

You do have more commonly an element where individuals have neither an interest or creative spark in them, these are the consumers who are the audience who criticize how crap something is and that things could be better and no matter how creative you are and cater for their needs, its still crap. There’s no pleasing some people.

I can’t do math. I count on my fingers to add stuff, or do things the long way I was rote-taught in school to do on paper, and even after years of wearing an analog watch, still count minutes because I still, after 30 years of practice, suck at telling time.

There’s creative thinking, and there’s being able to do math. If the student asking about “which for loop?” had known and understood math, then that student might have asked about javascript syntax for doing that kind of math. I think there’s a difference between the two because if the basic knowledge isn’t there then the most creative student in the world will, indeed, come up with a very creative, though likely cumbersome, bizaare, hard to read/maintain and innefficient, solution.

You oughtta see some of the garbage I’ve creatively come up with over the years to do what was probably just simple math to people who know simple math.

sumRange = function(x, y) {return (y-x+1)/2*(x+y);}

I found your formula (y-x+1)/2*(x+y) very interesting, so I did some research to find that it is a special case of a more general summation formula
(n=number of terms)/2 (2(x=first term)+((n=number of terms)-1)*(d=difference between terms))

In your formula d=difference between terms =1 and (y-x+1) is the number of terms. As expected, it fails when the difference between terms is other than 1.

The more general formula can be written as a javascript function with three inputs

function sumIt(n,x,d) { return n/2 *(2*x+(n-1)*d); }  

These are the results where
n= number of terms to be summed
x= the first term of the series
d= the common difference between terms

Positive integers, difference of 1
sumIt(3, 1, 1) = 6; or 1 + 2 + 3
sumIt(4, 1, 1) = 10; or 1 + 2 + 3 + 4

Positive integers, difference of 2
sumIt(3, 1, 2) = 9; or 1 + 3 + 5
sumIt(4, 1, 2) = 16; or 1 + 3 + 5 + 7

Positive and negative integers, difference of 2
sumIt(5, -1, 2) = 15; or -1 + 1 + 3 + 5 + 7

Positive and negative integers and npn-integers, difference of +0.5
sumIt(5, 1, 0.5) = 10; or 1.0 + 1.5 + 2.0 + 2.5 + 3.0
sumIt(6, -2.0, 0.5) = -4.5; or -2.0 + -1.5 + -1.0 + -0.5 + 0 + 0.5

I still think a loop is easier. :slight_smile: