65
\$\begingroup\$

A kitten is much like a cat. Some of the main differences are cuteness, lack of intelligence, and size. Similarly, the cat command is different from the kitten command. Fortunately, there is only one difference in this case. In the kitten command, all uppercase letters are replaced with lowercase letters.


Objective

To implement a program that behaves similarly to cat. All characters [A-Z] are outputted lowercase.


Input

A list of files as command line arguments. If no files are listed, then read from standard input. The input may contain unprintable characters and characters outside the ASCII range.


Output

If input is a bunch of files, concatenate the contents and output all characters as lowercase. If reading from STDIN, output the contents of STDIN with all uppercase letters as lowercase.

Note: Only make the characters [A-Z] lowercase. It is unacceptable if any other characters are made lowercase.


Examples

$ echo "HelLo" > file.txt
$ kitten file.txt
hello
$ echo "Good Bye" | kitten
good bye
$ echo "Ä" | kitten
Ä

As usual with , least bytes wins.

Leaderboards


Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=59029,OVERRIDE_USER=32700;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
6
  • 2
    \$\begingroup\$ By explicitly stating "Only make the characters [A-Z] lowercase" are you anticipating Unicode input? \$\endgroup\$ Sep 29 '15 at 16:55
  • 2
    \$\begingroup\$ @TimmyD Yes, but it is mainly to prevent people from using built in to lowercase functions. \$\endgroup\$ Sep 29 '15 at 16:58
  • 3
    \$\begingroup\$ @FryAmTheEggman permalink \$\endgroup\$
    – Dennis
    Sep 29 '15 at 17:06
  • 1
    \$\begingroup\$ How about Ü, Ñ and the likes? \$\endgroup\$
    – Mast
    Oct 1 '15 at 1:02
  • 3
    \$\begingroup\$ It's so nice when you don't see any Pyth at all in a codegolf... \$\endgroup\$
    – jmm
    Oct 4 '15 at 18:11

26 Answers 26

54
\$\begingroup\$

Perl, 6 bytes

5 bytes code + 1 byte command line

$_=lc

Example usage:

echo ABCdef | perl -p kitten.pl
abcdef

Confirmation of correct Unicode behaviour:

echo "HelloÉ" | perl -p kitten.pl
helloÉ
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Are you sure this doesn't affect Unicode characters? \$\endgroup\$ Sep 30 '15 at 8:03
  • 8
    \$\begingroup\$ @MartinBüttner It does not. We're in the “otherwise” category here: “ASCII rules are used for the case change. The lowercase of any character outside the ASCII range is the character itself.” My +1 for the answer. \$\endgroup\$
    – xebtl
    Sep 30 '15 at 12:59
182
\$\begingroup\$

Bash, 19 bytes

cat "$@"|tr A-Z a-z

The best way to make kittens is to use actual cats.

Example run

$ ./kitten kitten
cat "$@"|tr a-z a-z
\$\endgroup\$
6
  • 41
    \$\begingroup\$ The right tool for the job. \$\endgroup\$ Sep 29 '15 at 17:24
  • 125
    \$\begingroup\$ +1 for only needing one cat to make a kitten, always takes me two cats \$\endgroup\$ Sep 29 '15 at 23:00
  • 5
    \$\begingroup\$ Now that reminds me of those man woman jokes … \$\endgroup\$
    – xebtl
    Sep 30 '15 at 13:01
  • 3
    \$\begingroup\$ +1 for going for the cat cloning rather than mating method of creating offspring \$\endgroup\$
    – MD-Tech
    Sep 30 '15 at 15:45
  • 28
    \$\begingroup\$ @SnoringFrog He bashed the other one. \$\endgroup\$ Sep 30 '15 at 19:46
22
\$\begingroup\$

Perl, 11 bytes

10 bytes code + 1 byte command line

y/A-Z/a-z/

Example usage:

perl -p entry.pl input1.txt input2.txt
echo "ABCdef" | perl -p entry.pl
\$\endgroup\$
0
15
\$\begingroup\$

Python 3, 77 bytes

from fileinput import*
print(end=b''.join(input(mode='rb')).lower().decode())
\$\endgroup\$
1
  • 1
    \$\begingroup\$ That's clever, using bytes to avoid non-ASCII from changing. \$\endgroup\$
    – matsjoyce
    Sep 30 '15 at 7:29
