Sagen Sie meinen Freunden, zu welchem ​​„Komma-Club“ sie gehören

16

Inspiriert von Silicon Valley „Drei-Komma - Club“ Szenen wie diese , in dieser Herausforderung werden Sie zehn Menschen den „Komma - Club“ , zu denen sie jeweils gehören erzählen.

Wenn Sie mit dem Begriff "Komma-Club" nicht vertraut sind, lassen Sie mich erklären: Sie sind im Ein-Komma-Club, wenn das Geld, das Sie haben, im Bereich von 1.000,00 bis 999.999,99 US-Dollar liegt. Sie sind im Zwei-Komma-Club, wenn er zwischen 1.000.000,00 USD und 999.999.999,99 USD liegt. Diese "Clubs" wiederholen sich durch den Dreikomma-Club, da kein Individuum auf der Erde (AFAIK) mehr als eine Billion US-Dollar besitzt (japanischer Yen wäre sehr schnell eine andere Geschichte). Die Anzahl der Kommas auf Ihrem Bankkonto gibt gemäß den in den USA und Großbritannien am häufigsten verwendeten Notationsstandards den Komma-Club an, zu dem Sie gehören. Die gleichen "Komma" -Regeln gelten für negative Zahlen (obwohl Sie nicht im negativen Komma-Club sein möchten): negative Beträge im Inklusivbereich [-0.01, -999.

Die Testfälle

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

Die richtigen Antworten:

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.

Welches Array-Setup Sie auch benötigen, um ein friendsArray und ein amountsArray zu erhalten, zählt nicht für Ihre Punktzahl. Für Python zählt der folgende Code also nicht:

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']

Bearbeiten: Bitte beachten Sie die überarbeiteten Testfälle

Ich habe die eigentlichen String-Kommas aus den Testfällen entfernt, um die Sache etwas schwieriger zu machen, anstatt nur Kommas zu zählen.

Blacksite
quelle
2
Ich denke nicht, dass Sie das Ausgabeformat sehr klar gemacht haben. Ist so etwas "Name number,Name number,..."akzeptabel?
FryAmTheEggman
2
Sind die Einträge in f garantiert positiv oder wären sie -$1,234.56auch im 1-Komma-Club?
Jonathan Allan
2
@not_a_robot Könnten Sie Frys Kommentar ansprechen? Reicht es aus, Namens- und Zahlenpaare in einem beliebigen Format auszugeben?
Martin Ender
1
@FryAmTheEggman Nein, die Ausgabe muss das Format haben"<name> is in the <number of commas>-club."
blacksite
1
Testfälle sind nicht spez. Und selbst wenn dies der Fall wäre, gibt es keinen Testfall, der das von Jonathan Allan oben angesprochene Problem großer Negative abdeckt.
Peter Taylor

Antworten:

10

JavaScript (ES6), 80 Byte

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

Nimmt ein Array von [friend, amount] Arrays und gibt ein Array von "friend is in the n-comma club" zurück. Streicher. Fügt nachstehende Nullen hinzu, sodass die Länge für den 0-Komma-Club 6-8, für den 1-Komma-Club 9-11, für den 2-Komma-Club 12-15 usw. beträgt.

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

Neil
quelle
Ich denke nicht, dass dies für negative Zahlen funktioniert. Zum Beispiel würde es Nelly (-123,45) in den 1-Komma-Club setzen. Ich würde das kürzere vorschlagen Math.log10(n*n)/6|0.
Arnauld
@Arnauld Ah ja, ich hatte vergessen, |0auf Null abzuschneiden , also gibt es die richtige Antwort für Jamie.
Neil
8

PostgreSQL, 61 Bytes

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

@xist der absolute Wert von x, log(x)ist der Logarithmus zur Basis 10 unddiv(y, x) berechnet den ganzzahligen Quotienten von y / x.


Installieren:

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)

Ausgabe:

            ?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)
kennytm
quelle
Es ist schön, eine wettbewerbsfähige SQL-Antwort zu sehen - gut gemacht!
Toby Speight
6

Jelly , 34  32 Bytes

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

Eine dyadische Verknüpfung (Funktion), die eine Liste von Bankguthaben als Zahlen (Dezimalzahlen / Ganzzahlen) und eine Liste von Namen als Zeichenfolgen verwendet und eine Liste von Zeichenfolgen zurückgibt.

Probieren Sie es online! - Die FußzeileçYruft einfach die Funktion auf und verbindet die resultierende Liste mit Zeilenvorschüben, so dass sie eine schöne Ausgabe hat, wenn sie als vollständiges Programm ausgeführt wird.

Wie?

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
Jonathan Allan
quelle
4

PHP, 76 74 Bytes

// 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));

Zum Glück muss ich nicht auf int setzen (wie ich es in C tun müsste); PHP macht das implizit für %d.

Titus
quelle
Gee! Bin ich der Erste, der rechnet, anstatt Zeichen zu zählen?
Titus
4

Mathematica (86 Bytes)

Das Setup (mit Namen als Zeichenketten, Geld als Zahlen):

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}

Der Versuch:

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

Alle String-Funktionen von Mathematica enthalten "String" im Namen, daher denke ich, dass die Protokolle kürzer sind. Das Max[...,0]ist, um mit den lästigen negativen Zahlen oder der negativen Unendlichkeit für Leute umzugehen, die zwischen -1 und 1 Dollar besitzen. Das Protokoll einer negativen Zahl enthält imaginäres Material, aber Mathematica ignoriert dies beim Aufnehmen eines Floor!

Kein Baum
quelle
4

Japt , 36 Bytes

Dabei wird der Betrag als erste Eingabe und der Name als zweite Eingabe übernommen.

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

Erläuterung

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 verwendet die Shoco-Bibliothek zur Komprimierung von Strings.

Inspiriert von der Lösung von @ Neil .

7 Bytes gespart dank @ETHproductions

Probieren Sie es online!

Oliver
quelle
1
Ich denke, Sie können es einfach Vw0 x4 l /3-2|0in der Mitte tun und dabei 6 Bytes sparen :-)
ETHproductions
1
Ich denke, Sie können ein Byte speichern, indem Sie die Eingabe in umgekehrter Reihenfolge V+`...{w0...
vornehmen
3

MATL, 50 48 43 Bytes

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

Probieren Sie es bei MATL Online aus

Erläuterung

`                   % 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
Suever
quelle
3

R, 68 Bytes

Die Einrichtung:

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)

Die Lösung:

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

Nehmen Sie das Basis-10-Protokoll des absoluten Werts des Kontos, runden Sie es ab und drucken Sie es mit den Namen aus.

Ich bin nicht sicher, ob es kleiner sein könnte, wenn aein Zeichenvektor wäre ...

Joe
quelle
1
Was ist mit dem Fall von Nelly, die -123,45 Dollar hat? Dieser log10Aufruf erzeugt NaNs für Negative. Sieht aus wie log10(abs(a))würde funktionieren.
Blacksite
Hoppla, Sie haben Recht, in der obigen Stichprobe war Nelly nicht enthalten. Und ich habe die Spezifikation falsch verstanden ... Ich habe verstanden, dass ein negativer Wert 0 Komma Verein sein sollte.
Joe
abs(x)Verwenden Sie stattdessen pmax(a,1)- dies nimmt alles weniger als 1 und macht es 1, was gute Ergebnisse für negative Zahlen ergibt. Und stattdessen floor(log10(...)/3)können Sie verwenden log10(...)%/%3. Ich denke, das bringt es auf 66 Bytes (und für Negative korrigiert).
Gregor
1
Auch erwähnenswert, dass eine volle 7 Bytes sind dies cat()und \n... Drucken der Vektor mit den Saiten in ihm an die Konsole könnte in Betracht gezogen werden gut genug (* ahem * wie die Python Antworten).
Gregor
Dies hat eine zusätzliche Klammer nach 3. Es gibt auch den -1-Club für Jamie aus. Die Verwendung von pmax (a, 1) behebt das.
BLT
3

JavaScript, 59 Bytes

3 Bytes gespart dank @ETHproductions

2 Bytes gespart dank @Cyoce

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

Demo

Oliver
quelle
1
Speichern Sie ein Byte mit `${}`und Sie können die Funktion Curry n=>m=>...statt(n,m)=>...
Cyoce
2

Vim, 72 Bytes

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

Irgendwie sollte ich zeigen, dass es eine nachlaufende Rückkehr gibt, aber unsicher, wie. Dies ist nur eine einfache Regex-Antwort, die mit Sicherheit von jeder Regex-Sprache übertroffen werden kann. Ich hätte V verwendet, aber ich denke, dass die Ersatzbefehle in V verwenden/ standardmäßig als Trennzeichen verwendet werden, und ich konnte nicht herausfinden, wie man es dazu nicht über die Teilung zu beschweren.

Übernimmt Eingaben als OP-Tabelle und gibt Werte als Tabelle zurück, wobei jedoch die Finanzinformationen durch "Ist im X-Komma-Club" ersetzt werden.

Probieren Sie es online!

nmjcman101
quelle
Ich denke das \-=fügt nichts hinzu. Wenn Sie die zusätzlichen Leerzeichen in Ihrer Eingabe entfernen und auch die Regex ändern, können \v (\d*).*;Sie 4 Bytes sparen
DJMcMayhem
2

05AB1E , 32 Bytes

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

Probieren Sie es online!

Erläuterung

Ä                                 # 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
Emigna
quelle
2

Python 2, 69 Bytes

Richten Sie unsere Arrays ein:

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]

Und unsere Funktion kann dann sein:

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

Geben uns:

>>> [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']

Wenn das Array mit dem in der Frage angegebenen Array identisch sein muss, kostet die Lösung 76 Byte:

f=lambda n,a:'%s is in %s comma club'%(n,min(3,(len(str(int(float(a))))/3)))
Ich wurde von Agrue gegessen
quelle
2

Powershell, 82 Bytes

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

Angenommen, ein 2D-Array-Eingang von

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))

Die Ausgabe ist 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.

Tor
quelle
2

Haskell, 71 Bytes

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

Definiert einen Operator '#', der die richtige Antwort liefert. Z.B:

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

Leider hat Haskell keine kompakte log10Funktion wie viele andere Sprachen, aber eine nützliche logBaseFunktion, was bedeutet, dass wir unsere Antwort nicht durch 3 teilen müssen. Leider logBase 1000 0.05handelt es sich um eine negative Zahl, daher müssen wir die verwenden länger, truncateals floores abzurunden.

Volles Programm inklusive Testfälle:

(#) :: (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

Gibt die folgenden Ergebnisse aus:

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.
Jules
quelle
1

K, 66 Bytes

    /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")
Chromozorz
quelle
1

Python 2.7 , 89 86 84 Bytes

for g,b in zip(*input()):print g,'is in the',`(len('%d'%b)+~(b<0))/3`+'-comma club.'

Probieren Sie es online!

Vollständiges Programm, das ein Tupel von zwei Listen - Namen als Zeichenfolgen, Bankguthaben als Zahlen - verwendet und die resultierenden Zeichenfolgen druckt.

Jonathan Allan
quelle
1

C #, 125 Bytes

(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");};

Anonyme Funktion, die das Ergebnis im OP-Format druckt.

Volles Programm mit Testfällen:

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);
    }
}
adrianmp
quelle
1

Python 3 ( 207 159 110 95 86 Byte, danke an @iwaseatenbyagrue)

Ein bisschen Setup:

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]

Mein Versuch:

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

Ergebnisse:

['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.']

Edit: alles in absolute Werte umwandeln sparte mir 15 Bytes.

