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 %String
And 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? ;)

Vote up!
Vote down!

Rating: 4

Comments: 14 Views: 386

9 answers

Answer

As large as 20 chars in expression mode.

/// ("鑔" = chǎ - small cymbals) * ("斚" = jiǎ - a small ancient stone cup for libations)
ClassMethod main() As %String [ CodeMode = expression ]
{
$a("鑔")_$q*$a("斚")
}
Vote up!
Vote down!

Rating: 0

Answer

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

Vote up!
Vote down!

Rating: 1

Answer

21 in non-expression mode

My solution is following:
https://gist.github.com/adaptun/f04f15fc1474d57373d3f63928183284

Vote up!
Vote down!

Rating: 1

Answer

My result is 21.

It is similar to the variant of Alexander, but only _+"".

Vote up!
Vote down!

Rating: 1

So the question boils down to "How to represent 0 using two symbols"

Vote up!
Vote down!

Rating: 0

Rhetorical question - for what?
If for fun, then this is possible.
But I will tell the solution here later.

Vote up!
Vote down!

Rating: 0


 

Of course for fun!

Vote up!
Vote down!

Rating: 0

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:

Class ITPlanet.Task2 Abstract ]
{

Parameter p = {$zwbunpack("㤸㜶㔴㌲㄰")};

ClassMethod main() As %String
{
 ..#p
}

}

Class ITPlanet.Test Abstract ]
{

ClassMethod length(
  class = {$classname()},
  method "main"As %Integer CodeMode = expression ]
{
##class(%Dictionary.MethodDefinition).IDKEYOpen(classmethod).Implementation.Size
}

ClassMethod test(makeDeploy = {$$$NO})
{
  ;do ##class(ITPlanet.Test).test()

  set classname="ITPlanet.Task2"
  set check=9876543210
  do:makeDeploy $system.OBJ.MakeClassDeployed(classname)
  set result=$classmethod(classname,"main")
  write !,result,!,check,
        !,"correct: ",$select(result=check:"yes",1:"no"),
        !,"length: ",..length(classname)
}

}
USER>do ##class(ITPlanet.Test).test()
 
9876543210
9876543210
correct: yes
length: 9
USER>do ##class(ITPlanet.Test).test(1)
 
9876543210
9876543210
correct: yes
length: 0
Vote up!
Vote down!

Rating: 1


 

Nice! Next step is "-1" or less :-)

Vote up!
Vote down!

Rating: 0

$T

Vote up!
Vote down!

Rating: 1

Not always, If $T was set to 1 before, then it is not reseted on entering the method Main()

Vote up!
Vote down!

Rating: 0

Answer

main ≠ Main

Only I noticed it?

Vote up!
Vote down!

Rating: 0

Fixed that

Vote up!
Vote down!

Rating: 0

Answer
Class ITPlanet.Task2 [ Abstract ]
{
 
ClassMethod Main() As %String
{
q $tr($h,",")
}
 

}

 

*You may need to set your date and time settings to 2111-05-30 12:00:10  ;)

Vote up!
Vote down!

Rating: 1

Awesome!

Check method reports 19.

Vote up!
Vote down!

Rating: 0

Answer

19 in non-expression mode:

Set ^oddDEF("ITPlanet.Task2","m","main",30,1)=" q $lg("""_$c(7,4)_"ê"_$c(22)_"°L"_$c(2)_""")"
Do $System.OBJ.Compile("ITPlanet.Task2")

The actual class code contains a few control characters, but not ASCII 0-9.

Vote up!
Vote down!

Rating: 3

Oops, looks like Sean beat me by a few minutes!

Vote up!
Vote down!

Rating: 0

Only just! :)

Vote up!
Vote down!

Rating: 0

I think you need  to call:

Do UpdClsDef^%occLibrary("ITPlanet.Task2")

before compile.

Vote up!
Vote down!

Rating: 1

Good catch.

Vote up!
Vote down!

Rating: 0

Answer

I and @Eduard Lebedyuk came up with another solution. 28 symbols, though:

f p='""_+""-'"":-'"":"" w p
Vote up!
Vote down!

Rating: 1

Do not forget about the method signature:

ClassMethod main() As %String

Need not print the number, but return it.

Vote up!
Vote down!

Rating: 0


 

Log in to answer