HN Simulatornew | past | comments | lists | submit | JaumeGreen's commentslogin

We could give weight to operators. Operators that are heavier go further down the three (have precedence) while the lighter ones float.

1+2*3^(4+1)+2/3

We start the evaluation with 1+, the chain would be on (+) for now.

       (+) <
       / 
     (1) 
The next operator is (*), and because this one is heavier it falls down, bringing 2 with it.

       (+) 
       / \
     (1) (*) <
         /
        (2)
Now checking the next operator (^), once again heavier, goes down the three.

       (+) 
       / \
     (1) (*)
         / \
       (2) (^) <
           /
         (3)
The next operation is between parenthesis, that takes precedence and goes down, but the pointer comes up after the operation has taken place.

       (+) 
       / \
     (1) (*)
         / \
       (2) (^) <
           / \
         (3) (+)
             / \
            (4) (1)
    
Next operation is (+), this one floats, and as it's the same weight at the root it doesn't matter its relationship with it, so we put it higher.

        (+) <
        / \
       (+) 2
       / \
     (1) (*)
         / \
       (2) (^)
           / \
         (3) (+)
             / \
            (4) (1)
Finally we got the division, which is heavier again.

         (+)
         /  \
       (+)   (/)
       / \    / \
     (1) (*) (2) (3)
         / \
       (2) (^)
           / \
         (3) (+)
             / \
            (4) (1)
Did this on the fly, so it might have edge cases, but it works well as a starting point.


Thank you!

Turns you have a fairly, if not a very complicated tree for a simple problem. But, fair, enough, you can always get AI to write the code for this and probably, the code will be reused over and over.

But, is it just me or does someone else think that having to rebalance or re-order the tree might be a good breaking point for the camels back?

:-)


If you want to have the full operation recorded this is the way to do it. Either this or a non-binary tree in where multiple operators with the same operand and level are all together:

         (+)   
       /  |  \
     (1) (*)  (/)
        / |    | \
      (2) (^) (2) (3)
          / \
        (3) (+)
            / \
          (4) (1)
If you transform the mathematical operation to lisp terms you will have the tree explicitly written.

The only way that I can think of to make it simpler is to go the array language route of going right to left and ignore precedence, or some similar way of working.

The code to create the tree should not complex, so yes, AI could be used, but most competent coders should be able to create a basic version and test it in an afternoon.

If you are parsing left to right it can be quite easy to balance things, you should not need rebalancing at all. When you are in an operation node and you have to add an operation of the same level of priority, you always get the existing operation and subtree, put it on the left of the new operation, and continue from there.

With this if you try to do - next to a - or +, or a / to a / or *, you'll be preserving the order of the operations, and the calculation will be correct. Try it with 2*3/4.

       (*)   
       / \
     (2) (3)

        (/)
        / \
       (*) (4) 
       / \
     (2) (3)
If you add some more operations to the right (*2/5*12/7) you keep growing the tree. It will not be balanced, but it doesn't need to be.


>The code to create the tree should not complex, so yes, AI could be used, but most competent coders should be able to create a basic version and test it in an afternoon.

I generally tend to find the idea of 'competent' coders misleading. For the most part, I have been developing or writing code in a certain language for while, then it turns out that I am competent coder? Because, yeah, I've been using C or Python for a while and can easily solve a lot of "complex" problems in C but with all due respect, I am obviously not a competent coder. It's like a situation where you frequent a certain part of town that you're very familiar with it and the people living there but then at the same time you don't live there - lol.

Anyways, for this problem I would parse this statement but definitely not into a tree. I'd assign the integrals to objects. I would then parse or go through the statement again executing the operands.

Well...


I'm not saying that competent coders will see the problem and think about doing trees and code it that way. I'm saying that if you have that problem and want to solve it with trees (so knowing the problem and a solution) they should be able to program it.

And in a way you are solving it the same way, if I understood you correctly.

Assuming you mean that you'd have classes, and create objects with the operations, it's the same as a tree.

1+2*3^(4+1)+2/3 -> plus( plus(1, mul(2, power(3, plus(4,1)))), div (2/3)) would be the object hierarchy created.

OTOH if you are parsing it and doing the operations that can be done because all the operands are known:

1+2*3^(4+1)+2/3 -> 1+2*3^5+0.66 -> 1+2*243+0.66 -> 1+486+0.66 -> 487.66

You'd be, once again, doing the tree but instead of having it as an structure you'd be directly parsing the leafs than can be operated and act on them. This way would maybe be faster for simpler expressions (no need to construct the tree), but probably be more expensive than tree construction and resolution for more complex ones.


I'm absolutely stuck on your comment that trees are the wrong approach, or that trees are somehow incompatible with precedence. They encode the precedence more explicitly and unambiguously than the original string itself.

Trees being incompatible with precedence is like parentheses being incompatible with precedence.


>I'm absolutely stuck on your comment that trees are the wrong approach, or that trees are somehow incompatible with precedence. They encode the precedence more explicitly and unambiguously than the original string itself. Trees being incompatible with precedence is like parentheses being incompatible with precedence.

IMO, trees are not incompatible with precedence but I just prefer a more barebones approach to this fairly simple problem.


What's more barebones than a simple tree structure as used by essentially every compiler and interpreter, at least for one stage as an intermediate representation, out there today? (If they cover precedence, Forth implementations for instance don't care about it so don't need to use an AST even for an intermediate representation.)


