Может эта Римская цифра к Целочисленному коду преобразователя быть короче?

Я использовал

die() {
        echo $1
        kill $
}

прежде; я думаю, потому что 'выход' перестал работать для меня по некоторым причинам. Вышеупомянутые значения по умолчанию походят на хорошую идею, все же.

6
задан 9 revs, 5 users 70% 27 October 2018 в 09:33
поделиться

4 ответа

Shortest solutions from codegolf.com

There was a "Roman to decimal" competition over at Code Golf some time ago. (Well, actually it's still running because they never end.) A Perl golfer by the name of eyepopslikeamosquito decided to win all four languages (Perl, PHP, Python, and Ruby), and so he did. He wrote a fascinating four-part series "The golf course looks great, my swing feels good, I like my chances" (part II, part III, part IV) describing his approaches over at Perl Monks.

Here are his solutions:

Ruby, 53 strokes

n=1;$.+=n/2-n%n=10**(494254%C/9)%4999while C=getc;p$.

Perl, 58 strokes

$\+=$z-2*$z%($z=10**(19&654115/ord)%1645)for<>=~/./g;print

He also has a 53-stroke solution, but it probably doesn't work right now: (it uses the $^T variable during a few second period in 2011!)

$\+=$z-2*$z%($z=10**(7&$^T/ord)%1999)for<>=~/./g;print

PHP, 70 strokes

<?while(A<$c=fgetc(STDIN))$t+=$n-2*$n%$n=md5(o²Ûö¬Ñ.$c)%1858+1?><?=$t;

The six weird characters in the md5(..) are chr(111).chr(178).chr(219).chr(246).chr(172).chr(209) in Perl notation.

Python, 78 strokes

t=p=0
for r in raw_input():n=10**(205558%ord(r)%7)%9995;t+=n-2*p%n;p=n
print t
7
ответ дан 9 December 2019 в 22:35
поделиться

Python - 94 символа

дешевый снимок:)

I,V,X,L,C,D=1,5,10,50,100,500
M,R,r=D+D,vars(),lambda x:reduce(lambda T,x:T+R[x]-T%R[x]*2,x,0)
3
ответ дан 9 December 2019 в 22:35
поделиться

На самом деле определение моего собственного fromJust меньше, всего 98

r=foldl(\t c->t+y c-t`mod`y c*2)0 --34
y x=f$lookup x$zip"IVXLCDM"[1,5,10,50,100,500,1000] --52
f(Just x)=x --12
  -- assumes correct input

Haskell приближается.

import Data.Maybe --18
r=foldl(\t c->t+y c-t`mod`y c*2)0 --34
y x=fromJust$lookup x$zip"IVXLCDM"[1,5,10,50,100,500,1000] --59

total bytes = 111

Было бы 93, если i не требовался импорт для fromJust

1
ответ дан 9 December 2019 в 22:35
поделиться

Принятие ответа Джона Скита на ранее заданный аналогичный вопрос :

В моем пользовательском языке программирования «CPL1839079» это 3 байта:

r=f
0
ответ дан 9 December 2019 в 22:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: