g | x | w | all
Bytes Lang Time Link
036Uiua 0.11.0240529T174541ZRomanPro
014Stax210412T170318ZRazetime
025RProgN170131T042623ZATaco
176Python151228T234558ZTanMath
141JavaScript170130T190620ZAlvaro A
5278Unicorn ES6151229T024505ZETHprodu
200Racket170130T172415ZRodrigo
125SmileBASIC170128T174424Z12Me21
067Perl 6170128T163029Zsmls
086Python 3151229T151616ZSherlock
3379Unicorn ES6 Invalid160102T185750Zuser4616
075Ruby151229T161016ZMegaTom
083PHP151228T230002Zinsertus
426Rust151229T142533ZKroltan
078Ruby151229T135315ZBDA
118Mathematica151229T015944ZLegionMa
017Pyth151228T222457ZMaltysen

Uiua 0.11.0, 39 36 bytes

(transpiling part - 28 25 bytes)

- 3 bytes thanks to noodle man

Works only with string literals in the code, doesn't work with strings evaluated at runtime.

U! ←^ +@\0Γ—βŠ—:" πŸ¦„πŸ"βŠœβŠƒβŠ’β§»-@ .β†˜2β—‡βˆ˜βŠ’
U!$ <your Unicorn code here>

Try it out!

Stax, 14 bytes

