-1
1
A string like this one:
"a, 4.25, ((true, 5), 3, (false, false, false)), abc"
Describes a tree with 13 nodes, 9 of which are leaf nodes. In C# the leaf nodes in this example would be of types string
, float
and bool
, this differs between languages and depending on your implementation. The important structure forming symbols here are ,
(
and )
with spaces being ignored.
See the diagram in David Carrahers answer for a tree of the desired shape.
var a = new cake(4, "abc")
The above contains 8 symbols, I'm counting bracket and "
pairs as a half and things like .
as 1.
The goal is to write code with the fewest symbols which given a string like the one shown above, creates the tree it represents.
For example in the form of arrays inside each other, or interconnecting node objects.
60 extra points if you don't sort of cheat by adjusting the input string slightly then executing it.
I won't count the symbols that define the input string.
daniero
100 - (10 symbols)
+40 points for understanding numbers, strings, bools
and any other basic types the language understands.
+20 points for using a reasonably general language.
150 total points
fejesjoco
100 - (est 37 symbols)
+20 points for it understanding numbers as well as strings.
+40 points for using a reasonably general language.
97 total points
tomas
100 - (10 symbols)
90 total points
David Carraher
100 - (est 19 symbols)
81 total points
2Looks like homework, basic tokenizing as part of writing a script interpreter. – None – 2014-02-07T11:49:06.877
Please define the exact syntax of the string. – fejesjoco – 2014-02-07T13:00:21.840
I only see 12 nodes, can you explain it a bit better? – Teun Pronk – 2014-02-07T13:56:58.463
@TeunPronk I guess the 13th is the root node. – Joel Bosveld – 2014-02-07T14:27:05.563
The 13th node is the root, although this dosn't matter greatly. It's not homework or a part of a course. – alan2here – 2014-02-07T17:11:55.617
Why don't you give examples of the output you are expecting? – DavidC – 2014-02-08T02:31:24.253
*"[...] creates the tree it represents."* There are a lot of ways to form a tree out of a list. What defines a token (i.e. are your stings comma and space delimited, and why two delimitters)? What imposes structure on the tree (i.e are the parenthesis intended to indicate sub-trees)? Is the tree expected to be binary? This is very weakly specified, and consequently is not going to generate a very interesting set of responses. You can get help with these kinds of problems in chat or by posting to one of the meta sand-boxes.
– dmckee --- ex-moderator kitten – 2014-02-08T14:54:02.830The question now has more detail. Now I'd like to see your solution dmckee :) – alan2here – 2014-02-08T16:41:43.983
How is "adjusting input string" cheating? How is using symbols a bad thing? I don't understand the purpose of this challenge any more. It started as a good question but then you spoiled it with nonsense - and changed rules on the run! Retracting my upvote and -1! – Tomas – 2014-02-09T14:32:48.303
Symbols is equivalent to characters, see the description for the atomic-code-golf tag, most challenges here are for short code. And a solution like "s.toTree();" where "s" is the input string is not really a solution. – alan2here – 2014-02-09T21:47:40.443