progs/roman_sol.scala
changeset 265 59779ce322a6
parent 111 cd6b9fe4bce5
--- a/progs/roman_sol.scala	Wed Mar 20 21:50:20 2019 +0000
+++ b/progs/roman_sol.scala	Sat Jun 22 08:39:52 2019 +0100
@@ -126,62 +126,12 @@
 String2Int("XC") 	// 90
 String2Int("MDCLXVI")	// 1666
 
-String2Int("VIV")       // 9 (but should be written as IX) 
-String2Int("IVX")       // 14 (also invalid)
 
-// error cases
-String2Int("MC?I")
+// error/none cases
+String2Int("MC?I") 
 String2Int("abc")
 
 
-// (5) The file roman.txt contains a list of roman numerals. 
-// Read in these numerals, convert them into integers and then 
-// add them all up.
-
-import io.Source
-import scala.util._
-
-// function for reading files:
-// Source.fromFile("file_name")("ISO-8859-9")
-
-def addromanfile(filename: String) = {
-  val lines = Source.fromFile(filename)("ISO-8859-9").getLines.toList.map(_.trim)
-  lines.map(String2Int(_)).flatten.sum
-}
-
-
-addromanfile("roman.txt")
-
-val ls = """IIII
-IV        
-VI        
-IX        
-MCMLXXIX  
-MCMXLIV   
-          
-MDCLXI    
-MMMCMXCIX 
-XLVIII    
-MMVIII    
-
-MMXI      
-MIM       
-MCMLVI    
-
-III     
-XXX     
-CCC     
-MMM     
-VII     
-LXVI    
-CL      
-MCC     
-IV      
-IX      
-XC      
-MDCLXVI""".split("\n").map(_.trim).map(String2Int(_)).flatten
-
-String2Int("MIM")
 
 // Part 2 about Validation of Roman Numerals
 //===========================================
@@ -283,11 +233,3 @@
 RomanNumeral2Int(List(M,C,M,X,L,I,V))
 
 
-def addvalidromanfile(filename: String) = {
-  val lines = Source.fromFile(filename)("ISO-8859-9").getLines.toList.map(_.trim)
-  val ints = lines.map(String2RomanNumeral(_)).flatten.filter(isValidNumeral(_)).map(RomanNumeral2Int(_))
-  ints.sum
-}
-
-
-addvalidromanfile("roman2.txt")