Omnimaga

Calculator Community => Contests => Community Contests => Topic started by: JWinslow23 on September 01, 2014, 11:56:35 am

Title: [ENDED] Code Golf Contest #8
Post by: JWinslow23 on September 01, 2014, 11:56:35 am
This challenge should confuse some people.

NEXT: Here (http://www.omnimaga.org/other-calculator-discussion-and-news/code-golf-contest-9)
PREVIOUS: Here (http://www.omnimaga.org/other-calculator-discussion-and-news/code-golf-contest-7)

Challenge 8

Problem

Check if a string is conveniently palindromic, and output 1 if it is and 0 if it isn't. This means that the char pairs () {} [] <> should be handled such that strings such as
Code: [Select]
(<)i(>)
<}<{}>{>
][()][
}{[]}{
would return 1, and strings like
Code: [Select]
())(
<(){}[][}{)(<
(({))
<<
would return 0.
Case insensitive when possible.

Deadline
September 8, 2014, 1:00 AM EST

If any further clarification is needed, contact me. I'll try not to get everything backwards for you. (*crickets* Seriously, nothing? :/ )

Golfscript
RankUserSizeDateCode
1JWinslow23689/1/2014 2:39:28 PM
Spoiler For Spoiler:
{.96>32*-}/]''+.['()''{}''[]''<>']{.(;\);@1$/"\0"*2$/\*"\0"/\*}/-1%=

Ruby2
RankUserSizeDateCode
1Juju639/1/2014 2:59:26 PM
Spoiler For Spoiler:
p (a=gets.chop.upcase)==a.reverse.tr("[{(<>)}]","]})><({[")?1:0

TI-83+ BASIC
RankUserSizeDateCode
1JWinslow231779/2/2014 5:43:43 PM
Spoiler For Spoiler:
" "+Ans+" ->Str1
Ans->Str3
"({[<)}]>->Str2
For(X,1,length(Str1
For(Y,1,4
sub(Str1,X,1
5(Ans=sub(Str2,Y,1))+(Ans=sub(Str2,Y+4,1
If Ans
sub(Str1,1,X-1)+sub(Str2,Y+Ans-1,1)+sub(Str1,X+1,length(Str1)-X->Str1
End
End
Str1
For(X,1,length(Ans)-1
sub(Ans,2X,1)+Ans
End
Str3=sub(Ans,1,X

Nspire Lua
RankUserSizeDateCode
1Jens_K1459/4/2014 4:52:18 PM
Spoiler For Spoiler:
function cgc8(s)
R=1
r="<>()[]{}/\\"l=s:len()for i=1,l do
p=r:find(s:sub(i,i),1,1)or 0
p=p+p%2*2-1
q=l-i+1
R=p>0 and r:sub(p,p)~=s:sub(q,q)and 0 or R
end
print(R)
end

Language Ranking
RankLangUserSizeDate
1Ruby2Juju639/1/2014 2:59:26 PM
2GolfscriptJWinslow23689/1/2014 2:39:28 PM
3Nspire LuaJens_K1459/4/2014 4:52:18 PM
4TI-83+ BASICJWinslow231779/2/2014 5:43:43 PM
Title: Re: Code Golf Contest #8
Post by: Juju on September 01, 2014, 11:59:06 am
This one should be interesting. Also, 52 bytes.
Title: Re: Code Golf Contest #8
Post by: alberthrocks on September 01, 2014, 12:19:06 pm
If any further clarification is needed, contact me. I'll try not to get everything backwards for you. (*crickets* Seriously, nothing? :-\ )
I liked it! ;)

Quick question - is this case sensitive or insensitive?
Title: Re: Code Golf Contest #8
Post by: Princetonlion.tibd on September 01, 2014, 12:21:19 pm
I think I can do this :D
68k BASIC.
Title: Re: Code Golf Contest #8
Post by: calc84maniac on September 01, 2014, 12:22:42 pm
If any further clarification is needed, contact me. I'll try not to get everything backwards for you. (*crickets* Seriously, nothing? :/ )
I liked it! ;)

Quick question - is this case sensitive or insensitive?

On a related note, are we supposed to handle characters that aren't parentheses/brackets, and if so, do those also have to produce a palindrome?

For example, (b]o[b)
Title: Re: Code Golf Contest #8
Post by: Princetonlion.tibd on September 01, 2014, 12:24:54 pm
I think so, as it says
Check if a string is conveniently palindromic, and output 1 if it is and 0 if it isn't.
Title: Re: Code Golf Contest #8
Post by: Hayleia on September 01, 2014, 12:27:09 pm
How is the string supposed to be input ? I mean, from what I read, nothing prevents me from saying that my program only works when the string is copied in L1 (in Axe) without caring how it got in L1 since the problem is just "check", not "input and check" :P
Title: Re: Code Golf Contest #8
Post by: Adriweb on September 01, 2014, 12:53:13 pm
so, convieniently palindromic for letters, it'd be for "b" and "d", and "p" and "q" ? (also symetrical letters in themselves like "i", "l", "o", "v", "w", "x")

For example : b(][)d is conviniently palindromic, but not b(][)b

Looks harder if we have to handle chars different than brackets :P
Title: Re: Code Golf Contest #8
Post by: JWinslow23 on September 01, 2014, 01:00:42 pm
I shall change the rules to accomodate those kinds of letter pairs. () {} [] <> /\
Title: Re: Code Golf Contest #8
Post by: calc84maniac on September 01, 2014, 01:23:10 pm
I guess TI-83+ implementations should handle two-byte tokens (such as lowercase letters) properly? That seems kind of annoying, but as long as it's consistent among the entries that would be fine with me.

Edit: Actually, case insensitivity would really kill my code (z80 assembly). It's super hard to scan backwards through a token string if you don't know the size the preceding token should be, and I get that size from the token it should match scanning forward.
Title: Re: Code Golf Contest #8
Post by: Juju on September 01, 2014, 03:20:06 pm
no chars except the bd and pq should be case sensitive
I agree, that's probably overkill. Either it's sensitive or insensitive, not a mix (although you can try if you want).
Title: Re: Code Golf Contest #8
Post by: JWinslow23 on September 01, 2014, 03:27:28 pm
Progress on my Golfscript entry:

Returns correct results for all test cases given. The program actually can handle any number of arbitrary pairs. It is now 72.
Title: Re: Code Golf Contest #8
Post by: JWinslow23 on September 02, 2014, 05:55:01 pm
Bump.

I have another entry! TI-BASIC.