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

30

1

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

Sasha R

Posted 2017-10-02T08:25:16.063

Reputation: 467

1Welcome to the site. We do not do programming help but rather host programming competitions. This could certainly be an on topic programming competition but it would need a scoring criterion, probably [tag:code-golf]. – Post Rock Garf Hunter – 2017-10-02T08:30:17.717

Related – Arnauld – 2017-10-02T08:31:18.057

4So 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. – Adám – 2017-10-02T08:32:15.957

1Since the answer to this question is just a formula, it is not a good fit for a competition style site. – Adám – 2017-10-02T08:33:32.787

Yeah..I was just wondering if there was some method to solve this so that I could code it myself.I'll hence remove the code generation tag.Honestly amazed at how fast people respond!! – Sasha R – 2017-10-02T08:36:22.630

1More closely related. Or at least it would be if your description was matching the standard Camel definition. – Arnauld – 2017-10-02T08:38:02.447

The codes that people post for the code golf challenges..what kind of programming language is that?Again,this may be a very silly question..but am a beginner to programming,so please forgive my ignorance – Sasha R – 2017-10-02T08:42:58.850

1@SashaR A lot of people use dedicated golfing programming languages. Languages that, while often based on commonly used programming languages, have been modified to be a succinct as possible. – Adám – 2017-10-02T08:44:09.350

See here for more information about this site. – Arnauld – 2017-10-02T08:44:11.817

2@SashaR May I rewrite your question as a proper code golf challenge? – Adám – 2017-10-02T09:09:29.930

2Sure! That way I can also see how to word coding related questions in future – Sasha R – 2017-10-02T09:10:36.457

@SashaR There you go. – Adám – 2017-10-02T09:33:10.223

1

This is A000982.

– Shaggy – 2017-10-02T09:40:14.350

@Shaggy Thanks. Added. – Adám – 2017-10-02T09:42:51.957

15

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 https://codegolf.meta.stackexchange.com/questions/2140/sandbox-for-proposed-challenges?cb=1 ) 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.

– user202729 – 2017-10-02T14:52:26.710

Related: my challenge asking a generalisation of the opposite (fewest pieces that can be arranged so no more can be placed).

– trichoplax – 2017-10-02T18:58:46.877

@SashaR I attached a proof that this formula works to my answer.

– Lynn – 2017-10-02T20:48:57.487

16

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.

– Mark S. – 2017-10-03T11:26:47.703

2OTOH editing the question to the the standard name after answers have already been written using the name used in the question is also confusing. – Peter Green – 2017-10-04T08:40:07.617

Chess piece Queen is called "Vezir" in Turkish, I guess it is something close in Farsi and Arabic too. – Ege Bayrak – 2017-10-05T12:59:11.067

Answers

33

Whitespace, 45 bytes

   
	
		   
			 
 	  
   	
	      	 
	 	 	
 	

Try it online!

By the way, here is a proof that the ⌈n²/2⌉ formula is correct.

  • We can always place at least ⌈n²/2⌉ wazirs: just lay them out in a checkerboard pattern! Assuming the top-left tile is white, there are ⌈n²/2⌉ white tiles and ⌊n²/2⌋ black tiles on the n × n board. And if we place wazirs on the white tiles, no two of them are attacking each other, as every wazir only “sees” black tiles.

    Here’s how we place 13 wazirs on a 5 × 5 board (each W is a wazir).

              13 wazirs on a 5 × 5 board

  • We can’t do any better: let’s arbitrarily tile the checkerboard with 2 × 1 domino pieces, optionally using a 1 × 1 piece for the final corner of an odd-length chessboard, like so:

              domino cover of a 5 × 5 board

    We need ⌈n²/2⌉ dominoes to cover the chessboard. Clearly, putting two wazirs on one domino makes it so that they can attack one another! So each domino can only contain at most one wazir, meaning we can’t possibly place more than ⌈n²/2⌉ wazirs on the board.

Lynn

Posted 2017-10-02T08:25:16.063

Reputation: 55 648

