diff options
24 files changed, 2881 insertions, 2128 deletions
diff --git a/challenge-227/ulrich-rieke/cpp/ch-2.cpp b/challenge-227/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..4e153bef8a --- /dev/null +++ b/challenge-227/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,177 @@ +#include <iostream>
+#include <vector>
+#include <string>
+#include <map>
+#include <utility>
+#include <cmath>
+
+std::vector<std::string> split( const std::string & startline ,
+ const std::string & sep ) {
+ std::vector<std::string> separated ;
+ std::string::size_type start { 0 } ;
+ std::string::size_type pos ;
+ do {
+ pos = startline.find_first_of( sep , start ) ;
+ separated.push_back( startline.substr(start , pos - start )) ;
+ start = pos + 1 ;
+ } while ( pos != std::string::npos ) ;
+ return separated ;
+}
+
+int roman_to_arabic( const std::string & numberstring , const
+ std::map<std::string, int> & numbertable ) {
+ int len = numberstring.length( ) ;
+ auto found = numbertable.find( numberstring ) ;
+ if ( found != numbertable.end( ) ) {
+ return found->second ;
+ }
+ else {
+ int start = 0 ;
+ int sum = 0 ;
+ int howmany = 1 ;
+ while ( start + howmany < len + 1 ) {
+ std::string partString ( numberstring.substr( start , howmany ) ) ;
+ if ( numbertable.find( partString ) != numbertable.end( ) )
+ howmany++ ;
+ else {
+ howmany-- ;
+ partString = numberstring.substr( start , howmany ) ;
+ found = numbertable.find( partString ) ;
+ sum += found->second ;
+ start = start + howmany ;
+ howmany = 1 ;
+ }
+ }
+ howmany-- ;
+ std::string partString( numberstring.substr( start , howmany ) ) ;
+ found = numbertable.find( partString ) ;
+ sum += found->second ;
+ return sum ;
+ }
+}
+
+std::string arabToRoman( int number , const std::map<int , std::string> &
+ arabRomanAssos ) {
+ int num = 0 ;
+ std::string romanNumber ;
+ while ( number != 0 ) {
+ if ( number > 1000 ) {
+ num = number / 1000 * 1000 ;
+ }
+ if ( number < 1000 && number >= 100 ) {
+ num = number / 100 * 100 ;
+ }
+ if ( number < 100 && number >= 10 ) {
+ num = number / 10 * 10 ;
+ }
+ if ( number < 10 ) {
+ num = number ;
+ }
+ std::string associated ;
+ auto found = arabRomanAssos.find( num ) ;
+ romanNumber += found->second ;
+ number -= num ;
+ }
+ return romanNumber ;
+}
+
+int main( ) {
+ std::map<std::string , int> romanToIntMap ;
+ romanToIntMap.insert( {{"M" , 1000 } ,
+ {"MM" , 2000 } ,
+ {"MMM" , 3000 } ,
+ {"C" , 100 } ,
+ {"CC" , 200 } ,
+ {"CCC" , 300 } ,
+ {"CD" , 400 } ,
+ {"D" , 500 } ,
+ {"DC" , 600 } ,
+ {"DCC" , 700 } ,
+ {"DCCC" , 800 } ,
+ {"CM" , 900 } ,
+ {"X" , 10 } ,
+ {"XX" , 20 } ,
+ {"XXX" , 30 } ,
+ {"XL" , 40 } ,
+ {"L" , 50 } ,
+ {"LX" , 60 } ,
+ {"LXX" , 70 } ,
+ {"LXXX" , 80 } ,
+ {"XC" , 90 } ,
+ {"I" , 1 } ,
+ {"II" , 2 } ,
+ {"III" , 3 } ,
+ {"IV" , 4 } ,
+ {"V" , 5 } ,
+ {"VI" , 6 } ,
+ {"VII" , 7 } ,
+ {"VIII" , 8 } ,
+ {"IX" , 9 } } ) ;
+ std::map<int , std::string> intToRomanMap ;
+ for ( auto & p : romanToIntMap ) {
+ intToRomanMap.insert( std::make_pair( p.second , p.first ) ) ;
+ }
+ std::cout << "Enter a 2-term string in Roman numerals!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> allTerms ( split( line , " " ) ) ;
+ std::string firstRoman ( allTerms[ 0 ] ) ;
+ std::string secondRoman( allTerms[ 2 ] ) ;
+ std::string oper ( allTerms[ 1 ] ) ;
+ std::string result ;
+ int firstTerm = roman_to_arabic( firstRoman, romanToIntMap ) ;
+ int secondTerm = roman_to_arabic( secondRoman , romanToIntMap ) ;
+ if ( oper == "+" ) {
+ int sum = firstTerm + secondTerm ;
+ if ( sum > 3999 ) {
+ result = "non potest" ;
+ }
+ else {
+ result = arabToRoman( sum , intToRomanMap ) ;
+ }
+ }
+ if ( oper == "-" ) {
+ int difference = firstTerm - secondTerm ;
+ if ( difference < 0 ) {
+ result = "non potest" ;
+ }
+ if ( difference == 0 ) {
+ result = "nulla" ;
+ }
+ if ( difference > 0 ) {
+ result = arabToRoman( difference , intToRomanMap ) ;
+ }
+ }
+ if ( oper == "*" ) {
+ int product = firstTerm * secondTerm ;
+ if ( product > 3999 ) {
+ result = "non potest" ;
+ }
+ else {
+ result = arabToRoman( product , intToRomanMap ) ;
+ }
+ }
+ if ( oper == "/" ) {
+ int quotient = firstTerm / secondTerm ;
+ if ( secondTerm * quotient != firstTerm ) {
+ result = "non potest" ;
+ }
+ else {
+ result = arabToRoman( quotient , intToRomanMap ) ;
+ }
+ }
+ if ( oper == "**" ) {
+ int potence = static_cast<int>( std::pow( static_cast<double>( firstTerm ),
+ static_cast<double>( secondTerm ) )) ;
+ if ( potence > 3999 ) {
+ result = "non potest" ;
+ }
+ else {
+ result = arabToRoman( potence , intToRomanMap ) ;
+ }
+ }
+ std::cout << line << " = " << result << std::endl ;
+ return 0 ;
+}
+
+
diff --git a/challenge-227/ulrich-rieke/haskell/ch-1.hs b/challenge-227/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..52ff31e1fa --- /dev/null +++ b/challenge-227/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,18 @@ +module Challenge227
+ where
+import Data.Time.Calendar
+
+solution :: Integer -> Int
+solution year = length $ filter ( (== Friday ) . dayOfWeek ) allDays
+ where
+ allDays :: [Day]
+ allDays = map (\i -> fromGregorian year i 13 ) [1..12]
+
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a year, preferably between 1853 and 9999"
+ year <- getLine
+ let theYear = (read year :: Integer)
+ fridays = solution theYear
+ putStrLn ("There are " ++ show fridays ++ " Friday 13th in year " ++ year)
diff --git a/challenge-227/ulrich-rieke/haskell/ch-2.hs b/challenge-227/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..ead1e02d0b --- /dev/null +++ b/challenge-227/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,82 @@ +module Challenge227_2
+ where
+import Data.Maybe( isJust , fromJust)
+import Data.List ( sortOn )
+import Data.List.Split( splitOn )
+import Data.Char ( digitToInt )
+
+romanToArabMap :: [(String , Int)]
+romanToArabMap = [("M" , 1000) , ("MM" , 2000) , ("MMM" , 3000) , ("C" , 100 ) ,
+ ("CC" , 200) , ("CCC" , 300 ) , ( "CD" , 400 ) , ( "D" , 500 ),
+ ("DC" , 600 ) , ("DCC" , 700 ) , ("DCCC" , 800 ) , ("CM" ,
+ 900 ) , ("X" , 10 ) , ("XX" , 20 ) , ("XXX" , 30 ) ,
+ ("XL" , 40 ) , ( "L" , 50 ) , ("LX" , 60 ) , ("LXX" , 70 ) ,
+ ("LXXX" , 80 ) , ("XC" , 90 ) , ("I" , 1 ) , ("II" , 2 ) ,
+ ("III" , 3 ) , ( "IV" , 4 ) , ("V" , 5 ) , ("VI" , 6 ) ,
+ ("VII" , 7 ) , ("VIII" , 8 ) , ("IX" , 9 ) ]
+
+arabToRomanMap :: [(Int , String)]
+arabToRomanMap = map (\p -> (snd p , fst p ) ) romanToArabMap
+
+--the following function finds the largest start string that can be found in
+--romanToArabMap
+findLargestRomanStarter :: String -> String
+findLargestRomanStarter str = last $ sortOn length $ filter (\substr ->
+ isJust $ lookup substr romanToArabMap) $ map (\n -> take n str )
+ [1..length str ]
+
+--find all substrings that can be found in the mapping of Roman numerals to
+--Arab ones
+findAllSubstrings :: String -> [String]
+findAllSubstrings str = snd $ until ( null . fst ) step (str , [] )
+ where
+ step :: (String , [String]) -> (String , [String] )
+ step (aWord , aList ) = ( drop ( length theHead ) aWord , aList ++
+ [theHead] )
+ where
+ theHead :: String
+ theHead = findLargestRomanStarter aWord
+
+arabToRoman :: Int -> String
+arabToRoman n = foldl1 ( ++ ) $ map (\i -> fromJust $ lookup i
+ arabToRomanMap ) $ filter ( /= 0 ) $ zipWith ( * )
+ padded [1000 , 100 , 10 , 1]
+ where
+ padded :: [Int]
+ padded = map digitToInt (replicate ( 4 - ( length $ show n ) ) '0'
+ ++ show n )
+
+romanToArab :: String -> Int
+romanToArab numeral = sum $ map (\str -> fromJust $ lookup str
+ romanToArabMap ) $ findAllSubstrings numeral
+
+evaluate :: String -> String -> String -> String
+evaluate firstNumeral operator secondNumeral
+ |operator == "+" = if sum > 3999 then "non potest"
+ else arabToRoman sum
+ |operator == "-" = if difference < 0 then "non potest"
+ else if difference == 0 then "nulla"
+ else arabToRoman difference
+ |operator == "/" = if quotient * secondOp /= firstOp
+ then "non potest"
+ else arabToRoman quotient
+ |operator == "**" = if potence > 3999 then "non potest"
+ else arabToRoman potence
+ |operator == "*" = if product > 3999 then "non potest"
+ else arabToRoman product
+ where
+ firstOp = romanToArab firstNumeral
+ secondOp = romanToArab secondNumeral
+ sum = firstOp + secondOp
+ difference = firstOp - secondOp
+ product = firstOp * secondOp
+ potence = firstOp ^ secondOp
+ quotient = firstOp `div` secondOp
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a term with 2 Roman numerals!"
+ myTerm <- getLine
+ let [firstTerm , operator , secondTerm] = splitOn " " myTerm
+ result = evaluate firstTerm operator secondTerm
+ putStrLn $ myTerm ++ " = " ++ result
diff --git a/challenge-227/ulrich-rieke/perl/ch-1.pl b/challenge-227/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..8660f674ec --- /dev/null +++ b/challenge-227/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use DateTime ;
+
+say "Please enter a year from 1853 to 9999!" ;
+my $year = <STDIN> ;
+chomp $year ;
+my $sum = 0 ;
+for my $m (1..12) {
+ my $dt = DateTime->new(
+ year => $year ,
+ month => $m ,
+ day => 13 ,
+ hour => 0 ,
+ minute => 0 ,
+ second => 0 ,
+ nanosecond => 0 ,
+ time_zone => 'Asia/Taipei' ,
+ ) ;
+ if ( $dt->day_of_week == 5 ) {
+ $sum++ ;
+ }
+}
+say "The number of Friday 13th in $year is $sum!" ;
diff --git a/challenge-227/ulrich-rieke/perl/ch-2.pl b/challenge-227/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..47f476ab9f --- /dev/null +++ b/challenge-227/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,161 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use POSIX ;
+
+sub romanToArab {
+ my $number = shift ;
+ my $associations = shift ;#reference to the table with all associations of
+ #Roman to Arab numbers
+ if ( exists( $associations->{$number} ) ) {
+ return $associations->{$number} ;
+ }
+ else {
+#go letter by letter to the right of the Roman number until the substring
+#is no longer found in the association table. There, go one step back and add
+#the association found to the sum of Roman numbers. Repeat that same procedure
+#at the end of the string
+ my $sum = 0 ;
+ my $len = length $number ;
+ my $start = 0 ;
+ my $howmany = 1 ; #number of digits I take at the given start position
+ my $sub ;
+ while ( $start + $howmany < $len + 1 ) {
+ $sub = substr( $number , $start , $howmany ) ;
+ if ( exists( $associations->{$sub} ) ) {
+ $howmany++ ; #go further to the right until there is nof fit in the tab.
+ }
+ else {
+ $howmany-- ;
+ $sub = substr( $number , $start , $howmany ) ;
+ $sum += $associations->{$sub} ;
+ $start = $start + $howmany ;
+ $howmany = 1 ;
+ }
+ }
+ $howmany-- ;
+ $sub = substr( $number , $start , $howmany ) ;
+ $sum += $associations->{$sub} ;
+ return $sum ;
+ }
+}
+
+sub arabToRoman {
+ my $number = shift ;
+ my $arabRomanAssos = shift ;
+ my $num ;
+ my $romanNum = "" ;
+ while ( $number != 0 ) {
+ if ( $number > 1000 ) {
+ $num = int( $number / 1000 ) * 1000 ; #convert , for example ,
+#3498 to 3000 to better be able to look it up in the table
+ }
+ if ( ($number < 1000) && ($number >= 100) ) {
+ $num = int( $number / 100 ) * 100 ;
+ }
+ if ( ($number < 100 ) && ( $number >= 10 ) ) {
+ $num = int( $number / 10 ) * 10 ;
+ }
+ if ( $number < 10 ) {
+ $num = $number ;
+ }
+ my $asso = $arabRomanAssos->{$num} ;
+ $romanNum .= $asso ;
+ $number -= $num ;
+ }
+ return $romanNum ;
+}
+
+my %roman_To_Arab = (
+ "M" => 1000 ,
+ "MM" => 2000 ,
+ "MMM" => 3000 ,
+ "C" => 100 ,
+ "CC" => 200 ,
+ "CCC" => 300 ,
+ "CD" => 400 ,
+ "D" => 500 ,
+ "DC" => 600 ,
+ "DCC" => 700 ,
+ "DCCC" => 800 ,
+ "CM" => 900 ,
+ "X" => 10 ,
+ "XX" => 20 ,
+ "XXX" => 30 ,
+ "XL" => 40 ,
+ "L" => 50 ,
+ "LX" => 60 ,
+ "LXX" => 70 ,
+ "LXXX" => 80 ,
+ "XC" => 90 ,
+ "I" => 1 ,
+ "II" => 2 ,
+ "III" => 3 ,
+ "IV" => 4 ,
+ "V" => 5 ,
+ "VI" => 6 ,
+ "VII" => 7 ,
+ "VIII" => 8 ,
+ "IX" => 9
+) ;
+my %arab_To_Roman ;
+while ( my ( $key , $value ) = each( %roman_To_Arab ) ) {
+ $arab_To_Roman{ $value } = $key ;
+}
+say "Enter a 2 - term string in Roman numerals!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my $result ;
+my ( $firstExpr , $operator , $secondExpr ) = split( /\s/ , $line ) ;
+my $firstTerm = romanToArab( $firstExpr, \%roman_To_Arab ) ;
+my $secondTerm = romanToArab( $secondExpr, \%roman_To_Arab ) ;
+if ( $operator eq "+" ) {
+ my $sum = $firstTerm + $secondTerm ;
+ if ( $sum > 3999 ) {
+ $result = "non potest" ;
+ }
+ else {
+ $result = arabToRoman( $sum , \%arab_To_Roman ) ;
+ }
+}
+if ( $operator eq "-" ) {
+ my $difference = $firstTerm - $secondTerm ;
+ if ( $difference < 0 ) {
+ $result = "non potest" ;
+ }
+ if ( $difference == 0 ) {
+ $result = "nulla" ;
+ }
+ if ( $difference > 0 ) {
+ $result = arabToRoman( $difference , \%arab_To_Roman ) ;
+ }
+}
+if ( $operator eq "*" ) {
+ my $product = $firstTerm * $secondTerm ;
+ if ( $product > 3999 ) {
+ $result = "non potest" ;
+ }
+ else {
+ $result = arabToRoman( $product , \%arab_To_Roman ) ;
+ }
+}
+if ( $operator eq "/" ) {
+ my $fraction = $firstTerm / $secondTerm ;
+ if ( floor( $fraction ) != $fraction ) {
+ $result = "non potest" ;
+ }
+ else {
+ $result = arabToRoman( $fraction , \%arab_To_Roman ) ;
+ }
+}
+if ( $operator eq "**" ) {
+ my $potence = $firstTerm ** $secondTerm ;
+ if ( $potence > 3999 ) {
+ $result = "non potest" ;
+ }
+ else {
+ $result = arabToRoman( $potence , \%arab_To_Roman ) ;
+ }
+}
+say ( $line . " = " . $result ) ;
diff --git a/challenge-227/ulrich-rieke/raku/ch-1.raku b/challenge-227/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..ee2151de2a --- /dev/null +++ b/challenge-227/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,12 @@ +use v6 ;
+
+say "Enter a year, best between 1853 and 9999!" ;
+my $year = $*IN.get ;
+my $sum = 0 ;
+for (1..12) -> $month {
+ my $d = Date.new( $year , $month , 13 ) ;
+ if ( $d.day-of-week == 5 ) {
+ $sum++ ;
+ }
+}
+say "There are $sum Friday 13th in $year!" ;
diff --git a/challenge-227/ulrich-rieke/rust/ch-1.rs b/challenge-227/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..cd5ecb9693 --- /dev/null +++ b/challenge-227/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,20 @@ +use std::io ; +use chrono::{NaiveDate , Datelike , Weekday} ; + +fn main() { + println!("Enter a year!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let year : i32 = entered_line.trim( ).parse::<i32>().unwrap( ) ; + let months : Vec<u32> = vec![1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , + 11 , 12] ; + let mut sum : usize = 0 ; + for m in months { + if NaiveDate::from_ymd_opt( year , m , 13 ).unwrap( ).weekday( ) + == Weekday::Fri { + sum += 1 ; + } + } + println!("There are {} Friday 13th in {} !" , sum , year ) ; +} diff --git a/challenge-227/ulrich-rieke/rust/ch-2.rs b/challenge-227/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..5aaa413822 --- /dev/null +++ b/challenge-227/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,162 @@ +use std::io ; +use substring::Substring ; +use std::collections::HashMap ; + +fn roman_to_arabic( numberstring : &str , numbertable : &HashMap<&str , + u32> ) -> u32 { + let len : usize = numberstring.len( ) ; + if let Some( n ) = numbertable.get( &numberstring ) { + return *n ; + } + else { + let mut start : usize = 0 ; + let mut end : usize = start + 1 ; + let mut sum : u32 = 0 ; + while end < len + 1 { + let mut substr : &str = numberstring.substring( start , end ) ; + if numbertable.get( &substr ).is_some( ) { + end += 1 ; + } + else { + end -= 1 ; + substr = numberstring.substring( start , end ) ; + sum += numbertable.get( &substr ).unwrap( ) ; + start = end ; + end = start + 1 ; + } + } + end -= 1 ; + let substr : &str = numberstring.substring( start , end ) ; + sum += numbertable.get( &substr ).unwrap( ) ; + sum + } +} + +fn arabic_to_roman( mut number : u32 , inversed_table : &HashMap<u32 , &str> ) + -> String { + let mut roman : String = String::new( ) ; + while number != 0 { + let num : u32 = match number { + size if size >= 1000 => size / 1000 * 1000 , + size if size < 1000 && (size >= 100) => size / 100 * 100 , + size if size < 100 && size >= 10 => size / 10 * 10 , + size if size < 10 => size , + _ => 5 , + } ; + let value : &str = inversed_table.get( &num).unwrap( ) ; + let valstr : String = value.to_string( ) ; + roman.push_str( &valstr ) ; + number -= num ; + } + roman +} + +fn main() { + let mut roman_arab : HashMap<&str , u32> = HashMap::new( ) ; + roman_arab.insert( "M" , 1000 ) ; + roman_arab.insert( "MM" , 2000 ) ; + roman_arab.insert( "MMM" , 3000 ) ; + roman_arab.insert( "C" , 100 ) ; + roman_arab.insert( "CC" , 200 ) ; + roman_arab.insert( "CCC" , 300 ) ; + roman_arab.insert( "CD" , 400 ) ; + roman_arab.insert( "D" , 500 ) ; + roman_arab.insert( "DC" , 600 ) ; + roman_arab.insert( "DCC" , 700 ) ; + roman_arab.insert( "DCCC" , 800 ) ; + roman_arab.insert( "CM" , 900 ) ; + roman_arab.insert( "X" , 10 ) ; + roman_arab.insert( "XX" , 20 ) ; + roman_arab.insert( "XXX" , 30 ) ; + roman_arab.insert( "XL" , 40 ) ; + roman_arab.insert( "L" , 50 ) ; + roman_arab.insert( "LX" , 60 ) ; + roman_arab.insert( "LXX" , 70 ) ; + roman_arab.insert( "LXXX" , 80 ) ; + roman_arab.insert( "XC" , 90 ) ; + roman_arab.insert( "I" , 1 ) ; + roman_arab.insert( "II" , 2 ) ; + roman_arab.insert( "III" , 3 ) ; + roman_arab.insert( "IV" , 4 ) ; + roman_arab.insert( "V" , 5 ) ; + roman_arab.insert( "VI" , 6 ) ; + roman_arab.insert( "VII" , 7 ) ; + roman_arab.insert( "VIII" , 8 ) ; + roman_arab.insert( "IX" , 9 ) ; + let mut arab_roman : HashMap<u32 , &str> = HashMap::new( ) ; + for ( key , val ) in roman_arab.iter( ) { + arab_roman.insert( *val , key.clone( ) ) ; + } + println!("Please enter a 2 -term string in Roman numerals!" ) ; + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let terms : Vec<&str> = entered_line.split_whitespace( ).map( | s | + s.trim( ) ).collect( ) ; + let first_roman : &str = terms[ 0 ] ; + let second_roman : &str = terms[ 2 ] ; + let operator : &str = terms[ 1 ] ; + let first_term : u32 = roman_to_arabic( &first_roman , &roman_arab ) ; + let second_term : u32 = roman_to_arabic( &second_roman , &roman_arab ) ; + let result : String = match operator { + "+" => { + let res : u32 = first_term + second_term ; + if res > 3999 { + "non potest".to_string( ) + } + else { + arabic_to_roman( res , &arab_roman ) + } + } , + "-" => { + if let Some( v ) = first_term.checked_sub( second_term ) { + if v == 0 { + "nulla".to_string( ) + } + else { + arabic_to_roman( v , &arab_roman ) + } + } + else { + "non potest".to_string( ) + } + } , + "*" => { + let res : u32 = first_term * second_term ; + if res > 3999 { + "non potest".to_string( ) + } + else { + arabic_to_roman( res , &arab_roman ) + } + } , + "/" => { + if let Some( v ) = first_term.checked_div( second_term ) { + if v * second_term == first_term { + arabic_to_roman( v , &arab_roman ) + } + else { + "non potest".to_string( ) + } + } + else { + "non potest".to_string( ) + } + } , + "**" => { + let res : u32 = first_term.pow( second_term ) ; + if res > 3999 { + "non potest".to_string( ) + } + else { + arabic_to_roman( res , &arab_roman ) + } + } , + _ => "".to_string( ) , + } ; + let changed = entered_line.trim( ) ; + let mut inline = changed.to_string( ) ; + inline.push_str( &" = ".to_string( ) ) ; + inline.push_str( &result ) ; + println!("{}" , inline ) ; +} diff --git a/stats/pwc-challenge-226.json b/stats/pwc-challenge-226.json index a72d032522..296a6ad15c 100644 --- a/stats/pwc-challenge-226.json +++ b/stats/pwc-challenge-226.json @@ -3,216 +3,23 @@ "series" : { "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 + "enabled" : 1, + "format" : "{point.y}" } } }, + "xAxis" : { + "type" : "category" + }, + "chart" : { + "type" : "column" + }, "legend" : { "enabled" : 0 }, - "tooltip" : { - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "followPointer" : 1 - }, - "series" : [ - { - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 226", - "data" : [ - { - "drilldown" : "Adam Russell", - "name" : "Adam Russell", - "y" : 4 - }, - { - "y" : 2, - "name" : "Adriaan Dens", - "drilldown" : "Adriaan Dens" - }, - { - "y" : 4, - "name" : "Ali Moradi", - "drilldown" : "Ali Moradi" - }, - { - "y" : 2, - "name" : "Andreas Voegele", - "drilldown" : "Andreas Voegele" - }, - { - "drilldown" : "Arne Sommer", - "name" : "Arne Sommer", - "y" : 3 - }, - { - "name" : "Athanasius", - "y" : 4, - "drilldown" : "Athanasius" - }, - { - "drilldown" : "Avery Adams", - "name" : "Avery Adams", - "y" : 1 - }, - { - "y" : 4, - "name" : "BarrOff", - "drilldown" : "BarrOff" - }, - { - "drilldown" : "Bob Lied", - "name" : "Bob Lied", - "y" : 3 - }, - { - "drilldown" : "Bruce Gray", - "name" : "Bruce Gray", - "y" : 2 - }, - { - "drilldown" : "Cheok-Yin Fung", - "y" : 2, - "name" : "Cheok-Yin Fung" - }, - { - "drilldown" : "Dave Jacoby", - "name" : "Dave Jacoby", - "y" : 3 - }, - { - "y" : 2, - "name" : "David Ferrone", - "drilldown" : "David Ferrone" - }, - { - "drilldown" : "E. Choroba", - "y" : 2, - "name" : "E. Choroba" - }, - { - "drilldown" : "Flavio Poletti", - "name" : "Flavio Poletti", - "y" : 6 - }, - { - "drilldown" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas", - "y" : 5 - }, - { - "drilldown" : "Jan Krnavek", - "y" : 2, - "name" : "Jan Krnavek" - }, - { - "drilldown" : "Jorg Sommrey", - "y" : 2, - "name" : "Jorg Sommrey" - }, - { - "y" : 6, - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld" - }, - { - "name" : "Lubos Kolouch", - "y" : 2, - "drilldown" : "Lubos Kolouch" - }, - { - "drilldown" : "Luca Ferrari", - "name" : "Luca Ferrari", - "y" : 8 - }, - { - "y" : 2, - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson" - }, - { - "name" : "Matthew Neleigh", - "y" : 2, - "drilldown" : "Matthew Neleigh" - }, - { - "drilldown" : "Niels van Dijke", - "y" : 2, - "name" : "Niels van Dijke" - }, - { - "drilldown" : "Packy Anderson", - "name" : "Packy Anderson", - "y" : 5 - }, - { - "name" : "Peter Campbell Smith", - "y" : 3, - "drilldown" : "Peter Campbell Smith" - }, - { - "drilldown" : "PokGoPun", - "name" : "PokGoPun", - "y" : 2 - }, - { - "y" : 3, - "name" : "Robbie Hatley", - "drilldown" : "Robbie Hatley" - }, - { - "name" : "Robert DiCicco", - "y" : 4, - "drilldown" : "Robert DiCicco" - }, - { - "y" : 2, - "name" : "Robert Ransbottom", - "drilldown" : "Robert Ransbottom" - }, - { - "y" : 5, - "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West" - }, - { - "y" : 3, - "name" : "Simon Green", - "drilldown" : "Simon Green" - }, - { - "drilldown" : "Steven Wilson", - "name" : "Steven Wilson", - "y" : 2 - }, - { - "drilldown" : "Thomas Kohler", - "name" : "Thomas Kohler", - "y" : 4 - }, - { - "drilldown" : "Ulrich Rieke", - "y" : 4, - "name" : "Ulrich Rieke" - }, - { - "drilldown" : "W. Luis Mochan", - "name" : "W. Luis Mochan", - "y" : 3 - } - ] - } - ], "title" : { "text" : "The Weekly Challenge - 226" }, - "chart" : { - "type" : "column" - }, - "subtitle" : { - "text" : "[Champions: 36] Last updated at 2023-07-28 10:14:26 GMT" - }, "drilldown" : { "series" : [ |
