24
\$\begingroup\$

In this challenge you and your friends are debating on which case is better, uppercase or lowercase? To find out, you write a program to do this for you.

Because esolangs scare your friends, and verbose code scares you, your code will need to be as short as possible.


Examples

PrOgRaMiNgPuZzLeS & CoDe GoLf
0.52 uppercase

DowNGoAT RiGHtGoAt LeFTGoat UpGoAT
0.58 uppercase

Foo BaR Baz
0.56 lowercase

Specifications

The input will consist only of ASCII characters. All non-alphabetic characters should be ignored. There will be at least 1 character of each case

The output should be the amount of the case that appears the most often over the total amount of alphabetic characters. It should be a decimal accurate to at least 2 decimal places. If uppercase appears more often, the output should end with uppercase, or lowercase.

There will never the the same amount of uppercase and lowercase characters.

\$\endgroup\$
  • 6
    \$\begingroup\$ Esolangs do not scare my friends. Does that mean my code can be wildly verbose? \$\endgroup\$ – Alex A. Dec 25 '15 at 17:21
  • \$\begingroup\$ @AlexA. verbose code scares you, so your code will also need to be golfed. \$\endgroup\$ – Downgoat Dec 25 '15 at 17:22
  • 15
    \$\begingroup\$ Oh right, I had forgotten about my recurring Java nightmares. \$\endgroup\$ – Alex A. Dec 25 '15 at 17:23
  • 4
    \$\begingroup\$ Will there be input with only one case? \$\endgroup\$ – manatwork Dec 25 '15 at 18:02
  • 1
    \$\begingroup\$ Does "accurate to at least 2 decimal places" require at least two decimals to be printed, or can a second decimal of zero be left out? \$\endgroup\$ – hvd Dec 25 '15 at 23:03

35 Answers 35

0
\$\begingroup\$

Kotlin, 138 bytes

Code

let{var u=0.0
var l=0.0
forEach{when{it.isUpperCase()->u++
it.isLowerCase()->l++}}
"${maxOf(u,l)/(u+l)} ${if(u>l)"upp" else "low"}ercase"}

Usage

fun String.y():String =let{var u=0.0
var l=0.0
forEach{when{it.isUpperCase()->u++
it.isLowerCase()->l++}}
"${maxOf(u,l)/(u+l)} ${if(u>l)"upp" else "low"}ercase"}

fun main(args: Array<String>) {
    println("PrOgRaMiNgPuZzLeS & CoDe GoLf".y())
    println("DowNGoAT RiGHtGoAt LeFTGoat UpGoAT".y())
    println("Foo BaR Baz".y())
}
\$\endgroup\$
0
\$\begingroup\$

Pyth, 40 39 bytes

Jml@dQrBG1+jdeS.T,cRsJJc2."kw񽙽""ercase

Try it here

Explanation

Jml@dQrBG1+jdeS.T,cRsJJc2."kw񽙽""ercase
 m    rBG1                                For the lower and uppercase alphabet...
  l@dQ                                    ... count the occurrences in the input.
J                 cRsJJ                   Convert to frequencies.
               .T,     c2."kw񽙽"          Pair each with the appropriate case.
             eS                           Get the more frequent.
          +jd                    "ercase  Stick it all together.
\$\endgroup\$
0
\$\begingroup\$

Tcl, 166 bytes

proc C s {lmap c [split $s ""] {if [string is u $c] {incr u}
if [string is lo $c] {incr l}}
puts [expr $u>$l?"[expr $u./($u+$l)] upp":"[expr $l./($u+$l)] low"]ercase}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

APL(NARS), 58 char, 116 bytes

{m←+/⍵∊⎕A⋄n←+/⍵∊⎕a⋄∊((n⌈m)÷m+n),{m>n:'upp'⋄'low'}'ercase'}

test:

  h←{m←+/⍵∊⎕A⋄n←+/⍵∊⎕a⋄∊((n⌈m)÷m+n),{m>n:'upp'⋄'low'}'ercase'}
  h "PrOgRaMiNgPuZzLeS & CoDe GoLf"
0.52 uppercase
  h "DowNGoAT RiGHtGoAt LeFTGoat UpGoAT"
0.5806451613 uppercase
  h "Foo BaR Baz"
0.5555555556 lowercase
\$\endgroup\$
0
\$\begingroup\$

C, 120 bytes

f(char*a){int m=0,k=0,c;for(;isalpha(c=*a++)?c&32?++k:++m:c;);printf("%f %sercase",(m>k?m:k)/(m+k+.0),m>k?"upp":"low");}

test and result:

main()
{char *p="PrOgRaMiNgPuZzLeS & CoDe GoLf", *q="DowNGoAT RiGHtGoAt LeFTGoat UpGoAT", *m="Foo BaR Baz";
 f(p);printf("\n");f(q);printf("\n");f(m);printf("\n");
}

results

0.520000 uppercase
0.580645 uppercase
0.555556 lowercase

It suppose Ascii character set.

\$\endgroup\$
  • \$\begingroup\$ 116 bytes \$\endgroup\$ – ceilingcat Jan 2 at 18:13
  • \$\begingroup\$ @ceilingcat you can update your to that 116 bytes... This 120 bytes for me if is enough... \$\endgroup\$ – RosLuP Jan 3 at 10:46

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.