UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Python Puzzle: Find The Checksum To Ensure Flawless Data Transfer

Logeswaran
03/01/2018 0 0
Find below the puzzle:
 
sampleInput='''5195 753 2468'''
  • The first item's(5195) largest and smallest values are 9 and 1, and their difference is 8.
  • The second item's(753) largest and smallest values are 7 and 3, and their difference is 4.
  • The third item's(2468) difference is 6.
In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
 
What is the checksum for the below puzzle input?
 
puzzleInput='''1364 461 1438 1456 818 999 105 1065 314 99 1353 148 837 590 404 123
204 99 235 2281 2848 3307 1447 3848 3681 963 3525 525 288 278 3059 821
280 311 100 287 265 383 204 380 90 377 398 99 194 297 399 87
7698 2334 7693 218 7344 3887 3423 7287 7700 2447 7412 6147 231 1066 248 208
3740 837 4144 123 155 2494 1706 4150 183 4198 1221 4061 95 148 3460 550
1376 1462 73 968 95 1721 544 982 829 1868 1683 618 82 1660 83 1778
197 2295 5475 2886 2646 186 5925 237 3034 5897 1477 196 1778 3496 5041 3314
179 2949 3197 2745 1341 3128 1580 184 1026 147 2692 212 2487 2947 3547 1120
460 73 52 373 41 133 671 61 634 62 715 644 182 524 648 320
169 207 5529 4820 248 6210 255 6342 4366 5775 5472 3954 3791 1311 7074 5729
5965 7445 2317 196 1886 3638 266 6068 6179 6333 229 230 1791 6900 3108 5827
212 249 226 129 196 245 187 332 111 126 184 99 276 93 222 56
51 592 426 66 594 406 577 25 265 578 522 57 547 65 564 622
215 2092 1603 1001 940 2054 245 2685 206 1043 2808 208 194 2339 2028 2580
378 171 155 1100 184 937 792 1436 1734 179 1611 1349 647 1778 1723 1709
4463 4757 201 186 3812 2413 2085 4685 5294 5755 2898 200 5536 5226 1028 180
'''
(Try to solve by yourself before see the solution available below)
 
Have you tried ? Wants to confirm the implementation? find below the solution(python program)
 
==============================================================
 
puzList=re.findall('[0-9]{1,6}',puzzleInput) 
#puzzleInput is the actual input(you can find from the question above)
print puzList
checksum=0
print puzList
for i in puzList:
    newList=[]
    for j in i:
        newList.append(int(j)) #newList=[1,3,6,4] in the first iteration
        checksum+=max(newList)-min(newList)

print checksum # output for the given input(puzzleInput)==>1311
==============================================================
0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Python Dictionary
Python dictionary is an unordered collection of items. While other compound datatypes have only value as an element, a dictionary has a key: value pair. Dictionaries are optimized to retrieve values when...

Machine Learning With Python
1. Course description: Machine Learning with Python has been designed for the provision of having strong hold in creating Machine learning algorithms with the base of Python. This has been preferred as...
J

The Zen of Python
Writing programs that actually do what they are supposed to do is just one component of being a good python programmer. It's also important to write clean code that is easily understood, even weeks after...

Different types of data in python3
Python3 features Numbers(int,float,complex), String, Lists, Tuples, Dictionary and Sets type of data. long interger type numbers from python2 is no longer required. Below are examples of all python3 data...

Bit-wise operators
Operation Syntax Function Bitwise And a & b and_(a, b) Bitwise Exclusive Or a ^ b xor(a, b) Bitwise Inversion ~ a invert(a) Bitwise Or a b or_(a, b) Left...
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more