Jump to content
BrainDen.com - Brain Teasers
  • 0


superprismatic
 Share

Question

6 answers to this question

Recommended Posts

  • 0

The sequence starts with the numbers from 100 to 499 and from 900 to 999 (500 total), then the ones from 500 to 899 (400), then 1,2,3,4 and 9, then the numbers from 50 to 89 (40) then 36 more for 1000,1001..., 1100, 1101... and so on, then 1350,1351... until the 1001st number, which I think is 1368. I kinda lost my patience with this and I don't even know if I did it right, so here it goes.

Edited by archlordbr
Link to comment
Share on other sites

  • 0

Brute force method!

MCCCXCI 1391

Using a bash shell created the following script to convert decimal to roman numeral (Do multiple parenthesis work in roman numerals beyond 5 million?):


$>cat roman_numeral.sh 

#!/bin/bash


number=$1

roman=""


iteration=0;

ones_base=( "I" "X" "C" )

fives_base=( "V" "L" "D" )

ones=( $ones_base )

fives=( $fives_base )


if [[ ! $number =~ '^[0-9]+$' ]] ; then

        echo "Only argument is a single decimal number"

fi


while [[ $number -gt 0 ]] ; do

        nextitr=$(( $iteration + 1 ))

        openp=$( for (( re=0; re < $(( $nextitr / 3 )); re++)) ; do echo -n '('; done )

        closep=$( for (( re=0; re < $(( $nextitr / 3 )); re++)) ; do echo -n ')'; done )

        fives[$nextitr]="${openp}${fives_base[$nextitr % 3]}${closep}"

        openp=$( for (( re=0; re < $(( ($nextitr - 1) / 3 )); re++)) ; do echo -n '('; done )

        closep=$( for (( re=0; re < $(( ($nextitr - 1) / 3 )); re++)) ; do echo -n ')'; done )

        ones[$nextitr]="${openp}${ones_base[$nextitr % 3]}${closep}"

        remainder=$(( $number % 10 ))

        case $remainder in

         1)

                roman="${ones[$iteration]}${roman}" ;;

         2)

                roman="${ones[$iteration]}${ones[$iteration]}${roman}" ;;

         3)

                roman="${ones[$iteration]}${ones[$iteration]}${ones[$iteration]}${roman}" ;;

         4)

                roman="${ones[$iteration]}${fives[$iteration]}${roman}" ;;

         5)

                roman="${fives[$iteration]}${roman}" ;;

         6)

                roman="${fives[$iteration]}${ones[$iteration]}${roman}" ;;

         7)

                roman="${fives[$iteration]}${ones[$iteration]}${ones[$iteration]}${roman}" ;;

         8)

                roman="${fives[$iteration]}${ones[$iteration]}${ones[$iteration]}${ones[$iteration]}${roman}" ;;

         9)

                roman="${ones[$iteration]}${ones[$nextitr]}${roman}" ;;

        esac

        (( number /= 10 ))

        (( iteration++ ))

        if [[ $iteration -eq 2 ]] ; then

                ones_base[0]="M"

        fi

done


echo $roman

The sorting:

$>for (( re=1; re <= 2001; re++ )) ; do echo "`./roman_numeral.sh $re` $re"; done | sort | awk 'NR == 1001'

MCCCXCI 1391

What method did everyone else use?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...