Alex Martinez

Feb 21, 20232 min

DataWeave programming challenge #1: Add numbers separated by paragraphs and get the max number

Updated: Aug 31, 2023


Other posts from this series:

  1. DataWeave programming challenge #1: Add numbers separated by paragraphs and get the max number

  2. DataWeave programming challenge #2: Rock Paper Scissors game score system

  3. DataWeave programming challenge #3: Count palindrome phrases using the Strings module

  4. DataWeave programming challenge #4: Solve the Tower of Hanoi mathematical puzzle

  5. DataWeave programming challenge #5: Reverse a phrase's words, but keep the punctuation

  6. DataWeave programming challenge #6: Using tail-recursion to get the factorial of a number

  7. DataWeave programming challenge #7: Modify certain values from a JSON structure

  8. DataWeave programming challenge #8: Sum all digits to get a 1-digit number


In this post:

  • Input

  • Explanation of the problem

  • Expected output

  • Clues

  • Answer


This challenge is based on Advent of Code 2022 day 1

Try to solve this challenge on your own to maximize learning. We recommend you refer to the DataWeave documentation only. Try to avoid using Google or asking others so you can learn on your own and become a DataWeave expert!

Input

Consider the following input payload (can be of txt format):

1
 
2
 

 
3
 
4
 
5
 
0
 

 
15
 

 
20
 
5
 
1
 
3
 

 
25
 

 
6
 
4
 
4

Explanation of the problem

Create a DataWeave script to add all the numbers separated by a paragraph.

For example,

  • the first number would be 3 (2 + 1),

  • the second number would be 12 (3 + 4 + 5 + 0),

  • the third number would be 15, and so on.

After that, retrieve the highest number.

(Using code, not manually 😉)

Expected output

In this case, the expected output would be:

29

Clues

If you're stuck with your solution, feel free to check out some of these clues to give you ideas on how to solve it!

Answer

If you haven't solved this challenge yet, we encourage you to keep trying! It's ok if it's taking longer than you thought. We all have to start somewhere ✨ Check out the clues and read the docs before giving up. You got this!! 💙

There are many ways to solve this challenge, but you can find here some solutions we are providing so you can compare your result with us.

Feel free to comment your code below for others to see! 😄

Did you like this challenge?? Let us know what you think!! 👇

Subscribe to receive notifications as soon as new content is published ✨

    163920
    11