PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 3ms app.codeStats 0ms

/extra/project-euler/089/089.factor

http://github.com/abeaumont/factor
Unknown | 48 lines | 36 code | 12 blank | 0 comment | 0 complexity | 10c4e1aa88187e8573bd1acf578cdcdf MD5 | raw file
 1! Copyright (c) 2009 Doug Coleman.
 2! See http://factorcode.org/license.txt for BSD license.
 3USING: io.encodings.ascii io.files kernel math
 4project-euler.common roman sequences ;
 5IN: project-euler.089
 6
 7! http://projecteuler.net/index.php?section=problems&id=089
 8
 9! DESCRIPTION
10! -----------
11
12! The rules for writing Roman numerals allow for many ways of writing
13! each number (see FAQ: Roman Numerals). However, there is always a
14! "best" way of writing a particular number.
15
16! For example, the following represent all of the legitimate ways of
17! writing the number sixteen:
18
19! IIIIIIIIIIIIIIII
20! VIIIIIIIIIII
21! VVIIIIII
22! XIIIIII
23! VVVI
24! XVI
25
26! The last example being considered the most efficient, as it uses
27! the least number of numerals.
28
29! The 11K text file, roman.txt (right click and 'Save Link/Target As...'),
30! contains one thousand numbers written in valid, but not necessarily
31! minimal, Roman numerals; that is, they are arranged in descending units
32! and obey the subtractive pair rule (see FAQ for the definitive rules
33! for this problem).
34
35! Find the number of characters saved by writing each of these in their minimal form.
36
37! SOLUTION
38! --------
39
40: euler089 ( -- n )
41    "resource:extra/project-euler/089/roman.txt" ascii file-lines
42    [ ] [ [ roman> >roman ] map ] bi
43    [ [ length ] map-sum ] bi@ - ;
44
45! [ euler089 ] 100 ave-time
46! 14 ms ave run time - 0.27 SD (100 trials)
47
48SOLUTION: euler089