F# solution to Ayande’s tax calculation challenge
Ayande posted a tax calculation challenge the other day here, and here’s my F# solution for the challenge: Enjoy!
Ayande posted a tax calculation challenge the other day here, and here’s my F# solution for the challenge: Enjoy!
When you consider the age old problem of representing different shapes (circle, triangle, square, rectangle, etc.) my OO fed developer brain naturally jumps to a class hierarchy along the line of: This is perfectly fine and legit, but it’s not the only way to approach things. Since I’ve been on a more varied diet of …
F# – Use Discriminated Unions instead of class hierarchies Read More »
C# developers should be familiar with the yield keyword that was introduced in C# 2.0, and you’ll be pleased to know that F# also has the yield keyword which works in conjunction with F#’s equivalent of IEnumerable – sequences. You can create sequences in F# using sequence expressions: In addition, you can also use the …
In F#, you can defined record types which differ from tuples and discriminated unions in that they allow you to organize values into a type and name those values through fields: Looks like a cut-down version of a standard .Net class with a couple of properties? Yes they do, but records offer several advantages over …
I’m taking a bit of time to brush up my knowledge of F# and see if I can write better F# code and one of the things I notice is that whilst I use pipe-forward operator (|>) often when working with collections I don’t nearly use the pipe-backward operator (<|) as frequently as I should. …
After reading Ayende‘s post today, it got me thinking, just exactly what’s the cost of a try/catch block and more importantly what’s the cost of throwing exceptions. Like Ken Egozi mentioned in the comments, I too believe the test was unfair as the try/catch block was applied to the top level code as opposed to …
Problem Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107. A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR …
Problem A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317. The text file, keylog.txt, contains fifty successful login attempts. Given that …
Problem Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbersreversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either …
Problem The number 145 is well known for the property that the sum of the factorial of its digits is equal to 145: 1! + 4! + 5! = 1 + 24 + 120 = 145 Perhaps less well known is 169, in that it produces the longest chain of numbers that link back to …
By continuing to use the site, you agree to the use of cookies. more information
The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.