Blacksite
quelle
1
Am wichtigsten ist, dass dies ein Code-Snippet ist. In der Regel erlauben wir nur Funktionen oder vollständige Programme. Beim Golfen können Sie viele Leerzeichen entfernen. Versuch: ["%s is in the %d-comma club."%(p,v.count(','))for p,v in zip(f,a)]Außerdem müssen Sie eine Byteanzahl einschließen.
Conor O'Brien
Sie können die print'\n'.join([your array])Ausgabe durchführen und tatsächlich drucken.
Elronnd
2
Willkommen auf der Seite! Negative (z. B. -123.45) sind um eins ausgeschaltet (da Sie das zählen -). Aber warum nicht eine Liste von Zahlen nehmen und speichern (habe ich falsch interpretiert?). Sie müssten import-Anweisungen hinzufügen, und so wie es aussieht, handelt es sich um ein Snippet, kein Programm oder eine Funktion (wie es die Standardeinstellungen sind, und von Änderungen wird abgeraten, es sei denn, es gibt einen guten Grund).
Jonathan Allan
1
Danke, JonathanAllan. Ich versuche gerade, dies zu verbessern, damit ich die Importe nicht zählen muss. Mir ist klar, dass die Python- math.ceilFunktion meiner Partitur wahrscheinlich einiges an Overhead hinzufügt.
Blacksite
2
Sie können 9 Bytes speichern durch Ersetzen (-len(str(abs(v)).split('.')[0])mit len(str(int(float(v)))). In Ihrem Testset gibt es keine negativen Zahlen (in den Beispielen gibt es eine). Wenn Sie vollständig sein möchten, geben Sie 5 Bytes aus len(str(abs(int(float(v)))))- das spart Ihnen dann nur 4 Bytes.
iwaseatenbyagrue
1

Perl 6, 107 95 Bytes

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

Nicht meine stolzeste Arbeit, gib mir einen Kopf hoch, wenn ich irgendwelche Golftechniken vergessen habe. EDIT: -12 Bytes dank @Ven

Håvard Nygård
quelle
warum parens herum ^@f.elems? Aber das brauchst du nicht .elems, for ^@ffunktioniert. Sie müssen nicht benennen $x, verwenden Sie $_stattdessen. Und benutze nicht printf, benutze "{"interpolation"}".
Ven
Ich verstehe nicht mal, warum du das brauchst. Warum gehst for @fdu nicht ? Sie können ihn $++als Index verwenden (und in ihn indexieren @a).
Ven
Ich bearbeite, sobald ich auf dem PC bin :)
Håvard Nygård
1
@Ven danke für die Hinweise zum $ ++. Spart mir viel Ärger in meinen "echten" Programmen. Habe gerade Perl 6 abgeholt.
Håvard Nygård
Sind Sie sicher, dass Interpolationen keine Bytes speichern?
Ven
1

Python 2, 87 Bytes

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

Etwas älter (90 Bytes):

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

Übernimmt die Eingabe als Liste von Tupeln (Name, Menge).

Ich mache das auf meinem Handy in der Schule, damit ich es später testen kann.

Daniel
quelle
1

Gleichstrom, 56 54 Bytes

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

Dies übernimmt die Eingabe vom Stapel, der mit dem Vornamen oben im Stapel, der ersten Nummer, dem zweiten Namen, der zweiten Nummer usw. vorgeladen werden sollte.

Hier ist ein Beispiel für das Laden des Stacks und das Ausführen des Makros, 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

die die übliche Ausgabe erzeugt,

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.

Hier ist eine Exegese des Codes:

[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

Beachten Sie, dass ich in Edit 1 dZrX-(d = dup, Z = Länge der Zahl, r = Swap, X = Bruch, - = Subtrahieren) durch 1/Z(Teilen Sie die Zahl durch 1, wobei die Standardskala von Null auf eine ganze Zahl verkürzt wird; dann ist Z = Zahl Länge), spart zwei Bytes.

James Waldby - jwpat7
quelle
1

Swift , 166 158 145 Bytes

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)}

Und hier ist das Wörterbuch:

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
]

Probieren Sie es hier aus!

Mr. Xcoder
quelle
0

Clojure, 108 Bytes

(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)

Ich bin mir nicht sicher, ob der Betrieb an Schwimmern kurzgeschlossen ist als bei Zeichenfolgen. Ich bin mir nicht sicher, ob eine Antwort ohne Funktion in Ordnung ist, die eine Folge von Antworten zurückgibt.

NikoNyrh
quelle
0

Rebol, 118 Bytes

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."]]

Ungolfed mit Array-Deklaration:

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."]
]

Ausgabe:

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.
draegtun
quelle
0

Java 8 154 141 Bytes

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

Ungolfed

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);
}
anacron
quelle
1
Sie können das entfernen String.valueOfund (((""+Math.abs(m.get(k).longValue())).length()-1)/3)stattdessen verwenden.
Kevin Cruijssen
1
Sie können auch die Klammern entfernen k->.
Kevin Cruijssen