このチャレンジを投稿する前にサンドボックスをチェックしませんでした-このチャレンジは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は4文字であるため、次の数字は4です。
6を有する3次数であるので、文字を3、及び三つの有する5次数であるので、文字を5、及び5を有する4つの文字の次数であるので、4
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 [One Hundred]は11ではなく10文字です)1,742 [One Seven Seven Fourty-Two]は36文字ではなく31文字です
- 文字列に変換する場合、100は100または100、100または1000ではなく、1000は1000、または1000ではありません。
- 文字列に変換されるとき、142は、百と四十二ではなく、百四十二でなければなりません
- 出力は大文字と小文字を区別せず、「NはK、KはM、Mは...で、4はマジックナンバー」という形式に従う必要があります(入力が4の場合を除き、出力は単に「4はマジックナンバーです」)
- 出力は、プログラムに常に一貫性がある限り、文字の代わりに数字を使用できます(「5は4、4はマジック番号」ではなく「5は4、4はマジック番号」)。
- 出力は、関数の戻り値であるか、または
STDOUT
- 標準的な抜け穴が適用されます
- これはcode-golfであるため、バイト単位の最短プログラムが優先されます。がんばろう!
ボーナス
入力が-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