Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 497 498 [499] 500 501 ... 637

Author Topic: The small random questions thread [WAAAAAAAAAAluigi]  (Read 686327 times)

scriver

  • Bay Watcher
  • City streets ain't got much pity
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7470 on: June 14, 2021, 04:39:07 am »

Go for the manflesh jokes
Logged
Love, scriver~

Loud Whispers

  • Bay Watcher
  • They said we have to aim higher, so we dug deeper.
    • View Profile
    • I APPLAUD YOU SIRRAH
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7471 on: June 14, 2021, 03:31:10 pm »

Go for the manflesh jokes
MEAT'S BACK ON THE MENU BOYS

methylatedspirit

  • Bay Watcher
  • it/its
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7472 on: June 14, 2021, 09:41:11 pm »

Is there a C compiler that does precisely zero optimizations? No optimization, literally the closest one-to-one mapping between C and assembly possible. Even GCC at -O0 technically has optimizations. I count 60 with my GCC 9.3.0. (gcc -Q -O0 --help=optimizers | grep enabled | wc -l)

Why I'm asking is because older folks talk about how back in the olden days, C compilers weren't as optimizing as they are now. I remember reading an anecdote about John Carmack writing Doom, having to increment variables with "x++" instead of "x + 1" because "++" mapped directly to the INC instruction in x86, a faster instruction than an ADD at the time. Or in m_random.c, where he used an AND with hex FF instead of a modulo 256. Those kinds of micro-optimizations were needed just to get decent speed.
Logged