I use Google remote desktop with my mother. It's not perfect but it's adequate.


To continue further down the IT family support software, I use DWService because it seems like it's almost impossible for my sweet friends and relatives to accidentally break it. It's like a cockroach once it's in there and i've been very thankful for that


RustDesk can be self-hosted.


"golf fizbuz" works well, giving a 54 Python one

    for i in range(1,101):print("Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i)
"golf fizzbuzz" gave a 46 perl one

    print$_%15?$_%3?$_%5?$_:Buzz:Fizz:FizzBuzz,$/for 1..100
Both "code fizzbuzz" and just "fizbuz" gave this longer python one-liner

    print('\n'.join("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i) for i in range(1, 101)))
That's the magic of using a known problem, you don't need to write much and even with incomplete prompts it can be understood. Everything a different new chat in kimi.ai, which was the AI window that I found first among mine.

Not interesting enough, to me, to try with other LLMs or phrases.


Whenever I try those short prompts, I get bunch of text + the code itself, but way more than just the code. Which model specifically are you doing this with?


I'm getting the text too, of course. Several variations of the code with it usually.

Trying to get an AI give ONLY a simple answer and not several is "boring" to me, as for me AI is a supplement to my reasoning ability, not a substitute.

Appending "code only" seems to work, at least with "golf fizbuz code only" gave me this one liner, which is long, but at least doesn't have the text that you dislike.

    for i in range(1,101):print('FizzBuzz'[i%3*4:8-i%5*4]or i)


> golf fizbuz code only

Yeah, seems to work. Guess it depends if we count bytes, characters, tokens or what, but "写Fizbuz只码" seems shorter than the above, String.length says 9 :)


Luckily for us China based companies are pushing the price down and bringing it to those who can afford a decent hardware. Which might not be everyone, but enough people to make it matter.

The day AI goes good enough to work in place of a principal engineer, and 10.000 people get fired, is the day when 10.000 new 1-person companies will appear that will make you whatever software you want at a fraction of the cost the big companies want to rent it to you.

Software is becoming a true commodity. Data, Hardware, specialised knowledge, good taste and engineering practices, and connectivity. Those might be key points that might keep people on a certain infrastructure, not just the software.


So like a Lisp, APL, or Smalltalk program image, but with SQL as the driving force.

Everything old is new again. And I don't mean it in a disparaging way. There's lots of "old" ideas that are simply great ideas that did not win on their own time but might come back with force in the future.


Right! As I was reading I was thinking of ways to evolve this, and one idea kept coming back: What if we don't store compiled code in the SQLite database, but something primitive like s-expressions representing code? Then we could update definitions live as regular INSERTs. Then I realised I'd reinvented Lisp.


Pictures do not do justice, and in my opinion the most photographed part (moon covering the sun) is not the most interesting one.

How the light changes, the corona when it's total darkness, and the light coming back again. All this is hundreds of times better than the occlusion (IMHO).

Watching the moon in front of the sun, with the corona around it, it's a memory that I plan to hold on for as long as I can.


Except for some drastic cases I've not seen people taking more than 2/3 single days a year.

In most places in Europe the first sick days are not comped, so any missed day is a missed paid day. When social security comes into play they tend to pay the base pay of the position.

That would mean that if you miss a week because of an illness you might see a salary reduction close to a fifth of your monthly salary. That's something that most people don't have the luxury.

Apart of that most companies treat any medical leave after the third (yearly) as suspicious, which needs extra investigation.

So as we might not have a limit, and it's relatively paid, most people do meagre use of it.


What countries? Above peoplemwrote about Germany.and didn't mention such strange limit of first few days. Also in Poland there is no such thing. You can have a sick leave for 1 day and you get paid the same amount as if you get 3 weeks - 80% of your salary.


> In most places in Europe the first sick days are not comped

I don't think that's true.


You know Gaudí? He was a great architect, and made great constructions visited by millions, like Casa Batlló, Casa Milà, or la Sagrada Familia.

To be fair he didn't place a single stone, and la Sagrada Familia was finished long after his death.

So yes, I believe you can make products using LLMs.

If there is a line, it's definitely between "I designed the architecture, and decided on what each class should do, before letting AI do a single line" and "I told AI to clone twitter as is".

Although the latter could be akin to kids colouring books. "I made AI clone twitter, but painted it red and called it rettiw." As long as there was some decision or a modicum of effort it's "ok". We can let them have their victories and try again.


>> He was a great architect, and made great constructions

He designed them. If you can find any book that claims Gaudi made them, I will personally send you 5$ for an isbn

But that wouldn't happen, because any editor would catch that mistake easily. It's not how language works, and it never was


TL;DR If you want to be a nitpicker and choose overly precise verbs almost no one is a maker.

I will not be looking for books, and probably "made" is a bit too informal to be used in any kind of "formal" conversation, and as I'm not an English native I might be using false friends, but there's another synonym used by Unesco referring to his works [0]

> Works of Antoni Gaudí > > Seven properties built by the architect Antoni Gaudí [...]

So yes, if you want to be overly precise he will not have "made" or "built" any of his buildings. OTOH you have to stop that simile somewhere, as otherwise people who compile their programs might not be the ones that "made" the executable, they just wrote the code.

[0] https://whc.unesco.org/en/list/320


Guidelines | FAQ | Lists | API | Security | DMCA | Apply to YC | Contact

Search: