Programming Puzzles
  • Introduction
  • CTCI
    • Arrays and Strings
      • Is Unique
      • Check Permutation
      • URLify
      • Palindrome Permutation
      • One Away
      • String Compression
      • Rotate Matrix
      • Zero Matrix
      • String Rotation
    • Linked Lists
      • Remove Dups
      • Return Kth to Last
      • Delete Middle Node
      • Sum Lists
      • Palindrome
      • Intersection
    • Trees
      • Route Between Nodes
      • Minimal Tree
      • Check Balanced
      • Build Order
      • First Common Ancestor
      • BST Sequences
      • Check Subtree
      • Random Node
    • Stacks and Queues
      • Three in One
      • Stack Min
      • Stack of Plates
      • Queue via Stacks
      • Sort Stack
    • Sorting and Searching
      • Sorted Merge
      • Group Anagrams
      • Search in Rotated Array
      • Sorted Search, No Size
      • Sparse Search
      • Sort Big File
      • Missing Int
      • Find Duplicates
      • Sorted Matrix Search
    • Bit Manipulation
      • Insertion
    • Math and Puzzles
      • Two Ropes
      • Nine Balls
      • The Heavy Pill
      • Basketball
      • Dominos
    • Recursion and Dynamic Programming
      • Triple Step
      • Robot in a Grid
      • Magic Index
      • Power Set
      • Recursive Multiply
      • Towers of Hanoi
      • Permutations without Dups
      • Parens
      • Paint Fill
      • Coins
    • Object Oriented Design
      • Circular Array
    • Moderate
      • Number Swapper
      • Word Frequencies
      • Intersection
      • Tic Tac Win
      • Factorial Zeros
      • Smallest Difference
      • Number Max
      • Operations
      • Living People
      • Diving Board
      • Bisect Squares
      • Best Line
      • Sub Sort
      • Contiguous Sequence
      • Pattern Matching
      • Pond sizes
      • T9
      • Sum Swap
      • Pairs with Sum
    • Hard
      • Add Without Plus
      • Shuffle
      • Random Set
      • Count of 25
      • Baby Names
      • Majority Element
      • Word Distance
      • The Masseuse
      • Word Transformer
      • Sparse Similarity
  • EoPI
    • Arrays and Strings
  • LeetCode
    • 3 Longest Substring Without Repeating Characters
    • 4 Median of Two Sorted Arrays
    • 5 Longest Palindromic Substring
    • 6 ZigZag Conversion
    • 7 Reverse Integer
    • 8 String to Integer (atoi)
    • 9 Palindrome Number
    • 11 Container With Most Water
    • 14 Longest Common Prefix
    • 15 3Sum
    • 16 3Sum Closest
    • 17 Letter Combinations of a Phone Number
    • 19 Remove Nth Node From End of List
    • 20 Valid Parentheses
    • 21 Merge Two Sorted Lists
    • 22 Generate Parentheses
    • 23 Merge k Sorted Lists
    • 24 Swap Nodes in Pairs
    • 26 Remove Duplicates from Sorted Array
    • 27 Remove Element
    • 28 Implement strStr()
    • 29 Divide Two Integers
    • 30 Substring with Concatenation of All Words
    • 32 Longest Valid Parentheses
    • 33 Search in Rotated Sorted Array
    • 34 Search for a Range
    • 35 Search Insert Position
    • 36 Valid Sudoku
    • 37 Sudoku Solver
    • 38 Count and Say
    • 40 Combination Sum II
    • 41 First Missing Positive
    • 42 Trapping Rain Water
    • 43 Multiply Strings
    • 44 Wildcard Matching
    • 45 Jump Game II
    • 46 Permutations
    • 48 Rotate Image
    • 49 Group Anagrams
    • 53 Maximum Subarray
    • 54 Spiral Matrix
    • 59 Spiral Matrix II
    • 62 Unique Paths
    • 64 Minimum Path Sum
    • 66 Plus One
    • 67 Add Binary
    • 68 Text Justification
    • 69 Sqrt(x)
    • 70 Climbing Stairs
    • 71 Simplify Path
    • 73 Set Matrix Zeroes
    • 74 Search a 2D Matrix
    • 75 Sort Colors
    • 80 Remove Duplicates from Sorted Array II
    • 83 Remove Duplicates from Sorted List
    • 90 Subsets II
    • 91 Decode Ways
    • 99 Recover Binary Search Tree
    • 100 Same Tree
    • 103 Binary Tree Zigzag Level Order Traversal
    • 104 Maximum Depth of Binary Tree
    • 105 Construct Binary Tree from Preorder and Inorder Traversal
    • 112 Path Sum
    • 114 Flatten Binary Tree to Linked List
    • 119 Pascal's Triangle II
    • 120 Triangle
    • 128 Longest Consecutive Sequence
    • 129 Sum Root to Leaf Numbers
    • 133 Clone Graph
    • 136 Single Number
    • 137 Single Number II
    • 138 Copy List with Random Pointer
    • 144 Binary Tree Preorder Traversal
    • 146 LRU Cache
    • 148 Sort List
    • 150 Evaluate Reverse Polish Notation
    • 155 Min Stack
    • 157 Read N Characters Given Read4
    • 161 One Edit Distance
    • 162 Find Peak Element
    • 163 Missing Ranges
    • 167 Two Sum II - Input array is sorted
    • 168 Excel Sheet Column Title
    • 170 Two Sum III - Data structure design
    • 173 Binary Search Tree Iterator
    • 186 Reverse Words in a String II
    • 189 Rotate Array
    • 199 Binary Tree Right Side View
    • 200 Number of Islands
    • 202 Happy Number
    • 207 Course Schedule
    • 210 Course Schedule II
    • 214 Shortest Palindrome
    • 216 Combination Sum III
    • 217 Contains Duplicate
    • 221 Maximal Square
    • 226 Invert Binary Tree
    • 227 Basic Calculator II
    • 228 Summary Ranges
    • 229 Majority Element II
    • 230 Kth Smallest Element in a BST
    • 234 Palindrome Linked List
    • 236 Lowest Common Ancestor of a Binary Tree
    • 237 Delete Node in a Linked List
    • 239 Sliding Window Maximum
    • 240 Search a 2D Matrix II
    • 242 Valid Anagram
    • 243 Shortest Word Distance
    • 245 Shortest Word Distance III
    • 246 Strobogrammatic Number
    • 247 Strobogrammatic Number II
    • 253 Meeting Rooms II
    • 255 Verify Preorder Sequence in Binary Search Tree
    • 256 Paint House
    • 258 Add Digits
    • 260 Single Number III
    • 261 Graph Valid Tree
    • 263 Ugly Number
    • 264 Ugly Number II
    • 266 Palindromic Permutation
    • 270 Closest Binary Search Tree Value
    • 271 Encode and Decode Strings
    • 277 Find the Celebrity
    • 279 Perfect Squares
    • 280 Wiggle Sort
    • 281 Zigzag Iterator
    • 283 Move Zeroes
    • 284 Peeking Iterator
    • 285 Inorder Successor in BST
    • 286 Walls and Gates
    • 288 Unique Word Abbreviation
    • 290 Word Pattern
    • 292 Nim Game
    • 293 Flip Game
    • 296 Best Meeting Point
    • 297 Serialize and Deserialize Binary Tree
    • 298 Binary Tree Longest Consecutive Sequence
    • 301 Remove Invalid Parentheses
    • 304 Range Sum Query 2D - Immutable
    • 310 Minimum Height Trees
    • 311 Sparse Matrix Multiplication
    • 312 Burst Balloons
    • 313 Super Ugly Number
    • 315 Count of Smaller Numbers After Self
    • 316 Remove Duplicate Letters
    • 317 Shortest Distance from All Buildings
    • 319 Bulb Switcher
    • 322 Coin Change
    • 323 Number of Connected Components in an Undirected Graph
    • 326 Power of Three
    • 330 Patching Arrays
    • 333 Largest BST Subtree
    • 334 Increasing Triplet Subsequence
    • 335 Self Crossing
    • 338 Counting Bits
    • 340 Longest Substring with At Most K Distinct Characters
    • 344 Reverse String
    • 345 Reverse Vowels of a String
    • 346 Moving Average from Data Stream
    • 347 Top K Frequent Elements
    • 349 Intersection of Two Arrays
    • 356 Line Reflection
    • 357 Count Numbers with Unique Digits
    • 359 Logger Rate Limiter
    • 361 Bomb Enemy
    • 362 Design Hit Counter
    • 366 Find Leaves of Binary Tree
    • 367 Valid Perfect Square
    • 369 Plus One Linked List
    • 379 Design Phone Directory
    • 387 First Unique Character in a String
    • 389 Find the Difference
    • 394 Decode String
    • 395 Longest Substring with At Least K Repeating Characters
    • 396 Rotate Function
    • 399 Evaluate Division
    • 403 Frog Jump
    • 404 Sum of Left Leaves
    • 406 Queue Reconstruction by Height
    • 409 Longest Palindrome
    • 417 Pacific Atlantic Water Flow
    • 418 Sentence Screen Fitting
    • 422 Valid Word Square
    • 425 Word Squares
    • 434 Number of Segments in a String
    • 435 Non-overlapping Intervals
    • 438 Find All Anagrams in a String
    • 441 Arranging Coins
    • 445 Add Two Numbers II
    • 453 Minimum Moves to Equal Array Elements
    • 476 Number Complement
    • 482 License Key Formatting
    • 494 Target Sum
    • 496 Next Greater Element I
    • 500 Keyboard Row
    • 503 Next Greater Element II
    • 505 The Maze II
    • 506 Relative Ranks
    • 507 Perfect Number
    • 513 Find Bottom Left Tree Value
    • 514 Freedom Trail
    • 517 Super Washing Machines
    • 523 Continuous Subarray Sum
    • 530 Minimum Absolute Difference in BST
    • 531 Lonely Pixel I
    • 534 Design TinyURL
    • 545 Boundary of Binary Tree
    • 551 Student Attendance Record I
    • 554 Brick Wall
    • 563 Binary Tree Tilt
    • 567 Permutation in String
    • 572 Subtree of Another Tree
    • 604 Design Compressed String Iterator
    • 605 Can Place Flowers
    • 606 Construct String from Binary Tree
    • 624 Maximum Distance in Arrays
    • 630 Course Schedule III
    • 652 Find Duplicate Subtrees
    • 654 Maximum Binary Tree
    • 657 Judge Route Circle
    • 665 Non-decreasing Array
    • 669 Trim a Binary Search Tree
    • 672 Bulb Switcher II
    • 677 Map Sum Pairs
    • 681 Next Closest Time
    • 684 Redundant Connection
    • 686 Repeated String Match
    • 690 Employee Importance
    • 692 Top K Frequent Words
    • 212 Word Search II
    • 360 Sort Transformed Array
    • 616 Add Bold Tag in String
    • 318 Maximum Product of Word Lengths
    • 341 Flatten Nested List Iterator
    • 272 Closest Binary Search Tree Value II
    • 56 Merge Intervals
    • 215 Kth Largest Element in an Array
    • 98 Validate Binary Search Tree
    • 351 Android Unlock Patterns
    • 289 Game of Life
    • 575 Distribute Candies
    • 47 Permutations II
    • 267 Palindrome Permutation II
    • 308 Range Sum Query 2D - Mutable
    • 348 Design Tic-Tac-Toe
    • 68 Text Justification
    • 125 Valid Palindrome
    • 139 Word Break
    • 661 Image Smoother
    • 485 Max Consecutive Ones
    • 208 Implement Trie (Prefix Tree)
    • 140 Word Break II
    • 487 Max Consecutive Ones II
    • 61 Rotate List
    • 498 Diagonal Traverse
    • 231 Power of Two
    • 520 Detect Capital
    • 473 Matchsticks to Square
    • 127 Word Ladder
    • 251 Flatten 2D Vector
    • 244 Shortest Word Distance II
    • 245 Shortest Word Distance III
    • 423 Reconstruct Original Digits from English
    • 676 Implement Magic Dictionary
    • 332 Reconstruct Itinerary
    • 718 Maximum Length of Repeated Subarray
    • 172 Factorial Trailing Zeroes
    • 713 Subarray Product Less Than K
    • 36 Valid Sudoku
    • 752 Open the Lock
    • 65 Valid Number
    • 760 Find Anagram Mappings
    • 582 Kill Process
    • 594 Longest Harmonious Subsequence
    • 581 Shortest Unsorted Continuous Subarray
    • 599 Minimum Index Sum of Two Lists
    • 635 Design Log Storage System
    • 642 Design Search Autocomplete System
    • 379 Design Phone Directory
    • 295 Find Median from Data Stream
    • 232 Implement Queue using Stacks
    • 383 Ransom Note
    • 278 First Bad Version
    • 206 Reverse Linked List
    • 787 Cheapest Flights Within K Stops
    • 818 Race Car
    • Categorical
    • Array and Strings
      • Max Avg Number
      • Circular Array Cycle
      • Molecular Weight
      • Itoa
      • Average GPA
      • In Fibonacci Sequence
      • Shortest Rotated Distance
      • Sub-array Factor
      • Matrix Convolution
      • Add One to Array
      • Sum Two Arrays
      • Array Transformation
      • Unique Sub Arrays
      • Reverse and Simplify String
      • Reverse String
      • Information Masking
      • Minimum Array Reduction
      • Add Numbers in Unclean Data
      • Array Operations
      • Equilibrium Index
      • Visit All Places in Minimum Time
    • Linked List
      • Double Linked List Connected Components
    • Trees and Graphs
      • Directory Sum
      • Largest Subtree
      • Shortest Path DAG Source to Sink
      • HTML Parser
      • Infix to Postfix Expression Evaluater
      • Longest Path in Undirected Acyclic Graph
      • Decompress String
      • Pythagoras Tree
      • Kings
      • All Paths
      • Leaf Nodes
      • Proper Locking
      • Number of Cities at each Distance
      • Root Path as DLL
      • Binary Replacement
      • All Root to Leaf Paths
    • Recursion and Dynamic Programming
      • Recursive to_string
      • N Loop
      • Divisible by Set
      • Brute Force Seam Carving
      • Perimeter Island
      • Knight on a Phone
      • Coin Change Problem
      • Maximum Product in Matrix
      • Largest Sum of a Path in a Triangle
      • Linked List Tree
    • Sorting and Searching
      • Three Highest Numbers
      • Common Elements in Sorted Arrays
      • Inverse Spiral Matrix
      • Number Negatives in Sorted Matrix
      • Number of Bombs in Minesweeper
      • Two Sum Less Than
      • Frequency Compression
      • N Closest Points
      • Find Sum Pairs
      • Max with no Comparitor
      • Largest Subarray
      • Single Missing Number
      • Ternary Search
      • Fastest Frog Jump
    • Design
      • Random Hash DS
      • Road Trip
      • Load Balancer
      • Haircut Appointment Scheduler
      • Conway's Game of Life
      • Design Twitter
      • LogParser
      • Permission Management for a General Tree
      • Max Stack
      • Parking Lot
    • Probability
      • Simplified Blackjack
      • Rand7
      • Shuffle
    • Combinatorics
      • Binary Permutation
      • N Queens
      • Prefix Permutation
    • Mathematics
      • Angle Between Time
      • Line Segment Intersection
      • Maximum Points View Angle
      • Collatz Conjecture
      • Convex Hull
      • Swap In Place
      • Powers of 2
      • Monte Carlo Approximation of PI
      • Perfect Power
      • Derivative of a Polynomial
    • Bit Manipulation
      • Reverse Binary
    • Cryptography
      • Message Encyption and Decryption
      • Encryption
    • Other
      • Maximum Time Combination
      • Polish Notation String Calculator
  • Competition
    • CodeDavis
  • Project Eular
    • 1 Multiples of 3 and 5
    • 2 Even Fibonacci numbers
    • 3 Largest Prime Factor
    • 4 Largest Palindrome Product
    • 5 Smallest Multiple
    • 6 Sum Square Difference
    • 7 10001st Prime
    • 8 Largest Product in a Series
    • 9 Special Pythagorean Triplet
    • 10 Summation of Primes
    • 11 Largest Product in a Grid
    • 12 Highly Divisible Triangular Number
    • 13 Large Sum
    • 14 Longest Collatz Sequence
    • 15 Lattice Paths
    • 16 Power Digit Sum
    • 17 Number Letter Counts
    • 18 Maximum path sum I
    • 19 Counting Sundays
Powered by GitBook
On this page
  • 13 Large Sum
  • 13 Large sum

Was this helpful?

  1. Project Eular

13 Large Sum

13 Large Sum

13 Large sum

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.

        37107287533902102798797998220837590246510135740250
        46376937677490009712648124896970078050417018260538
        74324986199524741059474233309513058123726617309629
        91942213363574161572522430563301811072406154908250
        23067588207539346171171980310421047513778063246676
        89261670696623633820136378418383684178734361726757
        28112879812849979408065481931592621691275889832738
        44274228917432520321923589422876796487670272189318
        47451445736001306439091167216856844588711603153276
        70386486105843025439939619828917593665686757934951
        62176457141856560629502157223196586755079324193331
        64906352462741904929101432445813822663347944758178
        92575867718337217661963751590579239728245598838407
        58203565325359399008402633568948830189458628227828
        80181199384826282014278194139940567587151170094390
        35398664372827112653829987240784473053190104293586
        86515506006295864861532075273371959191420517255829
        71693888707715466499115593487603532921714970056938
        54370070576826684624621495650076471787294438377604
        53282654108756828443191190634694037855217779295145
        36123272525000296071075082563815656710885258350721
        45876576172410976447339110607218265236877223636045
        17423706905851860660448207621209813287860733969412
        81142660418086830619328460811191061556940512689692
        51934325451728388641918047049293215058642563049483
        62467221648435076201727918039944693004732956340691
        15732444386908125794514089057706229429197107928209
        55037687525678773091862540744969844508330393682126
        18336384825330154686196124348767681297534375946515
        80386287592878490201521685554828717201219257766954
        78182833757993103614740356856449095527097864797581
        16726320100436897842553539920931837441497806860984
        48403098129077791799088218795327364475675590848030
        87086987551392711854517078544161852424320693150332
        59959406895756536782107074926966537676326235447210
        69793950679652694742597709739166693763042633987085
        41052684708299085211399427365734116182760315001271
        65378607361501080857009149939512557028198746004375
        35829035317434717326932123578154982629742552737307
        94953759765105305946966067683156574377167401875275
        88902802571733229619176668713819931811048770190271
        25267680276078003013678680992525463401061632866526
        36270218540497705585629946580636237993140746255962
        24074486908231174977792365466257246923322810917141
        91430288197103288597806669760892938638285025333403
        34413065578016127815921815005561868836468420090470
        23053081172816430487623791969842487255036638784583
        11487696932154902810424020138335124462181441773470
        63783299490636259666498587618221225225512486764533
        67720186971698544312419572409913959008952310058822
        95548255300263520781532296796249481641953868218774
        76085327132285723110424803456124867697064507995236
        37774242535411291684276865538926205024910326572967
        23701913275725675285653248258265463092207058596522
        29798860272258331913126375147341994889534765745501
        18495701454879288984856827726077713721403798879715
        38298203783031473527721580348144513491373226651381
        34829543829199918180278916522431027392251122869539
        40957953066405232632538044100059654939159879593635
        29746152185502371307642255121183693803580388584903
        41698116222072977186158236678424689157993532961922
        62467957194401269043877107275048102390895523597457
        23189706772547915061505504953922979530901129967519
        86188088225875314529584099251203829009407770775672
        11306739708304724483816533873502340845647058077308
        82959174767140363198008187129011875491310547126581
        97623331044818386269515456334926366572897563400500
        42846280183517070527831839425882145521227251250327
        55121603546981200581762165212827652751691296897789
        32238195734329339946437501907836945765883352399886
        75506164965184775180738168837861091527357929701337
        62177842752192623401942399639168044983993173312731
        32924185707147349566916674687634660915035914677504
        99518671430235219628894890102423325116913619626622
        73267460800591547471830798392868535206946944540724
        76841822524674417161514036427982273348055556214818
        97142617910342598647204516893989422179826088076852
        87783646182799346313767754307809363333018982642090
        10848802521674670883215120185883543223812876952786
        71329612474782464538636993009049310363619763878039
        62184073572399794223406235393808339651327408011116
        66627891981488087797941876876144230030984490851411
        60661826293682836764744779239180335110989069790714
        85786944089552990653640447425576083659976645795096
        66024396409905389607120198219976047599490197230297
        64913982680032973156037120041377903785566085089252
        16730939319872750275468906903707539413042652315011
        94809377245048795150954100921645863754710598436791
        78639167021187492431995700641917969777599028300699
        15368713711936614952811305876380278410754449733078
        40789923115535562561142322423255033685442488917353
        44889911501440648020369068063960672322193204149535
        41503128880339536053299340368006977710650566631954
        81234880673210146739058568557934581403627822703280
        82616570773948327592232845941706525094512325230608
        22918802058777319719839450180888072429661980811197
        77158542502016545090413245809786882778948721859617
        72107838435069186155435662884062257473692284509516
        20849603980134001723930671666823555245252804609722
        53503534226472524250874054075591789781264330331690
#include <iostream>
#include <limits>
#include <fstream>
#include <vector>

using namespace std;

void pause() { cin.ignore(numeric_limits<streamsize>::max(), '\n'); }

// METHOD: Read the file, and store each number seperately reletive to their base. That way, I can then add each base respectively.



//vector<vector<long long int>> readFile()
void readFile()
{
    int numberQuantity = 100;
    int numberofDigitsPerNumber = 50;
    int nextSeekgPosition = numberofDigitsPerNumber;

    ifstream inFile;
    inFile.open("problem13.txt", ifstream::binary);

    if (inFile.fail())
    {
        cout << "Failed to open" << endl;
    }

    else if (inFile.is_open())
    {
        inFile.seekg(nextSeekgPosition - 1, ios::beg);
    }

    vector <char> vectorCurrentBase;
    vector < vector<char>> vectorBases;
    int getNextDigitCounter = 0;
    bool finishedReadingFile = false;

    while (!finishedReadingFile)
    {

        while (inFile.good()) // checks all flags
        {
            vectorCurrentBase.push_back(inFile.get());
            nextSeekgPosition += numberofDigitsPerNumber + 2; //+2 to ignore additional spaces
            inFile.seekg(nextSeekgPosition - 1, ios_base::beg);

        }

        vectorBases.push_back(vectorCurrentBase);
        vectorCurrentBase.clear();
        getNextDigitCounter++;
        nextSeekgPosition = numberofDigitsPerNumber - getNextDigitCounter; // The first digit does not have a space.

        if (getNextDigitCounter > numberQuantity - 1) finishedReadingFile = true;
    }
    //for (int i = 0; i < vectorBases.size(); i++)
    //{
    //    for (int j = 0; j < vectorBases[i].size(); j++)
    //    {
    //        cout << vectorBases[i][j] << " ";
    //        pause();
    //    }
    //    cout << "next line!";
    //}
    //cout << "done!";

    for (auto &x : vectorBases)
    {
        for (auto &y : x)
        {
            cout << y << endl;
        }
        cout << "next line!";
    }
    cout << "done";

    //for (int i = 0; i < vectorCurrentBase.size(); i++)
    //{
    //    if (isspace(vectorCurrentBase[i]))
    //    {
    //        cout << "space!" << endl;
    //    }
    //    else
    //    {
    //        cout << vectorCurrentBase.at(i) << " ";
    //    }
    //    pause();

    pause();

}



//5537376230
int main()
{
    //vector<vector<long long int>> readFile();
    readFile();


}

// Check if space:
/*
if (isspace(vectorCurrentBase[baseCounter]))
{
cout << "space";
}
intNumber = charNumber - '0';
*/

// Print out single array
/*



*/
Previous12 Highly Divisible Triangular NumberNext14 Longest Collatz Sequence

Last updated 5 years ago

Was this helpful?