Rolan7

  • Bay Watcher
  • [GUE'VESA][BONECARN]
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7473 on: June 14, 2021, 10:07:32 pm »

import ScriptingLanguages
joke()

I remember reading an anecdote about John Carmack writing Doom, having to increment variables with "x++" instead of "x + 1" because "++" mapped directly to the INC instruction in x86, a faster instruction than an ADD at the time. Or in m_random.c, where he used an AND with hex FF instead of a modulo 256. Those kinds of micro-optimizations were needed just to get decent speed.
Dang.  I can totally see the AND FF thing, the incrementing sounds a little sus but those were wild times so I can believe it.
Logged
She/they
No justice: no peace.
Quote from: Fallen London, one Unthinkable Hope
This one didn't want to be who they was. On the Surface – it was a dull, unconsidered sadness. But everything changed. Which implied everything could change.

wierd

  • Bay Watcher
  • I like to eat small children.
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7474 on: June 14, 2021, 10:22:04 pm »

The glorious one was the integer math implementation of single float computation.

(but it also broke on cyrix processors.)
Logged

methylatedspirit

  • Bay Watcher
  • it/its
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7475 on: June 16, 2021, 08:35:34 pm »

Is there a utility out there that takes a very large text file containing points, and spits out a more tractable version by just taking points every 1 unit (or closest approximation) on the x-axis?

The format of the list of points I'm looking at looks like this, for reference:

Code: [Select]
(-80.09,-47.71),
(-79.91,-47.62),
(-79.74,-47.54),
(-79.58,-47.45),
(-79.41,-47.37),
(-79.25,-47.28),
(-79.09,-47.2),
(-78.94,-47.12),
(-78.79,-47.04),
(-78.64,-46.96),
(-78.49,-46.88),
(-78.34,-46.8),
(-78.2,-46.72),
(-78.06,-46.64),
(-77.92,-46.56),
(-77.79,-46.49),
(-77.65,-46.41),
(-77.52,-46.34),
(-77.39,-46.26),
(-77.27,-46.19),
(-77.14,-46.11),
(-77.02,-46.04),
(-76.89,-45.97),
(-76.77,-45.9),
(-76.65,-45.83),
(-76.54,-45.76),
(-76.42,-45.69),
(-76.31,-45.62),
(-76.19,-45.55),
(-76.08,-45.48),
(-75.97,-45.41),
(...)

And the output should look something like:

Code: [Select]
(-80.09,-47.71),
(-78.94,-47.12),
(-77.92,-46.56),
(-77.02,-46.04),
(-75.97,-45.41),
(...)
Logged

Frumple

  • Bay Watcher
  • The Prettiest Kyuuki
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7476 on: June 16, 2021, 08:53:27 pm »

Dunno about a specialized utility, but you might be able to kludge something using either a spreadsheet or something like notepad++ and regular expressions. I'm pretty sure it's possible with the latter in particular, but the exact formatting to do it is way beyond my level of expertise with regex. Slightly less sure you could work something with spreadsheet formulas, but I think it's possible there, too.
Logged
Ask not!
What your country can hump for you.
Ask!
What you can hump for your country.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7477 on: June 16, 2021, 10:02:27 pm »

Seems like something to write a Python script for. If you're not good with regex, you can use string.Split() to split strings based on characters.

Edit: Wrote it:
Code: [Select]
import re #regex

def main():
regex_coords = re.compile(r"\s*\(\s*((?:-?\d*\.\d+)|(?:-?\d+))\s*,\s*((?:-?\d*\.\d+)|(?:-?\d+))\)\s*,?")
#valid numbers have at least one digit; if using decimal point, require at least one digit after it
coord_list = []
trimmed_list = []

try:
input_text = open("input.txt",'r')
except:
exit("ERROR: Unable to open input.txt")
try:
output_text = open("output.txt",'x')
except:
input_text.close()
exit("ERROR: Unable to create output.txt for writing. May already exist.")
try:
s = ""
for line in input_text:
results = regex_coords.split(s+line, maxsplit=1)
s += results[0] #string before match; handles lines without match
while len(results) > 1:
coord_list.append( ( float(results[1]), float(results[2]) ) ) #append coordinate pair
s = results[3] #string after match
results = regex_coords.split(s, maxsplit=1) #attempt another match on the line
if s != "" and not s.isspace():
if len(s) > 10:
print("WARNING: {} chars remaining unparsed!".format(len(s)))
else:
print("WARNING: Chars remaining unparsed:\n{}".format(s))
except:
input_text.close()
output_text.close()
exit("ERROR: Something happened during parsing.")
input_text.close()

if len(coord_list) < 1:
output_text.close()
exit("ERROR: No list!")
coord_list.sort() #sort ascending by x, then by y

int_value = round(coord_list[0][0]) #closest integer to x value
closest_pair = coord_list[0] #best matching coord pair
closest_dist = abs(int_value - coord_list[0][0]) #distance from integer

for pair in coord_list[1:]: #iterate list excluding first pair
if round(pair[0]) != int_value: #start a new integer
trimmed_list.append(closest_pair)
int_value = round(pair[0])
closest_pair = pair
closest_dist = abs(int_value - pair[0])
else:
dist = abs(int_value - pair[0])
if dist < closest_dist: #better match
closest_pair = pair
closest_dist = dist
trimmed_list.append(closest_pair) #append final pair

for pair in trimmed_list[:len(trimmed_list)-1]: #iterate list excluding last pair
print("{},".format(pair), file=output_text) #print to file with comma
print(pair, file=output_text) #print to file without comma
output_text.close()

if __name__ == "__main__":
main()

Takes input from input.txt in the script's directory and outputs to output.txt. Will fail if there's already an output.txt in the directory. I could make it delete the old one if that's a bother. I could also make it take an input file name as an argument, then output to "<filename>_out.txt". That'd be more suitable if you need to do large batches of files.

The output is actually:
Code: [Select]
(-80.09, -47.71),
(-78.94, -47.12),
(-78.06, -46.64),
(-77.02, -46.04),
(-75.97, -45.41),

-78.06 is closer to -78 than -77.92. Is that right?
« Last Edit: June 17, 2021, 08:24:27 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

WealthyRadish

  • Bay Watcher
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7478 on: June 17, 2021, 09:02:03 am »

Even without knowing what this is for, I'd question why you'd go for that approach. It may be better to create new values at the exact intervals of 'x' and interpolate the 'y' value, for instance.
Logged

methylatedspirit

  • Bay Watcher
  • it/its
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7479 on: June 17, 2021, 09:29:50 am »

-78.06 is closer to -78 than -77.92. Is that right?

Yeah. I was just doing Ctrl+F on the data, and I was being lazy.

Even without knowing what this is for, I'd question why you'd go for that approach. It may be better to create new values at the exact intervals of 'x' and interpolate the 'y' value, for instance.

I figured, "the command-line thing that I'm putting these values into takes floating-point values anyway, so I may as well be lazy". My concern is that if I just put the entire list into the program, it won't work because the argument will end up being way too long. Windows is limited to 8191 characters, Linux is limited to at least 10K, and I have 7 megabytes of data in here. That's why I have to shorten the list into a more tractable format.
Logged

McTraveller

  • Bay Watcher
  • This text isn't very personal.
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7480 on: June 17, 2021, 10:49:36 am »

I'd change the command line tool if possible; you should either make it read data from a file or use stdin and send the long data in with a pipe by cat'ing the input data or whatever.
Logged

Kagus

  • Bay Watcher
  • Olive oil. Don't you?
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7481 on: June 19, 2021, 04:41:36 pm »

Is it... Is it not common to be able to touch your tongue to your chin?

wierd

  • Bay Watcher
  • I like to eat small children.
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7482 on: June 19, 2021, 11:17:16 pm »

If you have a shallow chin, maybe not...

But most people cant put it there.
Logged

Great Order

  • Bay Watcher
  • [SCREAMS_INTERNALLY]
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7483 on: June 20, 2021, 06:43:17 pm »

Is there a name for a sudden, sharp pain in your chest where it feels almost like your pleura sticks for a moment? It's not Precordial Catch Syndrome, it resolves the instant it "unsticks" rather than lingering for a couple of minutes. Pretty sure it's not neural but something physical, because I can put it off with shallow breathing until I take a big breath, then it does a sort of painful click. It's not in a joint either, it happens anywhere on my chest.

Google's failed me here, it keeps telling me it's PCS, fluid buildup with infection, pleuritis, or that I'm straight up either having a heart attack or emphysema and none of those symptoms match.
Logged
Quote
I may have wasted all those years
They're not worth their time in tears
I may have spent too long in darkness
In the warmth of my fears

None

  • Bay Watcher
  • Forgotten, but not gone
    • View Profile
Re: The small random questions thread [WAAAAAAAAAAluigi]
« Reply #7484 on: June 20, 2021, 07:03:18 pm »

Huh, I thought Precordial Catch Syndrome did just 'unstick' since it's never lingered in my experience. I mean, it has to uncatch, right? I feel like I've had the same thing, does PCS ache past resolution in your experience?
Logged
Pages: 1 ... 497 498 [499] 500 501 ... 637