Hi, does anyone know how I could reduce the length of a string by a factor of 2, but keep the string in an undoable format, so that the string can be passed through an algorithm and the original string would be restored, I tried using RSA but that can't reduce its length
I know it sounds ridiculous, but I was wondering if there is at least a way of reducing the string length without using the compression algorithms that are used in 7zip or other software
I'm not trying to shoot your idea down. Instead I'm trying to illustrate the thought process and questions you need to ask in order to evaluate these ideas.
Say you want to compress 16 bit messages. There are 65536 different possible inputs, so with lossless compression we need 16 bits of output on average for each message, otherwise there won't be enough pigeonholes to hold all the messages.
However, it is often practical to use lossless compression because the range of messages we need to compress is a small fraction of the total space of possible inputs.
@JacobSchneider No, a pigeonhole is a whole encoded message.
The median annual household income was $39,000. Among five randomly selected U.S. households, find the probability that four or more have incomes exceeding $39,000 per year.
and she gives us this
Show work by writing out the individual probability formulas for P(X = x) and letting C(n,x) = "n choose x" since you will need to know it for exam questions.
Oh, good. Eg, if you compress sensible English text you can get a reasonable compression ratio because you don't need to compress totally random input bytes, and the possible sensible inputs of a given size is a small percentage of the total collection of possible byte sequences of the same size.
@PM2Ring I understand the last bit of what you said, but lost you at the first part, because a regular compression takes care of repetition, the most repetition in the enligsh langugae is 2 letters and very rarely 3 but nothing more. so there wouldn't be much compression.
@user2277747 Hmm. We do discuss other stuff apart from Python here. If you have a programming question relating to another language, that won't go down well, unless you disguise it so it sounds like you're talking about Python. ;) We do sometimes discuss general mathematical problems. But your homework problem is pretty specific, and would be more suitable in a room focused on statistics.
We could turn your problem into a Python problem. Try to figure out the formulas you need to calculate that stuff. Then write a program that generates a whole bunch of random test data, with each set of data being 5 households, then count how many sets have 4 or more households that earn more than 39,000.
@user2277747 You could do the same thing in JavaScript.
@JacobSchneider I often write little stats programs like that if I can't figure out the algebra for a combinations problem. Once you see the pattern, it can give you clues for what the formula has to look like.
@JacobSchneider Sorry, I got distracted. Simple repetition is important, but there's more to compression than that. Say if you had a file that only contained the words "america", "europe", "africa", "asia". Since there are only 4 possibilities we can encode each word with 2 bits.
@user2277747 Sorry, I'm a bit slow at typing on my phone.
Consider a random sample of 16 U.S households for the next question What is the probability of seeing at least 10 of the 16 households with annual incomes under $39,000?
@user2277747 So this is exactly the same as flipping 5 fair coins & finding the odds of getting 4 or 5 heads. Do you understand how to write the formula for that in terms of C(n, r)?
I spent more time on this than I'd like to admit. But it was fun. I know jack about javascript and canvas so this was a little experiment. pirsquared.github.io/clocks/PirClock
@user2277747 Yes. So if we toss a coin 5 times, on the first toss we have odds of .5 of getting a heads. On the 2nd toss we have .5 of getting heads, so to get heads both times the odds are .5 × .5 = .25
@piRSquared Very pretty! I haven't done any JS in ages. But I must admit that the HTML5 canvas is very good, one of the best graphics APIs I've ever used.
if you want even better canvas interaction, check out processing's p5 JS library. it's one of the most well thought out and all round libraries i've seen other than JQuery who'se purpose is different entirely, so yes, p5 is amazing.
Another option, especially if you want to to vector graphics in the browser, is to use SVG. It can do some pretty cool stuff, however some parts of the SVG spec were designed by a total lunatic. ;) But it can do some nice synchronized animation stuff, especially in combination with JS. The downside is that SVG is a XML format, but that's motly tolerable, compared to some usages of XML I've seen.
so you'd have a unique number for each combination but you then made me realise that that wasn't the best way to go as it didn't do anything
well SVG (XML) and HTML are each quite similar, so an XML document shouldn't be too different from a HTML one
I gotta say, your SVG sugestion has its upsides, but bitmaps are still not entirely obsolete, can you imagine the struggle of having to use vector graphics in game development? it would be mroe hassle than what it's worth, if you ask me
@JacobSchneider Well, you don't often get files that are that simple. :) But it was just a simple example to illustrate a principle that can actually be useful in more complex situations. A classic example is LZW compression, which is used in GIF. It's quite easy to write an LZW compressor / decompressor in Python that works on ASCII text & normally gives around 50% compression on reasonable sized chunks of sensible text.
@JacobSchneider Vector graphics & bitmaps each have their own uses, with not a lot of overlap. But it is nice when you can combine them to get the best of both worlds.
I remember using a vector graphics terminal in the mid 70s. It did its output via line drawing, it couldn't receive or display a bitmap. But it did have a light pen. :)
@AnttiHaapala I mentioned LZW because it's easy to understand, and a good intro for someone who wants to understand compression algorithms beyond simple RLE.
the actual reason I asked about compression algorithms is because I was coding yesterday and needed to look something up, but because it was like 10:00pm every single person was online, my brother streaming fortnite videos while playing and voicecalling the dude next door, and dad was watching netflix, so naturally, everything slowed to a crawl. so I was wondering how one could easily speed up internet download speeds, so I though about reducing the payload by compressing it
so if you have a file that contains 18446744073709551615 zero bytes, instead of spending 18446744073709551615 bytes, you can use 8 bytes with the 18446744073709551615 as binary...
I watched a few computerphile videos on compression and what he did was create essentially a dictionary so everytime a word, phrase or passage is repeated, you reference the dictionary. what's that called?
@PM2Ring the simple thing is that it specs a ring buffer
so the decompression goes like this: "get flag bits", "for i in range(0, 8): if the bit is set the next 2 bytes are a ring buffer reference, if not set, then the next byte is as is"
and for compression you need to have a buffer of maximum 2 * 8 bytes that
PNG is unusual because it has a variety of compression techniques it can choose from, depending on the data. But IIRC, the final layer of the compression scheme is gzip.
Most PNG savers will quickly try a couple of options and select what looks like the best one for the data. But a PNG optimizer can try a lot more options, and test more extensively, so if you can afford the time you can reduce a typical PNG considerably.
1% is nothing. It doesn't make sense to compress the outer chunk structure of a PNG. You want utilitiez to be able to determine that structure, and extract stuff like bitmap size, pixel depth, wheter it's palette mapped or true colour, without having to decompress it first. And you want to be able to customize the compression for the actual pixel data, you don't want to apply that compression to the non-pixel data as well.
@Aran-Fey If you want to reduce PNG size, and this isn't simply an exercise in investigating compressors, definitely take a look at optipng and pngcrush. They do a good job, and the resulting files are standard PNG, so you don't need to decompress them with a separate program to use them.
They normally use lossless compression, but optipng can also do some colour quantization too, if you want. IIRC. :) And I think it can also convert 24 bit to palette mapped, if the total number of colours is small enough. But I'd have to check the docs...
With the default options, 10% reduction is common. 30% isn't unusual, especially if you tell it to go crazy checking compression option combinations.
@AnttiHaapala A year or so ago I wrote some code to investigate ANS, which is interesting, but I didn't bother writing a practical compressor / decompressor because it's a bit slow doing stuff like that in Python. And my code wouldn't easily translate to C because I was doing the arithmetic with Python integers.
@Aran-Fey I guess you could have a process tha sits in the background that optimizes PNGs written to certain directories. It's not efficient to watch everything. And optimization takes time (& of course CPU cycles), so the amount of optimization really should depend on the intended use of the file.
A file that's going to sit on a Web site & be downloaded many times should be aggressively optimized. Files that are just going to sit on your hard drive & are rarely viewed can afford to waste a few bytes.
@Azazel Does that mean congratulations are in order? You don't sound very enthusiastic...
@AndrasDeak Fair point. I allowed it because it's language-agnostic and the room was quiet. And I think it's good for coders to know basic probability stuff like that.
But I must admit that when he couldn't answer my question about tossing 5 coins and getting all heads I almost told him that he needs to go back to his text book, or his teacher.
@PM2Ring "it's good for coders to know basic probability stuff like that": I completely agree ;)
I've seen multiple cases of "hey here's my completely unrelated math problem, please solve it because matlab people are smart" in the matlab room, and it gets old real fast. Like going to the butcher shop hoping that the butcher can give you sudoku tips
@AndrasDeak Sure. You may have noticed that I didn't actually give him the answer to his problem on a silver platter. ;) But I couldn't resist the opportunity to give him a little guidance in figuring it out himself.
I don't mind conversations about general principles. IMHO, that's no different to Kevin talking about doing stuff with Bézier curves. But when it's a "give me the exact answer to this homework problem", that's a different story.
OTOH, I'm not as strictly anti-homework problem as SE.Physics. The rules there are really strict... maybe a bit too strict. I understand why we don't want to deluge the site with worked solutions to every problem in every single physics textbook, or to have to check every crummy solution to homework exercises. But surely there must be some middle ground.
> Don't ask for answers to your recent Stack Overflow questions. Those who can answer are already watching the queue on the main site. > If your question is eligible for a bounty (>= 48 hours old) and hasn't received a useful response, then you may link to it.
@AndrasDeak Fair enough. And although it's reasonable for regulars to get a little more leeway because (presumably) they know the limits and won't go overboard, OTOH, we don't want to be unfair in our application of the room rules and leave ourselves open to accusations of favouritism.
I'm more than happy to openly and officially give leeway to regulars when it comes to being off topic :P
I don't think there's anything wrong with that from a social perspective
it's the difference between, say, friends on a hiking trip ending up talking about non-hiking things such as crocheting, and someone else approaching the hiking group with knitting questions out of the blue
Years ago, in response to a question on xkcd, I wrote a Python program that generates crocheting patterns for crocheting a sphere, given the size of the circumference. The OP posted patterns for 2 or 3 different sizes, and I figured out how to generalise them.
But when I showed a pattern to my mother (who was a knitting & crochet expert) she said the pattern used non-standard notation, so it was hard for her to read. She was going to help me change it to a more normal notation, but we never got around to it.
No worries, just try to look around, read the local rules, the chat faq and help and similar resources like this to familiarize yourself with how chat works ;)
I'm pretty sure my crochet program works properly, but it would be nice to actually test it by getting someone to actually crochet a sphere with it. Unfortunately, the OP on xkcd was a newbie who disappeared. I guess I could go looking for a crocheting forum... or something on Facebook. But I've never been on Facebook, and have no intention of changing that.
Let's talk program architecture: As everyone probably knows by now, I'm working on a backup program. Since the program will be started many times with similar settings (which files should be backed up, where should they be backed up to, etc), I'm planning to make a BackupConfig class to encapsulate all of these settings and to dump them to disk for future use. But there's also some data that shouldn't be dumped to disk, like the password that's used to encrypt the backup.
So I'm thinking of making another class, say BackupContext, that only exists while a backup is in progress, to store this temporary data. Basically like this. Does that sound reasonable, or is there a better way to go about this?
@AndrasDeak Ah! Your wife is also a mathematician, so she might be able to help me translate the notation to a more canonical form. :) The sphere pattern is fairly uniform, and only uses a very small number of stitch types.
@AndrasDeak This pattern only uses treble, and of course chain to get it started. The only complication is how the row length increase or decrease, which requires connecting 2 stitches in the current row to 1 in the previous when increasing. And I think that's the part of the notation that my mum said was weird.
@AnttiHaapala It's not the kind of builder that the builder pattern is referring to though, is it? Wikipedia lists "Requires creating a separate ConcreteBuilder for each different type of product." and "Requires the builder classes to be mutable." as two disadvantages, neither of which is true in python
@Aran-Fey Does BackupConfig save a hash of the password? Or do you not bother with that, and just attempt to use the password and catch the exception if it fails?
@PM2Ring I don't save a hash of the password, but I do have a mechanism that validates the password. I store a small encrypted chunk of data that I test the password against
@AndrasDeak Thanks. It might be a double rather than a treble. :) That would actually make more sense geometrically. I wrote this code 10 years ago, so I'm a bit hazy on the details.
@AnttiHaapala I'm only 3 paragraphs in, but the sentence "Functions are objects, first class objects (whatever that means)." is already getting me worried
@AndrasDeak I don't know much either. I can do chain stitch, though. :D I learned to knit when I was a kid, but mum always had to help me cast on & off. And I haven't done any knitting since then. It's pretty yamming boring if you have to concentrate on it. It's ok if you've learned to do it well enough so you can do it on autopilot while watching TV.
FWIW, mum was taught to knit by her dad, who was a carpenter by trade, and a general all-round handyman. Her mum didn't have the patience to be a good teacher. :)
My step-dad's mum was a prolific knitter, who kept the family supplied with excellent jumpers. But I didn't fully appreciate them at the time. :( I thought they were the poor person's alternative to "proper" machine-knitted clothes. What an idiot...
@AnttiHaapala Sorry, I didn't really get much out of that article. I still don't think that python has anything equivalent to a builder in the sense of the builder pattern. We have factories, yes - but not builders.
My grandpa could estimate the size of a piece of timber by eye accurate to 1/8 inch. And calculate the area of a board in his head accurate to 1/64 square inch. Not bad for a bloke who had to leave school at the end of 6th grade because he was needed on the family farm.
I have a question regarding several IP's that I have to call in a test.
The structure is as follows:
SSH on Switch 1
SSH on switch 2
My current source connects only to a switch
@Mornon Shouldn't you be working on making a MCVE for that question on the main site that you linked here an hour ago? If you don't do that, it will be very hard for anyone to give you a useful answer, so the question may be closed.