1 ! Copyright (c) 2009 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: io.encodings.ascii io.files kernel math
4 project-euler.common roman sequences ;
7 ! https://projecteuler.net/problem=89
12 ! The rules for writing Roman numerals allow for many ways of
13 ! writing each number (see FAQ: Roman Numerals). However, there
14 ! is always a "best" way of writing a particular number.
16 ! For example, the following represent all of the legitimate
17 ! ways of writing the number sixteen:
26 ! The last example being considered the most efficient, as it
27 ! uses the least number of numerals.
29 ! The 11K text file, roman.txt (right click and 'Save
30 ! Link/Target As...'), contains one thousand numbers written in
31 ! valid, but not necessarily minimal, Roman numerals; that is,
32 ! they are arranged in descending units and obey the subtractive
33 ! pair rule (see FAQ for the definitive rules for this problem).
35 ! Find the number of characters saved by writing each of these
36 ! in their minimal form.
42 "resource:extra/project-euler/089/roman.txt" ascii file-lines
43 [ ] [ [ roman> >roman ] map ] bi
44 [ [ length ] map-sum ] bi@ - ;
46 ! [ euler089 ] 100 ave-time
47 ! 14 ms ave run time - 0.27 SD (100 trials)