What do you mean by overhead from $lb?
What is $c(166), some magic number? And why you encode the string as a list of codes, why not keep it as a string?
$lb it is also a string, but compressed for some types of values.
- Log in to post comments
What do you mean by overhead from $lb?
What is $c(166), some magic number? And why you encode the string as a list of codes, why not keep it as a string?
$lb it is also a string, but compressed for some types of values.
I think bitlogic operations is the best which you can use with bitstring.
Congratulations, you did it.
I love Docker way. In Dev environment, when you need only some test data. You can use Docker, with all test data inside the image, just recreate container will clean all previous changes and return the database to state when this image was built. If you later will decide to keep some changes as default for next uses, you can commit this changes to the image.
Not sure, but maybe property method GetStored can help. It is ClassMethod which accept object Id as the first argument. Full name for the method <Property>GetStored(id)
I also solved this task, and I decided to choose a bit different way. As we have some kind of programming language, we can execute it, but how. We can transpile this code to Caché code, and execute it.
kill
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("c:\advent\input\day12.txt")
set src($i(src(0))) = "start(c) new (c)"
while 'fs.AtEnd {
set line = fs.ReadLine()
set pos = $i(src(0))
set code = $$transpile(line, pos, "start")
set src(pos) = code
}
set src($i(src(0))) = " zwrite a"
set src($i(src(0))) = " quit"
set sc = $compile(src, 0, errs, , , , "AdventDay12New")
do start^AdventDay12New()
do start^AdventDay12New(1)
quit
transpile(line, pos = 0, label) {
set result = ""
set $lb(cmd, arg1, arg2) = $lfs(line," ")
if cmd = "jnz" {
if +arg1=arg1 set result = " goto:("_arg1_") "_label_"+"_(pos+arg2-1)
else set result = " goto:(+$get("_arg1_")) "_label_"+"_(pos+arg2-1)
} elseif $lf($lb("cpy", "inc", "dec"), cmd) {
set args = $case(cmd, "cpy": $lb(arg2, arg1), "inc": $lb(arg1, arg1_" + 1"), : $lb(arg1, arg1_" - 1"))
set result = " set "_$lts(args, " = ")
}
quit result
}Spoiler. Task 25 have the same language with one more instruction. and with some little modifications in this code, becomes quite easy to solve that task, too.
As far as I understood, they discussing mounting volumes from another container.
As I know some kind of this possibility was in some previous versions of docker-compose. When you can configure to start multiple containers, and it offered to mount volumes_from another container in this configuration. But now docker-compose becomes bigger and supports swarm configuration, they decided to change volumes_from, to just named volumes. In this way, you can define one volume, and use it in different containers at the same time. And it works pretty well. And I think, it is quite enough, with different drivers available for volumes, you can use data from almost everywhere.
And it is now possible even with current Caché versions.
But I think, that way offered in the article could be less effective. You still have to mount volume but in some different way, but what important is how real storage is used.
If these data containers are just a connectors between cluster storage and application. A think it still possible to use it as a mounted volume, or you can configure mounting during the build of an image.
To release all LOCK's for your current process, you can use argumentless LOCK command.
To rollback all transactions in the current process, you can use TROLLBACK also without any arguments.
If you want to control locks outside, you can look at class SYS.Lock in %SYS namespace.
To find active locks, you can use either special global ^$LOCK or queries in the class %SYS.LockQuery
You can get transaction level with special variable $tlevel. For other processes, you can use class %SYS.ProcessQuery. To check if the process in a transaction or not. But you can't just rollback transaction inside another process, you can terminate it and transaction will be automatically rollbacked.
kill
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("c:\advent\input\day10.txt")
while 'fs.AtEnd {
set line = fs.ReadLine()
if $e(line)="v" {
set $lb(,value,,,type,bot)=$lfs(line," ")
set list(type, bot, value)=""
} else {
set $lb(,bot,,,,lowTo,low,,,,highTo,high)=$lfs(line," ")
set instructions(bot, "low") = $lb(lowTo, low)
set instructions(bot, "high") = $lb(highTo, high)
}
}
while $d(instructions) {
set bot=""
for {
set bot = $o(list("bot", bot))
quit:bot=""
set low = $o(list("bot", bot, ""))
set high = $o(list("bot", bot, ""), -1)
continue:low=high
if low=17,high=61 set result = bot
set $lb(type, num) = instructions(bot, "low")
set list(type, num, low) = ""
set $lb(type, num) = instructions(bot, "high")
set list(type, num, high) = ""
kill list("bot", bot)
kill instructions(bot)
}
}
write !,"Result1 = ",result
set result2 = 1
for i=0,1,2 set result2 = result2 * $o(list("output", i, ""))
write !,"Result2 = ",result2
quit
and using $lb on a right side, can help, when you need to swap values without using the third variable.
set $lb(b,a)=$lb(a,b)
Interesting, you decided to use a regex here. My code looks very similar to your, but in my case, I just replaced parens and 'x' to '|' and use $lb/$lfs to catch values.
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("c:\development\day9.txt")
set compressed = fs.Read(fs.Size)
set compressed = $tr(compressed, "(x)", "|||")
write !,"Length = ",$$uncompress(compressed)
write !,"Full Length = ",$$uncompress(compressed, 1)
quit
uncompress(str, deep = 0) public {
set length = 0
while $l(str) {
if $e(str)="|" {
set $lb(,count,times)=$lfs($p(str, "|", 1, 3), "|")
set $e(str, 1, $l($p(str, "|", 1, 3)) + 1) = ""
set tmp = $e(str, 1, count)
set length = length + $s(deep:$$uncompress(tmp,1) * times, 1: count * times)
set $e(str, 1, count) = ""
} else {
set size = $l($p(str, "|"))
if $i(length, size)
set $e(str, 1, size) = ""
}
}
quit length
}InterSystems delivered Cache distributive as a DMG file until 2016.2. And fortunately, they decided do not do it anymore.
But all the time, it was also available as tar.gz. Which is working in exactly the same way as any other Linux version.
So, you can use ccontrol tool, to see a list of instances, their status and start or stop.
csession can be used as a terminal in windows.
To open System Management Portal, you can just this URL in a Browser - http://localhost:57772/csp/sys/UtilHome.csp
I think could be even shorter, but as is
set sum = 0, north = ""
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("day4.txt")
while 'fs.AtEnd {
set line = fs.ReadLine()
do line(line)
}
w !,"Sum = ",sum
w !,"North = ",north
q
line(line) [ sum, north ] {
set name = $p(line, "-", 1, * -1)
set checkSumm = $piece($piece(line, "]"), "[", *)
for i=1:1:5 {
set char = $e(checkSumm, i)
set count = $l(name) - $l($tr(name, char))
set order( - count, char) = ""
}
set testSumm = ""
set i=""
for {
set i = $o(order(i))
quit:i=""
quit:i=0
set c = ""
for {
set c = $o(order(i, c))
quit:c=""
set testSumm = testSumm _ c
}
}
if testSumm=checkSumm {
set sector = $piece($piece(line, "["), "-", *)
set sum = sum + sector
for i=1:1:sector set name = $tr(name, "zabcdefghijklmnopqrstuvwxy-", "abcdefghijklmnopqrstuvwxyz ")
if name["north" set north = sector
}
}
One code for both passwords
set doorId = "reyedfim"
set (pass1,pass2) = ""
for i=1:1 {
set hash = $system.Encryption.MD5Hash(doorId _ i)
set key1 = $zla($reverse($e(hash, 1, 3))_$c(0))
continue:key1>15
if $l(pass1)<8 set pass1 = pass1 _ $zhex(key1)
continue:key1>7
continue:$tr($e(pass2, key1 + 1)," ")'=""
set $e(pass2, key1 + 1)=$zhex($a($e(hash,4))\16)
quit:($l($tr(pass2," "))=8)
}
w !,"Password #1 = ",pass1
w !,"Password #2 = ",pass2
Mine
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("day6.txt")
while 'fs.AtEnd {
set line = fs.ReadLine()
do line(line)
}
set (msg1,msg2)=""
for i=1:1 {
quit:'$d(count1(i))
if $o(count1(i, ""), -1, char) set msg1 = msg1 _ char
set msg2 = msg2 _ $o(count2(i, $o(count2(i, "")), ""))
}
w !,"msg1 = ",msg1
w !,"msg2 = ",msg2
q
line(line) [symbols, count1, count2 ] {
f i=1:1:$l(line) {
set char = $e(line, i)
set count = +$get(symbols(i, char))
kill count2(i, count, char)
set count = $i(symbols(i, char))
set count1(i, count) = char
set count2(i, count, char) = ""
}
}
Look at my solution for this task
k
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("day8.txt")
set count=0,width=50,height=6
for x = 1:1:width for y = 1:1:height set screen(x,y) = 0
while 'fs.AtEnd {
set line = fs.ReadLine()
do line(line)
}
do draw()
set count = 0
for x=1:1:width for y = 1:1:height set count = count + screen(x,y)
w !!,"Count = ", count
quit
line(line) [screen, width, height, x, y] {
set $lb(cmd, size, pos, , by) = $lfs(line, " ")
if cmd = "rect" {
set $lb(mx, my) = $lfs(size, "x")
f x = 1:1:mx f y=1:1:my set screen(x,y) = 1
} else {
set $lb(v1, pos) = $lfs(pos, "=")
set v2=$case(v1, "x":"y", :"x")
set max = $case(v1,"x":height, :width)
set @v1 = pos + 1, @v2 = 1
for i=1:1:by {
set prev = $g(screen(x,y))
for @v2 = 2:1:max set $lb(screen(x,y), prev) = $lb(prev, screen(x,y))
set @v2 = 1
set screen(x, y) = prev
}
}
}
draw() [screen, width, height] {
f y = 1:1:height {
w !
f x = 1:1:width {
write $case($get(screen(x,y)), 1:"#", :" ")
}
}
}
And for the second part, a bit different.
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("day7.txt")
set count=0
while 'fs.AtEnd {
set line = fs.ReadLine()
if $locate(line, "(\w)(?!\1)(\w)\1\w*(?:\[\w+\]\w*)*\[\w*\2\1\2\w*\]")||$locate(line, "\[\w*(\w)(?!\1)(\w)\1\w*\](?:\w*\[\w+])*\w*\2\1\2"), $i(count)
}
w !,count
Interesting, but I don't understand why you still trying to parse strings manually when InterSystems already supports Regex.
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("day7.txt")
set count=0
set abba = ##class(%Regex.Matcher).%New("(\w)(?!\1)(\w)\2\1")
set hyper = ##class(%Regex.Matcher).%New("\[\w*(\w)(?!\1)(\w)\2\1\w*\]")
while 'fs.AtEnd {
set line = fs.ReadLine()
set abba.Text = line
set hyper.Text = line
if abba.Locate(),'hyper.Locate(),$i(count)
}
w !,count
So simple, isn't it?
For regex maniac, maybe possible to join both regex's to one to get fewer operations. But anyway, in this simple example you can see the power of Regex.
And even shorter
set fs = ##Class(%Stream.FileCharacter).%New()
set sc=fs.LinkToFile("day7.txt")
set count=0
while 'fs.AtEnd {
set line = fs.ReadLine()
if $locate(line, "(\w)(?!\1)(\w)\2\1"), '$locate(line, "\[\w*(\w)(?!\1)(\w)\2\1\w*\]"), $i(count)
}
w !,count
Looks like it's from MS SQL
Even Eclipse itself offers the same way to upgrade platform. If you want to upgrade Eclipse to the newest version, you should change the link, and after that upgrade will be possible.
I think it mostly depends on your task, how strongly you should care about duplications.
And I think that SHA1 should be enough
Documentation now looks quite pure about Atelier.
As far as I know, Studio does lock for any files which in edit mode, not just opened but after some changes. While Atelier does not. When you save the file in Studio, it does not care what did you have before it just overrides. When Atelier checks if server's version was changed it offers to compare and choose what should be stored on server.
Or just add calculated indexable property with hash to this string, and use this property in SQL
Yep, right, looks like Index can't help here and problem not only 511(and this length could be different on different strings).
But, you still can use Index but you should set length which should be stored. But find duplicates you can do without SQL, just by reading this index, it should be much faster, to find, all duplicates by indexed value, and then you can compare real values.
For best performance, you need index on this property. And request something like this.
SELECT Home_City,list(ID) ids FROM sample.person GROUP BY Home_City HAVING count(*)>1
And result will be something like this

It has private access for now, and available only for you, yet.
Danny,
Thanks, It's amazing, to see such articles.
But how about coding style. If to be honest, your code looks like a mess of old-school code and modern.
As this articles mostly for beginners, it would be much better to have also modern style. Instead of OPEN/USE/READ use %Stream classes. I see this way as much readable.
And about how you use standalone ELSE command without brackets, not sure that beginners, can quickly get the trick here.
Open file:"R":1 Else Use 0 Write "Could not open file ",file Quit
You can remove saved password from windows registry
The same issue, just updated to latest beta version. Windows 10 x64, java version "1.8.0_152"

I would recommend instead of mark such object as deleted, with such flag like this. Just "move" it to another table some kind of Trash, when you can store this object as a serialized string for example. In this case object will really disappear from his table and will not be availble with via SQL or any other accesses. But in this Trash, you can have information about deletion data, who deleted and information to restore it.