Wc3C.net JASS quicksilver contest Round #1 (winners announced)
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

10-16-2006, 08:27 PM   #1
Vexorian
Free Software Terrorist

Technical Director

Join Date: Apr 2003
Posts: 14,898

Submissions (37)

JASS quicksilver contest Round #1 (winners announced)

Hello, let's see what's the deal here, remember the JASS survival challenge? Why did it fail? I think that it is because It required me to deal with up to 3 contests at the same time and I wasn't even able to deal with 2 of them, then I also had 2 think a lot of problem statements and make sure they had a very fair difficulty classifcation which was, seriously too difficult.

Yet I notice we need contests. So I am introducing you all these ones which are shorter and less fixed to some rules that made it impossible for me to do stuff.

Rules
- I release a problem.
- People try to solve
- Up to 1 week to get results
- Post solutions in pastebin, with a [quicksilver] preffix.
- 3 Fastest (take less time) solutions that solve the problem win.
- If somebody is too good I can classify him as too good for a round that would seem too easy for him, so more people have a chance.

Round one: The polish

There is an strange arithmetic language out there with these symbols:
• * : product
• ! : factorial
• (lowercase letter) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) : variable

A valid formula is :
- A variable (lowercase letter)
- ! preceding a valid formula
- + preceding 2 valid formulas
- * preceding 2 valid formulas

You have to make a function LargestValidFormula takes string symbols returns string
It takes a string with 1 to 100 characters containing some characters and returns the largest valid formula you can get with the symbols in the input (without repeating any of them)

If there are more like one result, either is a correct answer.

Examples

LargestValidFormula("a") returns "a"

LargestValidFormula("a+b") returns "+ab" or "+ba"

LargestValidFormula("+*!aa") returns "!+aa" or "+!aa" or "+a!a" or "!*aa" or "*!aa" or "*a!a"

LargestValidFormula("abcdefg!") returns "!b" or "!a" or "!c" , etc

LargestValidFormula("+++aaaa") returns "+a+a+aa" or "++aa+aa" or "+++aaaa"

LargestValidFormula("A") returns ""

Edit: The results of the survival challenge will come up eventually and we will have awards there.

Update : October 24th: Results announced

First place: Blu_da_noob (0.037267028 seconds)
Second place: Acehart (0.085897792 seconds)

Disqualified:
- Mathias (Limit op exceeded)

It was rather easy, the first thing you could notice is that the only case in which "" is returned is when there are no variables in the input.

Then you can figure out that all the unary operators can be added simply before a variable to get the result.

And that if you unify a binary operator and a variable they can become an unary operator so they follow above's rule.

This is my solution:
JASS:
globals
string factorialchars = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
string prodchars      = "****************************************************************************************************"
string pluschars      = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
endglobals
function LargestValidFormula takes string s returns string
local string c
local string r=""
local integer i=0
local integer L =StringLength(s)

local integer plus=0
local integer prod=0
local integer fact=0
local string  vars=""
local integer varn

loop

exitwhen i==L
set c=SubString(s,i,i+1)
set i=i+1

if (c=="!") then
set fact=fact+1
elseif (c=="+") then
set plus=plus+1
elseif (c=="*") then
set prod=prod+1
elseif (StringCase(c,true)!=c) then
set vars=vars+c
endif
endloop
set varn=StringLength(vars)

if (varn==0) then
return ""
endif

if ( varn > plus+prod) then
set varn=plus+prod+1
else
set i=varn-1
if (plus>=i) then
set plus=i
set prod=0
elseif (prod>=i) then
set prod=i
set plus=0
else
set plus=i-prod
endif
endif

return SubString(factorialchars,0,fact)+SubString(pluschars,0,plus)+SubString(prodchars,0,prod)+SubString(vars,0,varn)
endfunction
• In order to save the game some time, I avoid creating strings during the process so I only use counters, the variables part must use strings though.
• In this case the binary + variable becomes unary is still latent, but I just have it work as (binary)(exp)(variable) instead of (binary)(variable)(exp) it works the same.
• Then the result is always: (All the unary operators)( (x - 1) binary operatos )( x variables ) , where x depends on the input. Unless, there are no variables in the input then the result is ""
• Calculating x is the last problem, if there are more variables than binary operators, then x is (number of binary operators)+1 , else it is the number of variables present in the input and the number of binary operators in the output should change to x-1.

- Mathias, used a brute force approach, although it is not the fastest solution it is a good idea to check it in order to see how brute force works.

- Griffen's submission would have been the fastest if it wasn't for the error.

I am including a map with the test environment and all the submissions.
Attached Files
 quicksilver.w3x (56.6 KB, 27 views)
__________________
 Wc3 map optimizer 5.0 Someone should fix .wav sound in this thing. JassHelper 0.A.2.A Turns your simple code into something that is complicated enough to work.
 Wc3 map optimizer 5.0 JassHelper 0.A.2.A Xye 0.12.1 | Editor/Levels xe0.9 CS16.0 My spells jEdit modes for vJass&Zinc (v9) WarCiTy 0.2.0
Faster != more useful

10-16-2006, 09:32 PM   #2
Captain Griffen

Content Director

Join Date: Sep 2003
Posts: 5,375

Submissions (2)

*confused*
__________________
Quote:
 Originally Posted by Earth-Fury Griffen is correct, you are not.