You don't need the pigeonhole principle for the last part: you have exactly ⌈n²/2⌉ tiles, and at most camel per tile, so you have at most ⌈n²/2⌉ camels. – ShreevatsaR – 2017-10-03T07:29:28.043

8@ShreevatsaR What ensures you that you can't put x > ⌈n²/2⌉ camels in ⌈n²/2⌉ tiles? It's the pigeonhole principle... – frarugi87 – 2017-10-03T07:58:48.870

@frarugi87 In any single tile, you can put at most one camel. You don't need the pigeonhole principle for that. In other words: the total number of camels on the chessboard = sum_(over each tile) {number of camels in that tile} ≤ sum_(over each tile) 1 = number of tiles = ⌈n²/2⌉. Invoking the pigeonhole principle, though obviously correct, is an unnecessary use of contradiction when a direct proof is possible. – ShreevatsaR – 2017-10-03T14:30:42.963

Hand drawn red C's? That's a new one ;) And a nice answer! – geisterfurz007 – 2017-10-03T19:23:59.140

@frarugi87 BTW, when you frame the statement like “you can't put x > ⌈n²/2⌉ camels in ⌈n²/2⌉ tiles” it obviously strongly suggests the pigeonhole principle. If you state it is “as there are ⌈n²/2⌉ tiles and at most one camel per tile, there are at most ⌈n²/2⌉ camels”, you do not need the pigeonhole principle. So it's a bit underhanded to choose a statement that inherently has the very feature (contradiction) that I'm saying is unnecessary for the claim being proved. :-) – ShreevatsaR – 2017-10-03T21:51:12.010

2I thought at first the code didn't load, so I refreshed the page, and it still didn't. Then I realized what language name was written at the top. – Arthur – 2017-10-04T09:28:24.090

7I appreciate that you went and changed your C's to W's in your proof illustration. – Giuseppe – 2017-10-04T13:39:15.757

4I also appreciate that the W's are all on the WHITE SPACES with an answer in WHITESPACE. – corsiKa – 2017-10-04T16:13:29.123

For a brief moment there I wondered "where's the code" because I didn't read the language name. – Pharap – 2017-10-05T00:08:47.520

16

Oasis, 3 bytes

k>v

Try it online!

square - increment - integer halve

Leaky Nun

Posted 2017-10-02T08:25:16.063

Reputation: 45 011

10

Prolog (SWI), 22 19 bytes

Saved 3 bytes thanks to Kevin Cruijssen

X*Y:-Y is(X*X+1)/2.

Try it online!

Emigna

Posted 2017-10-02T08:25:16.063

Reputation: 50 798

X*Y:-Y is(X*X+1)/2. (19 bytes) – Kevin Cruijssen – 2017-10-02T13:43:41.180

2@KevinCruijssen: Doh! I suggested the same change to another user, but somehow I didn't take my own advice. Thank you :) – Emigna – 2017-10-02T14:06:04.247

9

APL (Dyalog), 9 7 6 bytes

Now uses Mr. Xcoder's formula.

This is an anonymous prefix tacit function which takes N as argument.

⌈2÷⍨×⍨

Try it online!

×⍨ square N (lit. multiplication selfie, i.e. multiply by self)

2÷⍨ divide by 2

 ceiling (round up)

Adám

Posted 2017-10-02T08:25:16.063

Reputation: 37 779

Wow!I have no idea how you did this !!Didn't get the logic thoughsigh – Sasha R – 2017-10-02T08:49:30.127

Darn, someone already found out the pattern. – Feathercrown – 2017-10-02T18:26:30.337

1Huh, just realized the formula is on the OEIS page. Probably shouldn't have linked that. – Feathercrown – 2017-10-02T18:27:28.450

7

JS (ES6) / C# polyglot, 11 bytes

n=>n*n+1>>1

Test cases

let f =

n=>n*n+1>>1

console.log(f(7))
console.log(f(8))
console.log(f(100))

Arnauld

Posted 2017-10-02T08:25:16.063

Reputation: 111 334

3C# polyglot – Shaggy – 2017-10-02T16:41:55.223

@Shaggy Thanks for noticing! – Arnauld – 2017-10-02T16:49:03.787

1JS and C# polyglot seems extremely rare, given the differences between them. +1 – caird coinheringaahing – 2017-10-04T11:36:11.530

6

dc, 6 bytes

2^2~+p

2^: square; 2~: divide by 2, pushing the quotient then the remainder; +p: add the remainder to the quotient & print.

Try it online!

brhfl

Posted 2017-10-02T08:25:16.063

Reputation: 1 291

5

C (gcc), 23 18 17 bytes

  • Saved a byte thanks to Tahg; golfing n/2+n%2 to n+1>>1.
f(n){n=n*n+1>>1;}

Try it online!

C (gcc), 22 bytes (not using undefined behavior)

f(n){return n*n+1>>1;}

Try it online!

Some people really do not like exploiting a certain compiler's undefined bahavior when using specific compiler flags. Doing so does save bytes, though.

Jonathan Frech

Posted 2017-10-02T08:25:16.063

Reputation: 6 681

3Odd way of providing an answer IMO, but: f(n){n=n*n+1>>1;} to save a byte. – Tahg – 2017-10-02T09:56:12.143

1@Tahg Thanks; though in what way do you find my way of providing an answer odd? – Jonathan Frech – 2017-10-02T10:51:33.503

2I didn't think changing the input argument was a normal way of returning a value in C. – Tahg – 2017-10-02T13:41:10.027

1@Tahg It is not; though n= it is shorter than return. – Jonathan Frech – 2017-10-02T15:15:24.783

In my opinion, this is a no-op function. – YSC – 2017-10-03T07:45:00.393

2@YSC Yet in the compiler's opinion it is understandable and creates an executable which works. – Jonathan Frech – 2017-10-03T15:10:49.637

so does f(){}. From the original post: "Given N, return the number of camels". Sorry my compiler doesn't like your definition of f: https://ideone.com/hRdzlY

– YSC – 2017-10-03T15:17:33.070

@YSC mine does. It works (on x86 and x86_64) simply because eax is used as scratch register, and coincides with the register used to return a value.

– Ruslan – 2017-10-03T19:54:20.580

@Ruslan maybe it should be C(undefined behaviour) 17 bytes then :D I don't disagree this solution works on some compiler. I just really don't like it and only see an astute no-op. Cope with it guys. – YSC – 2017-10-03T22:17:46.300

5@YSC We believe here on PPCG that, if the program works on one interpreter, it is a valid submission. It works on an online interpreter, it is therefore valid without any further remarks. – Conor O'Brien – 2017-10-03T22:37:28.610

5

05AB1E, 3 bytes

Straight implementation of the formula given by A000982

n;î

Try it online!

Explanation

n      # square
 ;     # divide by 2
  î    # round up

Emigna

Posted 2017-10-02T08:25:16.063

Reputation: 50 798

5

Python 2, 17 bytes

1 byte thanks to @ovs.

lambda x:x*x+1>>1

Try it online!

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

Alternatively: lambda x:-~x**2/2 – RoryT – 2017-10-02T23:46:28.460

4

Python 3, 19 bytes

