Skip to content

Instantly share code, notes, and snippets.

@CodeGolfScotland
Last active January 25, 2017 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeGolfScotland/6beb7b07a12608cf520d9af0c95310a8 to your computer and use it in GitHub Desktop.
Save CodeGolfScotland/6beb7b07a12608cf520d9af0c95310a8 to your computer and use it in GitHub Desktop.
The June 2016 challenge

June 2016 - sillyCASE

Task:

Create a function that takes a string and returns that string with the first half lowercased and the last half uppercased.

Example:

foobar => fooBAR

If the string length is an odd number then 'round' it up to find which letters to uppercase. See example below.

sillycase("brian")  
//         --^-- midpoint  
//         bri    first half (lower-cased)  
//            AN second half (upper-cased)  

About Code Golf Scotland

@joaquinferrero
Copy link

joaquinferrero commented Jul 1, 2016

Language: Perl 6
Length: 53 47

sub f{$_=$^a.lc;.substr-rw(.5+.chars×½).=uc;$_}

Demo:

$ perl6 -e 'say f("bRian"); sub f{$_=$^a.lc;.substr-rw(.5+.chars×½).=uc;$_}'
briAN

@salathe
Copy link

salathe commented Jul 1, 2016

It's not June any more, but here's a sneaky wee PHP one.

Language: PHP
Length: 88

function s($a){$o=-strlen($a)/2;return substr_replace($a,substr(strtoupper($a),$o),$o);}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment