4는 마법의 숫자입니다


26

이 챌린지를 게시하기 전에 샌드 박스 를 확인하지 않았습니다. 이 챌린지가 Cᴏɴᴏʀ O'Bʀɪᴇɴ 에서 제안한 것 같습니다 .

정수 입력이 주어지면 "4는 마법의 숫자"수수께끼를 출력하는 프로그램을 작성하십시오

  • 4는 마법의 숫자입니다
  • 5는 4이고 4는 마법의 숫자입니다
  • 6은 3, 3은 5, 5는 4, 4는 매직 넘버입니다
  • 11은 6, 6은 3, 3은 5, 5는 4, 4는 매직 넘버입니다
  • 5 백은 11, 11은 6, 6은 3, 3은 5, 5는 4, 4는 마법 수

수수께끼를 이미 알고 있거나 수수께끼가 무엇인지 알아 내기 위해 너무 게으른 경우 여기에 설명이 있습니다.

다음 숫자는 이전 숫자의 글자 수입니다. 예를 들어 5 에는 4 개의 문자가 있으므로 다음 숫자는 4 입니다.

63 개의 문자 를 가지 므로 다음 숫자는 3 , 35 개의 문자 를 가지 므로 다음 숫자는 5 , 54 개의 문자 를 가지 므로 다음 숫자는 4입니다

. 수수께끼 가 4로 끝나는 이유는 4 개의 문자가 있기 때문입니다 , 4는 4, 4는 4, 4는 4 ... (4는 매직 넘버)

테스트 사례

0 =>
  Zero is four and four is the magic number
1 =>
  One is three and three is five and five is four and four is the magic number
2 =>
  Two is three and three is five and five is four and four is the magic number
3 => 
  Three is five and five is four and four is the magic number
4 =>
  Four is the magic number
5 => 
  Five is four and four is the magic number
6 =>
  Six is three and three is five and five is four and four is the magic number
7 =>
  Seven is five and five is four and four is the magic number
8 =>
  Eight is five and five is four and four is the magic number
9 =>
  Nine is four and four is the magic number
10 =>
  Ten is three and three is five and five is four and four is the magic number
17 =>
  Seventeen is nine and nine is four and four is the magic number
100 =>
  One Hundred is ten and ten is three and three is five and five is four and four is the magic number
142 =>
  One Hundred Forty Two is eighteen and eighteen is eight and eight is five and five is four and four is the magic number
1,000 =>
  One Thousand is eleven and eleven is six and six is three and three is five and five is four and four is the magic number
1,642 =>
  One Thousand Six Hundred Forty Two is twenty nine and twenty nine is ten and ten is three and three is five and five is four and four is the magic number
70,000 =>
  Seventy Thousand is fifteen and fifteen is seven and seven is five and five is four and four is the magic number
131,072 =>
  One Hundred Thirty One Thousand Seventy Two is thirty seven and thirty seven is eleven and eleven is six and six is three and three is five and five is four and four is the magic number
999,999 =>
  Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine is fifty and fifty is five and five is four and four is the magic number

규칙

  • 입력은 STDIN함수 에서 가져 오거나 함수의 인수로 사용할 수 있습니다.
  • 입력은 0에서 999,999 사이의 양수입니다.
  • 입력 에는 숫자 포함됩니다 (정규식을 따릅니다 ^[0-9]+$)
  • 입력은 정수 또는 문자열로 취할 수 있습니다
  • 단어 문자열로 변환 할 때 공백과 하이픈은 개수에 포함하지 않아야합니다 (100 [100]은 11이 아닌 10 자입니다.
  • 문자열로 변환 할 때 100은 백 또는 백이 아닌 1 백이어야하고 1000은 천 또는 천이 아니라 1 천이어야합니다.
  • 문자열로 변환 할 때 142는 100 40이 아닌 100 분의 1이어야합니다.
  • 출력은 대소 문자를 구분하지 않으며 " NK 이고 KM 이고 M 은 ...이고 4는 매직 번호" 형식을 따라야합니다 (입력이 4가 아닌 경우 출력은 단순히 "4"여야 함). 마법 번호입니다 ")
  • 프로그램이 항상 일관된 한 출력 문자 대신 숫자를 사용할 있습니다 ( "5는 4, 4는 마법의 숫자"대신 "5는 4, 4는 마법의 숫자").
  • 출력은 함수의 반환 값이거나 STDOUT
  • 표준 허점 적용
  • 이것은 이므로 바이트 단위의 가장 짧은 프로그램이 승리합니다. 행운을 빕니다!

보너스

입력이 -999,999에서 999,999 사이 일 때 프로그램이 작동하면 -30 바이트 입니다.

음수는 단어로 변환 될 때 앞에 "음수"를 갖습니다. 예를 들어 -4"음수 4", 음수 4는 12, 12는 6, 6은 3, 3은 5, 5는 4, 4는 매직 넘버입니다.

프로그램이 숫자의 문자열 표현을 생성하기 위해 내장 함수를 사용하지 않는 경우 -150 바이트

리더 보드

리더 보드와 언어 별 수상자 개요를 모두 생성하는 스택 스 니펫입니다.

답변이 표시되도록하려면 다음 마크 다운 템플릿을 사용하여 헤드 라인으로 답변을 시작하십시오.

## Language Name, N bytes

여기서 N은 제출 크기 (바이트)입니다.

헤더에 여러 숫자를 포함하려면 (예를 들어, 오래된 점수를 받거나 바이트 수에 플래그 포함) 실제 점수가 헤더 의 마지막 숫자 인지 확인하십시오.

## Language Name, <s>K</s> X + 2 = N bytes


가능한 최대 입력이 있습니까?
Arcturus

7
앞으로도 샌드 박스를 확인하여 다른 사람이 귀하의 아이디어를 갖고 있는지 확인하십시오 .
El'endia Starman 5

@ El'endiaStarman 좋아, 난 그 게시물에 연결 도전의 상단에 몇 가지 텍스트를 추가
Jojodmo

내장 함수 보너스는 -150에서 -200 바이트와 같아야합니다.
TanMath

1
나는 이것을 그냥 버릴 것입니다-심지어 가장 최적화 된 이름 대 이름 변환기조차도 대부분의 언어에서 150 바이트 미만의 비용이 거의 들지 않습니다 .-150은 보너스보다 함정입니다.
ricdesi

답변:


9

Bash + 공통 유틸리티 (BSD 게임 포함), 123-30 = 93 바이트

for((n=$1;n-4;n=m)){
m=`number -l -- $n|sed 's/nus/&&/;s/\W//g'`
s+="$n is $[m=${#m}] and "
}
echo $s 4 is the magic number

운 좋게도 bsd-games number유틸리티 의 출력 은 거의 정확히 우리가 필요로하는 것입니다. 출력 번호는 모두 숫자로 작성되며 8 번째 글 머리 기호에 따라 단어로 표시되지 않습니다.

$ ./4magic.sh 131072
131072 is 37 and 37 is 11 and 11 is 6 and 6 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
$ ./4magic.sh -4
-4 is 12 and 12 is 6 and 6 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
$ 

6

C, 263261 바이트-180 = 81

char*i="jmmonnmoonmpprrqqsrrjjddeeecdd",x;f(n,c){return!n?n:n<0?f(-n,8):n<100?c+i[n<20?n:n%10]-i[20+n/10]:f(n/1000,8)+f(n/100%10,7)+f(n/100%10,0)+c;}main(int c,char**v){for(c=atoi(*++v);c-4;c=x)printf("%d is %d and ",c,x=c?f(c,0)):4;puts("4 is the magic number");}

Cole Cameron의 답변에서 영감을 얻었습니다 . 나는 매크로 정의없이 더 잘 할 수 있다고 생각했습니다. 나는 결국 관리했지만 달성하기 위해 약간의 압박이 필요했습니다!

연속 문자가있는 호스트 문자 세트가 필요합니다 (ASCII는 괜찮지 만 EBCDIC은 작동하지 않습니다). 조회 테이블 쌍입니다. 나는 j제로 문자로 선택 하고 두 번의 조회가 필요하다는 이점을 얻었으므로 두 제로에서 제로를 빼지 않고 다른 것을 뺄 수있었습니다.

댓글 버전 :

char*i=
    "jmmonnmoon"                /* 0 to 9 */
    "mpprrqqsrr"                /* 10 to 19 */
    "jjddeeecdd";               /* tens */
char x;                /* current letter count */

f(n,c){
return
    !n?n                        /* zero - return 0 (ignore c) */
    :n<0?f(-n,8)                /* negative n (only reached if c==0) */
    :n<100?c+i[n<20?n:n%10]-i[20+n/10] /* lookup tables */
    :
      f(n/1000,8)               /* thousand */
    + f(n/100%10,7)             /* hundred */
    + f(n%100,0)                /* rest */
    + c;                        /* carry-in */
}
main(int c, char**v)
{
    for(c=atoi(*++v);c-4;c=x)
        printf("%d is %d and ",c,x=c?f(c,0):4);
    puts("4 is the magic number");
}

로 대체 f(n/1000,8)하여 수백만을 지원할 수있는 확실한 확장 기능이 있습니다 f(n/1000000,7)+f(n/1000%1000,8).

테스트 출력

0 is 4 and 4 is the magic number
1 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
2 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
3 is 5 and 5 is 4 and 4 is the magic number
4 is the magic number
5 is 4 and 4 is the magic number
6 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
7 is 5 and 5 is 4 and 4 is the magic number
8 is 5 and 5 is 4 and 4 is the magic number
9 is 4 and 4 is the magic number
10 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
17 is 9 and 9 is 4 and 4 is the magic number
100 is 10 and 10 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
142 is 18 and 18 is 8 and 8 is 5 and 5 is 4 and 4 is the magic number
1000 is 11 and 11 is 6 and 6 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
1642 is 29 and 29 is 10 and 10 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
70000 is 15 and 15 is 7 and 7 is 5 and 5 is 4 and 4 is the magic number
131072 is 37 and 37 is 11 and 11 is 6 and 6 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number
999999 is 50 and 50 is 5 and 5 is 4 and 4 is the magic number

4

수학, 156-30 = 126 바이트

a=ToString;({a@#," is ",a@#2," and "}&@@@Partition[NestWhileList[#~IntegerName~"Words"~StringCount~LetterCharacter&,#,#!=4&],2,1])<>"4 is the magic number"&

나는 이것이 문자열을 사용하고 엄청나게 길지 않다는 것에 놀랐습니다 .


4

스위프트 2 , 408419-30 = 389 바이트

Swift가 정규 표현식 (하이픈과 공백 제거)으로 너무 자세하지 않으면 176 바이트를 제거 할 수 있습니다.

func c(var s:Int)->String{var r="";while(s != 4){r+="\(s)";let f=NSNumberFormatter();f.numberStyle=NSNumberFormatterStyle.SpellOutStyle;let v=f.stringFromNumber(s)!;s=v.stringByReplacingOccurrencesOfString("[- ]",withString:"",options:NSStringCompareOptions.RegularExpressionSearch,range:Range<String.Index>(start:v.startIndex,end:v.endIndex)).utf8.count+(s<0 ?3:0);r+=" is \(s) and "};return r+"4 is the magic number"}

이것은 swiftstub.com에서 테스트 할 수 있습니다.

나는 for 루프를 조금 실행했는데 1000030에서 999999 사이의 숫자는 가장 긴 문자열 결과를 가지고 있으며 6 번 반복됩니다.

10000323 , 2311 , 116 , 63 , 35 , 54 , 4 는 매직 넘버

언 골프

func a(var s: Int) -> String{
    var r = ""
    while(s != 4){
        r+="\(s)"

        let f = NSNumberFormatter()
        f.numberStyle = NSNumberFormatterStyle.SpellOutStyle
        let v = f.stringFromNumber(s)!
        s = v.stringByReplacingOccurrencesOfString(
            "[- ]",
            withString: "",
            options: NSStringCompareOptions.RegularExpressionSearch,
            range: Range<String.Index>(start: v.startIndex, end: v.endIndex)
        ).utf8.count + (s < 0 ? 3 : 0)

        r+=" is \(s) and "
    }
    return r+"4 is the magic number"
}

7
NSStringCompareOptions.RegularExpressionSearch그리고 JS String.fromCharCode가 장황 하다고 생각했습니다 . : P
ETHproductions

4
파이썬과 루비 : string.replace. 스위프트 :String.stringByReplacingOccurrencesOfString
cat

4

하스켈, 285-180 = 105 바이트

실제로 숫자를 표시하기위한 내장 기능이 전혀 없습니다. 나는 여전히 점수에 불만족했다. 의견을 주시기 바랍니다. 그래도 더 실험 해 보겠습니다. 여전히 점수는 스위프트의 점수보다 낫습니다.

c n|n<0=8+c(-n)|n>999=r 1000+8|n>99=7+r 100|n>19=r 10+2-g[30..59]+g[20..29]|n>15=r 10-1|2>1=[0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7]!!n where{g=fromEnum.elem n;r k=c(mod n k)+c(div n k)}
m 4="4 is the magic number"
m 0="0 is 4 and "++m 4
m n=show n++" is "++show(c n)++" and "++m(c n)

용법

m 7
"7 is 5 and 5 is 4 and 4 is the magic number"
m 999999
"999999 is 50 and 50 is 5 and 5 is 4 and 4 is the magic number"

설명.

m그러나 사소한 c것은 아닙니다. c영문 숫자의 문자 수를 계산하는 함수입니다.

c n |n<0=8+c(-n) -- Add word "negative" in front of it, the length is 8
    |n>999=r 1000+8 -- the english name for number with form xxx,yyy is xxx thousand yyy
    |n>99=7+r 100 -- the english name for number with form xyy is x hundred yy
    |n>19=r 10+2-g[30..59]+g[20..29] -- the english name for number with form xy with x more
                                     -- than 1 is x-ty. However *twoty>twenty,
                                     -- *threety>thirty, *fourty>forty, *fivety>fifty.
    |n>10=r 10-1-g(15:18:[11..13]) -- the english name for number with form 1x is x-teen.
                                     -- However, *oneteen>eleven, *twoteen>twelve,
                                     -- *threeteen>thirteen, *fiveteen>fifteen,
                                     -- *eightteen>eighteen
    |2>1=[0,3,3,5,4,4,3,5,5,4,3]!!n -- for number 0-10, the length is memorized. 0 is 0
                                    -- because it is omitted. Input zero is handled
                                    -- separately. If we defined 0 to be 4, then
                                    -- 20 => twenty zero.
  where g   =fromEnum.elem n      -- Check if n is element of argument array, if true, 1 else 0
        r k=c(mod n k)+c(div n k) -- Obvious.

1
아 그래? 글쎄, 스위프트는 ... 음 ... 높은 점수 ... (컴백에별로 좋지 않습니다)
Jojodmo

4

C, 268-180 = 88 바이트

#define t(x,o)n<x?o:f(n/x)+(n%x?f(n%x):0)
char*i="4335443554366887798866555766";f(n){return t(1000,t(100,n<20?n<0?8+f(-n):i[n]-48:i[n/10+18]-48+(n%10?f(n%10):0))+7)+8;}main(n){for(scanf("%d",&n);n^4;n=f(n))printf("%d is %d and ",n,f(n));puts("4 is the magic number");}

여기에서 시도 하십시오 .

언 골프

/* Encode number length in string (shorter representation than array) */
char*i="4335443554366887798866555766";

f(n)
{
    return n < 1000
        ? n < 100
            ? n < 20
                ? n < 0
                    ? 8 + f(-n) /* "Negative x" */
                    : i[n] - 48 /* "x" */
                : i[n/10+18] + (n%10 ? f(n%10) : 0) /* 20-99 */
            : f(n/100) + (n%100 ? f(n%100) : 0) + 7 /* x hundred y */
        : f(n/1000) + (n%1000 ? f(n%1000) : 0) + 8; /* x thousand y */
}

main(n)
{
    /* Keep printing until you get to the magic number */
    for(scanf("%d",&n);n^4;n=f(n))
        printf("%d is %d and ",n,f(n));
    puts("4 is the magic number");
}

3

자바, 800-150 = 650 바이트

class G{static String e="",i="teen",j="ty",k="eigh",y="thir",d="zero",l="one",n="two",m="three",h="four",s="five",c="six",t="seven",b=k+"t",g="nine",D="ten",L="eleven",N="twelve",M=y+i,H=h+i,S="fif"+i,C=c+i,T=t+i,B=k+i,G=g+i,o="twen"+j,p=y+j,q="for"+j,r="fif"+j,u=c+j,v=t+j,w=k+j,x=g+j,A=" ",O=" hundred ",z,E;public static void main(String a[]){z=e;int l=new Integer(a[0]);do{E=a(l,1,e);l=E.replace(A,e).length();z=z+E+" is "+a(l,1,e)+" and ";}while(l!=4);System.out.print(z+h+" is the magic number");}static String a(int P,int _,String Q){String[]f={e,l,n,m,h,s,c,t,b,g,D,L,N,M,H,S,C,T,B,G,e,D,o,p,q,r,u,v,w,x};int R=20,X=10,Y=100,Z=1000;return P==0?(_>0?d:e):(P<R?f[P]+Q:(P<Y?(f[R+(P/X)]+" "+a(P%X,0,e)).trim()+Q:(P<Z?a(P/Y,0,O)+a(P%Y,0,e)+Q:a(P/Z,0," thousand ")+a((P/Y)%X,0,O)+a(P%Y,0,e)+Q)));}}

골퍼

class G {

   static String e="",i="teen",j="ty",k="eigh",y="thir",d="zero",l="one",n="two",m="three",h="four",s="five",c="six",t="seven",b=k+"t",g="nine",D="ten",L="eleven",N="twelve",M=y+i,H=h+i,S="fif"+i,C=c+i,T=t+i,B=k+i,G=g+i,o="twen"+j,p=y+j,q="for"+j,r="fif"+j,u=c+j,v=t+j,w=k+j,x=g+j,A=" ",O=" hundred ",z,E;

   public static void main(String a[]){
     z = e;
     int l = new Integer(a[0]);
     do {
             E = a(l,1,e);
             l = E.replace(A,e).length();  
             z = z+E+" is "+a(l,1,e)+" and ";
     } while(l!=4);
     System.out.println(z+h+" is the magic number");
   }

   static String a(int P,int _,String Q) {
     String[] f = {e,l,n,m,h,s,c,t,b,g,D,L,N,M,H,S,C,T,B,G,e,D,o,p,q,r,u,v,w,x};
     int R=20,X=10,Y=100,Z=1000;
     return P==0?(_>0?d:e):(P<R?f[P]+Q:(P<Y?(f[R+(P/X)]+" "+a(P%X,0,e)).trim()+Q:(P<Z?a(P/Y,0,O)+a(P%Y,0,e)+Q:a(P/Z,0," thousand ")+ a((P/Y)%X,0,O)+a(P%Y,0,e)+Q)));
   }
}

1 년 이상이 지났음을 알지만 3 항 과제에서 괄호를 제거하고로 변경할 ==0<1있습니다. 그래서 : return P<1?_>0?d:e:P<R?f[P]+Q:P<Y?(f[R+(P/X)]+" "+a(P%X,0,e)).trim()+Q:P<Z?a(P/Y,0,O)+a(P%Y,0,e)+Q:a(P/Z,0," thousand ")+a((P/Y)%X,0,O)+a(P%Y,0,e)+Q;( -10 bytes )
Kevin Cruijssen

3

QC, 265-30-150 = 85 바이트

(✵1:oaT%=ta100%=ha100/⌋T%=X[0 3 3 5 4 4 3 5 5 4 3 6 6 8 8 7 7 9 8 8]=Y[6 6 5 5 5 7 6 6]=a0≟4a20<Xt☌YtT/⌋2-☌Xo☌+▲▲hXh☌7+0▲+)(❆1:na0<8*=ba‖1000/⌋=ca1000%=nbb✵8+0▲a✵++){I4≠:EEI" is "++=II❆=EEI" and "++=E!}E"4 is the magic number"+

테스트 스위트

언 골프 드 :

(✵1:
oaT%=                                        # ones
ta100%=                                      # tens
ha100/⌋T%=                                   # hundreds
X[0 3 3 5 4 4 3 5 5 4 3 6 6 8 8 7 7 9 8 8]=  # length of "zero", "one", "two", ..., "nineteen"
Y[6 6 5 5 5 7 6 6]=                          # length of "twenty", ..., "ninety"
a0≟
  4
  a20< 
    Xt☌ 
    YtT/⌋2-☌ Xo☌ +
  ▲ 
▲
hXh☌7+0▲+)

(❆1:
na0<8*=                 # if negative, add 8
ba‖1000/⌋=              # split aaaaaa into bbbccc
ca1000%=
n bb✵8+0▲ a✵ ++)

{I4≠:EEI" is "++=II❆=EEI" and "++=E!}E"4 is the magic number"+

숫자의 길이를 얻기 위해 내장 함수를 사용하지 않는 경우 실제로 점수에서 다른 150 을 뺄 수 있습니다
Jojodmo

2

자바 스크립트, 382-150-30 = 202 바이트

var o=[0,3,3,5,4,4,3,5,5,4],f=s=>(s[1]==1?[3,6,6,8,8,7,7,9,8,8][s[0]]:o[s[0]]+(s.length>1?[0,3,6,6,5,5,5,7,6,6][s[1]]:0))+(s.length==3?(7+o[s[2]]-(o[s[2]]==0?7:0)):0),l=n=>{var s=(""+n).split("").reverse();return f(s.slice(0,3))+(s.length>3?(f(s.slice(3,6))+8):0)};(n=>{var s="";while(n!=4){s+=n+" is ";n=n>=0?l(n):(l(-n)+8);s+=n+" and ";}console.log(s+"4 is the magic number");})()

입력은 즉시 호출 된 함수 표현식에 매개 변수로 제공됩니다.

테스트 입력 :

999999 ->
    999999 is 50 and 50 is 5 and 5 is 4 and 4 is the magic number
17 ->
    17  is 9 and 9 is 4 and 4 is the magic number
-404 ->
    -404 is 23 and 23 is 11 and 11 is 6 and 6 is 3 and 3 is 5 and 5 is 4 and 4 is the magic number

골퍼 해제 :

// array of the lengths of digits in ones place:
// one is 3, two is 3, three is 5, etc... zero is a special case
// and is assigned zero length because zero is never written out in a number name
var o=[0,3,3,5,4,4,3,5,5,4],

// function that computes the length of a substring of the input
// because the input is 6 digits, it can be broken into two 3 digit subsections
// each of which can have it's length calculated separately
f=s=>
  (
  s[1]==1? // check for if the tens digit is a one
    // when the tens is a one, pull the string length from an array that represents
    // ten, eleven, twelve, thirteen, etc...
    [3,6,6,8,8,7,7,9,8,8][s[0]]
  :
    // when the tens digit is not a one, add the ones digit normally and...
    o[s[0]]
    +
    // add the tens digit length from the array that represents
    // zero, ten, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
    (s.length>1?[0,3,6,6,5,5,5,7,6,6][s[1]]:0)
  )
  +
  (
  s.length==3? // check if the length is 3 and weren't not accidentally trying to do something wierd with a minus sign
    // if so, then we have to add a hundred (7 characters) to the length and the
    // length of the ones digit that is in the hundreds place like
    // 'one' hundred or 'two' hundred
    (7+o[s[2]]-
      (
        // also, if the hundreds place was a zero, subtract out those 7 characters
        // that were added because 'hundred' isn't added if there's a zero in its
        // place
        o[s[2]]==0?
          7
        :
          0
      )
    )
  :
    // if the length wasn't 3, then don't add anything for the hundred
    0
  ),

// function that computes the length of the whole six digit number
l=n=>{
  // coerce the number into a string and then reverse the string so that the
  // ones digit is the zeroth element instead of last element
  var s=(""+n).split("").reverse();
  return
    // calculate the character length of the first 3 characters
    // like in the number 999888, this does the '888'
    f(s.slice(0,3))
    +
    // then if there actually are any characters after the first 3
    (s.length>3?
        // parse the character length of the second 3 characters
        (f(s.slice(3,6))+8)
      :
        0
    )
};
// lastly is the Immediately-Invoked Function Expression
(n=>{
  var s="";
  // as long as we haven't reached four, just keep going through the loop
  while(n!=4){
    s+=n+" is ";
    n=n>=0?l(n):(l(-n)+8) // this handles negatives by only passing positive values to l and then just adding 8 onto the length for negatives
    s+=n+" and ";
  }
  // finally just say that '4 is the magic number'
  console.log(s+"4 is the magic number");
})(999999)

1

파이썬 641-150 = 501 바이트

적어도 Java보다 길지 않습니다! 문자열을 사용 하는 것을 제외하고 는 이것을 기반으로 합니다 .

편집 : 나는 0을 잊어 버렸고 "5는 4"라고 말하고 "4는 마법의 숫자"로 건너 뛰지 않아야합니다.

w={0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten",11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",16:"sixteen",17:"seventeen",18:"eighteen",19:"nineteen",20:"twenty",30:"thirty",40:"forty",50:"fifty",60:"sixty",70:"seventy",80:"eighty",90:"ninety"}
s=""
def i(n):
 global s
 e=""
 o=n%10
 t=n%100
 h=n/100%10
 th=n/1000
 if th:
  e+=i(th)
  e+='thousand'
 if h:
  e+=w[h]
  e+='hundred'
 if t:
  if t<20 or o==0:
   e+=w[t]
  else:
   e+=w[t-o]
   e+=w[o]
 if len(e)==4:s+="4 is the magic number";print s
 else: s+="%d is %d and "%(n,len(e));i(len(e))
In=input()
i(In)

여기 사용해보십시오!


이름을 표시하지 않아도됩니까?
Akangka

이것은 올바르지 않습니다. 대신에 i(5)인쇄합니다 . 4 is the magic number5 is 4 and 4 is the magic number
mbomb007

1

무, 182 176 / 192 188 바이트 - 30 = 158분의 146

188 바이트 버전 :

u=$string_utils;s="";i=args[0];while(i-4)j=u:english_number(i);s=s+j+(s?" and "+j|"")+" is ";i=length(u:strip_chars(j,"- "}));endwhile;return s+(s?"four and "|"")+"four is the magic number"

176 바이트 구현에 따른 버전 :

s="";i=args[0];while(i-4)j=#20:english_number(i);s=s+j+(s?" and "+j|"")+" is ";i=length(#20:strip_chars(j," -"));endwhile;return s+(s?"four and "|"")+"four is the magic number"

둘 다 기능입니다.


1

PHP, 168-30 = 138 바이트

function m($i){$e=strlen(preg_replace('/[^a-z-]/','',(new NumberFormatter("en",5))->format($i)));echo($i==$e?"":"$i is $e and "),($e==4?"4 is the magic number":m($e));}
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.