Quote:
 [13:32] hmm.. stil i want to have some unused women

 10-16-2006, 10:07 PM #3 UnMi User     Join Date: Aug 2006 Posts: 213 Submissions (1) ... ... ... Unlike the last two Problems you used to post, I do not understand a single bit of this one.
 10-16-2006, 11:28 PM #4 SeasonsOfLove A Nitpicky Map Reviewer   Official Map Reviewer   Join Date: Aug 2003 Posts: 257 I understand the problem. You're given a string with a bunch of symbols, all of which are either a variable (lowercase letter), an !, a *, or a +. You have to find the longest valid formula, which involves: A variable (a) A ! preceding one valid formula (!a, !+ab, !*ab) A * or + preceding two valid formulas (*ab, +ab, *!a!b, +*!a!b*!a!b) The hardest part for this is figuring out what he means by the question. Once you get that, it should become easier to figure out. __________________ Clan TDG - Quality mapmaking, dedicated playtesting.
 10-16-2006, 11:45 PM #5 Naakaloh User     Join Date: Jun 2003 Posts: 619 Submissions (2) It's not to hard to understand; there's just one issue I'd like to confirm. Could the example "abcdefg!" return "!a", "!b", "!c", etc.? __________________ "The geeks will play their game." - Kowalski
 10-17-2006, 01:14 AM #6 Chuckle_Brother Oh for the sake of fudge   Respected User   Join Date: Dec 2005 Posts: 782 Submissions (2) Yeah its pretty easy to understand, but implementation may be a bit more difficult. Edit: Something I don't get though are what would be considered valid formulas, I am gonna have to write this all out based on your little priority table. @Vex: You state "without repeating any of them", does this mean that if you have 3 ! in a symbol line for example you can use ! 3 times as Seasons seems to believe? Or can you use only one ! in the final product? __________________ "...you play a mean banjo" Last edited by Chuckle_Brother : 10-17-2006 at 01:28 AM.
10-17-2006, 02:14 AM   #7
Vexorian
Free Software Terrorist

Technical Director

Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Quote:
 It's not to hard to understand; there's just one issue I'd like to confirm. Could the example "abcdefg!" return "!a", "!b", "!c", etc.?
Yes.

Quote:
 @Vex: You state "without repeating any of them", does this mean that if you have 3 ! in a symbol line for example you can use ! 3 times as Seasons seems to believe? Or can you use only one ! in the final product?

You can use up to 3 "!" in that case
__________________
 Wc3 map optimizer 5.0 Someone should fix .wav sound in this thing. JassHelper 0.A.2.A Turns your simple code into something that is complicated enough to work.
 Wc3 map optimizer 5.0 JassHelper 0.A.2.A Xye 0.12.1 | Editor/Levels xe0.9 CS16.0 My spells jEdit modes for vJass&Zinc (v9) WarCiTy 0.2.0
Faster != more useful

 10-17-2006, 02:41 AM #8 Chuckle_Brother Oh for the sake of fudge   Respected User   Join Date: Dec 2005 Posts: 782 Submissions (2) Ahh excellent. Many thanks for the clearup. __________________ "...you play a mean banjo"
10-17-2006, 11:50 AM   #9
DotA_DR
User

Join Date: Aug 2006
Posts: 29

Quote:
 - Post solutions in pastebin, with a [quicksilver] preffix.
pastebin - what it is?

 10-17-2006, 12:09 PM #10 Thunder_Eye Lol I got a custom title!     Join Date: Aug 2004 Posts: 1,236 http://www.wc3campaigns.net/pastebin.php __________________
10-17-2006, 03:41 PM   #11
Rising_Dusk
Obscurity, the Art

Projects Director

Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Quote:
 Originally Posted by Vexorian Yet I notice we need contests.
So why did noone start the next spell contest?
Sheesh. :/
__________________

 10-17-2006, 03:57 PM #12 moyack Evil Emoticon   Respected UserProject Leader: PoC   Join Date: Jan 2006 Posts: 3,279 Submissions (17) YEAHHH, Spell contest!!! I need to make spells now!!
10-17-2006, 04:06 PM   #13
Fulla
Evil Overlord

Join Date: Jan 2006
Posts: 1,416

Submissions (3)

Quote:
 Originally Posted by Rising_Dusk So why did noone start the next spell contest? Sheesh. :/

Agreed

Was hoping to enter a jass spell :D
__________________

Last edited by Fulla : 10-17-2006 at 04:07 PM.

 10-17-2006, 04:16 PM #14 Rising_Dusk Obscurity, the Art Projects DirectorProject Leader: OD   Join Date: Feb 2006 Posts: 9,729 Submissions (27) I mean seriously, if people are too busy to start the spell sessions up again... I'll sacrifice my ability to partake in it and run it myself. Seriously though, we need spell sessions. They're always very popular and fun to participate in. __________________
10-17-2006, 04:30 PM   #15
moyack
Evil Emoticon

Respected User

Join Date: Jan 2006
Posts: 3,279

Submissions (17)

Quote:
 Originally Posted by Rising_Dusk I mean seriously, if people are too busy to start the spell sessions up again... I'll sacrifice my ability to partake in it and run it myself. Seriously though, we need spell sessions. They're always very popular and fun to participate in.

I'm with Rising, besides I think that one of JASS objectives is to make custom spell, and the best way to make some honour to this language is with a spell contest.