答:
Python 3, 156 bytes, 37692 + 715 + 50626 + 27806 + 148596 + 172675 = 438110 steps

This isn’t code-golf, but golf is fun anyway.  This steps to the cheese or takes the least traveled outgoing path, similar to mbomb007’s (not fully implemented) idea, but with ties broken by going to the alphabetically latest direction name.

Deterministic.  Run with python3 SCRIPT (tested in 3.5).

x=y=0
f={}
for l in iter(input,'0000'):c,d,x,y=p=max((f.setdefault(p,0),p)for p in zip(l,'nesw',[x,x+1,x,x-1],[y+1,y,y-1,y])if'!'!=p[0])[1];print(d);f[p]-=1
```

Title: Find the Cheese

Body:
Update: There are 6 mazes. They are included in the controller. There is a tar.gz of the mazes and their .bmp files here (dropbox). There is also a utility for making more mazes at that link (the maze_4.txt file is incorrect in archive). At this point, please feel free to run your own entry and update your score. Details on how to do so are included at the bottom. If you have questions or trouble, please ping me in chat.

You're a mouse. You're in a maze. Find the cheese.

Concept

You are in a maze that exists on a rectangular grid. Each space of the grid contains one of several things:

! - An impassable wall

  - An empty space, which is traversable

O - You, the mouse

+ - The cheese, your goal

Please use the same characters so that I do not have to modify the controller.

On each turn, you will be given the tiles that are North, South, East, and West of your current position. You must then output the direction that you wish to travel. You win when you get to the cheese. Fewer steps is better.

Input

You will be given input through stdin in the following fashion: nesw, where each letter represents the tile at that compass point. For example, if the current state looks like

```<code>  !          <--- Wall
 !O          <--- You
  +          <--- Cheese
</code>```

then you will be given the string ! +!.

At the end of the game, the controller will send you a string of four zeroes: 0000. Upon receiving this string, your program should terminate. No other input given will contain the 0 character.

Please ignore all other inputs.

Output

You are to output one letter n, s, e, or w, to indicate which direction you want to travel, followed by a new line character.

Scoring

Your score on each test is the number of steps it takes you to find the cheese.

Your overall score will be the sum of your average score per maze across a battery of mazes of variable sizes, all of which will fit inside a square of length 50.

For example, if it takes your bot 100 moves to complete each of the 6 mazes, then your score is 600.

If your bot is not deterministic, please try each maze 10 times and use average as the score for that maze. Your final score will be the sum of all the averages.

Rules

Each maze will fit inside a 50x50 square.

Each maze will have at least one valid path from start to cheese.

Each maze will be entirely walled in, except that the cheese will always be on the outer wall so that it essentially serves as an exit to the maze.

If you run into a wall, your submission is disqualified.

If your submission takes too long (as determined by me, as I start testing), it will be disqualified. This is in large part to prevent infinite loops. The soft limit will be one minute per maze, although I reserve the right to change this at any time in either direction.

Entries need not be deterministic, but if you are too random, you will likely be disqualified by the above point.

At some point, the battery of mazes will be released, future answers may not optimize toward them, and they are subject to change.

Submissions:

Your submission is a full program that takes input via stdin and output via stdout. This is important because the submission will be interacting with the maze controller. I'm not going to ban languages that are not freely available, but know that someone else will have to offer their time to run the tests if I do not have access to the language.

Please include instructions on how to run your submission.

Please state whether your submission is deterministic or not, so that I know whether I need to run it multiple times.

Test Mazes

In the test mazes, . characters outline the shortest route to the cheese. They are the same as the  (space) character. They are not visible to your submission. The controller replaces them with spaces.

```<code>!!!!!!!!+!
!O..!....!
! !.!.! !!
! !.!.!  !
! !.!.!! !
!!!.!.!! !
!  .!.! !!
!!!...   !
!!!!!!!!!!
</code>```

31x31 test maze. Shamelessly stolen.

```<code> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! O...!.......!   !  .....!.....!           !             !   !
 !!!!!.!.! !!!.! !!! !.!!!.!.!!!.!!!!!!! !!! !!!!!!!!! !!! ! ! !
 !   !...!   !.!     !.! !.!.! !.!       !   !         !   ! ! !
 ! !!!!! !!! !.!!!!!!!.! !.!.! !.! !!!!!!! !!! ! !!!!!!! !!! ! !
 !     !     !.........! !...!...!     !   !   ! !     !   ! ! !
 ! !!! !!!!!!!!!!!!!!!!! !!!!!.!!! !!! !!! ! ! !!! !!! !!! !!! !
 !   !         !     !   !.....!     !   ! ! ! !     !   !   ! !
 !!!!!!!!!!! ! ! !!! !!! !.!!!!!!!!!!!!! ! !!! ! !!!!!!! !!! ! !
 !           !   !       !.!             !   !     !     !     !
 ! !!!!!!! !!!!!!! !!!!!!!.! !!!!!!!!!!!!!!! !!!!!!! !!!!!!!!!!!
 ! !     ! !   !     !...!.!           !   !       ! !         !
 ! !!! ! ! ! ! !!!!!!!.!.!.! !!!!!!!!! ! ! !!!!!!! ! ! !!!!!!! !
 !   ! !   ! !       !.!...! !         ! !       ! ! !   !   ! !
 !!! ! !!!!! !!!!!!! !.!!!!!!! !!!!!!!!! !!! !!!!! ! !!! ! !!! !
 !   !   ! ! !       !...!     !   !     ! !           ! !   ! !
 ! !!!!! ! ! ! !!!!!!!!!.! !!!!! !!! !!!!! !!!!!!!!!!! ! ! ! ! !
 ! !       ! !   !   !...! !       ! !       !   !     ! ! ! ! !
 ! !!!!!!!!! !!! ! ! !.!!! !!!!!!! ! !!!!!!! ! ! !!!!!!! !!! ! !
 !             !   ! !...!       ! !     !   ! !             ! !
 !!!!!!!!!!!!!!!!!!! !!!.!!!!!!! ! !!!!! ! !!! !!!!!!!!!!!!!!! !
 !               !   !...!       !         !   !     !   !     !
 ! !!!!!!!!!!!!! ! ! !.!!! !!!!!!! !!!!!!!!! !!! !!! !!! ! !!! !
 ! !   !       !   ! !.! !     ! ! ! !     !     !   !   !   ! !
 ! ! ! !!!!! !!!!!!! !.! ! !!! ! ! ! ! !!! !!!!!!! !!! !!!!! !!!
 !   ! !   !       ! !.!     ! !     ! ! !     !   !       !   !
 !!!!! ! ! !!! !!! ! !.!!!!!!! !!!!!!! ! ! !!! ! !!!!!!!!! !!! !
 !     ! !   !   !   !.......!       ! ! ! !   !   !         ! !
 ! !!!!! !!! !!! !!!!!!!!!!!.!!!!!!! ! ! ! !!!!!!! ! !!!!!!! ! !
 !         ! !           !...!       ! ! !     !   ! !       ! !
 !!!!!!!!!!! !!!!!!!!!!! !.!!! !!!!!!! ! !!!!! ! !!! !!!!!!!!! !
 !         !     !     ! !.!       !   !     ! !     !         !
 ! !!!!!!! !!!!! ! !!! !!!.!!!!!!! ! !!!!! ! ! !!!!! ! !!!!!!!!!
 ! !     !     !   ! !   !.......! !       ! !       !         !
 ! ! !!! !!!!! ! !!! !!! !!!!!!!.! !!!!!!!!! !!!!!!!!!!!!!!!!! !
 !     !     ! !   !   ! !     !.!       !   ! !     !         !
 !!!!!!!!!!! ! !!! !!! ! ! ! !!!.! ! !!!!! !!! ! !!! ! !!!!!!! !
 !           ! !       !   ! !...! !       !   ! ! ! !     !   !
 ! !!!!!!!!!!! !!!!!!!!!!!!! !.!!! !!!!!!!!!!! ! ! ! ! !!! ! !!!
 !       !   !             ! !.! !   !         ! !   !   ! ! ! !
 !!!!!!! !!! !!!!!!!!!!!!! ! !.! !!! ! !!!!!!! ! !!! !!!!! ! ! !
 !       !         !     ! ! !.!   !   !     ! !   !       !   !
 ! !!!!!!! !!!!!!! ! !!!!! ! !.!!! !!!!!!! ! ! !!! !!!!!!!!!!!!!
 !   !         ! !   !       !.!           ! !   !             !
 ! ! ! !!!!!!! ! ! !!! !!!!!!!.! !!!!!!!!!!! ! !!!!!!!!!!!!!!! !
 ! ! ! !     ! !   !   ! !.....!   !   !     ! !...............!
 ! ! !!! !!! ! !!!!! !!! !.!!!!! ! ! ! !!!!!!! !.!!!!!!!!!!!!!.!
 ! !   !   ! !   !       !...!   !   !         !.!         !...!
 !!!!! !!! ! !!! ! !!!!!!!!!.!!!!!!! !!!!!!!!!!!.!!!!! !!!!!.!!!
 !     !   !   !   !       !.......!       !...!.....!      .! !
 ! !!!!! !!!!! !!!!! !!!!! !!!!!!!.!!!!!!!!!.!.!!!!!.!!!!!!!.! !
 !           !     ! !   !   !   !...........!...!...!.....!...!
 ! !!!!!!!!! !!!!! ! !!! ! !!! ! !!!!!!!!!!!!!!!.!.!!!.!!!.!!!.!
 ! !     !       ! !     !     !     !         !.!.....  !...!.!
 !!! !!! !!!!!!!!! !!!!! !!!!!!!!! ! !!!!!!! !!!.! !!!!!!!!!.!.!
 !   !     !   !   !   ! !       ! !         !...! !.........!.!
 ! !!!!!!! ! ! ! ! !!! ! !!!!!!! ! !!!!!!!!! !.!!!!!.!!!!!!!!!.!
 !       !   !   ! !   !         !   ! !   ! !.!.....!       !.!
 ! !!!!! !!!!!!!!! ! !!!!!!!!!!! !!! ! ! ! ! !.!.!!!!! !!!!! !.!
 ! !     !           !         ! ! ! !   !   !.!...!   !     !.!
 ! ! !!!!!!!!!!!!!!!!! !!! !!!!! ! ! !!!!!!!!!.!!!.! !!!!!!!!!.!
 ! !                     !         !          .....!          .!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!+!