11
\$\begingroup\$

Ruby, 13 bytes

The byte count includes 1 byte for the p flag. Run it like so: ruby -p kitten.rb.

$_.downcase!

Takes input from stdin or file arguments, just like grown up cat.

\$\endgroup\$
3
  • \$\begingroup\$ Does this only downcase ASCII, or also other characters like Ä? \$\endgroup\$ Sep 30 '15 at 7:58
  • 1
    \$\begingroup\$ @PaŭloEbermann: I just tested it: echo "HelloÉ" | ruby -p kitten.rb -> helloÉ \$\endgroup\$ Sep 30 '15 at 8:25
  • \$\begingroup\$ I swear there was a whole bunch of comments here regarding that yesterday. I don't know where those went, but: Yes, it works according to the spec. \$\endgroup\$
    – daniero
    Sep 30 '15 at 10:29
5
\$\begingroup\$

PowerShell, 112 Bytes

function l([string]$a){97..122|%{[char]$b=$_;$a=$a-split$b-join$b};$a}if($args){$args|%{l(gc $_)}}else{l $input}

Horrendously unreadable. Here's a slightly expanded version below:

function l([string]$a){
  97..122|%{
    [char]$b=$_
    $a=$a-split$b-join$b
  }
  $a
}

if($args){
  $args|%{
    l(gc $_)
  }
}
else{
  l $input
}

Defines an internal function l which iterates over a loop from 97 to 112 (i.e., ASCII a to ASCII z). Splits the input string over that character (yay case-insensitive default), the rejoins it with the "correct" lower case. Do note that yes, this means "Test" would briefly become "T st" as it's iterating through the e, for example. Doesn't affect output.

The second half is the tricky bit to figure out if we have pipeline input (equivalent to stdin for PowerShell) or command-line input. The special variable $args is only present if command-line input is present, so we loop over each one, gc (for Get-Content) and schlep that up to l. Otherwise, we just schlep our $input up to l. Note that we could swap our if/else statements (i.e., if($input)), but since "input" is one character longer than "args" this way is shorter.

\$\endgroup\$
1
  • \$\begingroup\$ @Nazek The built-in "String".ToLower() would also lowercase Unicode characters, which is against the rules. There's a lot of stuff that PowerShell doesn't do right with regards to Unicode, but unfortunately this is one instance that it works correctly. \$\endgroup\$ Sep 30 '15 at 2:39
5
\$\begingroup\$

R, 97 bytes

cat(chartr("A-Z","a-z",sapply(if(length(a<-commandArgs(T))){a}else{"stdin"},readLines)),sep="\n")

Usage:

$ echo "HeLlo" > file.txt
$ Rscript kitten.R file.txt
hello
$ echo "Good Bye" | Rscript kitten.R
good bye
$ echo "bLABLa" > file2.txt
$ Rscript kitten.R file.txt file2.txt
hello
blabla
$ echo Ä | Rscript kitten.R
Ä
\$\endgroup\$
5
\$\begingroup\$

CoffeeScript, 292 bytes

f=require 'fs';d='';p=process;v=p.argv;s=p.stdin;l=((d)=>console.log d.replace /([A-Z])/g,(a,l)=>l.toLowerCase());if v.length>2 then(v.forEach (v,i)=>if i>1 then(f.exists v, (e) =>if e then(f.readFile v,'utf-8',(r,d)=>l d) else l v))else(s.resume();(s.on 'data',(c)=>d+=c);s.on 'end',()=>l d)

Usage:

$ echo "HelLo" > file.txt
$ coffee kitten.coffee file.txt
hello
$ echo "Good Bye" | coffee kitten.coffee
good bye
$ echo "Ä" | kitten
Ä
$ coffee kitten.coffee file.txt SoMeTeXt
sometext
hello

My first participation on codegolf so please don't be rude :).

For sure this code can be golfed more and coffee/javascript isn't the best choice to do that, but it does what's expected.

When it reads arguments it also takes care about file existency (if file does not exists, the string is kittened.)

Any help or advice to improve this code is welcome !

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

Julia, 123 bytes

f(s)=for l=readlines(s) print(replace(l,r"[A-Z]",lowercase))end
A=ARGS
length(A)>0?for i=A open(f,i)end:open(f,readline())

