# How many Wazirs can be placed on an N×N Chessboard?

Suppose a new fairy chess piece named the Wazir is introduced to chess. Wazirs can move from a position (x, y) to:
(x+1, y)
(x, y+1)
(x-1, y)
(x, y-1)

That is, they move orthogonally like the rook, but only one step at a time like the king. How many such wazirs can be placed on an N×N chessboard so that no two wazirs can attack each other?

On a 1×1 board, there can be only 1 such piece.
On a 2×2 board, there can be 2 such pieces.
On a 3×3 board, there can be 5 such pieces.

Given N, return the number of wazirs that can be placed on an N×N chessboard.

This is OEIS sequence A000982.

### More test cases

725

832

1005000

• So the Camel is to the Rook what the King is to the Queen? I.e. can only move orthogonally, and only one step at a time.
Oct 2 '17 at 8:32
• @SashaR May I rewrite your question as a proper code golf challenge?
Oct 2 '17 at 9:09
• As a new user of this site, you've been very lucky this time. A lot of (off-topic) programming questions on this site has been permanently closed and downvoted, not edited as a challenge and upvoted like this one. As other people already explained, this site is for programming competitions only, not for asking homework. You can use the sandbox (at codegolf.meta.stackexchange.com/questions/2140/… ) before posting a challenge to avoid common mistakes next time; and note that most users on this site, as you have seen, use "unreadable" languages. Oct 2 '17 at 14:52
• This question is pretty confusing in that the Camel is already the standard fairy chess name for a piece like a knight that makes longer jumps and the piece you describe already has a fairy chess name: Wazir. Oct 3 '17 at 11:26
• OTOH editing the question to the the standard name after answers have already been written using the name used in the question is also confusing. Oct 4 '17 at 8:40

# TI-Basic, 7 bytes

round(Ans²/2,0


Alternatively (8 bytes):

int(Ans²/2+.5

• -int(-.5Ans² also works
– Oki
Oct 5 '17 at 14:56
• @Oki It sure does. I just wish they had a ceil( function. Oct 5 '17 at 17:55

# ///, 35 bytes

/I///,*/+,//+/I//**,/,A//*/A//,//,I


Try it online!

Takes input in unary using symbol *, and output in unary using symbol A. This is allowed for some specific languages, including /// (meta)

Because there is no way to take input in ///, input should be hardcoded:

/I/«put input here»//,*/+,//+/I//**,/,A//*/A//,//,I


for input = 4.

Explanation: (before reading, you need to know that the only syntax of /// are /pattern/replacement/, which replace every occurence of pattern by replacement; and \ for escaping; other characters is printed to output)

For n=4:

/I/****//,*/+,//+/I//**,/,A//*/A//,//,I    Start program.
/I/****/                                   Replace all I in the program by the input.

/,*/+,//+/****//**,/,A//*/A//,//,****      Remaining part of the program.
/,*/+,/                                    Use the , as a scanner, scan through * after it and convert to +.
/+/****//**,/,A//*/A//,//++++,      Note that only * in the second group is affected.
/+/****/                            Replace all + (which is just created) by n asterisks (from the first I group)

/**,/,A//*/A//,//****************,         Now at the last of the program before the , there are n² asterisks.
/**,/,A/                                   Scan the , to the left to perform division by 2:
replace each ** by a A as the scanner , pass through.
/*/A//,//,AAAAAAAA                         Remaining program.
/*/A/                                      If there is any * remaining (if n² is odd), replace it with A.
/,//                                  Remove the scanner ,.
AAAAAAAA                         Output the result.


# Cubically, 12 bytes

$:*FDF'+8/0%  Try it online! Personally I don't see any point with using language features newer than the challenge to get less bytes, because you mostly compete with yourself (almost always there are at most one answer/language/challenge), but I still updated, by MDXF's suggestion. : defaults to :7 is a good idea anyway. Explanation: $:*7FDF'+8/0%

Explanation:

• $ duplicate top of stack • * multiply • 1 push 1 • + add • 2 push 2 • / divide False only has 32-bit integers. # Haskell, 18 bytes w n=ceiling(n*n/2) Run as: main = print$ w n

Where n is the input number.

# x86 machine code, 6 bytes

Takes its argument in eax register, returns also there.

f7 e0   mul eax
40      inc eax
d1 e8   shr eax,1
c3      ret


echo $[$1*$1+1>>1]  Try it online # Excel, 15 bytes =ROUND(A1^2/2,)  Because we are dividing by 2, we can safely replace CEILING with ROUND, saving 3 bytes. =CEILING(A1^2/2,1)  # MMIX, 16 bytes (4 instrs) xxd, jelly code page 00000000: 1800 0000 2100 0001 3f00 0001 f801 0000 ð¡¡¡!¡¡¢?¡¡¢ẏ¢¡¡  disassembly waz MUL$0,$0,$0
ADD $0,$0,1
SRU $0,$0,1
POP 1,0


Uses the obvious trick of getting $$\\lceil{n^2\over2}\rceil\$$ by adding one and rounding down.

# BRASCA, 8 bytes

igC2^}2/


## Explanation

ig        - Turn charcodes into numbers, and concatenate input.
C       - Set implicit output to output numbers
2^     - (n**2
}    -      +1)
2/  -         /2
- NOTE: BRASCA only handles whole integers, and will automatically Math.floor().
- Implicitly output


Try it online!

# JavaScript (ES8), 16 bytes

x=>(h=x*x/2)+h%1
x=>                  // arrow function
(h=x*x/2)         // dictionarying
+h%1     // Math.ceil function