6502

Italy

gripho.it

Age: 49

Programmer... some infos on my personal webpage or something more structured on an older version (that is abandonware because I've yet to find a way to create time, so I had to take decisions instead).

1d
awarded Enlightened
1d
comment Avoid trailing zeroes in printf()
@paxdiablo: There's no need to dynamically create a format string for printf-like functions as they already support dynamic parameters (* special character): for example printf("%*.*f", total, decimals, x); outputs a number with the dynamically specified total field length and decimals.
1d
awarded Nice Answer
2d
revised Is it not possible to construct instances in a loop without a pointer?
added 83 characters in body
2d
answered Is it not possible to construct instances in a loop without a pointer?
2d
comment Why won't my comparison array work?
@Havamere: I'd probaly go for a dictionary instead. You start wih taken={} and do taken[row+"/"+col]=1 for each move. Before accepting a move if taken[row+"/"+col]===1 then the move is not valid... This way you don't need to make a loop.
2d
comment Why won't my comparison array work?
@Havamere: using == wouldn't solve because it's the same as === when the two expressions are of the same type. The difference is only that == does a type conversion when types are different (=== instead just returns false).
2d
answered Why won't my comparison array work?
2d
answered Unable To Assign Variable Within A described Function
2d
answered Threejs raycast not returning the correct point
Aug
29
revised about implementing a multi linked list
typo
Aug
29
answered Closest value (snapping)
Aug
29
revised Overlapping count of substring in a string in Python
added 225 characters in body
Aug
29
answered Overlapping count of substring in a string in Python
Aug
28
awarded Good Answer
Aug
26
comment Why can a floating point dictionary key overwrite an integer key with the same value?
@MarkRansom: an hash function that returns different outputs for inputs that compare equal is invalid (like also it would be invalid one that returns time.time() or random.random() or that calls sys.exit(1)). As perfectly explained by @immibis there is no real relation between hash and the fact that a dict cannot contain both 3 and 3.0 in different slots... the issue is in __eq__, not in __hash__.
Aug
26
comment Why can a floating point dictionary key overwrite an integer key with the same value?
@MarkRansom: sorry but probably I think my English is better than what it actually is. The hashing detail is irrelevant... what is relevant is equality comparison and that 3 == 3.0. A dict in python uses equality comparison to match keys (this is the key point) and that's why x[3] and x[3.0] are the same for a dict. It would be the same even without hash and just with linear scanning.
Aug
26
comment Why can a floating point dictionary key overwrite an integer key with the same value?
I find the discussion on hashing quite irrelevant. That is an implementation detail and an hash function that returns 42 for every value would be a valid albeit inefficient hash (thus you can never decide anything based on the hash value). The key point is that in Python 3 == 3.0 and that dictionary works on equality.
Aug
26
comment Why can a floating point dictionary key overwrite an integer key with the same value?
@leftaroundabout: if you like int and float to be different types then you shouldn't be happy with 3 == 3.0 either; but this is IMO highly annoying (even if OCaml guys think differently). If 3 == 3.0 then x[3] should be the same as x[3.0] too. 3.0000000001 on the other hand is something different and having it raising an error could help debugging problems. BTW note that double-precision numbers can represent exactly all integers with an absolute value less than 2^53... i.e. 9,007,199,254,740,992 (we're not going to have arrays that big around for quite a while).
Aug
26
comment Why can a floating point dictionary key overwrite an integer key with the same value?
@JeremyBanks: the difference for division was a "design bug" in Python 2.x that could not be fixed for backward compatibility and it has been fixed asap (i.e. in Python 3.x). I'd say that also the fact that you cannot use 3.0 as an array index is a bug and not a feature but may be Guido disagrees on this. Of course there are differences (e.g. type(3) and type(3.0) are not the same)... the point is if they are incidental differences (that we'd love to get rid of) or if they are desired differences...
1 2 3 4 5