![]() |
I used the exact same .iso file that I used a couple of weeks ago for today’s installation, but I ran into a bunch of problems. First of all, the laptop is a little Lenovo and I had to figure out how to get into the BIOS to fix the boot order, which was way more complicated than it should’ve been. I was able to load into the OpenSUSE installer, but in the process of customizing the partitioning settings something got messed up, and the 30 minute installation ended up doing nothing.
Eventually I just went with the standard, preset partitioning, but it did some weird stuff anyways. The laptop has a 250 GB SSD and a 32 Gb eMMC card. I’m pretty sure the eMMC is faster so I wanted to put something reasonably important on it, but in the end it’s completely unused and I think it’s not even included in any of the main partitions. Then I rebooted the laptop and it wouldn’t boot without the installation media. After finally getting into the system it works fine, but I think the bootloader is messed up. Turns out that OpenSUSE has a lot of extremely detailed documentation, including troubleshooting a bad installation, so I’m currently trying to reinstall the bootloader which requires me to go into a “change root” instance or something and it’s really confusing :jvang: |
[QUOTE=jvang;492806]Then I rebooted the laptop and it wouldn’t boot without the installation media. After finally getting into the system it works fine, but I think the bootloader is messed up.[/QUOTE]
As a general rule, there are 2 things to get sharply into focus when solving any problem like this: [LIST=1][*]How exactly is it supposed to work?[*]What is actually happening instead?[/LIST]Boot problems are harder to localize as you have fewer tools up and running at the point where it goes wrong. But the Gnu GRUB bootloader has lots of flexibility, which should help! |
[QUOTE=Nick;492822]As a general rule, there are 2 things to get sharply into focus when solving any problem like this:
[LIST=1][*]How exactly is it supposed to work?[*]What is actually happening instead?[/LIST]Boot problems are harder to localize as you have fewer tools up and running at the point where it goes wrong. But the Gnu GRUB bootloader has lots of flexibility, which should help![/QUOTE] Indeed, GRUB has a lot of things for me to try as far as fixing whatever’s wrong with the bootloader. Although if the problem isn’t the bootloader then I might have some trouble, since I’d rather not need the installation media for every boot/restart :max: |
[QUOTE=Nick;492280]Let n be a positive integer, and \( s=1+2+3+\ldots +n\).
Then we also have \( s=n+(n-1)+(n-2)+\ldots +3+2+1\). What happens if we add up corresponding terms on the right? \[\begin{eqnarray*} 1+n & = & n+1 \\ 2+(n-1) & = & n+1 \\ 3+(n-2) & = & n+1 \\ \vdots \\ (n-1)+2 & = & n+1 \\ n+1 & = & n+1 \\ \end{eqnarray*}\] So it follows that \[ 2s=\underbrace{(n+1)+(n+1)+\ldots +(n+1)}_{n} = n(n+1) \] hence \[ s=\frac{n(n+1)}{2}. \] Now multiply everything by 3 or by 5...[/QUOTE] I've taken another look at how this works since my dad was having trouble understanding it and applying it to [URL="https://www.codewars.com/kata/multiples-of-3-and-5-redux/"]Multiples of 3 and 5 redux[/URL]. I understand Gauss's trick, and multiplying the sum by any number returns the sum of the first n multiples of that number. In this case you would do this for multiples of 3, add that to the sum of the multiples of 5, and subtract the sum of the multiples of 15 (their LCM) But the CodeWars problem asks for the sum of the multiples [I]below[/I] the input number. I figured that I could just divide the sum by 3, 5, and/or 15: [$]\dfrac{n(n + 1)}{2} \div 3 = [/$] sum of multiples of 3 below n But... that doesn't completely work. It's very close and for several values it is accurate. Actually, a pattern: Edit: In the process of putting this post together I decided to write a function to compare summing the list of multiples the obvious way and the Gauss's trick way. I ran into a bunch of really weird newline problems and it took me way too long to put together this silly little function :ermm: The first outputted line is Gauss, second line is normal sum-list way. Another Edit: Aw man! In my first attempt I had "/n" instead of "\n". No wonder I was having so much trouble :bangheadonwall: Oh well, I'll keep the crazy code since it took too much of my time... [CODE]Prelude> gauss n = div (n * (n + 1)) 2 Prelude> comparison x = putStr $ unlines [(show (div (gauss x) 3)),(show (sum [3,6..x]))] Prelude> comparison 100 1683 1683 Prelude> comparison 101 1717 1683 Prelude> comparison 102 1751 1785 Prelude> comparison 103 1785 1785 Prelude> comparison 104 1820 1785 Prelude> comparison 105 1855 1890 Prelude> comparison 106 1890 1890 Prelude> comparison 107 1926 1890 Prelude> comparison 108 1962 1998 Prelude> comparison 109 1998 1998 Prelude> comparison 110 2035 1998[/CODE] When the input is a multiple of 3 plus 1, the values are the same. But I can't exactly only take inputs that are a multiple of 3 plus 1, so how would I code that? Btw, [c]unlines[/c] converts a list of strings to a string with newlines between each input string, and [c]putStr[/c] properly displays the newlines. |
[QUOTE=jvang;492865]But the CodeWars problem asks for the sum of the multiples [I]below[/I] the input number. I figured that I could just divide the sum by 3, 5, and/or 15:
[$]\dfrac{n(n + 1)}{2} \div 3 = [/$] sum of multiples of 3 below n But... that doesn't completely work. It's very close and for several values it is accurate. [/QUOTE] Let n be a positive integer and put m=div (n-1) 3, i.e. m is n-1 divided by 3 and rounded down to the nearest integer. Then the largest multiple of 3 below n is 3m. So what you want is \(3+6+9+\ldots +3m\), for which you've already worked out the formula! |
[QUOTE=Nick;492873]Let n be a positive integer and put m=div (n-1) 3, i.e. m is n-1 divided by 3 and rounded down to the nearest integer.
Then the largest multiple of 3 below n is 3m. So what you want is \(3+6+9+\ldots +3m\), for which you've already worked out the formula![/QUOTE] Ooooooook that math made sense but coding it was really weird :yucky: Here's what runs and gives the correct sum of the multiples of 3 below (and including) a number: [CODE]Prelude> gauss n = div (n * (n + 1)) 2 Prelude> thingy n = gauss ((3 * (div (n) 3)) + 1) Prelude> comparison x = putStr $ unlines [(show (div (thingy x) 3)),(show (sum [3,6..x]))] Prelude> comparison 98 1584 1584 Prelude> comparison 99 1683 1683 Prelude> comparison 100 1683 1683 Prelude> comparison 101 1683 1683 Prelude> comparison 102 1785 1785 Prelude> comparison 103 1785 1785 Prelude> comparison 104 1785 1785[/CODE] Yay! And it works for all the numbers I tested that were above -3, so that's nice. Ooh! A fancy command, [c]:set +m[/c] in GHCi allows [c]let[/c] statements to go over multiple lines, letting you define multiple-line functions in GHCi :whee: I applied this fancy new algorithm to multiples of 5 and 15, but I had to tweak each one individually: [CODE]Prelude> gauss n = div (n * (n + 1)) 2 Prelude> thingy3 n = gauss ((3 * (div (n) 3)) + 1) Prelude> comparison3 x = putStr $ unlines [(show (div (thingy3 x) 3)),(show (sum [3,6..x]))] Prelude> thingy5 n = gauss ((5 * (div (n) 5)) + 2) Prelude> comparison5 x = putStr $ unlines [(show (div (thingy5 x) 5)),(show (sum [5,10..x])) Prelude> thingy15 n = gauss ((15 * (div (n) 15)) + 7) Prelude> comparison15 x = putStr $ unlines [(show ((div (thingy15 x) 15) - 1)),(show (sum [15,30..x]))][/CODE] Each one returns the proper sum, but I had to do some custom trial-and-error tests to get the right tweaks with +/- 1 and stuff. Otherwise I'd be able to write a more generic [c]comparison[/c] function with 2 inputs, the first being the upper bound and the second being the multiples to count by. I don't understand why the [c]thingy[/c]s and whatnot need to be different though... I finally finished up the [URL="https://www.codewars.com/kata/multiples-of-3-and-5-redux"]kata[/URL]; renamed some functions and subtracted 1 from each input because I forgot it wanted the sum of the multiples below the input, [I]not[/I] inclusive. Runs as fast as some of the other solutions and about 10-20% slower than the best solution I found on the solutions page... [CODE]module Codewars.Kata.MultiplesRedux where solution :: Integer -> Integer solution x = mult3Sum (x-1) + mult5Sum (x-1) - mult15Sum (x-1) gaussSum n = div (n * (n + 1)) 2 mult3Sum n = div (gaussSum ((3 * (div (n) 3)) + 1)) 3 mult5Sum n = div (gaussSum ((5 * (div (n) 5)) + 2)) 5 mult15Sum n = (div (gaussSum ((15 * (div (n) 15)) + 7)) 15) - 1[/CODE] Thanks for your help Nick! :bow: |
On another note, I'm still unable to explain all of this to my dad. I'll break down the steps of your proof to see if we can clarify...
[QUOTE=Nick;492280]Let n be a positive integer, and \( s=1+2+3+\ldots +n\).[/QUOTE] He gets this. Yay! [QUOTE=Nick;492280]Then we also have \( s=n+(n-1)+(n-2)+\ldots +3+2+1\).[/QUOTE] He doesn't know why the last 3 numbers are 3, 2, 1. I said that we can assume a general case where the last term is [$]n - n[/$], which made more sense to him. [QUOTE=Nick;492280]What happens if we add up corresponding terms on the right? \[\begin{eqnarray*} 1+n & = & n+1 \\ 2+(n-1) & = & n+1 \\ 3+(n-2) & = & n+1 \\ \vdots \\ (n-1)+2 & = & n+1 \\ n+1 & = & n+1 \\ \end{eqnarray*}\][/QUOTE] He wasn't sure of where the [$]n + 1[/$] and [$]n - 1[/$] terms came from or what they represent, but the idea of equivalence was clear-ish. [QUOTE=Nick;492280]So it follows that \[ 2s=\underbrace{(n+1)+(n+1)+\ldots +(n+1)}_{n} = n(n+1) \] hence \[ s=\frac{n(n+1)}{2}. \][/QUOTE] Nothing from this makes sense to him. Where did all of these [$]n + 1[/$]s come from and what do they have to with [$]2s[/$]? He gets that [$]2s[/$]represents double the sum of [FONT="Fixedsys"][1..n][/FONT], but that's about it. How can I explain this to him? We haven't touched the solution to the kata yet, but I think that'll be easier to explain once this is sorted out. |
[QUOTE=jvang;492937]How can I explain this to him? We haven't touched the solution to the kata yet, but I think that'll be easier to explain once this is sorted out.[/QUOTE]
Here is a worked out example with n = 5. n+1 = 6. s = 15. 2s = 30. The rows are the n+1. There are n of them. The 1st column is (1+2+...n), second column is (n+(n-1)+...1) [CODE] 1 + 5 = 6 2 + 4 = 6 3 + 3 = 6 4 + 2 = 6 5 + 1 = 6 -------------- 15 + 15 = 30 [/CODE] |
[QUOTE=jvang;492937]On another note, I'm still unable to explain all of this to my dad.[/QUOTE]Your old man sounds like he is really dense.
:sad: The good news is: If you can explain something to him so that he fully understands it, then you really know what you are talking about! :tu: |
I have been attempting a hard puzzle and as part of that I need a function that can return a modified array. I thought this would be a good challenge for jvang.
modifyArray :: [[Int]] -> Int -> Int -> Int -> [[Int]] modifyArray orig row col newval = Input of [[2, 2, 1, 3],[2, 2, 3, 1],[1, 2, 2, 3],[3, 2, 1, 3]] 1 2 10 returns [[2, 2, 1, 3],[2, 2, 10, 1],[1, 2, 2, 3],[3, 2, 1, 3]] |
[QUOTE=henryzz;492980]I have been attempting a hard puzzle and as part of that I need a function that can return a modified array. I thought this would be a good challenge for jvang.
modifyArray :: [[Int]] -> Int -> Int -> Int -> [[Int]] modifyArray orig row col newval = Input of [[2, 2, 1, 3],[2, 2, 3, 1],[1, 2, 2, 3],[3, 2, 1, 3]] 1 2 10 returns [[2, 2, 1, 3],[2, 2, 10, 1],[1, 2, 2, 3],[3, 2, 1, 3]][/QUOTE] I don't have much experience with arrays (are they just lists of lists?), so I don't know how the newval is located with the rows and columns. At first glance I'd think that row 1, column 2 would be the second 2 in the first list, but instead it's the 3rd value of the second list... :jvang: Got my first couple of level 5 katas completed, [URL="https://www.codewars.com/kata/51fc12de24a9d8cb0e000001"]ISBN-10 Validation[/URL] and [URL="https://www.codewars.com/kata/530e15517bc88ac656000716"]Rot13[/URL]. Took some weird thinking and lots of trial and error, but definitely worth a shot. Learning about basic job control in Linux, using the [c]fg[/c] and [c]bg[/c] commands or ending input lines with [c]&[/c]. It's helpful when I'm writing large amounts of data to a USB drive, or doing something similar that takes a long time, since I can get the prompt back immediately for other tasks. From a quick look on Google it seems that you can write bash scripts to automatically start/stop processes, but that seems kinda complicated :unsure: |
| All times are UTC. The time now is 10:06. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.