hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

So long, and thanks for all the F#

Some notes about using F# in ProjectEuler

(After a long hiatus of just lurking and posting to the forums, I am trying to start blogging again.)

Like many people, I recently discovered http://projecteuler.net.  The site contains a set of mathematically oriented programming problems that get progressively harder.  I started solving them using F#.  While doing so, I've come up with some comments on how F# is really good for these kinds of problems and some improvements that would be nice and probably applicable to more general kinds of programs.

  1. BigInt rules!  Since a lot of the problems are calculations on large integers, it is nice to have them available.  It would be nice if there was a "bigint" equivalent to the "int" and "float" functions to simplify conversions.  It would be really nice if there was a way to override the default numeric behavior of assuming that every number is an int;  it would be nice to be able to switch to "float" or "bigint" mode and have the type checker make the appropriate assumptions.
  2. A minor nit, but it would be nice to have a predefined identity function.  I seem to have one in each program I write (even beyond ProjectEuler).
  3. For most of the problems, I'd create a sequence expression with individual calculations and then aggregate the desired result after filtering.  This demonstrated the convenience of sequence comprehensions, but we already knew that :-)
  4. I tried to avoid "normal" imperative for and while loops and created new helper functions to work on sequences:  seqUntil and seqWhile would process a sequence depending on a boolean function, seqAll would see if a function was true for all values in a sequence (the counterpart to Seq.exists), seqSkip would remove the first n entries in a sequence (really creative name, there :-),  etc.  I think that a lot of these functions, especially the ones that are in the Haskell Prelude for lists, would be good additions to the Seq module.
  5. It would be nice to have some of the aggregation operations be representable in the comprehension language.  This has been described Simon Peyton-Jones and Phil Wadler in Comprehensive Comprehensions for Haskell and should be applicable to F# as well.
  6. I've noticed that I mix the sequence comprehension syntax with the "old-style" pipeline syntax a lot, even when the function could be done in a sequence comprehension.  Looking back, it seems that if I am exploring (ok, guessing) a solution incrementally, it is easier to do that by adding new Seq.map, Seq.filter, or Seq.fold functions at the end with "|>" while running each step in fsi.  Would it help if there was a way to run and augment sequence comprehensions incrementally in fsi?  If I knew the path to the solution(or subsolution), I would choose to use the comprehension syntax first.
  7. While there seems to have been an interest in having F# be an alternative to Matlab for some kinds of engineering computing, I think that it could give Mathematica a run for its money in the computational and presentation space.  Adding full symbolic math support would be nice, but a harder challenge...

It has been a fun diversion to work on these problems, and interesting to see how concise the F# solutions are compared to the other languages represented.  The solutions in J are always the smallest, but I haven't grokked the syntax to understand the solutions yet :-)  The assembly language solutions are always interesting to read, but it is nice to see F# solutions that are as concise as the Ruby and Python solutions but running much faster...

 

Published Monday, January 14, 2008 9:20 PM by LewisBruck

Comments

 

EquMath: Math Lessons » Blog Archive » Some notes about using F# in ProjectEuler said:

January 15, 2008 2:56 AM
 

Lab49 Blog » Blog Archive » Experimental Feature in F# said:

January 29, 2008 9:40 PM
 

http://cs.hubfs.net/blogs/solong/archive/2008/01/14/4561.aspx said:

March 23, 2008 12:25 AM
 

projecteuler said:

May 24, 2008 1:49 PM
 

Cooling System Ford E150, 2003 E150 Tailgate Cap said:

May 20, 2010 10:52 AM
 

Ford Pinto Radiator Brake Disc, Pinto Episode Used Chevrolet said:

May 20, 2010 12:42 PM
 

Jeep Grand Wagoneer Headlight Assembly Replacement Tail Light, New Grand Wagoneer said:

May 20, 2010 1:27 PM
 

Scamp Plymouth Called Dodge Rampage, Turing Programming said:

May 20, 2010 1:32 PM
 

Replacement Storm Window Prices, Storm Exhaust Catalytic Converter Replacement said:

May 20, 2010 1:33 PM
 

Lw300 2001, Lw300 3 Car said:

May 20, 2010 2:26 PM
 

Ls400 Headlight Windshield Wiper Motor Lexus Es250, Lexus Es250 Performance Parts Including said:

May 20, 2010 2:27 PM
 

1997 Grand Marquis Review Marauder, Crown Victoria Marauder Lx said:

May 20, 2010 4:24 PM
 

Acura Nsx Half, Acura Nsx Replacement Toyota Recalls Lexus Lf said:

May 20, 2010 4:56 PM
 

C550 Sale C230 Sport C32 Amg, C55 Clearance Cl65 Amg Cl500 said:

May 20, 2010 5:21 PM
 

530xi Car Accessories Brake Pads, 530xi Find Classified said:

May 20, 2010 8:13 PM
 

Lss Sold, Carlsson Body Kit W204 said:

May 20, 2010 8:52 PM
 

Diplomat Replacement Just Want Britax Marathon, B Diplomat B Miramar said:

May 20, 2010 10:36 PM
 

Es250 Lexus Gs400 Auto Parts, Gigabyte Geforce 9400 Gt 1gb Oc said:

May 20, 2010 11:24 PM
 

Corrado Marriland, Corrado Radiator Nissens 2.8 L V6 said:

May 20, 2010 11:30 PM
 

Ford Festiva Glxi 1999, Festiva Media said:

May 20, 2010 11:32 PM
 

Es250 Reconditioned, Replacement Lexus Es250 said:

May 20, 2010 11:43 PM
 

Zephyr Used Mercury Cougar, Monarch Headlight Xtra Vision Mercury Cougar said:

May 21, 2010 2:47 AM
 

Tekken 5 Dark Resurrection Psp Torrent, V1 Part Torrent said:

May 21, 2010 3:13 AM
 

300td Sale Cars Mercedes Diesel Wagon, 300td Taillight 1983 Mercedes Benz said:

May 21, 2010 3:54 AM
 

733i Chandeliers, 733i Chandeliers said:

May 21, 2010 10:59 AM
 

Mirage Colt Gt, Cordia Discount Mighty Max Mitsubishi Mirage said:

May 21, 2010 1:58 PM
 

85 Cadillac Seville, Guadalquivir River Seville Spain Guide said:

May 21, 2010 2:14 PM
 

Glf Part Revolution Court, Glf New Tee Times Dallas Ft Worth said:

May 21, 2010 2:25 PM
 

1999 Audi A6 Quattro Parts, Buy Midi Keyboard M Audio Axiom said:

May 21, 2010 3:08 PM
 

245 Adoption Any, Goodyear 245 45 17 said:

May 21, 2010 3:29 PM
 

Chevrolet Laguna Discount Torque Converter, Shallow Sport Part Padre Island Lower Laguna Madre said:

May 21, 2010 5:56 PM
 

Scamp Tail Light Bulb, Part 1973 1972 Plymouth Scamp said:

May 21, 2010 6:22 PM
 

S Seafood Restaurant, Restaurants Hid said:

May 21, 2010 6:23 PM
 

G15 Review Gmc Pickup, C25 C2500 Silverado Diagram Gmc said:

May 21, 2010 6:54 PM
 

Cold Air Intake Dodge Challenger, 1970 Chrysler Newport Dodge Challenger said:

May 21, 2010 8:40 PM
 

S60r Transmission 2004 Volvo, Amazon S60r Volvo S70 said:

May 21, 2010 9:36 PM
 

I35 Fog Tail Light Assembly, Infiniti I35 Replacement Tail Light Bulbs said:

May 22, 2010 4:07 AM
 

C20 Heater 5.0 L, C20 Pickup Accessories Exhaust Manifold said:

May 22, 2010 7:04 AM
 

Honda Crv Real Estate, Crv Pt said:

May 22, 2010 7:19 AM
 

Aerostar Price Super 700 Charter, E 450 Econoline Super Duty Stripped Radiator Explorer Sport Trac Galaxie 500 said:

May 22, 2010 8:45 AM
 

Discount B210 Nissan Sentra, Find B210 Printer said:

May 22, 2010 8:58 AM
 

Spectra5 Exhaust 2009 Kia, Spectra5 Bulb 2005 Kia Replace said:

May 22, 2010 9:00 AM
 

1500 Hd Crew Cab Gmc Sierra 2500 Chevrolet Silverado, 1978 Ford 150 Sale said:

May 22, 2010 9:26 AM
 

C350 Hood Primered, G35 G3500 Van Coupon Fit said:

May 22, 2010 10:14 AM
 

Accessories Chevrolet Monza Catalytic Converter, Monza Alloys Real Estate said:

May 22, 2010 10:23 AM
 

