Talk:Longest string challenge: Difference between revisions

Content added Content deleted
Line 53: Line 53:
: While I think about how to word it, let me explain. This site allows people to compare implementations in different languages. Restrictions force people to find other ways. To choose the road less traveled. Now this may require a technique that would be useful in some other problem but perhaps overkill in the simple unrestricted case. This can show people different techniques. The C contribution's cmp procedure is a case in point (I think). My C is very rusty (entirely seized up) and it doesn't look like a cheat to me. But I only have an inkling of how it may work. I'd have to crack my old copy of K&R and scratch my head a bit for it to be clear. A fluent C programmer would 't need to, but on the other hand they wouldn't be on this site to read code. Where I failed in the task description is to require people to provide some description of how they got around the restriction so that people coming from other languages will be able to understand. I'll add this to the task description. --[[User:Dgamey|Dgamey]] 13:01, 13 August 2011 (UTC)
: While I think about how to word it, let me explain. This site allows people to compare implementations in different languages. Restrictions force people to find other ways. To choose the road less traveled. Now this may require a technique that would be useful in some other problem but perhaps overkill in the simple unrestricted case. This can show people different techniques. The C contribution's cmp procedure is a case in point (I think). My C is very rusty (entirely seized up) and it doesn't look like a cheat to me. But I only have an inkling of how it may work. I'd have to crack my old copy of K&R and scratch my head a bit for it to be clear. A fluent C programmer would 't need to, but on the other hand they wouldn't be on this site to read code. Where I failed in the task description is to require people to provide some description of how they got around the restriction so that people coming from other languages will be able to understand. I'll add this to the task description. --[[User:Dgamey|Dgamey]] 13:01, 13 August 2011 (UTC)
:: Well, the <code>cmp</code> function doesn't contain arithmetic operators is not the same as the code uses no arithmetics. <code>&p[1]</code> is taking address of the next element of pointer <code>p</code>, i.e. <code>p + 1</code>. And <code>if (p)</code> is the same as <code>if (p != 0)</code>, so one may argue if that contains comparison operator: it certain contains comparison ''operation''. If these are allowed, because pointers can be converted to integers, there really isn't any restriction on arithmetics now: you can increment p by &p[1] and decrement it by &p[-1], you can compare it to zero, then you can do addition and subtraction; with those you can do mulplication and division; if you work hard enough you can probably get a whole math library in there. --[[User:Ledrug|Ledrug]] 19:57, 13 August 2011 (UTC)
:: Well, the <code>cmp</code> function doesn't contain arithmetic operators is not the same as the code uses no arithmetics. <code>&p[1]</code> is taking address of the next element of pointer <code>p</code>, i.e. <code>p + 1</code>. And <code>if (p)</code> is the same as <code>if (p != 0)</code>, so one may argue if that contains comparison operator: it certain contains comparison ''operation''. If these are allowed, because pointers can be converted to integers, there really isn't any restriction on arithmetics now: you can increment p by &p[1] and decrement it by &p[-1], you can compare it to zero, then you can do addition and subtraction; with those you can do mulplication and division; if you work hard enough you can probably get a whole math library in there. --[[User:Ledrug|Ledrug]] 19:57, 13 August 2011 (UTC)
::: Thanks for the explanation, my rusty old C memory had it about half figured out. Now while there is admittedly an end of string comparison and pointer advancement happening, I think this passes the spirit of the task. The implicit end of string test is a != comparison for a very specific purpose and the addressing is implicitly moving through a string. Looking at the solutions posted to the Unicon TWiki, automatically advancing a character was fine but if someone used s[p+1] it was considered in violation of the intent. --[[User:Dgamey|Dgamey]] 05:33, 14 August 2011 (UTC)


==Icon uses boolean datatypes==
==Icon uses boolean datatypes==