</code>```

Controller

The controller is in Rust (1.11 Nightly)

    type Maze = Vec<Vec<char>>;

fn str_to_maze(input: &str) -> Result<Maze,i32> {
    let mut maze: Vec<Vec<char>> = vec![ vec![] ];
    let mut row: Vec<char> = vec![];

    for c in input.chars() {
        if c == '!' || c == '+' || c == 'O'  || c == ' ' {
            row.push(c);
        }
        else if c =='.' {
            row.push(' ');
        }
        else if c == '#' {
            maze.push(row);
            row = vec![];
        }
        else if c =='\0' {
            break;
        }
        else {
            println!("Bad character in maze: {}, exiting.", c);
            return Err(1);
        }
    }
    return Ok(maze);
}

fn display_maze(maze: &Maze, position: [usize;2]) {
    for y in 0..maze.len() {
        for x in 0..maze[y].len() {
            if [x,y] == position {
                print!("O");
            }
            else if maze[y][x] == '#' {
                println!("\n");
            }
            else {
                print!("{}",maze[y][x]);
            }
        }
        println!("");
    }
    println!("\n");
}

fn get_starting_position(maze: &mut Maze) -> Result<[usize;2],&str> {
    for y in 0..maze.len() {
        for x in 0..maze[y].len() {
            if maze[y][x] == 'O' {
                maze[y][x] = ' ';
                return Ok([x,y]);
            }
        }
    }
    return Err("No mouse found");
}

enum State {
    Continue([char;4]),
    Win,
    Disqualify,
}

fn output(maze: &Maze, position: [usize;2]) -> State {
    let x = position[0];
    let y = position[1];
    if maze[y][x] == '+' {
        return State::Win;
    }
    else if maze[y][x] == '!' {
        return State::Disqualify;
    }

    let n = maze[y-1][x];

    assert!(y+1<maze.len());
    let s = maze[y+1][x];

    let w = maze[y][x-1];

    assert!(x+1<maze[y].len());
    let e = maze[y][x+1];

    return State::Continue([n,e,s,w]);
}

fn get_input() -> char {
    use std::io;
    use std::io::Read;
    let mut buffer: [u8;2] = [0;2];
    io::stdin().read_exact(&mut buffer).unwrap();
    //println!("{:?}", buffer); // to see exactly what the input is
    return buffer[0] as char;
}

fn next_position(current_position: [usize;2], direction: char) -> Result<[usize;2],char> {
    let mut x = current_position[0];
    let mut y = current_position[1];
    if direction == 'n' {
        y -= 1;
    }
    else if direction == 'e' {
        x += 1;
    }
    else if direction == 's' {
        y += 1;
    }
    else if direction == 'w' {
        x -= 1;
    }
    else {
        return Err(direction);
    }
    return Ok([x,y]);
}

fn play(maze: &mut Maze) -> (State, usize) {
    let mut position: [usize;2];
    match get_starting_position(maze) {
        Ok(pos) => position = pos,
        Err(s) => {
            println!("{}",s);
            std::process::exit(2);
        }
    }

    let mut moves = 0;

    loop {

        let state = output(maze, position);

        /* uncomment below to view the maze at each step  */
        //display_maze(&maze, position);
        /* ----------------------------------------------*/

        match state {
            State::Win => {
                //println!("You found the cheese");
                return(State::Win, moves);
            }
            State::Disqualify => {
                //println!("You were disqualified");
                return(State::Disqualify, moves);
            }
            State::Continue(out) => {
                println!("{}{}{}{}",out[0],out[1],out[2],out[3]);
            }
        }
        // only get here with Continue
        let input = get_input();
        moves += 1;
        match next_position(position, input) {
            Err(c) => {
                println!("Invalid input: {}", c as u8);
                return (State::Disqualify, moves);
            }
            Ok(next_pos) => position = next_pos,
        }
    }
}

fn main() {

    let mut arg_counter = 0;
    for argument in std::env::args() {
        if arg_counter != 0 {

            let mut maze = match argument.as_str(){
                "1" => maze_1(),
                "2" => maze_2(),
                "3" => maze_3(),
                "4" => maze_4(),
                "5" => maze_5(),
                "6" => maze_6(),
                _ => {
                    println!("invalid input: {}, breaking", argument);
                    break;
                }

            };

            let game_result = play(&mut maze);

            println!("0000");
            match game_result.0 {
                State::Win => println!("WIN"),
                State::Disqualify => println!("DISQUALIFY"),
                _ => println!("Error"),
            }
            println!("moves: {}", game_result.1 );
        }
        arg_counter += 1;
    }

}

fn maze_1() -> Maze {
    let maze_str = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    !O !                    !      !#\
                    !. ! !!!!!!!!!!!!!!!!!! ! !!!!!!#\
                    !. !                    ! !    !#\
                    !. ! !!!!!!!!!!!!!!!!!!!! ! !! !#\
                    !. !...........           ! !!.+#\
                    !. !.!!!!!!!!!.!!!!!!!!!!!!!!!.!#\
                    !.!..!        ...............!.!#\
                    !.!.!! !!!!!!!!!!!!!!!!!!!!!.!.!#\
                    !.!.!! !!!  !               .!.!#\
                    !.!.!! !!!  !!!!!!!!!!!!!!!!.!.!#\
                    !...!! !!!                  .!.!#\
                    ! ! !! !!!                  .!.!#\
                    ! ! !! !!!  !!!!!!!!! !!!!!!.!.!#\
                    ! ! !! !!!  !      !! !     .!.!#\
                    ! ! !! !!!  ! !!!!!!! !     .!.!#\
                    ! ! !! !!!  !      !! !     .!.!#\
                    ! ! !! !!!  !      !! !     .!.!#\
                    ! ! !!   !  !      !! !     .!.!#\
                    ! ! !! ! !  !!!!!! !! !     .!.!#\
                    ! ! !! ! !  !      !! !     ...!#\
                    ! ! !! ! !  !      !! !        !#\
                    ! ! !! ! !  !      !! !      ! !#\
                    ! ! !! ! !  !  !!!!!! !      ! !#\
                    ! ! !! ! !  !      !! !      ! !#\
                    ! !    !    !      !! !      ! !#\
                    ! !!!!!!  !!!!!!!! !! !      ! !#\
                    !                ! !! !      ! !#\
                    ! !!!!!!!!!!! !!!! !! !      ! !#\
                    !                     !      ! !#\
                    ! !!!!!!!! !!!!       !        !#\
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    ";

    match str_to_maze(&maze_str) {
        Ok(x) => return x,
        Err(i) => std::process::exit(i),
    }
}

fn maze_2() -> Maze {
    let maze_str = "!!!!!!!!!!!!!!!#\
                    !      .......!#\
                    ! !!! !.!!!! .!#\
                    !   ! !.!!O!!.!#\
                    !!!   !....! .!#\
                    !   !!!!!!!!!.!#\
                    ! !!        ..!#\
                    !  !!!!!!!!!.!!#\
                    !           ..+#\
                    !!!!!!!!!!!!!!!#\
                    ";

    match str_to_maze(&maze_str) {
        Ok(x) => return x,
        Err(i) => std::process::exit(i),
    }
}

fn maze_3() -> Maze {
    let maze_str = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    !                            !!!#\
                    ! !  !!!  !!!!!!!!!!!!!!!!!!   !#\
                    ! !  ! !!!              !!!  ! !#\
                    ! !  ! !!!!!!!!!!!!!!!!     !! !#\
                    ! !  !                  !!!!   !#\
                    ! !! !!!!!!!!!!        !!    ! !#\
                    !  ! !        !!!! !!!!!   !!! !#\
                    !! ! ! !!!!      !         !   !#\
                    !! ! ! !!!!   !!!!!!!!!!!!!! ! !#\
                    !! ! ! !!!! ! !              ! !#\
                    !! ! ! !!!! ! ! !!!!       ! ! !#\
                    !! ! ! !!!! ! ! !   !!!    ! ! !#\
                    !  ! ! !!!! ! ! !     !!!  ! ! !#\
                    !  ! ! !!!! ! ! !!!!!      !   !#\
                    !  ! ! !!!! !!! !   !!     ! !!!#\
                    !  ! !  !!!  !! !    !!!   ! !!!#\
                    !  ! !     ! !! !!!!   !!  ! !!!#\
                    !  ! !!    ! !! !  !!      ! !!!#\
                    !  !  !   !! !!     !!!    ! !!!#\
                    !  !! !!!!     !!!    !!   !   !#\
                    !!  ! !! !       !!!   !!  !!! !#\
                    !!  !    !    !    !           !#\
                    !!  !!!!!!    !!   !!!!!!!!!!! !#\
                    !             !!!! !!!!!!!!!!! !#\
                    !  ..........O!!!! !!!!!!!!!!!.+#\
                    !! .!!!!!!    !!   !!!!!!!!!!!.!#\
                    !! .!    !    !    !          .!#\
                    !!..! !! !       !!!   !!  !!!.!#\
                    ! .!! !!!!     !!!    !!   !...!#\
                    ! .!  !   !! !!     !!!    !.!!!#\
                    ! .! !!    ! !! !  !!      !.!!!#\
                    ! .! !     ! !! !!!!   !!  !.!!!#\
                    ! .! !  !!!  !! !    !!!   !.!!!#\
                    ! .! ! !!!! !!! !   !!     !.!!!#\
                    ! .! ! !!!! ! ! !!!!!      !...!#\
                    ! .! ! !!!! ! ! !     !!!  ! !.!#\
                    !!.! ! !!!! ! ! !   !!!    ! !.!#\
                    !!.! ! !!!! ! ! !!!!       ! !.!#\
                    !!.! ! !!!! ! !              !.!#\
                    !!.! ! !!!!   !!!!!!!!!!!!!! !.!#\
                    !!.! ! !!!!      !         !  .!#\
                    !..! !        !!!! !!!!!   !!!.!#\
                    !.!! !!!!!!!!!!        !!    !.!#\
                    !.!  !                  !!!!  .!#\
                    !.!  ! !!!!!!!!!!!!!!!!     !!.!#\
                    !.!  ! !!!              !!!  !.!#\
                    !.!  !!!  !!!!!!!!!!!!!!!!!!...!#\
                    !............................!!!#\
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    ";

    match str_to_maze(&maze_str) {
        Ok(x) => return x,
        Err(i) => std::process::exit(i),
    }
}

fn maze_4() -> Maze {
    let maze_str = "!!!!!!!!!!!!!!!!!+!!!!!!!!!!!!!!#\
                    !.................           !!!#\
                    !.!  !!!  !!!!!!!!!!!!!!!!!!   !#\
                    !.!  ! !!!              !!!  ! !#\
                    !.!  ! !!!!!!!!!!!!!!!!     !! !#\
                    !.!  !                  !!!!   !#\
                    !.!! !!!!!!!!!!        !!    ! !#\
                    !..! !        !!!! !!!!!   !!! !#\
                    !!.! ! !!!!      !         !   !#\
                    !!.! ! !!!!   !!!!!!!!!!!!!! ! !#\
                    !!.! ! !!!! ! !              ! !#\
                    !!.! ! !!!! ! ! !!!!       ! ! !#\
                    !!.! ! !!!! ! ! !   !!!    ! ! !#\
                    ! .! ! !!!! ! ! !     !!!  ! ! !#\
                    ! .! ! !!!! ! ! !!!!!      !   !#\
                    ! .! ! !!!! !!! !   !!     ! !!!#\
                    ! .! !  !!!  !! !    !!!   ! !!!#\
                    ! .! !     ! !! !!!!   !!  ! !!!#\
                    ! .! !!    ! !! !  !!      ! !!!#\
                    ! .!  !   !! !!     !!!    ! !!!#\
                    ! .!! !!!!     !!!    !!   !   !#\
                    !!. ! !! !       !!!   !!  !!! !#\
                    !!. !    !    !    !           !#\
                    !!. !!!!!!    !!   !!!!!!!!!!! !#\
                    ! ........... !!!! !!!!!!!!!!! !#\
                    !           . !!!! !!!!!!!!!!! !#\
                    !!  !!!!!!  . !!   !!!!!!!!!!! !#\
                    !!  !    !  . !    !           !#\
                    !!  ! !! !  .    !!!   !!  !!! !#\
                    !  !! !!!!  .  !!!    !!   !   !#\
                    !  !  !   !!.!!     !!!    ! !!!#\
                    !  ! !!    !.!! !  !!      ! !!!#\
                    !  ! !     !.!! !!!!   !!  ! !!!#\
                    !  ! !  !!!..!! !    !!!   ! !!!#\
                    !  ! ! !!!!.!!! !   !!     ! !!!#\
                    !  ! ! !!!!.! ! !!!!!      !   !#\
                    !  ! ! !!!!.! ! !     !!!  ! ! !#\
                    !! ! ! !!!!.! ! !   !!!    ! ! !#\
                    !! ! ! !!!!.! ! !!!!       ! ! !#\
                    !! ! ! !!!!.! !              ! !#\
                    !! ! ! !!!!.  !!!!!!!!!!!!!! ! !#\
                    !! ! ! !!!!.....O!         !   !#\
                    !  ! !        !!!! !!!!!   !!! !#\
                    ! !! !!!!!!!!!!        !!    ! !#\
                    ! !  !                  !!!!   !#\
                    ! !  ! !!!!!!!!!!!!!!!!     !! !#\
                    ! !  ! !!!              !!!  ! !#\
                    ! !  !!!  !!!!!!!!!!!!!!!!!!   !#\
                    !                            !!!#\
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    ";

    match str_to_maze(&maze_str) {
        Ok(x) => return x,
        Err(i) => std::process::exit(i),
    }
}

fn maze_5() -> Maze {
    let maze_str = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    +......!!!!       !!!        !!!       !!!!     !!#\
                    !     .!       !!                            !!!!!#\
                    !  !!!.! !!      !!!  !!!!  !!!!!!!!!      !!!   !#\
                    ! !!...!   !!!!!   !!    !          !!    !!     !#\
                    !!!..!!         !    !!  !           !    !     !!#\
                    !! .!!........        !! !!!     !    !   !  !  !!#\
                    !!!. !.  !  !.   !      !!!!!    !!   !   ! !! !!!#\
                    !!!. !.  !  !.   !       !!!!!    !   !!    !  !!!#\
                    !!.. !.  !  !..  !        !  !    !!   !    !   !!#\
                    !!.! !.!  ! ! ..  ! !!!!!!  !      !   !    !   !!#\
                    !!.! !.!  ! !! .  ! !      !        !  !    !   !!#\
                    !!.! !.!  !  ! .  ! !!   !!    !!!! !  !    !   !!#\
                    !!.! !.!! !  ! .  !  !!!   !!!!     !  !    !!  !!#\
                    !!.! !. ! !  ! .  !    !!        !  !   !    !  !!#\
                    ! .!!!. ! !  !!.   !    !        !  !   !    !   !#\
                    ! .!!!. ! !   !.   !     !       !   !  !    !   !#\
                    ! .! !. ! !   !.   !     !       !   !   !   !   !#\
                    ! .! !. ! !!  !....!!!   !      !!   !     ! !   !#\
                    ! .!  ..!  !  !   ...!!!!       !    !     ! ! ! !#\
                    ! .!   .!  !  !!!!!!.... !!!!!!!             ! ! !#\
                    ! .! !!.!  !! !  !!!!  .!                        !#\
                    ! .!!!!.!   !!!! !!!   .!   !!!!!   !!!!!!!!!!!  !#\
                    ! .. !!.!    !!!  !!  !.!!                       !#\
                    !!!.. !. !   !!!      !..!        !!!   !   !    !#\
                    !!! .... !  !!!!      ! .!        !             !!#\
                    !!!!!!!!!!!!!!!!!!!!!!! .! !!!!!!!!!!!!!!!!!!!! !!#\
                    !!!  !                  .!                     !!!#\
                    !!   !   !!!  !!        .!                      !!#\
                    !!   !  !     !!  !!!!!!.!  !!!!!!              !!#\
                    !!   !  !    !!   !!!!!!.! !!!!!!!!          !  !!#\
                    !!  !   !   !!   !!!!!!!.! !!!!!! !!   !  !     !!#\
                    !!  !   !   !   !!!!!!!!.! !!!  !  !   !        !!#\
                    !!  !   !   !  !!!!!!!!!.! !!!! !   !  !  !  !  !!#\
                    !!  !   !   !           .!  !!  !   !  !     !  !!#\
                    !! !!!  !   !   !!!!!!  .!      !    !!         !!#\
                    !! ! !   !  !   !     !!. !    !!!    !    !    !!#\
                    !! ! !   !  !   ! !     .  !   ! !!    !     !  !!#\
                    !! ! !   !  !   ! !!  !!.   !!!   !!   !   ! !  !!#\
                    !! ! !   !  !!  ! !!! ! .....     !!   !      ! !!#\
                    !! ! !   !   !  ! !!!!!!!   .     !    !        !!#\
                    !  ! !   !   !  !  !!!  !   .!!!!     !  !       !#\
                    !  ! !   !   !! !       !   .!      !!.......... !#\
                    ! !! !   !    !  !!!!!!!!!  .!    !!  .!   !!!!. !#\
                    ! !  !   !    !!       !!!  .!!!!!   ..   !    . !#\
                    ! !  !    !!   !!!     !!!  .......... !!!!    . !#\
                    ! !  !     !!     !!!!      !!!!!!!!!!!!      !. !#\
                    ! !         !         !!!!!!                  O. !#\
                    !           !                                    !#\
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    ";

    match str_to_maze(&maze_str) {
        Ok(x) => return x,
        Err(i) => std::process::exit(i),
    }
}

fn maze_6() -> Maze {
    let maze_str = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    !      !!!!   ....!!!        !!!       !!!!     !!#\
                    !      !      .!!..........                  !!!!!#\
                    !  !!! ! !!   ...!!!  !!!!. !!!!!!!!!      !!!   !#\
                    ! !!   !   !!!!!.. !!    !.         !!    !!     !#\
                    !!!  !!         !.   !!  !.....      !    !     !!#\
                    !!  !!          ..    !! !!!  .  !    !   !  !  !!#\
                    !!!  !   !  !   .!      !!!!! .  !!   !   ! !! !!!#\
                    !!!  !   !  !   .!       !!!!!.   !   !!    !  !!!#\
                    !!   !   !  !   .!        !  !.   !!   !    !   !!#\
                    !! ! ! !  ! !   . ! !!!!!!  ! ..   !   !    !   !!#\
                    !! ! ! !  ! !!  . ! !      !   .....!  !    !   !!#\
                    !! ! ! !  !  !  . ! !!   !!    !!!!.!  !    !   !!#\
                    !! ! ! !! !  !  ..!  !!!   !!!!    .!  !    !!  !!#\
                    !! ! !  ! !  !   .!    !!        ! .!   !    !  !!#\
                    !  !!!  ! !  !!  . !    !        ! .!   !    !   !#\
                    !  !!!  ! !   !  ..!     !       ! . !  !    !   !#\
                    !  ! !  ! !   !   .!     !       ! . !   !   !   !#\
                    !  ! !  ! !!  !   .!!!   !      !! . !     ! !   !#\
                    !  !    !  !  !   ...!!!!       !  . !     ! ! ! !#\
                    !  !    !  !  !!!!!!.... !!!!!!!   .         ! ! !#\
                    !  ! !! !  !! !  !!!!  .!          .             !#\
                    !  !!!! !   !!!! !!!   .!   !!!!!  .!!!!!!!!!!!  !#\
                    !    !! !    !!!  !!  !.!!..........             !#\
                    !!!   !  !   !!!      !. !.       !!!   !   !    !#\
                    !!!      !  !!!!      !. !.       !             !!#\
                    !!!!!!!!!!!!!!!!!!!!!!!. !.!!!!!!!!!!!!!!!!!!!! !!#\
                    !!!  !                 . !.....................!!!#\
                    !!   !   !!!  !!  O..... !                    ..!!#\
                    !!   !  !     !!  !!!!!! !  !!!!!!             .!!#\
                    !!   !  !    !!   !!!!!! ! !!!!!!!!          ! .!!#\
                    !!  !   !   !!   !!!!!!! ! !!!!!! !!   !  !    .!!#\
                    !!  !   !   !   !!!!!!!! ! !!!  !  !   !       .!!#\
                    !!  !   !   !  !!!!!!!!! ! !!!! !   !  !  !  ! .!!#\
                    !!  !   !   !            !  !!  !   !  !     ! .!!#\
                    !! !!!  !   !   !!!!!!   !      !    !!        .!!#\
                    !! ! !   !  !   !     !!  !    !!!    !    !   .!!#\
                    !! ! !   !  !   ! !        !   ! !!    !     ! .!!#\
                    !! ! !   !  !   ! !!  !!    !!!   !!   !   ! ! .!!#\
                    !! ! !   !  !!  ! !!! !           !!   !      !.!!#\
                    !! ! !   !   !  ! !!!!!!!         !    !       .!!#\
                    !  ! !   !   !  !  !!!  !    !!!!     !  !     . !#\
                    !  ! !   !   !! !       !    !      !!         . !#\
                    ! !! !   !    !  !!!!!!!!!   !    !!   !   !!!!. !#\
                    ! !  !   !    !!       !!!   !!!!!        !    . !#\
                    ! !  !    !!   !!!     !!!   !         !!!!    . !#\
                    ! !  !     !!     !!!!      !!!!!!!!!!!!      !..+#\
                    ! !         !         !!!!!!                     !#\
                    !           !              !                     !#\
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#\
                    ";

    match str_to_maze(&maze_str) {
        Ok(x) => return x,
        Err(i) => std::process::exit(i),
    }
}
```

<p>To test the larger maze, simply replace the maze string in the <code>maze_1</code> function. Make sure to append the correct <code>#\</code> characters to each line. </p>

<p><strong>Testing your entry</strong></p>

<p>This script can be used to test entries</p>

<pre class="lang-bash prettyprint-override"><code>#!/bin/bash

mkfifo /tmp/pipe1
mkfifo /tmp/pipe2

for arg in "$@"; do
    <path to controller> $arg < /tmp/pipe1 | tee /tmp/pipe2 trascript.txt &
    ( <path to entry> < /tmp/pipe2 | tee /tmp/pipe1 ) > /dev/null
done

rm /tmp/pipe1
rm /tmp/pipe2
</code>```

For example, my script looks like:

#!/bin/bash

mkfifo /tmp/pipe1
mkfifo /tmp/pipe2

for arg in "$@"; do
    ./maze/target/release/maze $arg < /tmp/pipe1 | tee /tmp/pipe2 trascript.txt &
    ( ./maze_test/main < /tmp/pipe2 | tee /tmp/pipe1 ) > /dev/null
done

rm /tmp/pipe1
rm /tmp/pipe2
```

<p>It is used in the following way:</p>

```./script <mazes to test>
```

<p>For example </p>

```./script 1 2 3 4 5 6
```