Ford Escort Zx Coupe, 1959 Mercury Colony Park Ford Country Squire said:

May 22, 2010 10:40 AM
 

1962 Starfire Convertible For Sale, Starfire Game System Sky Marshal said:

May 22, 2010 11:15 AM
 

Honda Fit 2008 Price, 2005 Honda S2000 0 60 said:

May 22, 2010 11:54 AM
 

Ford E150 Econoline Club Wagon Ebay, E 100 E150 Van Parts said:

May 22, 2010 1:26 PM
 

Husqvarna S550, 2010 E 350 S550 said:

May 22, 2010 3:04 PM
 

Part Chevy Malibu Accessories Brake Pads, Malibu Removal Car Stereo Repair said:

May 22, 2010 4:04 PM
 

2000 Cadillac Eldorado Sts, Brake Pads 1998 Cadillac Eldorado said:

May 22, 2010 4:07 PM
 

2002 Infiniti I35 Parts Side Marker, I35 Sale Infiniti Qx4 said:

May 22, 2010 4:18 PM
 

Discount Marauder Body, Mercury Marauder Crown Victoria said:

May 22, 2010 6:28 PM
 

Parts Car Oxygen Sensor 1989 Buick Reatta, Used Cars Terraza Buick Reatta said:

May 22, 2010 7:52 PM
 

2nd Hand Envoy Xuv, Yukon Xl 2500 Used Gmc Envoy Xuv Classified Schedule said:

May 22, 2010 7:54 PM
 

350z Aftermarket Fender, Buy Used 2008 Nissan 350z said:

May 22, 2010 8:25 PM
 

Lw200 Buy L Series Saturn Sc2, Sc2 Radiator Fit - 49.an74.com said:

May 22, 2010 9:21 PM
 

Porta Borsari Di Verona Piazza Delle Erbe, Verona Sx 405s 12 Gauge - 60.defutbolazo.com said:

May 22, 2010 10:57 PM
 

Quantum Mechanics Angular Momentum, Quantum Review Cooling - 435.defutbolazo.com said:

May 23, 2010 12:26 AM
 

E350 Bumper 2008 Mercedes Benz, 1978 450slc W107 Mercedes Benz Club - 304.zapstreaming.com said:

May 23, 2010 1:26 AM
 

B2300 Coupon Samsung Blu Ray Disc Player, B2300 Xenon Kit Compare - 118.jeepsunlimted.com said:

May 23, 2010 2:32 AM
 

Mirada Wholesale User Reviews, Episode D Una Mirada - 6.computeronlinebingo.com said:

May 23, 2010 4:23 AM
 

Change Battery Sansa E250, 1996 250 Econoline Ford E250 Van - 364.tvshowzone.com said:

May 23, 2010 5:23 AM
 

Ventura Price Scramble, 2005 Chevrolet Ventura Pontiac Montana - 1.luna-atra.net said:

May 23, 2010 5:32 AM
 

Ford Expedition 4x4 Light, Sale Used Ford Expedition El Explorer Sport Trac Crown Victoria - 393.rkwrh.com said:

May 23, 2010 5:50 AM
 

Protege5 Dvd Player Shift Knob, Supermodel Mazda Protege5 - 41.mfbattle.com said:

May 24, 2010 6:43 AM
 

Blackwood Mkx Lincoln Aviator For Sale, Taillight Used Lincoln Blackwood - 190.defutbolazo.com said:

May 24, 2010 7:07 AM
 

Sephia Replacement Headlight Housing 2002 Kia Sportage, Central Heating 1995 Kia Sephia Brake Caliper - 440.tvshowzone.com said:

May 24, 2010 8:41 AM
 

Car Gmc C25 A2550 Pickup, Download K15 K1500 Pickup 1972 Gmc - 461.tvshowzone.com said:

May 24, 2010 10:41 AM
 

Uhp 250w Repair Projector Lamp, 46v2500 Used 1080p Lcd Hdtv - 12.unlockiphone30.net said:

May 24, 2010 11:41 AM
 

Order Magentis, Kia Magentis Custom - 478.jordanbrandallamerican.com said:

May 24, 2010 11:51 AM
 

1998 Mpg 2002 Lexus Es300, 1996 Lexus Es300 For Sale - 340.eumreborn.com said:

May 24, 2010 3:39 PM
 

Hud Homes Sale Las Vegas, Las Vegas Used Selection Findlay - 223.1fh.org said:

May 24, 2010 4:20 PM
 

