10
\$\begingroup\$

Let's make a little stupid program that simulates the meme "Mr. incredible becoming uncanny", but in this case, our little ASCII friend is going to react to our code length.

Objective:

Create a program that takes anything (preferably a program) as input and outputs this:

Pov: 
<face>   you score X on codegolf

Where X is the length of the input and the face depends on the value of X:

X < 20         = \(^-^)/
20 ≤ X < 50    = -(o_o)-
50 ≤ X < 100   = /(¬_¬)\
100 ≤ X < 250  = /(º-º)\
250 ≤ X < 500  = /(ª@ª)\
X ≥ 500        = /(x_x)\

Example:

I have made my own ungolfed version in C#: Try it online!

using System;
class Program {
static void Main(string[] args) {
    Console.WriteLine("Pov:");

    if(args[0].Length < 20){
        Console.WriteLine("\\(^-^)/   you score "+args[0].Length+" on codegolf");

    }else if(args[0].Length < 50){
        Console.WriteLine("-(o_o)-   you score "+args[0].Length+" on codegolf");

    }else if(args[0].Length < 100){
        Console.WriteLine("/(¬_¬)\\   you score "+args[0].Length+" on codegolf");

    }else if(args[0].Length < 250){
        Console.WriteLine("/(º-º)\\   you score "+args[0].Length+" on codegolf");

    }else if(args[0].Length < 500){
        Console.WriteLine("/(ª@ª)\\   you score "+args[0].Length+" on codegolf");

    }else{
        Console.WriteLine("/(x_x)\\   you score "+args[0].Length+" on codegolf");

    }
}
}

If the program takes itself as input, it will output:

Pov:
/(x_x)\   you score 741 on codegolf

Rules:

  • The output must have exactly three spaces betwen the face and the text.
  • The shortest code in bytes wins.
  • Input length should be counted in characters, not bytes.
\$\endgroup\$
6
  • 1
    \$\begingroup\$ If we are to assume the input is always our own code, then we can just ignore the input, per consensus. At this point, the task is just to output one of these literal strings, and implementing the rest of the challenge becomes unobservable \$\endgroup\$
    – pxeger
    Jan 13 at 16:32
  • \$\begingroup\$ @pxeger yep, just after write this a had left my house for some time and i was thinking in that xd, i am going to fix this \$\endgroup\$ Jan 13 at 17:05
  • \$\begingroup\$ Length of the input is what exactly? Because usually string length is not the number of bytes. In fact it seems most answers here don't even score themselves accurately. \$\endgroup\$
    – Wheat Wizard
    Jan 13 at 21:31
  • \$\begingroup\$ @WheatWizard its true, i hadnt realized that some characters count as 2 bytes, but lets say that the count of bytes from the output is more ¿"symbolic"? or easier idk, i am going to add a rule about that to leave it clear \$\endgroup\$ Jan 13 at 22:45
  • 2
    \$\begingroup\$ @ZeroCodeException Still not fully clear. Characters as in bytes in the used charset, as in Unicode code points, as in Unicode grapheme clusters, or as in "whatever of these the language can output with the shortest code"? \$\endgroup\$
    – cg909
    Jan 14 at 1:39

10 Answers 10

5
\$\begingroup\$

Charcoal, 106 102 96 94 85 bytes

PPov:DP✂⁺”|ecT#F>”xªº´¬o^_@--_-ΣEI⪪”←⧴⟲º"Q⪫+R” ‹Lθιφ⁶←‖B”↶±=⧴KCX≕‹#”ILθ”↶←∨^⁹⁰y↔]

Try it online! Link is to verbose version of code. Note that the deverbosifier miscalculates the length of characters in the ISO-8851 code page; non-ASCII characters should count 3 bytes instead of 1. Explanation:

PPov:D

Print Pov: without moving the cursor (so it gets overwritten below), and output that on its own line.

P✂⁺”|ecT#F>”xªº´¬o^_@--_-ΣEI⪪”←⧴⟲º"Q⪫+R” ‹Lθιφ⁶

Concatenate the compressed string ////-\(((((( with the incompressible string xªº¬o^_@--_- (Charcoal can only compress ASCII strings), slice that with a starting offset depending on how many of the numbers in the compressed string 500 250 100 50 20 are greater than the length of the input and a step of 6, and print without moving the cursor.

←‖B

Butterfly the canvas, leaving the cursor after the face.

”↶±=⧴KCX≕‹#”

Print the compressed string you score .

ILθ

Print the length of the input as a string.

”↶←∨^⁹⁰y↔]

Print the compressed string on codegolf.

\$\endgroup\$
5
  • \$\begingroup\$ This does not output Pov: \$\endgroup\$
    – Makonede
    Jan 13 at 22:45
  • \$\begingroup\$ @Makonede An almost identical fix ;-) \$\endgroup\$
    – Neil
    Jan 14 at 0:19
  • \$\begingroup\$ If you're scoring with a codepage you can only use characters in said codepage, which ªº¬ don't appear to be. \$\endgroup\$
    – emanresu A
    Jan 17 at 6:48
  • \$\begingroup\$ @emanresuA ¬ is in said code page. Charcoal also has a 3-byte encoding for characters with ordinals less than 16512, however as I mention the deverbosifier doesn't actually perform the encoding so I manually adjusted the byte count. \$\endgroup\$
    – Neil
    Jan 17 at 8:20
  • \$\begingroup\$ @emanresuA To clarify, the deverbosifier only automatically adjusts the byte count for characters with ordinals above 255. \$\endgroup\$
    – Neil
    Jan 17 at 8:24
5
\$\begingroup\$

Excel, 151 bytes

=LET(x,LEN(A1),"Pov:
"&IFS(x<20,"\(^-^)/",x<50,"-(o_o)-",x<100,"/(¬_¬)\",x<250,"/(º-º)\",x<500,"/(ª@ª)\",1,"/(x_x)\")&"   you score "&x&" on codegolf")

Input is in the cell A1. Output is wherever the formula is.

Everything I try that seems more clever than this simple approach ends up adding a few bytes.

\$\endgroup\$
4
\$\begingroup\$

Python 3, 158 bytes

x=len(open(0).read())
print("Pov:\n"+r"////-\((((((xªº¬o^_@-__-xªº¬o^))))))\\\\-/"[sum(x<q*10for q in[2,5,10,25,50])::6],f"  you score {x} on codegolf")

Try it online!

-1 byte thanks to pxeger
-9 bytes thanks to Kateba

\$\endgroup\$
7
  • 1
    \$\begingroup\$ 167 \$\endgroup\$
    – pxeger
    Jan 13 at 16:31
  • 1
    \$\begingroup\$ Got it down to 158 \$\endgroup\$
    – Kateba
    Jan 13 at 19:31
  • \$\begingroup\$ @Kateba oh, that's a nice trick \$\endgroup\$
    – hyper-neutrino
    Jan 13 at 20:28
  • \$\begingroup\$ Interestingly this gives "152" as it's own score not 158. \$\endgroup\$
    – Wheat Wizard
    Jan 13 at 21:32
  • \$\begingroup\$ @WheatWizard unless I've read the challenge specs wrong I believe this is intended since the scoring mechanism for this challenge is bytes, but the length of X should be given in character length and not true byte count. \$\endgroup\$
    – hyper-neutrino
    Jan 13 at 23:37
4
\$\begingroup\$

Retina 0.8.2, 139 bytes

s`.+
Pov:¶$.&$*_   you score $.& on codegolf
_{500,}
/(x_x)\
_{250,}
/(ª@ª)\
_{100,}
/(º-º)\
_{50,}
/(¬_¬)\
_{20,}
-(o_o)-
_+
\(^-^)/

Try it online! Explanation:

s`.+
Pov:¶$.&$*_   you score $.& on codegolf

Get the length of the input and substitute it into the output string, plus also insert that many underscores for the face checking.

_{500,}
/(x_x)\
_{250,}
/(ª@ª)\
_{100,}
/(º-º)\
_{50,}
/(¬_¬)\
_{20,}
-(o_o)-
_+
\(^-^)/

Replace the underscores with the appropriate face.

\$\endgroup\$
2
  • \$\begingroup\$ This does not output Pov: \$\endgroup\$
    – Makonede
    Jan 13 at 22:45
  • \$\begingroup\$ @Makonede Whoops, overlooked that. \$\endgroup\$
    – Neil
    Jan 14 at 0:17
4
\$\begingroup\$

Zsh, 138 bytes

f='\(^-^)/-(o_o)-/(¬_¬)\/(º-º)\/(ª@ª)\/(x_x)\'
<<<"Pov:
${f:$[i=$#1/50+($#1>19),i>9?5:i>3?3+i/5:i]*7:7}   you score $#1 on codegolf"

Try it online!

Fancy ternaries, let's go through them:

i=$#1/50+($#1>19)         # div by 50, add one if at least 20
i>9?5:                    # if i > 9, then $#1 was at least 500
      i>3?3+i/5           # else if i > 3, then $# was between 100 and 500
               :i         # else i is correct

      ${f:$[ ... ]*7:7}           # string slice starting from $[ ]*7 of length 7
<<<"..${f:$[ ... ]*7:7}...$#1.."  # substitute in string. Embedded newlines are fine
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 155 bytes

f=(s,i=0)=>[.4,1,2,5,10,n=s.length][i]*50>n?`Pov:
${"/-\\"[q=2>>i]}(${(c="^o¬ºªx"[i])+"-__-@_"[i]+c})${"\\-/"[q]}   you score ${n} on codegolf`:f(s,i+1)

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Jelly, 89 bytes

“µð1|ż‘Ḥ‘>@LS‘ị“\-/“(“^oḄṾȥx“-__-@_‘ŒḄ‘6¦U7¦0ịxɗ€6a"ƊZỌ¤
L⁶;“£ṭṛẇṣLe“¦ŒɱṣṀ^Tż»jṭÇ“Pov:¶”;

A full program accepting a (Python formatted) string argument that prints the result.

Try it online! Or see the test-suite.

How?

“...‘Ḥ‘>@LS‘ị“...‘ŒḄ‘6¦U7¦0ịxɗ€6a"ƊZỌ¤ - Helper: list of characters, X
“...‘                                  - list of numbers = [9,24,49,124,249]
     Ḥ                                 - double = [18,48,98,248,498]
      ‘                                - increment = [19,49,99,249,499]
       >@L                             - length of X greater than? (vectorises)
          S                            - sum
           ‘                           - increment -> our "face index"
                                     ¤ - nilad followed by link(s) as a nilad:
             “...‘                     -   list of lists of numbers
                                           ...the ordinals of the characters:
                                              "\-/", "(", "^o¬ºªx", "-__-@_"
                  ŒḄ                   -   bounce
                                           ...this appends:
                                              "^o¬ºªx", "(", "\-/"
                    ‘6¦                -   increment the sixth - 2nd "(" -> ")"
                       U7¦             -   reverse seventh - 2nd "\-/" -> "/-\"
                                  Ɗ    -   last three links as monad:
                               6       -     literal six
                             ɗ€        -     for each - f(list, 6):
                          0ị           -       get the last one
                            x          -       repeat it six times
                                a"     -       zip with logical AND
                                               ...effectively extend the lists to
                                                  length six using the rightmost
                                                  ordinal.
                                   Z   -   transpose
                                    Ọ  -   convert the integers to characters
                                           ...a list of the faces
            ị                          - "face index" index into "faces"

L⁶;“...»jṭÇ“Pov:¶”; - Main Link: list of characters, X
L                   - length of X
 ⁶;                 - prefix with a space
   “...»            - compressed list of strings = "   you score", " on codegolf"
        j           - join with the score
          Ç         - call the helper link, above with X as the argument -> face
         ṭ          - tack the face to the front
           “Pov:¶”  - "Pov\n"
                  ; - concatenate
                    - implicit, smashing print
\$\endgroup\$
2
\$\begingroup\$

C# (.NET 6), 190 \$\cdots\$ 172 170 bytes

int l=args[0].Length;Console.Write($"Pov:\n{(l<20?"\\(^-^)/":l<50?"-(o_o)-":l<100?"/(¬_¬)\\":l<250?"/(º-º)\\":l<500?"/(ª@ª)\\":"/(x_x)\\")}   you score {l} on codegolf");

Golf of example code in OP

Passing the program text as the first command line argument outputs:

Pov:
/(º-º)\   you score 170 on codegolf

Works on .Net 6 but not on TIO.

\$\endgroup\$
2
\$\begingroup\$

Rust, 192 191 bytes

|x:&str|print!("Pov:
{}   you score {} on codegolf",match x.len(){0..=19=>r"\(^-^)/",0..=49=>"-(o_o)-",0..=99=>r"/(¬_¬)\",0..=249=>r"/(º-º)\",0..=499=>r"/(ª@ª)\",_=>r"/(x_x)\"},x.len())

Try it online!

-1 byte thanks to Aiden4

\$\endgroup\$
3
  • \$\begingroup\$ You can save a few bytes with type hint when assigning the closure, and by outputting directly to stdout. Try it online! \$\endgroup\$
    – Aiden4
    Jan 17 at 2:37
  • \$\begingroup\$ @Aiden4 Thanks, I didn't even think about printing to stdout. But using a closure type hint outside the counted bytes feels to much like cheating for me :-) \$\endgroup\$
    – cg909
    Jan 18 at 20:59
  • \$\begingroup\$ FYI, it's standard practice for the rust users of the forum to use type hints when assigning the closures, so long as it coerces into a function pointer of the correct type. \$\endgroup\$
    – Aiden4
    Jan 18 at 22:26
2
\$\begingroup\$

05AB1E, 118 113 112 80 bytes

-32 thanks to Kevin Cruijssen.

’ƒËŠˆ’Ig•È¼Ÿò8Ãx°иšü•"(\^-)/-o_¬ºª@x"Åв6ä•Û³™•51вT*ÅΔIg›}èJ.º“Pov:
ÿ  €îŒÂ ÿ€‰ ÿ

Try it online! Beats all other answers.

\$\endgroup\$
7
  • 6
    \$\begingroup\$ Well, it used to beat all the other correct answers, but I think you'll find that's not true any more... \$\endgroup\$
    – Neil
    Jan 14 at 0:20
  • 1
    \$\begingroup\$ 87 bytes. Not sure why you do ’IO.‚Ø :€Ÿ’.E, just take the input as multi-line string and use I instead. I've also golfed the U5FXNè®›iNˆ]5ˆ¯н to ÅΔIg›}, and you can remove the ÀÀ by not starting the base-string with \. @Neil Now it's true again. ;) \$\endgroup\$ Jan 14 at 8:02
  • \$\begingroup\$ 80 bytes by using the mirror builtin for halve the faces. \$\endgroup\$ Jan 14 at 9:25
  • 1
    \$\begingroup\$ @KevinCruijssen Bah, and I had just found an 82-byte Charcoal golf... \$\endgroup\$
    – Neil
    Jan 14 at 9:39
  • \$\begingroup\$ (Actually 86 bytes because I'd miscounted. Although I did golf a further byte off.) \$\endgroup\$
    – Neil
    Jan 14 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.