lambda x:-(-x*x//2)

Try it online!

lambda x:-(-x*x//2)  # Unnamed function
lambda x:            # Given input x:
            x*x      # Square
           -         # Negate
               //2   # Halve and Floor (equivalent of Ceil)
         -(       )  # Negate again (floor -> ceil)

-1 byte thanks to Mr. Xcoder

HyperNeutrino

Posted 2017-10-02T08:25:16.063

Reputation: 26 575

x**2 -> x*x – Mr. Xcoder – 2017-10-02T13:00:57.847

@Mr.Xcoder Facepalm thanks – HyperNeutrino – 2017-10-02T13:06:42.210

What about lambda x:x*x+1>>1 ? – Alix Eisenhardt – 2017-10-02T15:47:20.197

Or lambda x:x*x+1//2 Disclaimer: I don't know this language's syntax or order of operations, so I guessed; I'm saying add 1 before you //2 instead of negating twice. – Dan Henderson – 2017-10-02T15:57:54.043

@DanHenderson You still need parentheses otherwise it's parsed as (x*x) + (1//2), so that isn't actually shorter. – Skyler – 2017-10-02T17:09:07.200

4

Brachylog, 6 bytes

^₂/₂⌉₁

Try it online!

Erik the Outgolfer

Posted 2017-10-02T08:25:16.063

Reputation: 38 134

4

x86_64 machine language (Linux), 9 8 bytes

0:       97                      xchg   %eax,%edi
1:       f7 e8                   imul   %eax
3:       ff c0                   inc    %eax
5:       d1 f8                   sar    %eax
7:       c3                      retq

To Try it online!, compile and run the following C program.

#include<stdio.h>
const char *f="\x97\xf7\xe8\xff\xc0\xd1\xf8\xc3";
int main() {
  for(int i=1; i<10; i++) {
    printf("%d\n", ((int(*)())f)(i));
  }
}

ceilingcat

Posted 2017-10-02T08:25:16.063

Reputation: 5 503

3

J, 8 bytes

Anonymous tacit prefix function.

2>.@%~*:

Try it online!

*: square

>. ceiling (round up)
@ after
2%~ dividing by two

Adám

Posted 2017-10-02T08:25:16.063

Reputation: 37 779

Alternate solutions: <.@-:@*: and *:<.@%2: – Conor O'Brien – 2017-10-03T22:39:08.260

2@ConorO'Brien 2>.@%~*:‽ Where did I get that from? I can't read that – looks like line noise to me… – Adám – 2017-10-03T22:47:38.300

>.@-:@*: gets my vote. – Jonah – 2017-10-04T02:56:23.603

1@Jonah If you squint, you can see a camel. – Adám – 2017-10-04T08:30:39.247

3

R, 22 21 bytes

cat((scan()^2+1)%/%2)

Try it online!

Square, increment, integer divide. Easy peasy.

Input from stdin; it can take space or newline separated input and it will compute the max wazirs for each input boardsize. Output to stdout.

-1 byte thanks to plannapus

Giuseppe

Posted 2017-10-02T08:25:16.063

Reputation: 21 077

@plannapus fixed, thank you. – Giuseppe – 2017-12-11T20:48:39.763

3

Actually, 3 bytes

²½K

Try it online!

Sherlock9

Posted 2017-10-02T08:25:16.063

Reputation: 11 664

2

Pyth, 6 bytes

.E**.5

Try it online!

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

2

Pyke, 3 bytes

Xhe

Try it here!

How?

X   - Square.
 h  - Increment.
  e - Floor halve.

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

2

C# (.NET Core), 14 12 bytes

-2 bytes thanks to Emigna

n=>(n*n+1)/2

Try it online!

my pronoun is monicareinstate

Posted 2017-10-02T08:25:16.063

Reputation: 3 111

Save 2 bytes – Emigna – 2017-10-02T12:46:25.980

2n=>n*n+1>>1 (11 bytes) – Kevin Cruijssen – 2017-10-02T13:40:07.230

I have noticed the javascript answer to do the same, and this change would make our answers byte to byte equivalent. – my pronoun is monicareinstate – 2017-10-02T13:41:17.790

2

Perl 5, 16 bytes

$_=0|$_*$_/2+.5

Try it online!

Xcali

Posted 2017-10-02T08:25:16.063

Reputation: 7 671

$_=$_*$_+1>>1 14 bytes – Nahuel Fouilleul – 2017-10-04T08:11:33.480

2

MATL, 5 bytes

UH/Xk

Try it online!

Cinaski

Posted 2017-10-02T08:25:16.063

Reputation: 1 588

1or UQ2/k at the same byte count. – Giuseppe – 2017-10-02T13:31:09.547

2

Cubix, 11 bytes

Iu*:^\)2,O@

Heheh, :^\)

Try it online!

Expands to the following cube:

    I u
    * :
^ \ ) 2 , O @ .
. . . . . . . .
    . .
    . .

Which is the same algorithm that many use.

  • ^Iu : read in input as int and change directions
  • :* : dup top of stack, multiply
  • \) : change direction, increment
  • 2, : push 2, integer divide
  • O@ : print output as int, end program.