Transmission 2002 Ford Escort Timing Belt, Belk Aftermarket - 6.tgrconversions.com said:

May 24, 2010 4:41 PM
 

Used Gl 10 Loyale Subaru Svx, Buy Svx Vst - 219.mfbattle.com said:

May 24, 2010 4:53 PM
 

Isuzu Vehicross Interior Power Locks, Coldplay Isuzu Vehicross - 210.computeronlinebingo.com said:

May 24, 2010 5:10 PM
 

220d Aftermarket Buy Online 1973 Mercedes, 220d Blub Mercedes Benz 380sl - 323.luna-atra.net said:

May 25, 2010 1:06 AM
 

1996 2002 Saturn Sl2, 1996 Saturn Sl2 Timing Belt - 255.tijuanareader.com said:

May 25, 2010 1:51 AM
 

Sport Wagon Volvo V50, S70 Second Hand Used Volvo V50 Tuning - 343.computeronlinebingo.com said:

May 25, 2010 3:29 AM
 

Es250 Sale Rx 400h Sc, Dodge Ram 2500 Led Tail Lights - 52.tijuanareader.com said:

May 25, 2010 4:22 AM
 

Wagovan Replacement Catalog Sold, Wagovan Coupon Cylinder - 212.zapstreaming.com said:

May 25, 2010 11:13 AM
 

D100 Pickup Replacement K Ram 1500, D100 Car Parts Ram 2500 - 239.dlmreza.net said:

May 25, 2010 12:47 PM
 

1995 Volkswagen Eurovan Air Intake, Eurovan Part Bus Gifts - 295.jeepsunlimted.com said:

May 25, 2010 12:49 PM
 

E55 Amg Problems Common, Parts Replacement Mercedes Benz C320 E55 Amg - 263.akemet.com said:

May 25, 2010 1:06 PM
 

Cheap Pro Rodeo Wrangler Wrancher, Used Sale 1999 Isuzu Rodeo Ls - 443.akemet.com said:

May 25, 2010 2:53 PM
 

2008 Mitsubishi Eclipse Factory, 2000 Eclipse Aftermarket Tail Lights - 77.renters.ws said:

May 25, 2010 3:30 PM
 

Yoga Saratoga Springs Ny, Days Inn Saratoga - 76.luna-atra.net said:

May 25, 2010 4:28 PM
 

Buy Bmw 635csi Auto Parts, List 635csi - 378.tgrconversions.com said:

May 25, 2010 6:53 PM
 

American Express Axiom Review, 2005 Isuzu Axiom Rodeo Sport - 183.mfbattle.com said:

May 25, 2010 7:03 PM
 

2000 - 1991 @ 525xi Blub Car Bmw 323ci, 525xi Replacement Brake 2007 Bmw Shock Absorbers - 296.luna-atra.net said:

May 27, 2010 8:55 AM
 

1981 - 2001 @ 190d Parts Replacement Direct 0e, 1965 Mercedes Benz 190d Gasoline Engine - 299.computeronlinebingo.com said:

May 30, 2010 4:52 PM
 

1989 - 1988 @ Buy Buick Gran Sport Wildcat Electra, 1963 Buick Wildcat Convertible Gran Sport - 474.animejin.com said:

May 30, 2010 5:42 PM
 

1996 - 1983 @ Cb300 Turn Signal Dodge Ramcharger, Sts Parts Remote Mount Turbo Charger - 203.tvshowzone.com said:

May 30, 2010 10:45 PM
 

1989 - 1988 @ Iquest Handheld, Aftermarket Automotive Quest Specialty Chemicals Huron Capital - 89.dlmreza.net said:

May 30, 2010 11:32 PM
 

2006 - 1982 @ Chrysler Conquest Engine Parts Rear Wheel Drive, Chrysler Discount Mitsubishi Starion Conquest Tsi - 123.dlmreza.net said:

May 31, 2010 12:10 AM
 

1987 - 1991 @ 2005 Clk500 Specifications, Clk500 Replacement Free - 160.tijuanareader.com said:

May 31, 2010 12:28 AM
 

1980 - 1991 @ Mercedes Benz E430 Part Tail Light Headlight Assembly, E430 Central Heating Call - 160.renters.ws said:

May 31, 2010 12:49 PM
Anonymous comments are disabled

This Blog

Post Calendar

<January 2008>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

Syndication

Powered by Community Server, by Telligent Systems