Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Now, this is a time-memory tradeoff, but my time on this earth is limited so I decided to meta-program the if statements using a programmer program in a different programming language.

  for i in range(2*8):
    if i % 2 == 0:
No comment...




Yeah... I come here to talk about that. Should have been

  for i in range(0, 2**8, 2):
      print("    if (number == "+str(i)+")")
      print("        printf(\"even\\n\");")
      print("    if (number == "+str(i + 1)+")")
      print("        printf(\"odd\\n\");")
or

  for i in range(0, 2**8, 2):
      print(f"""    if (number == {i})
          puts("even");
      if (number == {i + 1})
          puts("odd");""")

What happens when you try to compute 2**8+1 ?

If its too large you could just subtract 2*8 and try again.

Should work fine with long long?

I think we can improve this. Just make a microservice who generates the code on the fly and streams it to the compiler. Then you also just have to create the necessary code and don't waste the SSD with unused code-paths.

I’m disappointed there is no docker image for this. How will I test it out?

Microservice kinda implies usage of a container for me. How else would we google-scale it to serve all requests in parallel?

But thinking about, we probably have to use some more microservices, we can't put all that burden on the requester. So a dedicated service for compiling and executing in sandboxes would be necessary. Also, some local load balancers to control the flow and filter out the useless answers. So I'm not an expert on that devops-magic, but I guess this means ~12.5 billion pods fast enough result. Do Amazon or Google offer planetary scale for services?


How horridly inefficient, he should have just flipped a Boolean on each iteration.

Horridly inefficient. Just unfold the loop.

Just output odd and even for each pass and increment by two. Need to make sure you have the right starting value, and check for off-by-one errors.

Claude's version:

  even, odd = "even", "odd"
  for i in range(2\*32):
      print(f'    if (number == {i}) puts("{even}");')
      even, odd = odd, even
As usual, a non-marginally superior mind to commentators.

It should have used a flag that is being toggled.



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

Search: