Output 9876543210 without using numbers
Hi, Community!
Last weekend we held the Final of InterSystems Contest on InterSystems Caché and DeepSee as a part of IT Planet Student Championship in Sochi. BTW, this year we had about 2 000 participants in InterSystems Contest.
One of the tasks for the finals was to solve the following with Caché ObjectScript and use the minimum code.
Problem description
Write a method that would return the string 9876543210, however cls code should not contain numbers 0-9.
The goal is to write the shortest method.
Here's a method signature (it can't be modified):
ClassMethod main() As %StringAnd call sample:
USER>write ##class(ITPlanet.Task2).main() 9876543210
Also, here's the code to check your result's length:
ClassMethod length(class = {$classname()}, method = "main") As %Integer
{
#dim methodObj As %Dictionary.MethodDefinition
set methodObj = ##class(%Dictionary.MethodDefinition).IDKEYOpen(class, method)
quit methodObj.Implementation.Size
}
The best result was 25.
What's yours? ;)
It is not possible to past my result here, it will not work after that. But my result is 22.
Attached source with this method
contest.xml.zip
in expression mode it become 19
So the question boils down to "How to represent 0 using two symbols"
Fixed that
Awesome!
Check method reports 19.
Oops, looks like Sean beat me by a few minutes!
I think you need to call:
before compile.
Do not forget about the method signature:
Need not print the number, but return it.
21 in non-expression mode
My solution is following:
https://gist.github.com/adaptun/f04f15fc1474d57373d3f63928183284
Rhetorical question - for what?
If for fun, then this is possible.
But I will tell the solution here later.
Of course for fun!
Ok, exclusively for fun.
I made some improvements and now my score is 9, but if you try very hard, even - 0!
Who less ? ;)
Here is the code:
Nice! Next step is "-1" or less :-)
Not always, If $T was set to 1 before, then it is not reseted on entering the method Main()
Only just! :)
Good catch.
My result is 21.
It is similar to the variant of Alexander, but only _+"".
main ≠ Main
Only I noticed it?
}
*You may need to set your date and time settings to 2111-05-30 12:00:10 ;)
16
https://gist.github.com/SeanConnelly/a5c603399109bcaca9d196a0d19be205
19 in non-expression mode:
The actual class code contains a few control characters, but not ASCII 0-9.
I and [@Eduard Lebedyuk] came up with another solution. 28 symbols, though:
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue