You can become a serverless blackbelt. Enrol in my course Learn you some Lambda best practice for great good! and learn best practices for performance, cost, security, resilience, observability and scalability. By the end of this course, you should be able to make informed decisions on which AWS service to use with Lambda and how to build highly scalable, resilient and cost efficient serverless applications.
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …
By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
Using words.txt (right click and ‘Save Link/Target As…’), a 16K text file containing nearly two-thousand common English words, how many are triangle words?
open System.IO // read the content of the file into an array of words let words = File.ReadAllLines (@"C:\TEMP\words.txt") |> Array.map (fun s -> s.Replace("\"", "")) |> Array.collect (fun s -> s.ToUpper().Trim().Split(',')) // function to calculate the word value of a word let wordValue word = word.ToString().ToCharArray() |> Array.map (fun c -> int(c) - int('A') + 1) |> Array.sum // convert all words to their corresponding word values let wordValues = words |> Array.map wordValue let maxWordValue = wordValues |> Array.max // the sequence of triangle numbers let naturalNumbers = Seq.unfold (fun state -> Some(state, state + 1)) 1 let T n = n * (n + 1) / 2 let TSeq = naturalNumbers |> Seq.map T let answer = TSeq |> Seq.takeWhile (fun t -> t <= maxWordValue) |> Seq.map (fun t -> wordValues |> Array.filter (fun n -> n = t) |> Array.length) |> Seq.sum
To get started on this problem, I first read all the words in the downloaded text file into an array of strings, each being one of the two thousand words. Then I build a function to calculate the word value of a word and converted the word array into an array of word values. The max word value is useful here because it allows me to cap how many elements in the T sequence I should check.
I specialise in rapidly transitioning teams to serverless and building production-ready services on AWS.
Are you struggling with serverless or need guidance on best practices? Do you want someone to review your architecture and help you avoid costly mistakes down the line? Whatever the case, I’m here to help.
Check out my new podcast Real-World Serverless where I talk with engineers who are building amazing things with serverless technologies and discuss the real-world use cases and challenges they face. If you’re interested in what people are actually doing with serverless and what it’s really like to be working with serverless day-to-day, then this is the podcast for you.
Check out my new course, Learn you some Lambda best practice for great good! In this course, you will learn best practices for working with AWS Lambda in terms of performance, cost, security, scalability, resilience and observability. We will also cover latest features from re:Invent 2019 such as Provisioned Concurrency and Lambda Destinations. Enrol now and start learning!
Check out my video course, Complete Guide to AWS Step Functions. In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. There is something for everyone from beginners to more advanced users looking for design patterns and best practices. Enrol now and start learning!
Are you working with Serverless and looking for expert training to level-up your skills? Or are you looking for a solid foundation to start from? Look no further, register for my Production-Ready Serverless workshop to learn how to build production-grade Serverless applications!
Here is a complete list of all my posts on serverless and AWS Lambda. In the meantime, here are a few of my most popular blog posts.
- Lambda optimization tip – enable HTTP keep-alive
- You are wrong about serverless and vendor lock-in
- You are thinking about serverless costs all wrong
- Just how expensive is the full AWS SDK?
- Many faced threats to Serverless security
- We can do better than percentile latencies
- Yubl’s road to Serverless
- AWS Lambda – should you have few monolithic functions or many single-purposed functions?
- AWS Lambda – compare coldstart time with different languages, memory and code sizes
- Guys, we’re doing pagination wrong
- Top 10 Serverless framework best practices