algorithm

How to process a Scala String one character at a time

This is a page from my book, Functional Programming, Simplified

Tail-Recursive Algorithms in Scala

“Tail recursion is its own reward.”

From the “Functional” cartoon on xkcd.com.

Goals

The main goal of this lesson is to solve the problem shown in the previous lessons: Simple recursion creates a series of stack frames, and for algorithms that require deep levels of recursion, this creates a StackOverflowError (and crashes your program).

This is a page from my book, Functional Programming, Simplified

Recursion: Thinking Recursively

“To understand recursion,
one must first understand recursion.”

Stephen Hawking

Goal

This lesson has one primary goal: to show that the thought process followed in writing the sum function follows a common recursive programming “pattern.” Indeed, when you write recursive functions you’ll generally follow the three-step process shown in this lesson.

This is a page from my book, Functional Programming, Simplified

Functional Programming is Like Unix Pipelines

“Pipes facilitated function composition on the command line. You could take an input, perform some transformation on it, and then pipe the output into another program. This provided a very powerful way of quickly creating new functionality with simple composition of programs. People started thinking how to solve problems along these lines.”

Alfred Aho, one of the creators of the AWK programming language, in the book, Masterminds of Programming

A Java method to calculate the NFL Passer Rating

Note: The code below is based on the Wikipedia formula, which is not correct. The correct algorithm seems to be at this page. I’ll update the code below once I verify this for sure.

In working on my “XO Play” Android football game, I just created this Java method to calculate the NFL Passer Rating for my quarterbacks: