Newest at the top
2024-04-20 14:17:07 +0200 | <Guest13> | I understand that this works now I just need to understand foldl vs foldr |
2024-04-20 14:16:32 +0200 | <Guest13> | I think a map would be good also |
2024-04-20 14:16:27 +0200 | <Guest13> | yes this would be better |
2024-04-20 14:15:51 +0200 | <ph88> | https://bpa.st/FXRA |
2024-04-20 14:15:40 +0200 | <ncf> | you should zip with [0..] |
2024-04-20 14:15:36 +0200 | <ncf> | oh i see you already have an off-by-one since you're zipping with [1..] instead of [0..] |
2024-04-20 14:15:20 +0200 | divya | (~user@202.170.201.110) (Ping timeout: 245 seconds) |
2024-04-20 14:15:16 +0200 | <ph88> | does the compiler optimize this function by short circuiting on Left? https://bpa.st/RNTQ |
2024-04-20 14:15:10 +0200 | tromp | (~textual@92-110-219-57.cable.dynamic.v4.ziggo.nl) (Read error: Connection reset by peer) |
2024-04-20 14:14:54 +0200 | ph88 | (~ph88@91.64.63.48) |
2024-04-20 14:14:26 +0200 | <Guest13> | yes I've got the correct answer now thank you! I changed it to acc!!(I-1) also as well as using foldl |
2024-04-20 14:13:15 +0200 | <Guest13> | scanL? |
2024-04-20 14:13:11 +0200 | <Guest13> | scan? |
2024-04-20 14:12:57 +0200 | <ncf> | btw you can replace fold with scan to see the intermediate results |
2024-04-20 14:12:29 +0200 | <Guest13> | I do want it to go from left to right |
2024-04-20 14:12:22 +0200 | <Guest13> | I think this is it yes |
2024-04-20 14:11:05 +0200 | <ncf> | then i get [(1,1),(2,2),(3,4),(4,8),(5,12),(6,1)], a bit off from what you expect |
2024-04-20 14:10:43 +0200 | <ncf> | i think you want to traverse wins left-to-right, so use foldl instead of foldr |
2024-04-20 14:09:57 +0200 | <Guest13> | } |
2024-04-20 14:09:56 +0200 | <Guest13> | } |
2024-04-20 14:09:56 +0200 | <Guest13> | } |
2024-04-20 14:09:55 +0200 | <Guest13> | cards_vec[i+j as usize] += 1 * cards_vec[I]; |
2024-04-20 14:09:55 +0200 | <Guest13> | if (i + j as usize) < cards_vec.len() { |
2024-04-20 14:09:54 +0200 | <Guest13> | for j in 1..=win { |
2024-04-20 14:09:54 +0200 | <Guest13> | for (i, &win) in wins_vec.iter().enumerate() { |
2024-04-20 14:09:53 +0200 | <Guest13> | let mut cards_vec = vec![1; wins_vec.len()]; |
2024-04-20 14:09:53 +0200 | <Guest13> | not sure if it helps, but what I am trying to do is something like what I did in Rust: |
2024-04-20 14:08:12 +0200 | <Guest13> | the desired output of the fold is [(1,1),(2,2),(3,4),(4,8),(5,14),(6,1)] |
2024-04-20 14:06:37 +0200 | <Guest13> | https://play.haskell.org/saved/pPbc3Jm5 |
2024-04-20 14:06:30 +0200 | <Guest13> | sorry let me put the test in string |
2024-04-20 14:06:23 +0200 | <ncf> | Main: input/04.txt: openFile: does not exist (No such file or directory) |
2024-04-20 14:06:01 +0200 | madeleine-sydney | (~madeleine@c-76-155-235-153.hsd1.co.comcast.net) (Quit: Konversation terminated!) |
2024-04-20 14:04:44 +0200 | <Guest13> | https://play.haskell.org/saved/Fw88Z29V |
2024-04-20 14:03:21 +0200 | <ncf> | can you post a reproducer on https://play.haskell.org/ ? |
2024-04-20 14:01:52 +0200 | <Guest13> | it updates the correct values but it should be a +2 because multiplier = snd(2,2) |
2024-04-20 14:01:15 +0200 | <Guest13> | sorry, the correct second step should be [(1,1),(2,2),(3,4),(4,4),(5,2),(6,1)] |
2024-04-20 14:00:51 +0200 | <Guest13> | the correct second step should be [(1,1),(2,2),(3,4),(5,4),(6,1)] |
2024-04-20 14:00:51 +0200 | <Guest13> | third step: [(1,1),(2,2),(3,3),(4,4),(5,3),(6,1)] |
2024-04-20 14:00:50 +0200 | <Guest13> | second step: [(1,1),(2,2),(3,3),(4,3),(5,2),(6,1)] |
2024-04-20 14:00:50 +0200 | <Guest13> | first step: [(1,1),(2,2),(3,2),(4,2),(5,2),(6,1)] |
2024-04-20 13:59:40 +0200 | <ski> | "is multiplier set to the value at each step of fold?" -- yes. each step gets a new `acc', and `multiplier' depends on this particular `acc' |
2024-04-20 13:59:32 +0200 | <Guest13> | this is what I would want |
2024-04-20 13:59:14 +0200 | <ncf> | it's defined in a where clause local to `go`, so you get a new value for each step of the fold |
2024-04-20 13:58:42 +0200 | <ski> | or, differently said, you update by making a new version, which differs in the way you wanted the "update" |
2024-04-20 13:58:29 +0200 | <Guest13> | or before the fold starts it is set |
2024-04-20 13:58:18 +0200 | <Guest13> | is multiplier set to the value at each step of fold? |
2024-04-20 13:57:20 +0200 | <ncf> | you don't update things in haskell |
2024-04-20 13:56:31 +0200 | <Guest13> | I feel like multiplier is set to 1 at the start and not updated in each step of the fold like I would want |
2024-04-20 13:56:01 +0200 | <Guest13> | which it shouldnt |
2024-04-20 13:55:57 +0200 | <Guest13> | funnily enough changing it to I produces the same result |