[challenge] Da Impossibru Math

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 2259 Views - Last Post: 20 October 2015 - 07:07 PM

#16 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 456
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: [challenge] Da Impossibru Math

Posted 19 October 2015 - 07:14 PM

Aha! No, no further changes to the challenge rules. ; )

From the beginning I thought about making so many restrictions on operators as to make you think it's about some really quirky and obscure usage of the language, when in reality, I haven't said anything about forbidding the inclusion of standard facilities - and there's <functional> with everything needed to make the challenge as easy as it gets. : )

However, you of course can do it without <functional>. ; )

This post has been edited by Xupicor: 19 October 2015 - 08:07 PM

Was This Post Helpful? 0
  • +
  • -

#17 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5824
  • View blog
  • Posts: 19,835
  • Joined: 05-May 12

Re: [challenge] Da Impossibru Math

Posted 19 October 2015 - 07:42 PM

Seems like fair game to me since those are not overloads. And even if they were to be treated as overloads, the list above did not include operator() which the functors use.
Was This Post Helpful? 0
  • +
  • -

#18 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1739
  • View blog
  • Posts: 5,895
  • Joined: 03-August 09

Re: [challenge] Da Impossibru Math

Posted 19 October 2015 - 08:23 PM

here is a really terrible way to get the inverse of something which is all we are really missing (go teamwork!)

Spoiler


I'm not sure how satisfying this is however.

This post has been edited by ishkabible: 19 October 2015 - 08:27 PM

Was This Post Helpful? 0
  • +
  • -

#19 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5824
  • View blog
  • Posts: 19,835
  • Joined: 05-May 12

Re: [challenge] Da Impossibru Math

Posted 19 October 2015 - 08:38 PM

Here's the version using <functional>:
Spoiler

Was This Post Helpful? 2
  • +
  • -

#20 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5824
  • View blog
  • Posts: 19,835
  • Joined: 05-May 12

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 05:17 AM

ishkabible: Why not cast to bool for smaller range?
Was This Post Helpful? 0
  • +
  • -

#21 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 456
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 06:25 AM

I've got some ideas how to do it without <functional>.

Spoiler



Could you do it without using standard library facilities, though?
Spoiler

This post has been edited by Xupicor: 20 October 2015 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

#22 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1739
  • View blog
  • Posts: 5,895
  • Joined: 03-August 09

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 10:06 AM

View PostSkydiver, on 20 October 2015 - 01:17 PM, said:

ishkabible: Why not cast to bool for smaller range?


The range is -100 to 100 so if I cast to a bool I'll miss out on all the negatives and anything higher than 1. With char I get -128 to 127 which is probably about as small as I can get things without mod or some bitwise operators.
Was This Post Helpful? 0
  • +
  • -

#23 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5824
  • View blog
  • Posts: 19,835
  • Joined: 05-May 12

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 10:33 AM

Ah, I see now what you wee trying to do. I completely misunderstood what the goal was due to lack of sleep.
Was This Post Helpful? 0
  • +
  • -

#24 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1739
  • View blog
  • Posts: 5,895
  • Joined: 03-August 09

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 12:14 PM

Here is the full submission using my idea for negation with Skydiver's modification of Salem_c's code as a base (anyone else want to get on this train?). I also used a switch as suggested. I tested it and it seems to work.

Spoiler


Also:
Spoiler

This post has been edited by ishkabible: 20 October 2015 - 12:45 PM

Was This Post Helpful? 0
  • +
  • -

#25 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 456
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 01:10 PM

That's some train. ; )

$ g++ -std=c++14 -pedantic -Wall -Wextra ishkakible.cpp -o ishka.exe && ./ishka.exe
ishkakible.cpp: In function 'int main()':
ishkakible.cpp:28:55: error: cast from 'char*' to 'unsigned int' loses precision [-fpermissive]
         result = (int)reinterpret_cast<unsigned int>(p);
                                                       ^
$ g++ --version
g++.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Hmm.

Let's try something different:
Compiler output — x86 clang 3.5.1 (clang version 3.5.1 (tags/RELEASE_351/rc2))
24 : error: use of undeclared identifier 'int8_t'
while(neg = (int8_t)rand(), &(&q[m])[neg]);
^
28 : error: cast from pointer to smaller type 'unsigned int' loses information
result = (int)reinterpret_cast<unsigned int>(p);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Compiler output — x86 gcc 5.2.0 (g++ (GCC-explorer-build) 5.2.0)
/tmp/gcc-explorer-compiler115920-68-1o7es42/example.cpp: In function 'int main()':
24 : error: 'int8_t' was not declared in this scope
while(neg = (int8_t)rand(), &(&q[m])[neg]);
^
24 : error: expected ')' before 'rand'
while(neg = (int8_t)rand(), &(&q[m])[neg]);
^
24 : error: 'rand' was not declared in this scope
while(neg = (int8_t)rand(), &(&q[m])[neg]);
^
28 : error: cast from 'char*' to 'unsigned int' loses precision [-fpermissive]
result = (int)reinterpret_cast<unsigned int>(p);
^
Compilation failed

This post has been edited by Xupicor: 20 October 2015 - 01:10 PM

Was This Post Helpful? 0
  • +
  • -

#26 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5824
  • View blog
  • Posts: 19,835
  • Joined: 05-May 12

Re: [challenge] Da Impossibru Math

Posted 20 October 2015 - 07:07 PM

More pointer math because I was too lazy to go all the way with the bitset idea I had...
Spoiler

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2