ΓΌβ”΄(gΓ‡%β•©[↑÷>7β™«β–‘

Run and debug it

RProgN, 25 bytes

~`🐐'πŸ¦„πŸ¦„'R'(πŸ¦„+)%s*'{Lc}R do

Explained

~                             # Zero Space Segment
 `🐐                         # The String literal "🐐"
   'πŸ¦„πŸ¦„'                   # The String literal "πŸ¦„πŸ¦„"
       R                     # Replace, turning all goats into twonicorns
        '(πŸ¦„+)%s*'          # The pattern string "(πŸ¦„+)%s*", which is "A fewnicorns, then as much whitespace as possible, or none.
                 {Lc}R      # Replace with the result of the function, which converts the captured subgroup to it's Length, then to a char.
                       do   # Straight up do it.

Once again, RProgN falls into the trap of being consistently okay.

Try it online!

Python 179 176 bytes

EDIT: I just learnt s.split(' ')=s.split()

Here is the second "actual" programming language Unicorn interpreter. I call this version of Unicorn "UnicornPy" pronounced as "unicorn pie". I am making this much too official!

s=raw_input()
s=s.replace('🐐','πŸ¦„πŸ¦„')
s=s.replace('πŸ¦„','u')
for i in s:
    if i not in "ug ":
        s=s.replace(i,'')
s=s.split()
for i in s:
    s[s.index(i)]=chr(len(i))
exec(''.join(s))

For some reason, it needs me to convert the unicorn and goat emojis to u and g. I do not know why.

Try it here!

JavaScript, 140 154 141 bytes

var s='';i.split(" ").forEach((e)=>{s+=String.fromCharCode((e.split("πŸ¦„").length-1)+2*(e.split("🐐").length-1));});console.log(eval(s));

It splits the input string in an array of strings, using space as a needle. It then proceeds to count the amount of unicorns and goats*2 and concatenate the summed result to what will be evaluated.

More readable:

var s = '';
i.split(" ").forEach((e) => {
    s+=String.fromCharCode((e.split("πŸ¦„").length-1)+2*(e.split("🐐").length-1));
});
console.log(eval(s));


Edit:

Updated code to accept an argument from CLI, use: node unicorn.js "πŸπŸ¦„ πŸ¦„πŸ¦„"

var s='';process.argv[2].split(' ').forEach((e)=>{s+=String.fromCharCode((e.split('πŸ¦„').length-1)+2*(e.split('🐐').length-1));});console.log(eval(s));

Ungolfed:

var s = '';
process.argv[2].split(' ').forEach((e) => {
    s+=String.fromCharCode((e.split('πŸ¦„').length-1)+2*(e.split('🐐').length-1));
});
console.log(eval(s));


Edit 2:

Edited to accept input as a function parameter, use node unicorn.js

i=>{var s='';i.split(' ').forEach((e)=>{s+=String.fromCharCode((e.split('πŸ¦„').length-1)+2*(e.split('🐐').length-1));});return eval(s);};

Ungolfed:

i =>{
    var s = '';
    i.split(' ').forEach((e) => {
        s+=String.fromCharCode((e.split('πŸ¦„').length-1)+2*(e.split('🐐').length-1));
    });
    return eval(s);
};

Try it online!

Unicorn (ES6), 5934 5278 bytes

Under the custom encoding, this is 5278 bytes (1 byte per char); but with UTF-8, it would 4 bytes per char (though only 1 for a space), or 20869 total.

(too many Unicorns and Goats to reasonably display here)

Instead, here's a pastebin. This Unicorn code transpiles to this JS snippet:

s=>eval(s.replace(/\S+ ?/g,c=>String.fromCharCode(c.length>>1<<c.charCodeAt()%2)))

Now, this isn't the shortest possible version; this is shorter:

s=>eval(s.replace(/\S+ ?/g,c=>String.fromCharCode(c.length>>1<<("πŸ¦„">c))))

However, the one unicorn in there would transpile to 56034 goats, thus multiplying the score by roughly 11.

Here's the function I used to transpile to Unicorn:

function g(s){return s.replace(/./g,function(c){i=c.charCodeAt();return(i%2?"πŸ¦„".repeat(i):"🐐".repeat(i/2))+" "}).slice(0,-1)}
<textarea id=O cols=100></textarea><button id=P onclick="Q.value=g(O.value);R.innerHTML=(Q.value.length+Q.value.split(' ').length-1)/2">Run</button><br><textarea id=Q rows=10 cols=100>Output appears here.</textarea><br><p>Length: <span id=R>0</span><br></p>

Note: I haven't actually tested the program, as there isn't an online interpreter that I could find (although I suppose I could hook up the .js file to HTML...?)

Racket, 200 bytes

(define(f s)(eval(read(open-input-string(list->string(map integer->char(map(Ξ»(x)(foldl(Ξ»(y a)(case y[(#\u)(add1 a)][(#\g)(+ a 2)]))0 x))(map string->list(string-split s)))))))(make-base-namespace)))

Ungolfed:

(define(f s)
  (eval(read(open-input-string
             (list->string ;;back to string
              (map integer->char ;;back to char
                   (map(Ξ»(x)
                         (foldl(Ξ»(y a)
                                 (case y
                                   [(#\u)(add1 a)]
                                   [(#\g)(+ a 2)]))
                               0 x))
                       (map string->list (string-split s))))))) ;;splitting by space, converting to list of chars
       (make-base-namespace)))

It starts by splitting the string into list of strings by spaces, then creates a list of chars per splitted string. Then each list of chars is reduced into a number by adding 1 if unicorn, 2 if goat. Finally, each list containing the sum is made a list of chars, then a string which is passed to eval.

Try it online!

SmileBASIC, 125 bytes

INPUT S$WHILE LEN(S$)R=ASC(POP(S$))IF R-32THEN C=C+!(R-117)+2*!(R-103)ELSE O$=CHR$(C)+O$C=0
WEND
SAVE"TXT:@",CHR$(C)+O$EXEC"@

Using PRGEDIT to execute the code without saving would have been a lot nicer, but also a lot longer.

code:

INPUT CODE$ 'making the user type 1000s of characters just so I could save 2 or 3
WHILE LEN(CODE$)
 CHAR$=POP(CODE$) 'I convert the code backwards, since POP( is shorter than SHIFT(
 IF CHAR$==" " THEN
  UNSHIFT OUT$,CHR$(CHAR)
  CHAR=0
 ELSE
  INC CHAR,(CHAR$=="u")+(CHAR$=="g")*2
 ELSE
WEND
SAVE "TXT:@",CHR$(CHAR)+OUT$
EXEC "TXT:@"

Perl 6, 67 bytes

{use MONKEY-SEE-NO-EVAL;EVAL [~] .wordsΒ».&{chr m:g/\πŸ¦„/+2*m:g/\🐐/}}

Python 3, 94 86 bytes

This is a simple parser that works even if you mix u and g in one section.

s=input().split();exec(''.join(chr(sum([[0,2][j<"u"],1][j>"g"]for j in i))for i in s))

As an example (using u and g in separate sections):

gggggggggggggggggggggggggggggggggggggggggggggggggggggggg ggggggggggggggggggggggggggggggggggggggggggggggggggggggggg uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu ggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggg uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

should parse to

print(1)

Unicorn ES6 (Invalid), 3379 bytes

This is invalid because it uses the latest version of Unicorn with rainbows, sun with clouds, and sparkles. Thanks to @ETHproductions for the JS code to interpret unicorn.

code is in the paste bin below

Pastebin: http://pastebin.com/raw/Q9Kd4ixA
This is only 3379 bytes if sparkles, sun/clouds, and rainbows also are 1 byte.

Ruby, 75 characters

A nifty ruby interpreter that replaces all πŸ¦„ with ' ' (a space) and all 🐐 with ' ' (two spaces), and gets the length of each segment.

I call this version of Unicorn RubyUnicorn Rubycorn.

->s{eval s.split(a=' ').map{|r|r.gsub('πŸ¦„',a).gsub('🐐',a*2).size.chr}.join}

PHP, 83 80 86 87 bytes

Now Unicorn-ready

For the cost of 3 bytes I made this unicorn ready:

$a=mb_substr_count;foreach(explode(" ",$argv[1])as$b)echo chr($a($b,πŸ¦„)+2*$a($b,🐐));

Takes an input from command line, like:

$ unciorns.php "πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„πŸ¦„"

This will output 32.

Demo

Try before buy


Unfortunately OS X 10.10.5 doesn't support is hiding Unicorns. Here's the alternative ug-approach (80 bytes):

$s=substr_count;foreach(explode(' ',$argv[1])as$c)echo chr($s($c,u)+2*$s($c,g));

Takes an argument from command line, like:

$ php unicorns.php "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuug uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"

Try the ug-version


Edits

Demo discarded version (86 bytes)

for($_=$argv[1].' ';$c=$_[$i++];)$t+=u==$c?1:(g==$c?2:(' '==$c?-$t+!print chr($t):0));

Rust, 426 bytes

use std::io::Write;macro_rules!c{($n:expr,$a:expr)=>(println!("{}",std::str::from_utf8(&std::process::Command::new($n).arg($a).output().unwrap().stdout).unwrap());)}fn main(){let d:String=std::env::args().skip(1).next().unwrap().split(' ').map(|s|s.chars().fold(0u8,|a,c|a+match c as char{'πŸ¦„'=>1,'🐐'=>2,_=>0}) as char).collect();std::fs::File::create("o").unwrap().write_all(d.as_bytes()).unwrap();c!("rustc","o");c!("o","");}

This probably can be golfed the hell down, but type safety and checked errors are quite verbose.

Since Rust is a compiled language, this program outputs the decoded program to a file and invokes the compiler on said file, then executes the resulting binary.

Ungolfed:

use std::io::Write;

macro_rules! command {
    ($name:expr,$argument:expr) => (println!("{}", std::str::from_utf8(
        std::process::Command::new($name)
                              .arg($argument)
                              .output()
                              .unwrap()
    ));)
}

fn main() {
    let decoded: String = std::env::args()
        .skip(1) //ignore program name
        .next().unwrap().split(' ') //get first arg split on spaces
        //transform every section in a char
        .map(|section| section.chars()
            .fold(0u8, |accumulator, chr| accumulator + match chr as char {
            'πŸ¦„' => 1,
            '🐐' => 2,
            _ => 0
        }) as char)
        //convert iterator to string
        .collect();

    std::fs::File::create("o").unwrap()
        .write_all(decoded.as_bytes()).unwrap();
    command!("rustc", "o");
    command!("o", "");
}

Ruby, 78 Bytes

eval ARGV[0].gsub(/[^ug ]/,'').split.map{|b|(b.size*(b[0]=='u'?1:2)).chr}.join

It basically reads the first command line argument, splits it at every space character, maps the size of the block to the appropriate character and joins it all together.

Edit: Forgot the requirement that all other characters should be ignored

Mathematica, 118 bytes

a=StringCount;ToExpression@FromCharacterCode[If[#~StringTake~1=="u",#~a~"u",2IntegerLength[#~a~"g"]]&/@StringSplit@#]&

Performs exactly as described in the specification. I couldn't use emoji in Mathematica string literals without the interpreter exploding, so I used u and g.

Pyth - 23 17 bytes

.vsmC+/d\πŸ¦„y/d\🐐cz

Try it online.

It works by splitting the input by spaces, then for each section counting the number of unicorns and number of goats * 2 then adding them, then taking the char at the code point. It finished by summing the char array and pyth-evaling.