I don't get how to get around this - I need a hintier hint please ;)
I assume there's some bind() thing that I'm missing, but as far as I can tell the error comes from teh call, not the function that is called? SO I can't work out how to modify the scope of the test
When I see returning a pointer in a C++ version of a kata, I beat my head against a nearby wall and switch to a different language. Even more so when I see returning a pointer to a pointer for a rectangular array.
As for the terms, int[4][4] is what I'd call a multidimensional array, while an array of arrays is just an array of arrays.
In C++ after you create an array of arrays you can use [][] for multidimensional indexing.
But you can not declare an array of array by writing [][]!
In C++ the mentioned int ans[4][4] is just one array: int *ans. Meaning that it's equivalent with int ans[16] and the compiler is nice enough to do the reindexing for you.
It is used to make sure that every sub-array's dimension is equal, or to ensure that the allocation of the n x n element is contiguous, hence it is one (contiguous) array.
True multidimensional arrays on the other hand can be "anywhere" in memory, only sub-arrays will be contiguous, not the whole.
And to hell: even every sub-array can have different dimension!
The functions are expecting int **, so you have to create an array of int * first, then the sub-arrays in that.
Many solution used the new[] allocation... but I really hate the idea to using new without delete, so I went with static (aka globals :) ).
I know, but I don't know how to apply arguments to the block { having(5).fingers }. I can't understand why the block { having(5).fingers } accepts no arguments (instead of { |x| having(5).fingers.call(x) }).
I am surprised this approach does not time out. Tried myself. 11.9s for the full test, good job!
I don't get how to get around this - I need a hintier hint please ;)
I assume there's some bind() thing that I'm missing, but as far as I can tell the error comes from teh call, not the function that is called? SO I can't work out how to modify the scope of the test
Solved.
_rqy dalao!
Ooh I like that your "nothing" value for
Min
was namedInf
, that makes more semantic sense in context than myNaught
.Should the type signature of
def
in Hints beSomeMonad SomeVariable -> Integer
?When I see returning a pointer in a C++ version of a kata, I beat my head against a nearby wall and switch to a different language. Even more so when I see returning a pointer to a pointer for a rectangular array.
As for the terms,
int[4][4]
is what I'd call a multidimensional array, while an array of arrays is just an array of arrays.In C++ after you create an array of arrays you can use
[][]
for multidimensional indexing.But you can not declare an array of array by writing
[][]
!In C++ the mentioned
int ans[4][4]
is just one array:int *ans
. Meaning that it's equivalent withint ans[16]
and the compiler is nice enough to do the reindexing for you.It is used to make sure that every sub-array's dimension is equal, or to ensure that the allocation of the n x n element is contiguous, hence it is one (contiguous) array.
True multidimensional arrays on the other hand can be "anywhere" in memory, only sub-arrays will be contiguous, not the whole.
And to hell: even every sub-array can have different dimension!
The functions are expecting
int **
, so you have to create an array ofint *
first, then the sub-arrays in that.Many solution used the
new[]
allocation... but I really hate the idea to usingnew
withoutdelete
, so I went with static (aka globals :) ).Oh sorry, I'm too naive(and yesterday I'm too tired to think about it).
This comment is hidden because it contains spoiler information about the solution
It's not mathematics, it's category theory.
The
Greatest
kata I have solved!Until this moment I can't believe these things in programming (types, classes, and so on) have so much to do with mathematics.
Could someone tell me where (or how) to learn more about this?
Oh maybe I know how to do that. Thank you! :)
Yes, that's the only ugly part is this kata, which requires some ugly hacks to make it work.
Tip: Some stuff doesn't need to be declared (like
|x|
) to be used. Think about why ;-)I know, but I don't know how to apply arguments to the block
{ having(5).fingers }
. I can't understand why the block{ having(5).fingers }
accepts no arguments (instead of{ |x| having(5).fingers.call(x) }
).Loading more items...