<p>It will print everything to the console as well as writing everything to a file called <code>transcript.txt</code></p>

<p>For the purpose of developing your entry, you can uncomment the </p>

```display_maze(&maze, position)
```

line in the play function. This will cause the controller to display the maze at each step.


问:
Rube Goldberg Hello World
For this golf, you will need to use more than one language.

The task

A Rube Goldberg machine is a contraption that takes an enormous number of complicated steps in order to execute a very simple task. The goal of this golf is to output Rube Goldberg... but not directly.

The machine

Your "machine" is the source code that, once executed, will give another source code in another language that will output Rube Goldberg upon execution. Got it?

I rephrase: your initial code must give another code, that other code must output Rube Goldberg. Both codes must be written in different languages.

The bonus which is more like the only fun way to do it

There is a bonus if your code outputs a code that will output a code that will ... that will output Rube Goldberg.

NOTE: any sort of output can be used (stdout, stderr, dialog box, ...)

The points

The number of points is equal to the number of bytes used in your code, divided by the number of distinct, extra languages that you used.

NOTE: different languages use different encodings. The number of bytes is counted in the initial language with its own encoding.

Examples

Pyth -> J -> Javascript -> output in 30 bytes = 30/2 = 15 points (J and Javascript are the extra languages)

Java -> C# -> C++ -> PHP -> output in 36 bytes = 36/3 = 12 points (More bytes and more languages can win over fewer bytes and fewer languages (I know there is no way that these languages do it in 36 bytes))

C -> output in 10 bytes = 10/0 = Infinity points (No extra languages)

Python -> Perl -> Ruby -> Python -> Ruby in 44 bytes = 44/2 = 22 points (Perl and Ruby are the extra languages, the second Python is not counted as it is not an extra language, the second Ruby is not counted as it has already been used)

NOTE: Languages that output their input can't be used. That would be an extra language with absolutely no additional bytes.

The answer

Please provide an answer that clearly states which languages you used and shows us the code at each step (i.e.: in each language).

The winner

Of course, like usual, the lowest score wins.

NOTE: As usual, standard loopholes and "cheats" are not allowed.

答:
Foo → gs2 → M → Jelly → Retina → Aeolbonn → Par → Actually → Sprects → sed → Universal Lambda → Lines → /// → m4: 19/13 ≈ 1.4615 points

```<code>"“GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
</code>```

All answers are given in the Jelly code page. ¶ represents a newline.

Mechanism

```<code>  Language      Code
 ——————————————————————————————————————
  Foo           "“GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
  gs2           “GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
  M             “GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ
  Jelly         “¶:`".c Rube Goldberg#\/”
  Retina        ¶:`".c Rube Goldberg#\/
  Aeolbonn      :`".c Rube Goldberg#\/
  Par           `".c Rube Goldberg#\/
  Actually      ".c Rube Goldberg#\/
  Sprects       .c Rube Goldberg#\/
  sed           c Rube Goldberg#\/
  U.Lambda       Rube Goldberg#\/
  Lines         Rube Goldberg#\/
  ///           Rube Goldberg#/
  m4            Rube Goldberg#
</code>```

EDIT: Oops, there was an error in the Pyth program. I replaced Pyth and GolfScript by Par.

EDIT 2: Added GNU m4.

EDIT 3: Added Foo and M.

ContentLicense: CC BY-SA 4.0

Title: Rube Goldberg Hello World

Body:
Foo → gs2 → M → Jelly → Retina → Aeolbonn → Par → Actually → Sprects → sed → Universal Lambda → Lines → /// → m4: 19/13 ≈ 1.4615 points

"“GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦

All answers are given in the Jelly code page. ¶ represents a newline.

Mechanism

  Language      Code
 ——————————————————————————————————————
  Foo           "“GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
  gs2           “GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
  M             “GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ
  Jelly         “¶:`".c Rube Goldberg#\/”
  Retina        ¶:`".c Rube Goldberg#\/
  Aeolbonn      :`".c Rube Goldberg#\/
  Par           `".c Rube Goldberg#\/
  Actually      ".c Rube Goldberg#\/
  Sprects       .c Rube Goldberg#\/
  sed           c Rube Goldberg#\/
  U.Lambda       Rube Goldberg#\/
  Lines         Rube Goldberg#\/
  ///           Rube Goldberg#/
  m4            Rube Goldberg#

EDIT: Oops, there was an error in the Pyth program. I replaced Pyth and GolfScript by Par.

EDIT 2: Added GNU m4.

EDIT 3: Added Foo and M.

ContentLicense: CC BY-SA 3.0


答:
Ruby, 61 bytes

```<code>def f(n);a=[n];n.times{a=a.map{|i|(1..i).to_a}.flatten};a;end
</code>```

Title: Count Up, Replace, Repeat!

Body:
Definition

Define the nth array of the CURR sequence as follows.

Begin with the singleton array A = [n].

For each integer k in A, replace the entry k with k natural numbers, counting up from 1 to k.

Repeat the previous step n - 1 more times.

For example, if n = 3, we start with the array [3].

We replace 3 with 1, 2, 3, yielding [1, 2, 3].

We now replace 1, 2, and 3 with 1; 1, 2 and 1, 2, 3 (resp.), yielding [1, 1, 2, 1, 2, 3].

Finally, we perform the same replacements as in the previous step for all six integers in the array, yielding [1, 1, 1, 2, 1, 1, 2, 1, 2, 3]. This is the third CURR array.

Task

Write a program of a function that, given a strictly positive integer n as input, computes the nth CURR array.

The output has to be a flat list of some kind (and array returned from a function, a string representation of your language's array syntax, whitespace-separated, etc.).

This is code-golf. May the shortest code in bytes win!

Test cases

```<code> 1 -> [1]
 2 -> [1, 1, 2]
 3 -> [1, 1, 1, 2, 1, 1, 2, 1, 2, 3]
 4 -> [1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4]
 5 -> [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]
 6 -> [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]
</code>```

Body:
Ruby, 61 bytes

def f(n);a=[n];n.times{a=a.map{|i|(1..i).to_a}.flatten};a;end


问:
Convert YYYYMM to MMMYY
Basing on this SO question.

Challenge is rather simple: given a date period in the format YYYYMM output it in the format MMMYY.

Rules:

The input will be a number or a string exactly 6 characters long, consisting only of digits.

Last two digits will be between 01 and 12.

Output must be in the form MMMYY, where MMM represents uppercase three-letter code for the month (below) and YY represents two last digits of the YYYY part of the input.

List of months with corresponding code:

```<code>MM    MMM
01    JAN
02    FEB
03    MAR
04    APR
05    MAY
06    JUN
07    JUL
08    AUG
09    SEP
10    OCT
11    NOV
12    DEC
</code>```

Examples:

```<code>Input     Output
201604    APR16
200001    JAN00
000112    DEC01
123405    MAY34
</code>```

答:
C, <s>147</s> <s>145</s> 112 bytes

main(m){char a[99]="JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";scanf("%4s%d",a+50,&m);printf("%.3s%s",a+--m*3,a+52);}
```

Online demo

Thanks ugoren!

Title: Convert YYYYMM to MMMYY

Body:
C, <s>147</s> <s>145</s> 112 bytes

main(m){char a[99]="JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";scanf("%4s%d",a+50,&m);printf("%.3s%s",a+--m*3,a+52);}

Online demo

Thanks ugoren!


问:
Generate a valid sequence of numbers with specific rules

The challenge

The program must return a valid sequence of numbers into some rules

Rules

x is the size of the sequence;

x cannot be less than 4 or greater than 9 (Thanks David Carraher);

Digits of the sentence can't repeat, each one must appear once;

All digits between 1 to x must be in the sequence;

A valid sequence never begins nor ends with 1 or x;

Into the sequence, numbers can never appear "together";

Examples

If x=4:

2413 valid

3142 valid

1423 not valid, because begins with 1 and 23 are "together".

2134 not valid, because ends with x and 34 are "together".

Still don't get it?
Other example:

If x=8:

28375146 valid, because don't start with 1 nor x(8), don't end with 1 nor x, and no numbers are "together"(no numbers touches, no numbers are the next or previous)

Sorry, I really don't know how to explain the last rule. Hope the example make it understandable.

Additional Information

x does not need to be an input, you can show the outputs for x=4 and x=9 working;

Since any language will be accepted and, I don't know how all of them work, I will ask you people to help me with this;

The winner will be the one who got more up-votes in 1 week, so please, vote the answer you find the best; I will mark it as the Correct one;

Good, luck. =)

答:
PHP, 64

If I understand the rules correctly, this should work:

for($i=1;$i<=$x;$i++)echo($x%2?2*$i%$x+1:2*$i-($x+1)*($i>$x/2));

If x is odd, this simply cycles through multiples of 2 % x + 1 to produce sequences like 357924681. If x is even, this does the same, but halfway through subtracts 1+x because 2i%x+1 would otherwise never produce even values.


问:
Decode a Microsoft MS-DOS 5.0 FAT directory entry
The Microsoft FAT file system has a directory table to represent which "files" are in which "folders" on the disk. For the time, these entries crammed a lot of information into a small amount of bits. There are a bunch of technical specifications over on Wiki for the curious, but the challenge here is going to focus on a "simple" decoding of an entry.

Each entry consists of a 32-byte binary word, broken up into several sections. For consistency in this challenge, we'll be using the MS-DOS 5.0 version, the bytes are ordered as big endian, and we're calling byte 0x00 as the left-most, and byte 0x1F as the right-most.

Below is a brief schematic of the relevant sections, and what should be the output for each section (in bold).

The first 11 bytes are the file name in ASCII format (this is where the famous 8.3 filename comes from -- 8 bytes for the file name, 3 bytes for the extension). These are straight ASCII encoding, and should be output as ASCII with a period (.) between.

Note: both the 8 and the 3 parts are padded with spaces to make a full-length entry. The output should ignore spaces (i.e., don't output them).

The file extension may be empty (i.e., all spaces), in which case the output should not output the dot.

Since ASCII only uses the lower 7 bits, the bytes will all have a leading 0.

The next byte (0x0b) is a bitmask of the following:

0x01 Read Only - output RO

0x02 Hidden - output H

0x04 System - output S

0x08 Volume Label - output VL. File size (below) should be output as 0, regardless of its actual entry.

0x10 Subdirectory - output SD. File size (below) should be output as 0, regardless of its actual entry.

0x20 Archive - output A

0x40 Device - ignored for this challenge.

0x80 Reserved - ignored for this challenge.

Since this is a bitmask, multiple flags are possible - all applicable outputs should be concatenated together in any order. For example, 0xff could be ROHSVLSDA (or any other combination).

The next two bytes (0x0c and 0x0d) are not used under MS-DOS 5.0.

The next two bytes (0x0e and 0x0f) are the creation time as follows:

Bits 15 to 11 are the hours in 24-hour format - output 00 to 23

Bits 10 to 5 are the minutes - output 00 to 59

Bits 4 to 0 are the seconds/2 - output 00 to 58 (note that seconds are only in two-second resolution)

For clarification: hhhhhmmmmmmsssss when written big-endian.

The next two bytes (0x10 and 0x11) are the creation date as follows:

Bits 15 to 9 are the year - output 1980 for 0 up to 2107 for 127

Bits 8 to 5 are the months - output 1 to 12 (with or without leading zero)

Bits 4 to 0 are the day - output 0 to 31 (with or without leading zero)

For clarification: yyyyyyymmmmddddd when written big-endian.

The next two bytes (0x12 and 0x13) are the last access date. While used in MS-DOS 5.0, we're ignoring this portion for this challenge.

The next two bytes (0x14 and 0x15) are not used by MS-DOS 5.0.

The next two bytes (0x16 and 0x17) are the last modified time, following the same format as the creation time, above.

The next two bytes (0x18 and 0x19) are the last modified date, following the same format as the creation date, above.

The next two bytes (0x1a and 0x1b) are the cluster location of the file on disk. We're ignoring this portion for this challenge.

The final four bytes (0x1c, 0x1d, 0x1e, and 0x1f) are the file size - output as an unsigned integer, unless the VL or SD flags are set (above), in which case output 0.

Visual representation

```<code>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
\______________________________FILENAME________________________________________________/\_ATTR_/\___NOTUSED____/\_CREATIONTIME_/\_CREATIONDATE_/\__LASTACCESS__/\___NOTUSED____/\_MODIFIEDTIME_/\_MODIFIEDDATE_/\___NOTUSED____/\___________FILESIZE___________/
</code>```

Input

A single 32-byte word (i.e., 256 bits), in whatever format is convenient.

This could be as a string of 1 and 0, as several unsigned ints, an array of Boolean values, etc.

Please specify in your answer what format you're using for input.

You cannot take multiple input (i.e., an array pre-broken into the relevant byte sizes) unless that is the only way for your language to take input. Parsing the input is part of the challenge.

You can assume input to be valid (for example, you don't need to perform date checking to verify that the date is valid).

Bytes that are unused can be all 0, all 1, etc., just so long as they are present. In the below examples, I used all 0 for the unused bytes.

Output

Either printed to screen or returned, the following:

The filename as an ASCII string

The file attributes as an ASCII string

The creation time and creation date, with appropriate separators (colons, slashes, something to distinguish the components)

The modified time and modified date, again with appropriate separators

The file size

The output can be a space-separated or newline-separated single string, separate elements in an array, etc. Please specify in your answer how your output is formatted.

Rules

Standard I/O formats are acceptable.

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

This is code-golf, so all usual golfing rules apply, and the shortest code wins.

Built-ins that perform exactly this function are forbidden.

Examples

```<code>0111000001110010011011110110011101110010011000010110110101101101011010010110111001100111000001100000000000000000101000100100010001001000110101000000000000000000000000000000000010100010010001000100100011010100000000000000000000000000000000001101000000000000

programm.ing HS 20:18:08 2016/06/20 20:18:08 2016/06/20 53248

0010000000100000001000000010000001110000011100000110001101100111001000000010000000100000000101000000000000000000010111010110110000111101100111110000000000000000000000000000000010100010010001000100100011010100000000000000000011110000000100111111001011100001

ppcg SDS 11:43:24 2010/12/31 20:18:08 2016/06/20 0
</code>```

Body:
JavaScript (ES6), 369

(b,Z=n=>n>9?n:'0'+n,W=n=>s[n]<<8|s[n+1],U=n=>[Z((t=W(n))>>11)+`:${Z(t>>5&63)}:`+Z(t%32*2),((t=W(n+2))>>9)+1980+`/${t>>5&15}/`+t%32],X=l=>String.fromCharCode(...s.slice(p,p+=l)).trim(),s=b.match(/.{8}/g).map(x=>+('0b'+x)),p=0)=>[X(8)+((x=X(3))?'.'+x:x),[...b].map((b,i)=>'A,SD,VL,S,H,RO'.split`,`[z=(2*z|b)%4294967296,i*b-90]||'',z=0).join``,U(14),U(22),b[92]|b[91]?0:z]

Less golfed

(b,
  Z=n=>n>9?n:'0'+n, // zero pad
  W=n=>s[n]<<8|s[n+1], // get word
  U=n=>[
   Z((t=W(n))>>11)+`:${Z((t>>5&63)}:`+Z(t%32*2),  // decode time
   ((t=W(n+2))>>9)+1980+`/${t>>5&15}/`+t%32 // decode date
  ],
  X=l=>String.fromCharCode(...s.slice(p,p+=l)).trim(), // extract space padded string
  s=b.match(/.{8}/g).map(x=>+('0b'+x)), // convert bits to bytes
  p=0
)=>
  [ X(8)+((x=X(3))?'.'+x:x),
    [...b].map((b,i)=>'A,SD,VL,S,H,RO'.split`,`[i*b-90]||'').join``,
    [...b].slice(-32).map((b,i)=>z=2*z|b,z=0), // this line merged with the preceding one in the golfed code
    U(14),U(22),
    b[92]|b[91]?0:z
  ]

Test

f=(b,Z=n=>n>9?n:'0'+n,W=n=>s[n]<<8|s[n+1],U=n=>[Z((t=W(n))>>11)+`:${Z(t>>5&63)}:`+Z(t%32*2),((t=W(n+2))>>9)+1980+`/${t>>5&15}/`+t%32],X=l=>String.fromCharCode(...s.slice(p,p+=l)).trim(),s=b.match(/.{8}/g).map(x=>+('0b'+x)),p=0)=>[X(8)+((x=X(3))?'.'+x:x),[...b].map((b,i)=>'A,SD,VL,S,H,RO'.split`,`[z=(2*z|b)%4294967296,i*b-90]||'',z=0).join``,U(14),U(22),b[92]|b[91]?0:z]

O.textContent+='\n'+f('0111000001110010011011110110011101110010011000010110110101101101011010010110111001100111000001100000000000000000101000100100010001001000110101000000000000000000000000000000000010100010010001000100100011010100000000000000000000000000000000001101000000000000')
O.textContent+='\n'+f('0010000000100000001000000010000001110000011100000110001101100111001000000010000000100000000101000000000000000000010111010110110000111101100111110000000000000000000000000000000010100010010001000100100011010100000000000000000011110000000100111111001011100001')

<pre id=O></pre>


答:
Oracle SQL, 49 Bytes

```<code>select to_char(to_date(n,'yyyymm'),'MONyy')from t
</code>```

The data must be inserted in a table called T with a column N of type VARCHAR2(6), CHAR(6) or , only if all the years are > 1000,  NUMBER

Usage:

```<code>drop table t;
create table t (n VARCHAR2(6));
insert into t values ('201604');
insert into t values ('200001');
insert into t values ('000112');
insert into t values ('123405');

select to_char(to_date(n,'yyyymm'),'MONyy')from t;
</code>```

Title: Convert YYYYMM to MMMYY

Body:
Basing on this SO question.

Challenge is rather simple: given a date period in the format YYYYMM output it in the format MMMYY.

Rules:

The input will be a number or a string exactly 6 characters long, consisting only of digits.

Last two digits will be between 01 and 12.

Output must be in the form MMMYY, where MMM represents uppercase three-letter code for the month (below) and YY represents two last digits of the YYYY part of the input.

List of months with corresponding code:

```<code>MM    MMM
01    JAN
02    FEB
03    MAR
04    APR
05    MAY
06    JUN
07    JUL
08    AUG
09    SEP
10    OCT
11    NOV
12    DEC
</code>```

Examples:

```<code>Input     Output
201604    APR16
200001    JAN00
000112    DEC01
123405    MAY34
</code>```

Body:
Oracle SQL, 49 Bytes

select to_char(to_date(n,'yyyymm'),'MONyy')from t

The data must be inserted in a table called T with a column N of type VARCHAR2(6), CHAR(6) or , only if all the years are > 1000,  NUMBER

Usage:

drop table t;
create table t (n VARCHAR2(6));
insert into t values ('201604');
insert into t values ('200001');
insert into t values ('000112');
insert into t values ('123405');

select to_char(to_date(n,'yyyymm'),'MONyy')from t;


答:
Java 8, <s>154</s> 113 bytes

import java.text.*;s->new SimpleDateFormat("MMMyy").format(new SimpleDateFormat("yyyyMM").parse(s)).toUpperCase()
```
<p><strong>Explanation:</strong></p>
<p>Try it online.</p>
<pre class="lang-java prettyprint-override"><code>import java.text.*;                 // Required import for SimpleDateFormat
s->                                 // Method with String as both parameter and return-type
  new SimpleDateFormat("MMMyy")     //  Create a formatter with format "MMMyy"
   .format(                         //  Format the following:
     new SimpleDateFormat("yyyyMM") //   Create another formatter with format "yyyyMM"
     .parse(s))                     //   Parse the input with this format
  .toUpperCase()                    //  Convert everything to Uppercase and return
</code>```

Title: Convert YYYYMM to MMMYY

Body:
Java 8, <s>154</s> 113 bytes

import java.text.*;s->new SimpleDateFormat("MMMyy").format(new SimpleDateFormat("yyyyMM").parse(s)).toUpperCase()

Explanation:

Try it online.

import java.text.*;                 // Required import for SimpleDateFormat
s->                                 // Method with String as both parameter and return-type
  new SimpleDateFormat("MMMyy")     //  Create a formatter with format "MMMyy"
   .format(                         //  Format the following:
     new SimpleDateFormat("yyyyMM") //   Create another formatter with format "yyyyMM"
     .parse(s))                     //   Parse the input with this format
  .toUpperCase()                    //  Convert everything to Uppercase and return


问:
Calculate Euler's totient function

Background

Euler's totient
function φ(n) is defined as the number of whole numbers less than or equal to n that are relatively prime to n,
that is, the number of possible values of x in 0 < x <= n for which
gcd(n, x) == 1.
We've had
a
few totient-related challenges
before, but never one which is just calculating it.

The mapping of the totient function onto the whole numbers is OEIS A000010.

Challenge

Given an integer n > 0, calculate φ(n).
You may take input through
command-line arguments,
standard input,
function arguments,
or anything else reasonable.
You may give output through
standard output,
return values,
or anything else reasonable.
Anonymous functions are acceptable.
You may assume that the input will not overflow your natural method of storing integers, e.g. int in C, but you must support inputs up to 255.
If your language has a built-in totient function, you may not use it.

Examples

```<code>φ(1) => 1
φ(2) => 1
φ(3) => 2
φ(8) => 4
φ(9) => 6
φ(26) => 12
φ(44) => 20
φ(105) => 48
</code>```

Shortest answer in bytes wins. If your language uses an encoding other than UTF-8, mention it in your answer.

答:
Haskell, 28 bytes

f n=sum[1|1<-gcd n<$>[1..n]]
```
<p>Uses Haskell's pattern matching of constants. The tricks here are fairly standard for golfing, but I'll explain to a general audience.</p>
<p>The expression <code>gcd n<$>[1..n]</code> maps <code>gcd n</code> onto <code>[1..n]</code>. In other words, it computes the <code>gcd</code> with <code>n</code> of each number from <code>1</code> to <code>n</code>:</p>
```[gcd n i|i<-[1..n]]
```

From here, the desired output is the number of 1 entries, but Haskell lacks a count function. The idiomatic way to filter to keep only 1's, and take the resulting length, which is much is too long for golfing.

Instead, the filter is simulated by a list comprehension [1|1<-l] with the resulting list l. Usually, list comprehensions bind values onto variable like in [x*x|x<-l], but Haskell allows a pattern to be matched against, in this case the constant 1.

So, [1|1<-l] generating a 1 on each match of 1, effectively extracting just the 1's of the original list. Calling sum on it gives its length.

Title: Calculate Euler's totient function

Body:
Haskell, 28 bytes

f n=sum[1|1<-gcd n<$>[1..n]]

Uses Haskell's pattern matching of constants. The tricks here are fairly standard for golfing, but I'll explain to a general audience.

The expression gcd n<$>[1..n] maps gcd n onto [1..n]. In other words, it computes the gcd with n of each number from 1 to n:

[gcd n i|i<-[1..n]]

From here, the desired output is the number of 1 entries, but Haskell lacks a count function. The idiomatic way to filter to keep only 1's, and take the resulting length, which is much is too long for golfing.

Instead, the filter is simulated by a list comprehension [1|1<-l] with the resulting list l. Usually, list comprehensions bind values onto variable like in [x*x|x<-l], but Haskell allows a pattern to be matched against, in this case the constant 1.

So, [1|1<-l] generating a 1 on each match of 1, effectively extracting just the 1's of the original list. Calling sum on it gives its length.


答:
Retina, <s>71</s> 70 bytes

Thanks to Sp3000 for saving 1 byte.

Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.

```<code>(..)(..)$
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
+`...¶

R-6`.
</code>```

Try it online!

Explanation

Taking 201604 as an example:

```<code>(..)(..)$
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
</code>```

This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, and prepending the list of months in reverse so we'd get:

```<code>20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
</code>```

Where the ¶ represent linefeeds (0x0A).

```<code>+`...¶

</code>```

Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:

```<code>20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
20DECNOVOCTSEPAUGJULJUNMAYAPR16
</code>```

This is why we've inserted that XXX: since the months start counting from 1, we'll always remove at least three characters, even for January.

```<code>R-6`.
</code>```

Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.

Title: Convert YYYYMM to MMMYY

Body:
Retina, <s>71</s> 70 bytes

Thanks to Sp3000 for saving 1 byte.

Byte count assumes ISO 8859-1 encoding. The trailing linefeed is significant.

(..)(..)$
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1
+`...¶

R-6`.

Try it online!

Explanation

Taking 201604 as an example:

(..)(..)$
DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX$2$*¶$1

This swaps the last two digits of the year with the month while also expanding the month in unary using linefeeds, and prepending the list of months in reverse so we'd get:

20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16

Where the ¶ represent linefeeds (0x0A).

+`...¶

Now we repeatedly remove three non-linefeed characters followed by a linefeed. That is we eat up the list of months from the end for each linefeed representing a month:

20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJANXXX¶¶¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEBJAN¶¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMARFEB¶¶16
20DECNOVOCTSEPAUGJULJUNMAYAPRMAR¶16
20DECNOVOCTSEPAUGJULJUNMAYAPR16

This is why we've inserted that XXX: since the months start counting from 1, we'll always remove at least three characters, even for January.

R-6`.

Finally, we remove everything up to the 6th character from the end. In other words we only keep the last five characters.


答:
Python 2, 44 bytes

f=lambda n,d=1:d/n or-f(d)*(n%d<1)-~f(n,d+1)
```
<p>Less golfed:</p>
<pre class="lang-python prettyprint-override"><code>f=lambda n:n-sum(f(d)for d in range(1,n)if n%d<1)
</code>```

Uses the formula that the Euler totients of the divisors of n have a sum of n:

The value of ϕ(n) can then be recursively computed as n minus the sum over nontrivial divisors. Effectively, this is doing Möbius inversion on the identity function. I used the same method in a golf to compute the Möbius function.

Thanks to Dennis for saving 1 byte with a better base case, spreading the initial value of +n into +1 for each of the n loops, done as -~.

Title: Calculate Euler's totient function

Body:
Background

Euler's totient
function φ(n) is defined as the number of whole numbers less than or equal to n that are relatively prime to n,
that is, the number of possible values of x in 0 < x <= n for which
gcd(n, x) == 1.
We've had
a
few totient-related challenges
before, but never one which is just calculating it.

The mapping of the totient function onto the whole numbers is OEIS A000010.

Challenge

Given an integer n > 0, calculate φ(n).
You may take input through
command-line arguments,
standard input,
function arguments,
or anything else reasonable.
You may give output through
standard output,
return values,
or anything else reasonable.
Anonymous functions are acceptable.
You may assume that the input will not overflow your natural method of storing integers, e.g. int in C, but you must support inputs up to 255.
If your language has a built-in totient function, you may not use it.

Examples

```<code>φ(1) => 1
φ(2) => 1
φ(3) => 2
φ(8) => 4
φ(9) => 6
φ(26) => 12
φ(44) => 20
φ(105) => 48
</code>```

Shortest answer in bytes wins. If your language uses an encoding other than UTF-8, mention it in your answer.

Body:
Python 2, 44 bytes

f=lambda n,d=1:d/n or-f(d)*(n%d<1)-~f(n,d+1)

Less golfed:

f=lambda n:n-sum(f(d)for d in range(1,n)if n%d<1)

Uses the formula that the Euler totients of the divisors of n have a sum of n:

The value of ϕ(n) can then be recursively computed as n minus the sum over nontrivial divisors. Effectively, this is doing Möbius inversion on the identity function. I used the same method in a golf to compute the Möbius function.

Thanks to Dennis for saving 1 byte with a better base case, spreading the initial value of +n into +1 for each of the n loops, done as -~.


问:
Same length sub arrays

Background:

Here's a little simple challenge. You want to be able to find out whether the arrays inside an array have the same length.

Input:

Your input should consist of exactly one array (this is the value passed to the function, not a user input). Your function takes exactly 1 parameter.  It could contain arrays or be empty. No error checking needed, assume only list is ever passed in. Assume a 1-D array such as [1] or [1,2,3,4,5] is never passed in.

Output:

Return true if all the list elements have the same length, false if they don't, and the parameter itself if the list is empty (or null if your language doesn't support multiple return types).

Some test cases:

```<code>List: [] - [] (or null/your language equivalent)
List: [[1], [1], [2]] - True
List: [[1]] - True
List: [[1, 2, 3, 4]] - True
List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
List: [[1, 2, 3, 4], [1]] - False
</code>```

No std(in/out) input/output needed (however, it is allowed, just not required!), the function only needs to return boolean values true or false; or the parameter itself if the function is passed an empty list (or null/your language equivalent). Only one return value is returned.

Rules:

Shortest byte count wins, only function is necessary (full programs are allowed if you desire).

答:
APL, 13 bytes

```<code>1=(×∘⍴⍴≢)∪≢¨⎕
</code>```

In English:

compute the unique of the tallies of each of the subarrays;

reshape the result with the signum of its shape: if its an empty vector, it remains an empty vector;

is it equal to 1?

Title: Same length sub arrays

Body:
APL, 13 bytes

1=(×∘⍴⍴≢)∪≢¨⎕

In English:

compute the unique of the tallies of each of the subarrays;

reshape the result with the signum of its shape: if its an empty vector, it remains an empty vector;

is it equal to 1?


问:
Play scrabble with the periodic table
You've got a set of tiles with the symbols from the periodic table. Each symbol appears once. You're thinking up words to make but you want to know if it's possible or not.

The Challenge

Write a program in your favourite language that will take in a string as an input parameter. You may assume that input is not null, has no spaces and consists of ASCII characters.

Your program should take that string and output a truthy value if that word can made up of symbols from the periodic table of elements, and a falsey value if the word cannot.

To make this challenge more difficult, you may not use a symbol twice. So if you use Nitrogen N you may not use N again in the same word.

Rules

Standard loopholes are not allowed. You may use symbols from elements 1-118 (Hydrogen to Ununoctium). You can find a list of all the elements here. You may read the list of symbols in from a file or input arguments if you wish.

Test Cases:

```<code>Laos - true (LaOs)
Amputation - true (AmPuTaTiON)
Heinous - true (HeINoUS)
Hypothalamus - true (HYPoThAlAmUS)
Singapore - true (SiNGaPoRe)
Brainfuck - true (BRaInFUCK)
Candycane - false
</code>```

This is a code golf challenge, shortest code wins.

BEFORE YOU CLOSE AS DUPLICATE: While this may seem similar to this challenge, I feel it is different because it is not 'Generate a list of all words that are possible from the periodic table', it is 'Take in arbitrary input and determine if it can be made from the periodic table'

答:
JavaScript (Firefox 48 or earlier), 103 bytes

```<code>f=(w,e=`
H
He
... (list of elements not included in the byte count) ...
Uus
Uuo
`)=>!w||e.match(/\w+/g).some(s=>!w.search(s,`i`)&&f(w.slice(s.length),e.replace(`
${s}
`,`
`)))
</code>```

Title: Play scrabble with the periodic table

Body:
JavaScript (Firefox 48 or earlier), 103 bytes

f=(w,e=`
H
He
... (list of elements not included in the byte count) ...
Uus
Uuo
`)=>!w||e.match(/\w+/g).some(s=>!w.search(s,`i`)&&f(w.slice(s.length),e.replace(`
${s}
`,`
`)))


答:
05AB1E, 16 bytes

```<code>œvyŒ€J})˜Ùvy²Q}O
</code>```

Explained

```<code>œv                # for each permutation of the list of elements
  yŒ              # get all sublist of elements
    €J            # join as strings to form the words possible to spell
      })˜Ù        # convert to list of unique spellable strings
          vy²Q}   # compare each word with input word
               O  # sum giving 1 if the word is found, else 0
</code>```

Warning: Extremely slow. I recommend testing on a much smaller subset of elements in the online interpreter.

Takes list of elements as first argument.

Takes word to test as second argument.

Returns 1 for true and 0 for false.

Try it online on a small subset of elements

Title: Play scrabble with the periodic table

Body:
You've got a set of tiles with the symbols from the periodic table. Each symbol appears once. You're thinking up words to make but you want to know if it's possible or not.

The Challenge

Write a program in your favourite language that will take in a string as an input parameter. You may assume that input is not null, has no spaces and consists of ASCII characters.

Your program should take that string and output a truthy value if that word can made up of symbols from the periodic table of elements, and a falsey value if the word cannot.

To make this challenge more difficult, you may not use a symbol twice. So if you use Nitrogen N you may not use N again in the same word.

Rules

Standard loopholes are not allowed. You may use symbols from elements 1-118 (Hydrogen to Ununoctium). You can find a list of all the elements here. You may read the list of symbols in from a file or input arguments if you wish.

Test Cases:

```<code>Laos - true (LaOs)
Amputation - true (AmPuTaTiON)
Heinous - true (HeINoUS)
Hypothalamus - true (HYPoThAlAmUS)
Singapore - true (SiNGaPoRe)
Brainfuck - true (BRaInFUCK)
Candycane - false
</code>```

This is a code golf challenge, shortest code wins.

BEFORE YOU CLOSE AS DUPLICATE: While this may seem similar to this challenge, I feel it is different because it is not 'Generate a list of all words that are possible from the periodic table', it is 'Take in arbitrary input and determine if it can be made from the periodic table'

Body:
05AB1E, 16 bytes

œvyŒ€J})˜Ùvy²Q}O

Explained

œv                # for each permutation of the list of elements
  yŒ              # get all sublist of elements
    €J            # join as strings to form the words possible to spell
      })˜Ù        # convert to list of unique spellable strings
          vy²Q}   # compare each word with input word
               O  # sum giving 1 if the word is found, else 0

Warning: Extremely slow. I recommend testing on a much smaller subset of elements in the online interpreter.

Takes list of elements as first argument.

Takes word to test as second argument.

Returns 1 for true and 0 for false.

Try it online on a small subset of elements


答:
GolfScript, <s>22</s> 20 chars

```<code>~.1|,.+2%(;(@.1&,~;\
</code>```

Outputs the following sequences for the inputs 4 through 9:

```<code>2413
41352
246135
4613572
24681357
468135792
</code>```

For even inputs, just ~),.+2%(; would suffice.  I'm not too happy with the kluge for handling odd input values; there's got to be a more efficient way to do it.

Edit: Saved two chars by changing the output for odd inputs a bit and playing silly stack manipulation tricks.  Still not too happy with the length.

Title: Generate a valid sequence of numbers with specific rules

Body:
The challenge

The program must return a valid sequence of numbers into some rules

Rules

x is the size of the sequence;

x cannot be less than 4 or greater than 9 (Thanks David Carraher);

Digits of the sentence can't repeat, each one must appear once;

All digits between 1 to x must be in the sequence;

A valid sequence never begins nor ends with 1 or x;

Into the sequence, numbers can never appear "together";

Examples

If x=4:

2413 valid

3142 valid

1423 not valid, because begins with 1 and 23 are "together".

2134 not valid, because ends with x and 34 are "together".

Still don't get it?
Other example:

If x=8:

28375146 valid, because don't start with 1 nor x(8), don't end with 1 nor x, and no numbers are "together"(no numbers touches, no numbers are the next or previous)

Sorry, I really don't know how to explain the last rule. Hope the example make it understandable.

Additional Information

x does not need to be an input, you can show the outputs for x=4 and x=9 working;

Since any language will be accepted and, I don't know how all of them work, I will ask you people to help me with this;

The winner will be the one who got more up-votes in 1 week, so please, vote the answer you find the best; I will mark it as the Correct one;

Good, luck. =)

