Skip to main content
added 15 characters in body
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 451 429429 423 bytes

import Data.List
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
q ','='\n'
q a=a
i=do l<-getLine;putStrLn$f$lines$mapi=getLine>>=putStrLn.f.lines.map q l

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 8070 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings (q helps by replacing , with \n) and calls p.

Haskell, 451 429 bytes

import Data.List
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
q ','='\n'
q a=a
i=do l<-getLine;putStrLn$f$lines$map q l

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 80 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings (q helps by replacing , with \n) and calls p.

Haskell, 451 429 423 bytes

import Data.List
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
q ','='\n'
q a=a
i=getLine>>=putStrLn.f.lines.map q

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 70 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings (q helps by replacing , with \n) and calls p.

added 42 characters in body
Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 451451 429 bytes

import Data.List
import Network.CGI.Protocol
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
q ','='\n'
q a=a
i=do l<-getLine;putStrLn$f$lines$replace ','getLine;putStrLn$f$lines$map '\n'q l

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 10080 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings (q helps by replacing , with \n) and calls p.

Haskell, 451 bytes

import Data.List
import Network.CGI.Protocol
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
i=do l<-getLine;putStrLn$f$lines$replace ',' '\n' l

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 100 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings and calls p.

Haskell, 451 429 bytes

import Data.List
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
q ','='\n'
q a=a
i=do l<-getLine;putStrLn$f$lines$map q l

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 80 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings (q helps by replacing , with \n) and calls p.

Source Link
nimi
  • 35.9k
  • 4
  • 34
  • 99

Haskell, 451 bytes

import Data.List
import Network.CGI.Protocol
(#)=splitAt
(%)=map
w=length
r"X"=10
r('X':a)=10+r a
r a=case elemIndex a["I","II","III","IV","V","VI","VII","VIII","IX"]of Just i->i+1;_->0
s l=[r%[a,b,c]|x<-[2..w l],y<-[1..x],let(d,c)=x#l;(a,b)=y#d,r a*r b*r c>0]
e[a,b,c]=a==b&&a==c
p[l,m,n]=[1|a<-l,b<-m,c<-n,e$sum%[a,b,c],e$sum%(transpose[a,b,c])]
f i=(show$product$w%(s%i))++","++(show$0<(w$p$s%i))
i=do l<-getLine;putStrLn$f$lines$replace ',' '\n' l

Usage:

*Main> i                           -- repl prompt, call i
VIIIIVI,IIIVVII,IVIXII             -- input via STDIN    
24,True                            -- output
*Main> i
IIIXVIII,IVIII,VIIII
210,False

About 100 bytes just to get the input and output format right.

The function r converts a roman number (given as a string) to an integer (if it's not a valid roman number 0 is returned). s splits a string of roman digits into 3 substring and keeps those triples with valid roman numbers and converts them via r to integers . e checks if all integers of a three element list are equal. p takes three strings of roman digits, splits them via s into lists of integers, combines one integer of each list to triples and keeps those with equal sums in all directions. f calculates the number of valid matrices and checks if p returns the empty list (no valid solution) or not (valid solution exists). The main function i reads the input from STDIN, converts it to a list of strings and calls p.