友達に「コンマクラブ」を教えてください


16

このようなシリコンバレーの「3コンマクラブ」シーンに触発され、このチャレンジでは10人にそれぞれが属する「コンマクラブ」を伝えます。

「コンマクラブ」という用語に慣れていない場合は、説明しましょう。持っているお金が1,000.00ドルから999,999.99ドルの範囲であれば、1コンマクラブにいます。$ 1,000,000.00から$ 999,999,999.99の範囲にある場合、2コンマクラブにいます。地球上の個人(AFAIK)は1兆ドル以上を所有していないため、これらの「クラブ」は3コンマクラブを通じて繰り返されます(日本円はすぐに別の話になります)。したがって、銀行口座のカンマの数は、米国および英国で最も一般的な表記基準に従って、あなたが所属するカンマクラブを示します。同じ「コンマ」ルールが負の数値にも適用されます(ただし、負のコンマクラブにはなりたくないでしょう)。包括範囲[-0.01、-999の負の量。

テストケース

Friend    Amount
John      100000
Jamie     0.05
Kylie     1549001.10
Laura     999999999.99
Russ      986000000
Karla     1
Reid      99.99
Mark      999.99
Manson    1000.01
Lonnie    999999999999.00
Nelly     -123.45

正しい答え:

John is in the 1-comma club.
Jamie is in the 0-comma club.
Kylie is in the 2-comma club.
Laura is in the 2-comma club.
Russ is in the 2-comma club.
Karla is in the 0-comma club.
Reid is in the 0-comma club.
Mark is in the 0-comma club.
Manson is in the 1-comma club.
Lonnie is in the 3-comma club.
Nelly is in the 0-comma club.

配列を取得するために必要な配列設定が何であれfriendsamounts配列はスコアにカウントされません。したがって、Pythonの場合、次のコードは考慮されません。

f = ['John', 'Jamie', 'Kylie', 'Laura', 'Russ', 'Karla', 'Reid', 'Mark', 'Manson', 'Lonnie']
a = ['100000', '0.05', '1549001.10', '999999999.99', '986000000', '1', '99.99', '999.99', '1000.01', '999999999999.00']

編集:改訂されたテストケースをご覧ください

テストケースから実際の文字列のコンマを削除して、コンマを数えるだけではなく、少し難しくしました。


2
出力フォーマットを非常に明確にしたとは思わない。"Name number,Name number,..."受け入れられるようなものですか?
FryAmTheEggman

2
fのエントリは、ポジティブであることが保証されていますか、それとも-$1,234.561コンマクラブにもありますか?
ジョナサンアラン

2
@not_a_robot Fryのコメントに対処できますか?名前と番号のペアを任意の形式で出力するだけで十分ですか?
マーティンエンダー

1
@FryAmTheEggmanいいえ、出力は次の形式である必要があります"<name> is in the <number of commas>-club."
ブラックサイト

1
テストケースは仕様ではありません。そして、たとえそうであったとしても、上記のジョナサン・アランによって提起された大きなネガティブの問題をカバーするテストケースはありません。
ピーターテイラー

回答:


10

JavaScript(ES6)、80バイト

a=>a.map(([s,n])=>s+` is in the ${n.toFixed(n<0?3:4).length/3-2|0}-comma club.`)

[friend、amount]配列の配列を取り、「friend is in n-comma club」という配列を返します。文字列。余分な末尾のゼロを追加して、長さが0コンマクラブで6〜8、1コンマクラブで9〜11、2コンマクラブで12〜15などになるように機能します。

https://jsfiddle.net/cau40vmk/1/


これは負の数では機能しないと思います。たとえば、Nelly(-123.45)を1コンマクラブに入れます。短い方をお勧めしMath.log10(n*n)/6|0ます。
アーナルド

@Arnauldああ、はい、|0ゼロに切り捨てることを忘れていたので、ジェイミーに正しい答えを与えました。
ニール

8

PostgreSQL、61バイト

SELECT f||' is in the '||div(log(@a),3)||'-comma club.'FROM p

@xはの絶対値でxlog(x)10を底とdiv(y, x)する対数であり、y / xの整数商を計算します。


セットアップ:

CREATE TEMP TABLE p AS
SELECT * FROM (VALUES
    ('John', 100000),
    ('Jamie', 0.05),
    ('Kylie', 1549001.10),
    ('Laura', 999999999.99),
    ('Russ', 986000000),
    ('Karla', 1),
    ('Reid', 99.99),
    ('Mark', 999.99),
    ('Manson', 1000.01),
    ('Lonnie', 999999999999.00),
    ('Nelly', -123.45)
) AS p (f, a)

出力:

            ?column?            
--------------------------------
 John is in the 1-comma club.
 Jamie is in the 0-comma club.
 Kylie is in the 2-comma club.
 Laura is in the 2-comma club.
 Russ is in the 2-comma club.
 Karla is in the 0-comma club.
 Reid is in the 0-comma club.
 Mark is in the 0-comma club.
 Manson is in the 1-comma club.
 Lonnie is in the 3-comma club.
 Nelly is in the 0-comma club.
(11 rows)

競争力のあるSQLの回答を見るのは素晴らしいことです。
トビースパイト

6

ゼリー34  32 バイト

AḞbȷL’⁶;“£ṙƬs⁾`¬ụṂ“¢<ỴȦ8£l»jµ€⁹żY

銀行残高のリストを数字(10進数/整数)として、名前のリストを文字列として受け取り、文字列のリストを返すダイアディックリンク(関数)。

オンラインでお試しください!-フッターçYは関数を呼び出すだけで、結果のリストを改行で結合するため、完全なプログラムとして実行したときに素晴らしい出力が得られます。

どうやって?

AḞbȷL’⁶;“£ṙƬs⁾`¬ụṂ“¢<ỴȦ8£l»jµ€⁹żY - Main link: bankBalances, names
                             €    - for each bankBalance:
A                                 - absolute value (treat negatives and positives the same)
 Ḟ                                - floor (get rid of any pennies)
  bȷ                              - convert to base 1000
    L                             - length (number of digits in base 1000)
     ’                            - decrement by one
      ⁶;                          - concatenate a space with that   ...because -------.
        “         “       »       - compressed list of strings:                       ↓
         £ṙƬs⁾`¬ụṂ                -     " is in the"  ← cannot compress a trailing space :(
                   ¢<ỴȦ8£l        -     "-comma club."
                           j      - join that list of strings with the "number plus space"
                            µ     - monadic chain separation (call that result L)
                              ⁹   - right argument (names)
                               ż  - zip with L

4

PHP、76 74バイト

// data as associative array
$d=[Poorman=>-1234,John=>100000,Jamie=>0.05,Kylie=>1549001.10,Laura=>999999999.99,Russ=>1000000000,Karla=>1,Reid=>99.99,Mark=>999.99,Manson=>1000.01,Lonnie=>999999999999.00];
// code
foreach($d as$n=>$a)printf("$n is in the %d-comma club.
",log($a*$a,1e6));

幸い、intにキャストする必要はありません(Cでする必要があります)。PHPはそれを暗黙的に行い%dます。


うん!私はここで文字を数える代わりに計算する最初のものですか?
タイタス

4

Mathematica(86バイト)

セットアップ(名前は文字列、お金は数字):

n = {"John", "Jamie", "Kylie", "Laura", "Russ", "Karla", "Reid", "Mark", "Manson", "Lonnie", "Nelly"};
m = {100000, 0.05, 1549001.10, 999999999.99, 1000000000, 1, 99.99, 999.99, 1000.01, 999999999999.00, -123.45}

試み:

MapThread[#~~" is in the "~~ToString@Max[Floor@Log[10^3,#2],0]~~"-comma club."&,{n,m}]

Mathematicaのすべての文字列関数には名前に「String」が含まれているため、ログは短いと思います。これMax[...,0]は、-1ドルから1ドルの間で所有する人々の厄介な負の数または負の無限大に対処することです。負の数のログには虚数が含まれていFloorますが、!


4

Japt、36バイト

これは、量を最初の入力、名前を2番目の入力として受け取ります。

V+`   e {w0 x4 l /3-2|0}-¬mµ club

説明

V+`   e {w0 x4 l /3-2|0}-¬mµ club
V+                                   // Second input +
  `                                  // compressed string:
      e                              // " is in the " 
        {              }             // Insert here:
         w0                          //   The larger of 0 and the first input
            x4                       //   Rounded to the 4th decimal
               l                     //   Length
                        -¬mµ club    // "-comma club"
                                     // A closing backtick is auto-inserted at the end of the program

Japtは、文字列の圧縮にshocoライブラリを使用します。

@Neilのソリューションに触発されました。

@ETHproductionsのおかげで7バイト節約

オンラインでお試しください!


1
Vw0 x4 l /3-2|06バイトを節約して、真ん中のセクションでできると思います:
ETHproductions

1
逆の順序で入力を取得することで、バイトを節約できると思いますV+`...{w0...
。– ETHproductions

3

MATL、50 48 43バイト

`j' is in the 'i|kVn3/XkqV'-comma club'&hDT

MATL Online試しください

説明

`                   % Do...While loop
  j                 % Explicitly grab the next input as a string
  ' is in the the ' % Push this string literal to the stack
  i                 % Grab the next input as a number
  |                 % Compute the absolute value
  k                 % Round towards zero
  V                 % Convert to a string
  n3/Xk             % Divide the length of the string by 3 and round up
  q                 % Subtract one
  V                 % Convert to a string
  '-comma club'     % Push this string literal to the stack
  &h                % Horizontally concatenate the entire stack
  D                 % Display the resulting string
  T                 % Push TRUE to the stack, causing an infinite loop which automatically
                    % terminates when we run out of inputs
                    % Implicit end of do...while loop

3

R、68バイト

セットアップ:

f <- c('John', 'Jamie', 'Kylie', 'Laura', 'Russ', 'Karla', 'Reid', 'Mark', 'Manson', 'Lonnie', 'Nelly')
a <- c(100000, 0.05, 1549001.10, 999999999.99, 986000000, 1, 99.99, 999.99, 1000.01, 999999999999.00, -123.45)

ソリューション:

cat(paste0(f, " is in the ",floor(log10(abs(a))/3)),"-comma club.\n"))

アカウントの絶対値の10を底とするログを取得し、切り捨ててから名前を付けて印刷します。

a文字ベクトルの場合、もっと小さくできるかどうかはわかりません...


1
-123.45ドルのネリーの場合はどうですか?そのlog10呼び出しはNaN、否定に対してsを生成します。log10(abs(a))うまくいくように見えます。
ブラックサイト

おっと、そうですね、上記のサンプルにはネリーが含まれていませんでした。そして、私は仕様を読み間違えました...私は負の値が0コンマクラブであるべきだと理解しました。
ジョー

の代わりに-をabs(x)使用します。pmax(a,1)これは1未満のものを取り、1にします。負の数に対しては良い結果が得られます。そして、代わりにfloor(log10(...)/3)を使用できますlog10(...)%/%3。これで66バイトになります(ネガを修正します)。
グレゴール

1
また、そのうちの7バイトがすべてでcat()あり\n、文字列を含むベクターをコンソールに出力することで十分であると見なされることもあります(* ahem *はPythonの回答のように)。
グレゴール

これは、3の後に余分な括弧があります。また、ジェイミーの-1クラブを出力します。pmax(a、1)を使用すると修正されます。
BLT

3

JavaScript、59バイト

@ETHproductionsのおかげで3バイト節約

@Cyoceのおかげで2バイト節約

n=>m=>n+` is in the ${m>1?Math.log10(m)/3|0:0}-comma club.`

デモ


1
でバイトを保存すると`${}`n=>m=>...代わりに関数をカリーできます(n,m)=>...
チョイス

2

Vim、72バイト

:%s;\v +\-=(\d+).*;\=' is in the '.(len(submatch(1))-1)/3.' comma club'

どういうわけか、私はトレーリングリターンがあることを示す必要がありますが、どのように確信している。これは単なる基本的な正規表現の答えであり、どの正規表現言語にも負けないはずです。私はVを使用し/ていましたが、デフォルトではVの代替コマンドがセパレーターとして使用されると思います。

入力をOPのテーブルとして受け取り、値をテーブルとして返しますが、財務情報は「is in the Xカンマクラブ」に置き換えられます

オンラインでお試しください!


\-=は何も追加するとは思わない。また、入力の余分なスペースを削除し、正規表現も変更すると、\v (\d*).*;4バイト節約できます
DJMcMayhem

2

05AB1E、32バイト

Äï€g3/î<“-comma†Ú“«“€ˆ€†€€ “ì‚ø»

オンラインでお試しください!

説明

Ä                                 # absolute value of input
 ï                                # convert to int
  €g                              # length of each
    3/                            # divided by 3
      î                           # round up
       <                          # decrement
        “-comma†Ú“«               # append string "-comma club" to each number
                   “€ˆ€†€€ “ì     # prepend string "is in the " to each number
                             ‚    # pair with second input
                              ø   # zip
                               »  # join by spaces and newlines

2

Python 2、69バイト

アレイをセットアップします。

n = ['John', 'Jamie', 'Kylie', 'Laura', 'Russ', 'Karla', 'Reid', 'Mark', 'Manson', 'Lonnie']
a = [100000, 0.05, 1549001.10, 999999999.99, 1000000000, 1, 99.99, 999.99, 1000.01, 999999999999.00]

そして、関数は次のようになります。

f=lambda n,a:'%s is in %s comma club'%(n,min(3,(len(str(int(a)))/3)))

私たちに与える:

>>> [f(x,y) for x,y in zip(n,a)]
['John is in 2 comma club', 'Jamie is in 0 comma club', 'Kylie is in 2 comma club', 'Laura is in 3 comma club', 'Russ is in 3 comma club', 'Karla is in 0 comma club', 'Reid is in 0 comma club', 'Mark is in 1 comma club', 'Manson is in 1 comma club', 'Lonnie is in 3 comma club']

配列が質問で提供された配列と同一である必要がある場合、ソリューションのコストは76バイトです。

f=lambda n,a:'%s is in %s comma club'%(n,min(3,(len(str(int(float(a))))/3)))

2

Powershell、82バイト

$args[0]|%{$_[0]+" is in the "+(('{0:N}'-f$_[1]-split',').Count-1)+"-comma club."}

の2D配列入力を想定

cc.ps1 @(@("John",100000),@("Jamie",0.05),@("Kylie",1549001.10),@("Laura",999999999.99),@("Russ",986000000),@("Karla",1),@("Reid",99.99),@("Mark",999.99),@("Manson",1000.01),@("Lonnie",999999999999.00),@("Nelly",-123.45))

出力は John is in the 1-comma club. Jamie is in the 0-comma club. Kylie is in the 2-comma club. Laura is in the 2-comma club. Russ is in the 2-comma club. Karla is in the 0-comma club. Reid is in the 0-comma club. Mark is in the 0-comma club. Manson is in the 1-comma club. Lonnie is in the 3-comma club. Nelly is in the 0-comma club.


2

Haskell、71バイト

n#a=n++" is in the "++(show.truncate.logBase 1e3.abs$a)++"-comma club."

正解を提供する演算子「#」を定義します。例えば:

*Main> "John"#100000
"John is in the 1-comma club."

残念ながら、Haskellにはlog10他の多くの言語のようなコンパクトな関数はありませんが、便利なlogBase関数があります。つまり、答えを3で割る必要はありません。残念なことに、logBase 1000 0.05負の数なので、それを丸めるtruncateよりも長いfloor

テストケースを含む完全なプログラム:

(#) :: (RealFrac n, Floating n) => [Char] -> n -> [Char]
n#a=n++" is in the "++(show.truncate.logBase 1e3.abs$a)++"-comma club."

testCases = [
 ("John",      100000),
 ("Jamie",     0.05),
 ("Kylie",     1549001.10),
 ("Laura",     999999999.99),
 ("Russ",      986000000),
 ("Karla",     1),
 ("Reid",      99.99),
 ("Mark",      999.99),
 ("Manson",    1000.01),
 ("Lonnie",    999999999999.00),
 ("Nelly",     -123.45)]

main = putStrLn $ unlines $ map (uncurry (#)) testCases

次の結果が得られます。

John is in the 1-comma club.
Jamie is in the 0-comma club.
Kylie is in the 2-comma club.
Laura is in the 2-comma club.
Russ is in the 2-comma club.
Karla is in the 0-comma club.
Reid is in the 0-comma club.
Mark is in the 0-comma club.
Manson is in the 1-comma club.
Lonnie is in the 3-comma club.
Nelly is in the 0-comma club.

1

K、66バイト

    /n is names and a is amounts
    n
    ("John";"Jamie";"Kylie";"Laura";"Russ";"Karla";"Reid";"Mark";"Manson";"Lonnie")
    a
    ("100000";"0.05";"1549001.10";"999999999.99";"1000000000";,"1";"99.99";"999.99";"1000.01";"999999999999.00")
    /the function
    {x," is in the ",($(#.q.cut[3;*"."\:y])-1)," comma club"}./:+(n;a)
    /output
    ("John is in the 1 comma club";"Jamie is in the 0 comma club";"Kylie is in the 2 comma club";"Laura is in the 2 comma club";"Russ is in the 3 comma club";"Karla is in the 0 comma club";"Reid is in the 0 comma club";"Mark is in the 0 comma club";"Manson is in the 1 comma club";"Lonnie is in the 3 comma club")


1

C#、125バイト

(p,n)=>{for(int x=0;x<p.Length;x++)Console.Write(p[x]+" is in the "+(n[x]<1e3?0:n[x]<1e6?1:n[x]<1e9?2:3)+"-comma club.\n");};

OPの形式で結果を出力する匿名関数。

テストケースを含む完全なプログラム:

using System;

class CommaClub
{
    static void Main()
    {
        Action<string[], double[]> f =
        (p,n)=>{for(int x=0;x<p.Length;x++)Console.Write(p[x]+" is in the "+(n[x]<1e3?0:n[x]<1e6?1:n[x]<1e9?2:3)+"-comma club.\n");};

        // test cases:
        string[] personArr = new[] {"John", "Jamie", "Kylie", "Laura", "Russ", "Karla", "Reid", "Mark", "Manson", "Lonnie", "Nelly"};
        double[] amountArr = new[] {100000, 0.05, 1549001.10, 999999999.99, 1000000000, 1, 99.99, 999.99, 1000.01, 999999999999.00, -123.45};
        f(personArr, amountArr);
    }
}

1

Python 3(207 159 110 95 86バイト、@ iwaseatenbyagrueのおかげ)

少しセットアップ:

f = ['John', 'Jamie', 'Kylie', 'Laura', 'Russ', 'Karla', 'Reid', 'Mark', 'Manson', 'Lonnie', 'Nelly']
a = [100000, 0.05, 1549001.10, 999999999.99, 986000000, 1, 99.99, 999.99, 1000.01, 999999999999.00, -123.45]

私の試み:

['%s is in the %d-comma club.'%(p,-(-len(str(int(abs(v))))//3)-1) for p,v in zip(f,a)]

結果:

['John is in the 1-comma club.', 'Jamie is in the 0-comma club.', 'Kylie is in the 2-comma club.', 'Laura is in the 2-comma club.', 'Russ is in the 2-comma club.', 'Karla is in the 0-comma club.', 'Reid is in the 0-comma club.', 'Mark is in the 0-comma club.', 'Manson is in the 1-comma club.', 'Lonnie is in the 3-comma club.', 'Nelly is in the 0-comma club.']

編集:すべてを絶対値に変換すると、15バイト節約できました。


1
最も重要なことは、これはコードスニペットです。通常、関数または完全なプログラムのみを許可します。ゴルフに関しては、多くのスペースを削除できます。試してください:["%s is in the %d-comma club."%(p,v.count(','))for p,v in zip(f,a)]また、バイトカウントを含める必要があります。
コナーオブライエン

print'\n'.join([your array])出力を実行し、実際に印刷できます。
エルロンド

2
サイトへようこそ!負の数(例:)-123.45は1つずれています(数えるので-)。しかし、なぜ数字のリストを取得して保存してください(誤解していませんか?)。importステートメントを追加する必要がありますが、これは現状ではプログラムまたは関数ではなくスニペットです(デフォルトはそうであり、正当な理由がない限りそれらから変更することはお勧めしません)。
ジョナサンアラン

1
ありがとう、@ JonathanAllan。現在、これを改善しようとしているので、インポートをカウントする必要はありません。Pythonのmath.ceil機能は私のスコアにかなりのオーバーヘッドを追加する可能性が高いことを理解しています。
ブラックサイト

2
に置き換える(-len(str(abs(v)).split('.')[0])と、9バイト節約できますlen(str(int(float(v))))。テストセットには、負の数はありません(例では1つあります)。完全になりたい場合は、5バイトを費やすlen(str(abs(int(float(v)))))ことで、4バイトしか節約できません。
iwaseatenbyagrue

1

Perl 6、107 95バイト

for @f {printf "%s is in the %d-comma club.\n",@f[$++],(abs(@a[$++].split(".")[0]).chars-1)/3;}

私の最も誇りに思う仕事ではありません。ゴルフのテクニックを忘れてしまったら、気をつけてください。編集:@Venのおかげで-12バイト


なぜ周りに丸刈り^@f.elems?ちなみに、あなたはそれを必要としない.elemsfor ^@f動作します。に名前を付ける必要はありません。代わり$xに使用してください$_。また、printfは使用しないでください"{"interpolation"}"
ベン

なぜそれが必要なのかさえ理解できません。なぜ行ってみませんfor @fか?$++インデックスとして使用して、それに合わせてインデックスを作成できます(インデックスを作成します@a)。
ヴェン

すぐにPC上のIMのように病気に編集:)
HåvardNygårdの

1
@Venは、$ ++について頭を上げてくれてありがとう。「本物の」プログラムでのトラブルを大幅に軽減します。ただ、Perlの6拾った
HåvardNygårdの

補間はバイトを節約しませんか?
ヴェン

1

Python 2、87バイト

for n,a in input():print n+' is in the %dd-comma club.'%'{:20,.2f}'.format(a).count(',')

少し古い(90バイト):

for n,a in input():print n+' is in the '+`'{:20,.2f}'.format(a).count(',')`+'-comma club.'

タプル(名前、量)のリストとして入力を受け取ります。

私は学校の電話でこれをしているので、後でテストします。


1

dc、56 54バイト

[P[ is in the ]Pd*vdZrX-1-3/n[-comma club.]pstz0<g]sglgx

これは、スタックの入力を受け取ります。これには、スタックの先頭にあるファーストネーム、ファーストナンバー、セカンドネーム、セカンドナンバーなどが事前にロードされている必要があります。

スタックをロードしてマクロgを実行する例を次に示します。

#!/usr/bin/dc
_123.45         [Nelly]
999999999999.00 [Lonnie]
1000.01         [Manson]
999.99          [Mark]
99.99           [Reid]
1               [Karla]
986000000       [Russ]
999999999.99    [Laura]
1549001.10      [Kylie]
0.05            [Jamie]
100000          [John]
[P[ is in the ]Pd*v1/Z1-3/n[-comma club.]pstz0<g]sglgx

通常の出力が生成されます。

John is in the 1-comma club.
Jamie is in the 0-comma club.
Kylie is in the 2-comma club.
Laura is in the 2-comma club.
Russ is in the 2-comma club.
Karla is in the 0-comma club.
Reid is in the 0-comma club.
Mark is in the 0-comma club.
Manson is in the 1-comma club.
Lonnie is in the 3-comma club.
Nelly is in the 0-comma club.

コードの例は次のとおりです。

[P[ is in the ]Pd*v1/Z-1-3/n[-comma club.]pstz0<g]sglgx

[                    # begin macro string
P                    # print and pop person name
[ is in the ]P       # print and pop ' is in the '
# Get absolute value of number by squaring and square root
d*v                  # d=dup, *=multiply, v=root
1/                   # 1/ truncates to integer since scale is 0
Z                    # Z=number length
1-3/n                # n=print and pop (#digits - 1)//3
[-comma club.]p      # print '-comma club.' and newline
st                   # pop '-comma club.' off stack into register t
z0<g                 # Do macro g if 0 is less than z=stack height
]                    # end macro string
sg                   # Save macro g
lgx                  # Load g and do its initial execution

編集1では、dZrX-(d = dup、Z = number length、r = swap、X = fraction、-= subtract)に置き換えました(1/Zデフォルトのスケールがゼロで整数に切り捨て、次にZ = number長さ)、2バイトを節約します。


1

スウィフト166の 158 145バイト

var c="comma club",i=0
f.map{k,v in var a=abs(v);print(k,(1000..<1000000~=a ?1:1000000..<1000000000~=a ?2:1000000000..<1000000000000~=a ?3:0),c)}

そして、ここに辞書があります:

var f = [
    "John": 100000, "Jamie": 0.05, "Kylie" : 1549001.10,
    "Laura": 999999999.99,"Russ":1000000000,"Karla": 1,
    "Reid": 99.99,"Mark": 999.99, "Manson": 1000.01,
    "Lonnie": 999999999999.00, "Nelly": -123.45
]

ここで試してみてください!


0

Clojure、108バイト

(def f ["John", "Jamie", "Kylie", "Laura", "Russ", "Karla", "Reid", "Mark", "Manson", "Lonnie", "Nelly"])
(def a ["100000", "0.05", "1549001.10", "999999999.99", "986000000", "1", "99.99", "999.99", "1000.01", "999999999999.00", "-123.45"])

(map #(str %" is in the "(quot(-(count(nth(partition-by #{\.}(drop-while #{\-}%2))0))1)3)"-comma club.")f a)

floatでの操作が文字のシーケンスでの操作よりも短いかどうかはわかりません。一連の回答を返す、関数以外の回答が適切かどうかはわかりません。


0

Rebol、118バイト

d: charset"0123456789"forskip s 2[c: 0 parse s/2[opt"-"any[3 d and d(++ c)]]print[s/1"is in the"join c"-comma club."]]

配列宣言でゴルフを解く:

s: [
    {John} {100000}
    {Jamie} {0.05}
    {Kylie} {1549001.10}
    {Laura} {999999999.99}
    {Russ} {986000000}
    {Karla} {1}
    {Reid} {99.99}
    {Mark} {999.99}
    {Manson} {1000.01}
    {Lonnie} {999999999999.00}
    {Nelly} {-123.45}
    {Baz} {1.12345678}     ;; added extra Baz test case
]

d: charset "0123456789"
forskip s 2 [
    c: 0
    parse s/2 [
        opt "-"
        any [3 d and d (++ c)]
    ]
    print [s/1 "is in the" join c "-comma club."]
]

出力:

John is in the 1-comma club.
Jamie is in the 0-comma club.
Kylie is in the 2-comma club.
Laura is in the 2-comma club.
Russ is in the 2-comma club.
Karla is in the 0-comma club.
Reid is in the 0-comma club.
Mark is in the 0-comma club.
Manson is in the 1-comma club.
Lonnie is in the 3-comma club.
Nelly is in the 0-comma club.
Baz is in the 0-comma club.

0

Java 8 154 141バイト

m.keySet().stream().map(k->k+" is in the "+(((""+Math.abs(m.get(k).longValue()))).length()-1)/3+"-comma club.").forEach(System.out::println);

非ゴルフ

public static void main(String[] args) {
    Map<String, Number> m = new LinkedHashMap<String, Number>(){{
        put("John", 100000);
        put("Jamie", 0.05);
        put("Kylie", 1549001.10);
        put("Laura", 999999999.99);
        put("Russ", 1000000000);
        put("Karla", 1);
        put("Reid", 99.99);
        put("Mark", 999.99);
        put("Manson", 1000.01);
        put("Lonnie", 999999999999.00);
        put("Nelly", -123.45);
    }};
    m.keySet().stream().map(k->k+" is in the "+(((""+Math.abs(m.get(k).longValue()))).length()-1)/3+"-comma club.").forEach(System.out::println);
}

1
を削除して代わりにString.valueOf使用でき(((""+Math.abs(m.get(k).longValue())).length()-1)/3)ます。
ケビンCruijssen

1
また、丸かっこを削除することもできますk->
ケビンCruijssen
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.