Ungolfed:

function file_to_lower(s::Stream)
    # Loop over the lines of the input stream
    for l in readlines(r)
        # Print the lowercased line
        print(replace(l, r"[A-Z]", lowercase))
    end
end

if length(ARGS) > 0
    # Loop over the files specified from the command line
    for i in ARGS
        # Open the file, apply the function, then close it
        open(file_to_lower, i)
    end
else
    # Get the input file from STDIN
    open(file_to_lower, readline())
end
\$\endgroup\$
4
\$\begingroup\$

Python 2, 53 bytes

from fileinput import*
print''.join(input()).lower(),
\$\endgroup\$
0
4
\$\begingroup\$

CJam, 18 bytes

ea_:gs{q}?'_,_eler

The list of files must be supplied in form of URLs, which is the only format CJam understands.

Example runs

$ cjam kitten <<< "AaÁáÄä"
aaÁáÄä
$ cjam kitten file:///home/dennis/kitten file:///home/dennis/kitten
ea_:gs{q}?'_,_elerea_:gs{q}?'_,_eler

How it works

ea                  Push the array of command-line arguments.
  _                 Push a copy.
   :g               Retrieve the contents of all files with those URLS.
     s              Flatten the resulting array of strings.
      {q}           Push a block that reads all input from STDIN.
         ?          Select the string of the array of args is non-empty.
                    Otherwise, execute the code block.
          '_,       Push the string of all ASCII characters before _.
             _el    Push a copy and convert it to lowercase.
                er  Perform transliteration.
\$\endgroup\$
4
\$\begingroup\$

Python 2, 100 102 97 bytes

Functionality corrected (and 4 bytes added) by matsjoyce. Fortunately, I saved two bytes by switching to Python 2.

from sys import*;print''.join(f.read().lower()for f in(map(open,argv[1:])if argv[1:]else[stdin]))

Takes arguments from the command line, or from STDIN if no arguments found.

This abuses the default arguments of some functions. By default, open uses read-only text mode, which is exactly what we want. read, if called with no arguments, will return all text in the stream.

Ungolfed:

import sys

if len(sys.argv) > 1:              # If we have command-line arguments:
    source = []                    # Initialize an empty list
    for path in sys.argv[1:]:      # Iterate through every filename we have
        kitfile = open(path, 'rt') # Open the file in read-only text mode
        source.append(kitfile)     # Add it to the list
else:                              # Otherwise, if the args are empty:
    source = [sys.stdin]           # Set our source to STDIN wrapped in a list

kittened = []                      # Initialize an empty list
for kitfile in source:             # Iterate through every file (or just STDIN)
    text = kitfile.read()          # Read everything from the stream
    kitten_text = text.lower()     # Make it lowercase
    kittened.append(kitten_text)   # Add it to the list
final = ''.join(kittened)          # Join everything together
print final                        # Print the result
\$\endgroup\$
2
  • 1
    \$\begingroup\$ This won't work for stdin, as you only read one line, and do not lowercase it. \$\endgroup\$
    – matsjoyce
    Sep 29 '15 at 19:43
  • \$\begingroup\$ @matsjoyce I've fixed my code. Thanks for the reminder! Unfortunately, it added four bytes, but by no longer depending on input not evaluating, I could switch to Python 2 and remove the parentheses on print. \$\endgroup\$
    – jqblz
    Sep 29 '15 at 22:34
3
\$\begingroup\$

Python 3, 124 123 bytes


from sys import*
for f in list(map(open,argv[1:]))or[stdin]:print(f.read().translate({i:i+32for i in range(65,91)}),end="")

Python eats kittens!

$ python kitten.py file.txt
hello
$ echo "Good Bye" | python kitten.py 
good bye
$ echo "Ä" | python kitten.py 
Ä
\$\endgroup\$
3
\$\begingroup\$

C, 106 108 bytes

Edit: Fixed a mistake that creeped in when squeezing bytes. Stdin wasn't working, now it is.

I'm pretty sure I could squeeze some bytes away, but here's an easy-to-grasp, not at all language abusive, submission:

main(n,s,f,c)void**s;{for(f=n-1?open(*++s,0,0):0;read(f,&c,1);putchar(64<c&c<91?c+32:c));n-->2&&main(n,s);}

