Question regarding CIS 194 Homework Assignment 1

My apologies, this is only tangentially related to Haskell and I am not looking for a solution. I am confused with the assignment itself and hence asking here. The assignment (https://www.seas.upenn.edu/~cis194/spring13/hw/01-intro.pdf) says: ====== BEGIN Double the value of every second digit beginning from the right. That is, the last digit is unchanged; the second-to-last digit is dou- bled; the third-to-last digit is unchanged; and so on. For example, [1,3,8,6] becomes [2,3,16,6] Add the digits of the doubled values and the undoubled dig- its from the original number. For example, [2,3,16,6] becomes 2+3+1+6+6 = 18 ======== END Firstly, I am confused as to how the doubled values are being added to the undoubled number in the above example. It looks like only the individual numbers of the doubled values are being added Secondly, later on in the assignment: ======== BEGIN Example : validate 4012888888881881 = True Example : validate 4012888888881882 = False ========= END If we are to follow the algorithm described (double the value of "every second digit" beginning from the right, last digit unchanged", then the above numbers are identical EXCEPT For the last digits (1 and 2) Any help is appreciated in decoding these instructions. Again please do not provide Haskell code, since I want to attempt to write it myself. I am just looking for help with the algorithm. Regards,

Hey,
Firstly, I am confused as to how the doubled values are being added to the undoubled number in the above example. It looks like only the individual numbers of the doubled values are being added
The assignment states "Add the *digits* of the doubled values and the undoubled digits", so it specifically states to add digits (which are 0 1 2 3 ... 9) and that is why when you have [2, 3, 16, 6] you do not simply do 2 + 3 + 16 + 6 but you do it digit wise 2 + 3 + 1 + 6 + 6. That is [2, 3, 16, 6] becomes "23166" and you simply sum all the digits.
If we are to follow the algorithm described (double the value of "every second digit" beginning from the right, last digit unchanged", then the above numbers are identical EXCEPT For the last digits (1 and 2)
The assignment states "Add the digits of the doubled values *and the
undoubled digits*", so the sum will be different for the two numbers
provided in the example because both doubled and undoubled values (their
digits actually) are being summed. That is why for the first number
validates gives True and for the other it gives False.
Hope that was clear enough for you to understand. You got confused by a
single sentence in the assignment.
Konstantin
On Wed, May 20, 2015 at 2:47 PM, Vaibhav Goel
My apologies, this is only tangentially related to Haskell and I am not looking for a solution. I am confused with the assignment itself and hence asking here.
The assignment (https://www.seas.upenn.edu/~cis194/spring13/hw/01-intro.pdf) says:
====== BEGIN Double the value of every second digit beginning from the right. That is, the last digit is unchanged; the second-to-last digit is dou- bled; the third-to-last digit is unchanged; and so on. For example, [1,3,8,6] becomes [2,3,16,6]
Add the digits of the doubled values and the undoubled dig- its from the original number. For example, [2,3,16,6] becomes 2+3+1+6+6 = 18 ======== END
Firstly, I am confused as to how the doubled values are being added to the undoubled number in the above example. It looks like only the individual numbers of the doubled values are being added
Secondly, later on in the assignment:
======== BEGIN Example : validate 4012888888881881 = True Example : validate 4012888888881882 = False
========= END
If we are to follow the algorithm described (double the value of "every second digit" beginning from the right, last digit unchanged", then the above numbers are identical EXCEPT For the last digits (1 and 2)
Any help is appreciated in decoding these instructions. Again please do not provide Haskell code, since I want to attempt to write it myself. I am just looking for help with the algorithm.
Regards, _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (2)
-
Konstantin Saveljev
-
Vaibhav Goel