Giuseppe

Posted 2017-10-02T08:25:16.063

Reputation: 21 077

2

Mathematica, 12 bytes

⌈#^2/2⌉&

J42161217

Posted 2017-10-02T08:25:16.063

Reputation: 15 931

211 bytes: ⌈#.5#⌉& – user202729 – 2017-10-05T00:48:33.873

2

Pyke, 3 bytes

Xhe

Try it here!

X   -   input ** 2
 h  -  ^ + 1
  e - floor_half(^)

Blue

Posted 2017-10-02T08:25:16.063

Reputation: 26 661

I ninja'd you by about 12 hours :-/

– Mr. Xcoder – 2017-10-03T11:56:59.100

2

Ohm v2, 3 bytes

²½ı

Try it online!

² squares, ½ halves, ı ceils.

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

1

Jelly, 3 bytes

-1 thanks to Mr. Xcoder.

Based on my APL solution.

²HĊ

Try it online!

² Square

HHalve

ĊCeiling (round up)

Adám

Posted 2017-10-02T08:25:16.063

Reputation: 37 779

1

Japt, 4 bytes

Been sitting on these since the challenge was closed.

²Ä z

Try it

Explanation: Square, add 1, floor divide by 2


Alternative

²ÄÁ1

Try it

Explanation: Square, add 1, bit-shift right by 1.

Shaggy

Posted 2017-10-02T08:25:16.063

Reputation: 24 623

1

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%
$                  Read input as number.
 :                 Set notepad value (face 6) to input.
  *                Multiply notepad value with itself.
   FDF'            Scramble the cube so face 8 value will be 1 
                   (unsolved) and face 0 value will be 2.
       +8          Add 1 (face 8 value) to notepad value.
         /0        Divide notepad value by 2 (face 0 value),
                   get integer part.
           %       Output notepad value as number.

This program works because ceil(n^2 / 2) == floor((n^2 + 1) / 2).

user202729

Posted 2017-10-02T08:25:16.063

Reputation: 14 620

Save 1 byte by replacing *7 with * as * implicitly is equivalent to *6, another byte by replacing %6 with %. Thanks for suggesting these changes! – MD XF – 2017-10-08T21:39:35.817

:7 can be replaced with :, %6 can be replaced with %, and *7 can be replaced with *6 which can be replaced with *. Also, the rule about languages/interpreters needing to be older than the language was revoked, so the golfed program does not need to be non-competing. – MD XF – 2018-01-09T03:30:09.267

1

Commentator, 19 bytes

//{-//-}! {-#  -}<!

Try it online!

Who needs golfing languages? I've got confusing languages!

Ungolfed version:

5//{-8}//{5-}
print(10!= 5)
x={-1,3,4} # Smiley :-}
print(5<!=10)*/ # Weird comparision.

Try it online!

How does it work? I'll explain, with input 5

//                         - Take input.                           Tape: [5 0 0]
  {-//-}!                  - Square the input.                     Tape: [25 0 0]
  {-                         - Move one along the tape
    //                       - Copy the input to the tape.         Tape: [5 5 0]
      -}                     - Move one back along the tape
        !                    - Take the product of the tape.       Tape: [25 5 0]
         <space>           - Increment the tape head.              Tape: [26 5 0]
                 {-#  -}<! - Halve the tape head (floor division). Tape: [13 2 0]
                 {-          - Move one along the tape
                   #         - Set the tape head to 2.             Tape: [26 2 0]
                      -}     - Move one back along the tape
                        <!   - Reduce the tape by floor division.  Tape: [13 2 0]

caird coinheringaahing

Posted 2017-10-02T08:25:16.063

Reputation: 13 702

1

OCaml, 19 bytes

let f n=(n*n+1)/2;;

Try it online!

I'm a bit bummed the name got changed from "camels" to "wazirs" before I managed to write this, but I figured I'd post it anyway.

Giuseppe

Posted 2017-10-02T08:25:16.063

Reputation: 21 077

1

TI-Basic, 7 bytes

round(Ans²/2,0

Alternatively (8 bytes):

int(Ans²/2+.5

Timtech

Posted 2017-10-02T08:25:16.063

Reputation: 12 038

-int(-.5Ans² also works – Oki – 2017-10-05T14:56:27.347

@Oki It sure does. I just wish they had a ceil( function. – Timtech – 2017-10-05T17:55:36.487

1

///, 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.

user202729

Posted 2017-10-02T08:25:16.063

Reputation: 14 620

0

Husk, 3 bytes

⌈½□

Try it online!

The code is pretty much self-explanatory:

  • Square.

  • ½ Halve.

  • Ceil.

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

? Hust uses APL symbols :-) – Adám – 2017-10-02T16:19:59.297

0

Java 8, 20 11 bytes

i->i*i+1>>1

Roberto Graham

Posted 2017-10-02T08:25:16.063

Reputation: 1 305

1i->(i*i+1)/2 (with int instead of double as return type) is shorter (12 bytes). And i->i*i+1>>1 (11 bytes) is probably the shortest. – Kevin Cruijssen – 2017-10-02T13:38:21.847

0

Convex, 5 bytes

{²½¯}

Try it online!

This is the same as CJam's {2#2./m]}.

Erik the Outgolfer

Posted 2017-10-02T08:25:16.063

Reputation: 38 134

0

,,,, 7 bytes

2*1+1»

Try it online!

Yay, commata works for something!

Fudge, I didn't implement ceiling...

totallyhuman

Posted 2017-10-02T08:25:16.063

Reputation: 15 378

0

Neim, 3 bytes

ᛦ>ᚺ

Try it online!

Okx

Posted 2017-10-02T08:25:16.063

Reputation: 15 025

0

Gaia, 3 bytes

sḥ⌉

Try it online!

s squares, halves, ceils.

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

0

RProgN 2, 6 bytes

2^1+2÷

Try it online!

Mr. Xcoder

Posted 2017-10-02T08:25:16.063

Reputation: 39 774

0

PocoLithp, 21 bytes

(#(N)(/(+(* N N)1)2))

Anonymous lambda taking argument N. Can be used in either of the following ways:

  • ((#(N)(/(+(* N N)1)2))7) - call with argument 7

  • (begin (define camel (#(N)(/(+(* N N)1)2))) (camel 7))

Enter either of these lines into the REPL to test.

This language was created a few weeks ago, and the most recent changes a day ago are just bug fixes.

Andrakis

Posted 2017-10-02T08:25:16.063

Reputation: 361

0

ARBLE, 11 bytes

ceil(n^2/2)

Try it online!

ATaco

Posted 2017-10-02T08:25:16.063

Reputation: 7 898

0

Bash, 18 bytes

echo $[$1*$1+1>>1]

Try it online

Nahuel Fouilleul

Posted 2017-10-02T08:25:16.063

Reputation: 5 582

0

Add++, 13 bytes

+?
^2
+1
/2
O

Try it online!

Looks like I got here too late (again)

caird coinheringaahing

Posted 2017-10-02T08:25:16.063

Reputation: 13 702

0

ASP, 13 bytes

a((x*x+1)/2).

Call with clingo -c x=7 or by putting #const x=7. in source.

aluriak

Posted 2017-10-02T08:25:16.063

Reputation: 141

0

Haskell, 18 bytes

w n=ceiling(n*n/2)

Run as:

main = print $ w n

Where n is the input number.

Pharap

Posted 2017-10-02T08:25:16.063

Reputation: 195

0

FALSE, 6 bytes

$*1+2/

Explanation:

  • $ duplicate top of stack
  • * multiply
  • 1 push 1
  • + add
  • 2 push 2
  • / divide

False only has 32-bit integers.

Pharap

Posted 2017-10-02T08:25:16.063

Reputation: 195

0

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

Ruslan

Posted 2017-10-02T08:25:16.063

Reputation: 1 283

0

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)

Wernisch

Posted 2017-10-02T08:25:16.063

Reputation: 2 534

-1

JavaScript (ES8), 16 bytes

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

user75217

Posted 2017-10-02T08:25:16.063

Reputation: 1