And a somewhat more neatly formatted version for reading:

main(n,s,f,c)
void**s;
{
    for(f=n-1?open(*++s,0,0):0; read(f,&c,1); putchar(64<c&c<91?c+32:c));
    n-->2&&main(n,s);
}
\$\endgroup\$
1
  • \$\begingroup\$ +1 because this taught me that implicit int parameters are only possible with K&R syntax. \$\endgroup\$ Oct 1 '15 at 22:50
2
\$\begingroup\$

Mathematica, 66 bytes

kit=StringReplace[#,x:RegularExpression["[A-Z]"]:>ToLowerCase[x]]&

Called as

kit@"HelLo"

Mathematica already has a ToLowerCase function, but it converts special (Unicode and mathematical) characters as well. So I had to kittenize it. This function will take any input.

\$\endgroup\$
3
  • \$\begingroup\$ @TheNumberOne - that is how it works in Mathematica. No more code is needed to do this. If you want an executable, then Mathematica isn't the tool. \$\endgroup\$
    – Verbeia
    Oct 1 '15 at 23:39
  • \$\begingroup\$ Does this concatenate files whose names are input as command-line arguments, as required? \$\endgroup\$
    – msh210
    Mar 6 '16 at 6:19
  • \$\begingroup\$ Command-line args don't exist in Mathematica. It conkittenates its function inputs. Also you don't need to assign to a variable. \$\endgroup\$ Mar 7 '16 at 0:51
2
\$\begingroup\$

C#, 230 226 bytes

namespace System{using Linq;class P{static void Main(string[]a){Console.Write(string.Concat((a.Length>0?string.Concat(a.Select(f=>IO.File.ReadAllText(f))):Console.In.ReadToEnd()).Select(c=>c>'@'&&c<'['?char.ToLower(c):c)));}}}

Ungolfed:

namespace System
{
    using Linq;
    class P
    {
        static void Main(string[] a)
        {
            Console.Write(                                                  // Print...
                string.Concat(                                                  // ...all chars combined to a string...
                    (a.Length > 0 ?                                             // ...commandline arguments?...
                        string.Concat(a.Select(f => IO.File.ReadAllText(f))) :  // ...then all files as single string...
                        Console.In.ReadToEnd()                                  // ...else STDIN input
                    ).Select(c => c > '@' && c < '[' ? char.ToLower(c) : c)     // ...Lowercase only A..Z
                )
            );  
        }
    }
}
\$\endgroup\$
2
\$\begingroup\$

Haskell, 133

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
f[]=[getContents]
f n=map readFile n
l x=[x..]!!sum[32|x>'@',x<'[']

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

Explaining l, the function to lowercase one character:

  • sum[32|condition] is a shorter form of if condition then 32 else 0.
  • [x..]!!count is iterate succ x !! count is toEnum $ fromEnum x + count and shorter than importing and using Data.Char.toLower with a condition to restrict it to ASCII.
  • '@' and '[' are the characters immediately preceding A and following Z, so that I can use < instead of <=.

Thanks to Anders Kaseorg for contributing the sum[...|...] and [x..]!! tricks.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ l x=[x..]!!sum[32|x>'@',x<'['] \$\endgroup\$ Feb 26 '16 at 23:41
1
\$\begingroup\$

C#, 342 bytes

  • takes file list from passed arguments.
  • read every char in every file than only converts to lower case if and only if the character in the A..Z range than send it to STDOUT.
  • If there is no file list than reads STDIN, reads every char, converts to lower case if and only if the character in the A..Z range than send it to STDOUT.
namespace System{
using IO;
using Linq;
class P{
static void Main(string[]a){
Action<char>e=C=>{var c=char.ToLower(C);Console.Out.Write(c>='a'&&c<='z'?c:C);};
if(a.Length>0)a.ToList().ForEach(f=>File.ReadAllText(f).ToCharArray().ToList().ForEach(e));
else 
while(true) Console.In.ReadLine().ToCharArray().ToList().ForEach(e);
}
}
}

C#, 319 bytes

single-liner, same as above:

namespace System{using IO;using Linq;class P{static void Main(string[]a){Action<char>e=C=>{var c=char.ToLower(C);Console.Out.Write(c>='a'&&c<='z'?c:C);};if(a.Length>0)a.ToList().ForEach(f=>File.ReadAllText(f).ToCharArray().ToList().ForEach(e));else while(true)Console.In.ReadLine().ToCharArray().ToList().ForEach(e);}}}
\$\endgroup\$
0
1
\$\begingroup\$

S.I.L.O.S 179 characters

loadLine :
a = 256
x = get a
lbla
X = x
B = x
C = 91
B - 64
if B c
printChar x
GOTO x
lblc
C - x
if C D
printChar x
GOTO x
lblD
x + 32
printChar x
lblx
a + 1
x = get a
if x a
lblb

Feel free to try this code online!


Essentially it translates to this in pusedocode.

String input = input();
for(char c in input)
if(c is uppercase) print c + 32/*lowercase c*/else print c
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 4 bytes

AuA‡

Try it online! Beats all other answers.

AuA‡  # full program
   ‡  # replace all characters of...
A     # "abcdefghijklmnopqrstuvwxyz"...
 u    # in uppercase...
   ‡  # with corresponding character in...
  A   # "abcdefghijklmnopqrstuvwxyz"...
   ‡  # in...
      # implicit input
      # implicit output
\$\endgroup\$
1
\$\begingroup\$

Vyxal, 5 bytes

kAkaĿ

Try it Online!

You'll be cackling with laughter when you see this! :p

I lost by one byte but the funny pronunciation of the program is worth it. Simply transliterate the upper-case alphabet with the lower-case alphabet.

\$\endgroup\$
1
  • \$\begingroup\$ cackles nice job \$\endgroup\$ May 1 at 22:12
1
\$\begingroup\$

Julia 1.x, 65 bytes

!s=print.(c+32('@'<c<'[') for c=read(s,String))
.!ARGS>[]||!stdin

Try it online! (stdin)

Try it online! (files)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Julia is one of my favorite languages ^-^ \$\endgroup\$ Aug 2 at 20:31
0
\$\begingroup\$

sed, 14 bytes

s/[A-Z]/\L\0/g

Run with env -i sed -f kitten.sed.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Since this is just a fancy way for saying LANG=C sed -f kitten.sed, I'm unsure if I should apply a penalty to account for that. This question doesn't specify how to count program calls, and it doesn't seem addressed in meta. \$\endgroup\$
    – Ángel
    Oct 1 '15 at 0:25
  • \$\begingroup\$ Does this concatenate files whose names are input as command-line arguments, as required? \$\endgroup\$
    – msh210
    Mar 6 '16 at 6:18
  • \$\begingroup\$ @msh210 Yes, of course. \$\endgroup\$
    – Ángel
    Mar 14 '16 at 1:12
  • 1
    \$\begingroup\$ @Ángel s/.*/\L&/ for a nine bytes solution \$\endgroup\$ Jul 24 '16 at 14:52
  • \$\begingroup\$ Thanks @someonewithpc. Both s/.*/\L&/ and s/./\L&/g are indeed 9-byte solutions! \$\endgroup\$
    – Ángel
    Jul 24 '16 at 19:50
0
\$\begingroup\$

Java, 198 bytes

b->B->{B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;};

You are forced to use the above lambda with files, so there's no need to take input from STDIN! Also, it's a Function<File[], UnaryOperator<String>>. It's used like foo.apply(anArrayOfFiles).apply(anything).

As something that makes more sense to those who are new to Java, it takes 223 bytes:

String A(java.io.File[]b){String B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;}

As something that compiles, it takes up 232 bytes:

class a{String A(java.io.File[]b){String B="";for(java.io.File c:b)B+=new java.util.Scanner(c).useDelimiter("\\Z").next();for(int c=0;c++<B.length;)if(B.charAt(c)>64&B.charAt(c)<91)B=B.replace(B.charAt(c),B.charAt(c)|32);return B;}}
\$\endgroup\$
0
\$\begingroup\$

Go, 89 bytes

package main
import(."fmt"
."strings")
func main(){s:=""
for{Scan(&s)
print(ToLower(s))}}
\$\endgroup\$
0
\$\begingroup\$

Japt, 5 bytes

;dBíC

Try it

Japt v2.0a0, 5 bytes

r\A_v

Try it

\$\endgroup\$

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.