Body:
GolfScript, <s>22</s> 20 chars

~.1|,.+2%(;(@.1&,~;\

Outputs the following sequences for the inputs 4 through 9:

2413
41352
246135
4613572
24681357
468135792

For even inputs, just ~),.+2%(; would suffice.  I'm not too happy with the kluge for handling odd input values; there's got to be a more efficient way to do it.

Edit: Saved two chars by changing the output for odd inputs a bit and playing silly stack manipulation tricks.  Still not too happy with the length.


答:
Microsoft SQL Server, 57 Bytes

```<code>SELECT UPPER(FORMAT(CAST('201601'+'01' AS DATE),'MMMyy'))
</code>```

The Upper function is required as format does not produce Upper case months as would be expected with the MMM format pattern.

Usage:

```<code>drop table t;
create table t (n VARCHAR(6));
insert into t values ('201604');
insert into t values ('200001');
insert into t values ('000112');
insert into t values ('123405');

SELECT UPPER(FORMAT(CAST(n+'01' AS DATE),'MMMyy')) FROM t
</code>```

Title: Convert YYYYMM to MMMYY

Body:
Microsoft SQL Server, 57 Bytes

SELECT UPPER(FORMAT(CAST('201601'+'01' AS DATE),'MMMyy'))

The Upper function is required as format does not produce Upper case months as would be expected with the MMM format pattern.

Usage:

drop table t;
create table t (n VARCHAR(6));
insert into t values ('201604');
insert into t values ('200001');
insert into t values ('000112');
insert into t values ('123405');

SELECT UPPER(FORMAT(CAST(n+'01' AS DATE),'MMMyy')) FROM t


Title: Convert YYYYMM to MMMYY

Body:
Pyth, 39 bytes

Hexdump:

0000000: 2b 40 63 2e 22 41 59 12 56 0a 7c bd 93 e3 1c 07 +@c."AY.V.|.....
0000010: e3 d4 d9 ed 5b 49 02 cd b4 92 83 86 22 33 73 3e ....[I......"3s>
0000020: 32 7a 3a 7a 32 20 34                            2z:z2 4

Test suite.


问:
Character Counting System
GOAL :
 To Implement a character counting program

This is how this counting system works :

input of the program is a set of printable ASCII characters . the program counts each type of character , and outputs the number of each character , starting from first mentioned character to last mentioned character .

Example :

```<code>input : aaaabbbbbcccc    123445b
output : 4 6 4 4 1 1 1 2 1
</code>```

Which 4 is number of as , 6 is number of bs , 4 is number of cs , 4 is number of spaces () and so on . Also you can split answers with space (like example) , EOL , or anything other than numerals .

Rules

Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.

Your program must be a full, runnable program, and not a function or snippet

It's optional to mention the ungolfed version of program and/or a short explanation  .

Test input :  ThIs Is ThE iNPUT , WITH 72/2 CHARS!

Test output :  4 2 3 2 7 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1

答:
05AB1E, 6 bytes

```<code>Ùv¹y¢,
</code>```

Explained

```<code>Ùv      # for each unique char in original order
  ¹y¢   # count number of occurances in input string
     ,  # print on newline
</code>```

Try it online

Title: Character Counting System

Body:
05AB1E, 6 bytes

Ùv¹y¢,

Explained

Ùv      # for each unique char in original order
  ¹y¢   # count number of occurances in input string
     ,  # print on newline

Try it online


答:
Pyth, 4 bytes

```<code>/LQ{
</code>```

Test suite.

Explanation

```<code>/LQ{    Input: Q
/LQ{Q   Implicitly fill arguments

   {Q   Yield the unique elements of Q.
 L      For each unique element:
/       Yield its number of occurrences
  Q     in Q.
</code>```

Title: Character Counting System

Body:
GOAL :
 To Implement a character counting program

This is how this counting system works :

input of the program is a set of printable ASCII characters . the program counts each type of character , and outputs the number of each character , starting from first mentioned character to last mentioned character .

Example :

```<code>input : aaaabbbbbcccc    123445b
output : 4 6 4 4 1 1 1 2 1
</code>```

Which 4 is number of as , 6 is number of bs , 4 is number of cs , 4 is number of spaces () and so on . Also you can split answers with space (like example) , EOL , or anything other than numerals .

Rules

Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.

Your program must be a full, runnable program, and not a function or snippet

It's optional to mention the ungolfed version of program and/or a short explanation  .

Test input :  ThIs Is ThE iNPUT , WITH 72/2 CHARS!

Test output :  4 2 3 2 7 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1

Body:
Pyth, 4 bytes

/LQ{

Test suite.

Explanation

/LQ{    Input: Q
/LQ{Q   Implicitly fill arguments

   {Q   Yield the unique elements of Q.
 L      For each unique element:
/       Yield its number of occurrences
  Q     in Q.


答:
Mathematica, 56 bytes

```<code>Print@StringRiffle[Last/@Tally@Characters@InputString[]]
</code>```

Essentially, Tally does exactly what the challenge asks for (although it gives pairs of {element, count}). The rest is just for working with strings and proper I/O for a full program.

Title: Character Counting System

Body:
Mathematica, 56 bytes

Print@StringRiffle[Last/@Tally@Characters@InputString[]]

Essentially, Tally does exactly what the challenge asks for (although it gives pairs of {element, count}). The rest is just for working with strings and proper I/O for a full program.


答:
CJam, 9 bytes

```<code>l__&\fe=p
</code>```

Test it here.

Explanation

```<code>l    e# Read input.
__   e# Make two copies.
&    e# Set intersection - removes duplicates.
\    e# Swap with input.
fe=  e# For each (unique) character, count its occurrences.
p    e# Print as array literal.
</code>```

Title: Character Counting System

Body:
CJam, 9 bytes

l__&\fe=p

Test it here.

Explanation

l    e# Read input.
__   e# Make two copies.
&    e# Set intersection - removes duplicates.
\    e# Swap with input.
fe=  e# For each (unique) character, count its occurrences.
p    e# Print as array literal.


答:
Retina, <s>30</s> 28 bytes

2 bytes thanks to Martin Ender.

```<code>+`((.).+)\2
$2$1
(.)\1*
$.&¶
</code>```

Try it online!

Title: Character Counting System

Body:
Retina, <s>30</s> 28 bytes

2 bytes thanks to Martin Ender.

+`((.).+)\2
$2$1
(.)\1*
$.&¶

Try it online!


答:
MATL, 3 bytes

```<code>8#u
</code>```

Input is a string enclosed with quotation marks (which is allowed by default)

Try it online!

Explanation

u is the unique function, which essentially removes duplicates. It can produce up to four outputs. The fourth output is the count of unique characters, identified in order of appearance.

8# specifies that the fourth output of u should be produced. In general, 2# means "produce two outputs", 3# means "produce three outputs" etc. When the maximum number of function outputs is reached, larger numbers mean "take the first output only", or "the second only" etc. Thus, since u has four possible outputs, 4# would produce all four outputs; 5# produces the first, 6# the second, etc.

Title: Character Counting System

Body:
MATL, 3 bytes

8#u

Input is a string enclosed with quotation marks (which is allowed by default)

Try it online!

Explanation

u is the unique function, which essentially removes duplicates. It can produce up to four outputs. The fourth output is the count of unique characters, identified in order of appearance.

8# specifies that the fourth output of u should be produced. In general, 2# means "produce two outputs", 3# means "produce three outputs" etc. When the maximum number of function outputs is reached, larger numbers mean "take the first output only", or "the second only" etc. Thus, since u has four possible outputs, 4# would produce all four outputs; 5# produces the first, 6# the second, etc.


答:
Brachylog, 32 bytes

```<code>:efd:?:{tL,?he:L:{t:.m~h?}fl.}f.
</code>```

Awfully long but there's no simple way of counting elements of something yet…

Title: Character Counting System

Body:
Brachylog, 32 bytes

:efd:?:{tL,?he:L:{t:.m~h?}fl.}f.

Awfully long but there's no simple way of counting elements of something yet…


问:
Shorten text with Run Length Encoding
Shorten (or not) text using run length encoding

Input:

```heeeello
woooorld
```

Output:

```1h4e2l1o
1w4o1r1l1d```

Read lines from stdin.

Print to stdout.

Stderr is of course discarded.

Assume there are hidden testcases (no embedding of the output)

Input/Output as ASCII

Any language is accepted

Title: Shorten text with Run Length Encoding

Body:
Burlesque (17B)

{=[{J[-jL[Q}\m}WL

{=[{^^[~\/L[Sh}\m}WL

Older/Alternative and longer versions:

{=[{^^L[Sh\/-]Sh.+}m[\[}WL
{=[{^^L[Sh\/-][-.+}m[\[}WL
{=[{^^L[Sh\/-~.+}m[\[}WL
{=[{^^L[Sh\/-].+}\m}WL
{=[{^^L[Sh\/[~.+}\m}WL
{=[{^^L[Sh\/[~_+}\m}WL
{=[{^^L[Sh\/fc.+}\m}WL
{=[{^^L[Sh\/-~.+}\m}WL
{=[{^^L[Sh\/-]\/}\m}WL


问:
Counting in bijective base 62
The task is to generate all the strings from 'a' to '999' including upper case characters like so:

```<code>'a', 'b', 'c' ... 'y', 'z', 'A', 'B', 'C' ... 'Y', 'Z', '0', '1', 2' ...
'8', '9', 'aa', 'ab', 'ac' ... 'az', 'aA', 'aB' ... 'aZ', 'a0' ... 'a9', 'ba'
</code>```

and so on (filling in the gaps), optionally starting with the empty string.

Input:

The amount of consecutive characters the program has to print up to.

Output:

An array containing each string OR one string per line

Clarifications:

The order doesn't matter, you can print uppercase or lowercase letters first if you want.

The output can return any type of enumerable, doesn't have to be an array specifically, although I doubt printing all the combinations won't be the easiest way to go.

An input of 3 would print all the string from 'a' (or '') to '999'‚ an input of 5 up to '99999' and so on.

答:
APL, 38 37 bytes

```<code>{⊃{⍵,,⍺∘.,⍵}/⍵⍴⊂,¨⎕a,⎕d,⍨⎕ucs 96+⍳26}
</code>```

Title: Counting in bijective base 62

Body:
APL, 38 37 bytes

{⊃{⍵,,⍺∘.,⍵}/⍵⍴⊂,¨⎕a,⎕d,⍨⎕ucs 96+⍳26}


答:
Java 7, <s>246</s> <s>235</s> <s>231</s> 213 bytes

Loads of bytes removed thanks to cliffroot.

```<code>import java.util.*;class M{public static void main(String[]a){Map<Long,Long>m=new LinkedHashMap();for(long c:a[0].toCharArray())m.put(c,m.get(c)!=null?m.get(c)+1:1);for(Long e:m.values())System.out.print(e+" ");}}
</code>```

Ungolfed & test code:

Try it here.

```<code>import java.util.*;

class Main{
  public static void main(String[] a){
    // Test code:
    a = new String[]{ "ThIs Is ThE iNPUT , WITH 72/2 CHARS!" };

    Map<Long, Long> m = new LinkedHashMap();
    for(long c : a[0].toCharArray()){
      m.put(c, m.get(c) != null ? m.get(c) + 1 : 1);
    }
    for(Long e : m.values()){
      System.out.print(e + " ");
    }
  }
}
</code>```

Output:

```<code>4 2 3 2 7 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1
</code>```

Title: Character Counting System

Body:
Java 7, <s>246</s> <s>235</s> <s>231</s> 213 bytes

Loads of bytes removed thanks to cliffroot.

import java.util.*;class M{public static void main(String[]a){Map<Long,Long>m=new LinkedHashMap();for(long c:a[0].toCharArray())m.put(c,m.get(c)!=null?m.get(c)+1:1);for(Long e:m.values())System.out.print(e+" ");}}

Ungolfed & test code:

Try it here.

import java.util.*;

class Main{
  public static void main(String[] a){
    // Test code:
    a = new String[]{ "ThIs Is ThE iNPUT , WITH 72/2 CHARS!" };

    Map<Long, Long> m = new LinkedHashMap();
    for(long c : a[0].toCharArray()){
      m.put(c, m.get(c) != null ? m.get(c) + 1 : 1);
    }
    for(Long e : m.values()){
      System.out.print(e + " ");
    }
  }
}

Output:

4 2 3 2 7 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1


答:
Dyalog APL, 10 bytes

Shortest by byte count

```<code>+⌿t∘.=∪t←⍞
</code>```

t←⍞ get character input and store as t

`∪' unique elements of

t∘.= table of which elements of t are equal to (the unique elements of t)

+⌿ sum the columns

5 character solution which unfortunately is 15 bytes:

```<code>⊢∘≢⌸⍞
</code>```

⍞ get character input

⌸ make a table of contents containing...

⊢∘≢ the tally (≢) of the indices while the entries are ignored (⊢)

Title: Character Counting System

Body:
Dyalog APL, 10 bytes

Shortest by byte count

+⌿t∘.=∪t←⍞

t←⍞ get character input and store as t

`∪' unique elements of

t∘.= table of which elements of t are equal to (the unique elements of t)

+⌿ sum the columns

5 character solution which unfortunately is 15 bytes:

⊢∘≢⌸⍞

⍞ get character input

⌸ make a table of contents containing...

⊢∘≢ the tally (≢) of the indices while the entries are ignored (⊢)


答:
J, <s>18</s> 15 bytes

```<code>echo#/.~stdin''
</code>```

Following the challenge spec to write a program, the above is a one-line script in J that reads a line from stdin, computes the result, and prints it to stdout.

If using an online interpreter, it would require 4 bytes since without stdio, only function arguments could be used.

```<code>#/.~
</code>```

Straight-forward application of adverbs /. and ~ to the tally # verb.

Usage

As a script,

```<code>$ echo -n 'aaaabbbbbcccc    123445b' | jconsole golf.j
4 6 4 4 1 1 1 2 1
</code>```

As a function,

```<code>   (#/.~) 'aaaabbbbbcccc    123445b'
4 6 4 4 1 1 1 2 1
</code>```

Explanation

```<code>#/.~  Input: s
   ~  Reflects the input
 /.   An adverb that executes a verb on each set of identical items in s
      Operates in the order of first-seen distinct items in s
#     Get the size of each set of identical items
      Returns a list of the sizes of identical items
</code>```

Title: Character Counting System

Body:
J, <s>18</s> 15 bytes

echo#/.~stdin''

Following the challenge spec to write a program, the above is a one-line script in J that reads a line from stdin, computes the result, and prints it to stdout.

If using an online interpreter, it would require 4 bytes since without stdio, only function arguments could be used.

#/.~

Straight-forward application of adverbs /. and ~ to the tally # verb.

Usage

As a script,

$ echo -n 'aaaabbbbbcccc    123445b' | jconsole golf.j
4 6 4 4 1 1 1 2 1

As a function,

   (#/.~) 'aaaabbbbbcccc    123445b'
4 6 4 4 1 1 1 2 1

Explanation

#/.~  Input: s
   ~  Reflects the input
 /.   An adverb that executes a verb on each set of identical items in s
      Operates in the order of first-seen distinct items in s
#     Get the size of each set of identical items
      Returns a list of the sizes of identical items