2024/11/01

Newest at the top

2024-11-01 12:34:55 +0100 <mauke> nthPowerTwo k could be replaced by 2 ^ k
2024-11-01 12:34:23 +0100 <mauke> anyway, that looks like it would work
2024-11-01 12:33:05 +0100 <mauke> (and give us the link)
2024-11-01 12:32:24 +0100 <sprotte24> ok
2024-11-01 12:31:58 +0100 <mauke> use a paste site like https://paste.tomsmeding.com to show code
2024-11-01 12:31:50 +0100 <mauke> plase don't paste into IRC
2024-11-01 12:31:43 +0100 <sprotte24> nthPowerTwo n = if n==0 then 1 else 2*nthPowerTwo(n-1)
2024-11-01 12:31:43 +0100 <sprotte24> nthPowerTwo :: Int -> Int
2024-11-01 12:31:43 +0100 <sprotte24> -- 3.1 nthPowerTwo
2024-11-01 12:31:10 +0100 <sprotte24> roundUpToPowerTwo n = roundUpToPower2 n 1
2024-11-01 12:31:08 +0100 <sprotte24> roundUpToPowerTwo :: Int -> Int
2024-11-01 12:31:08 +0100 <sprotte24> else roundUpToPower2 n (k + 1)
2024-11-01 12:31:08 +0100 <sprotte24> else if (nthPowerTwo k) >= n then (nthPowerTwo k)
2024-11-01 12:31:08 +0100 <sprotte24> roundUpToPower2 n k = if n == 1 then 1
2024-11-01 12:31:08 +0100 <sprotte24> roundUpToPower2 :: Int -> Int -> Int
2024-11-01 12:31:08 +0100 <sprotte24> -- 3.3 next power2
2024-11-01 12:30:05 +0100 <Hecate> sprotte24: don't hesitate to use play.haskell.org !
2024-11-01 12:29:05 +0100 <sprotte24> I show it, one moment please
2024-11-01 12:28:49 +0100 <sprotte24> I had a solution, but that solution used 2 parameters n and k.
2024-11-01 12:28:06 +0100 <sprotte24> In my recursive loop I have to Test an to increment the Power index.
2024-11-01 12:27:34 +0100morb(~morb@pool-108-41-100-120.nycmny.fios.verizon.net) (Ping timeout: 260 seconds)
2024-11-01 12:26:55 +0100 <mauke> any "loop variable" that changes in the loop is going to become a function parameter
2024-11-01 12:26:33 +0100lortabac(~lortabac@2a01:e0a:541:b8f0:55ab:e185:7f81:54a4) (Ping timeout: 265 seconds)
2024-11-01 12:26:32 +0100 <mauke> (or a data structure like a list, but you're not allowed to do that, apparently)
2024-11-01 12:26:15 +0100 <mauke> yeah, if you want to emulate a loop in functional code, it's always going to be a recursive function
2024-11-01 12:25:44 +0100 <sprotte24> I plan to build an recursive solution?
2024-11-01 12:24:51 +0100 <sprotte24> I suppose I need a local variaable for k?
2024-11-01 12:24:42 +0100 <mauke> where are you stuck?
2024-11-01 12:24:30 +0100weary-traveler(~user@user/user363627) user363627
2024-11-01 12:24:24 +0100 <mauke> ah, the slow way
2024-11-01 12:24:01 +0100 <sprotte24> One Problem: my input parameter is n and I have to increment k until the condition is satisfied
2024-11-01 12:23:36 +0100misterfish(~misterfis@31-161-39-137.biz.kpn.net) misterfish
2024-11-01 12:22:41 +0100 <sprotte24> I have to test whether nearestPowerOfTwo n >= 2^k
2024-11-01 12:22:40 +0100morb(~morb@pool-108-41-100-120.nycmny.fios.verizon.net)
2024-11-01 12:21:45 +0100 <Rembane> Hecate: Sure thing! :D
2024-11-01 12:21:33 +0100 <Hecate> Rembane: lovely. :) Say hi to Andreas Abel from me if you meet him
2024-11-01 12:21:21 +0100 <sprotte24> I am not allowed to use a list
2024-11-01 12:20:29 +0100 <Rembane> Hecate: Still at Chalmers! I'll be done any day now. :D
2024-11-01 12:20:21 +0100 <lambdabot> (Ord c, ?n::c, Num c) => c
2024-11-01 12:20:20 +0100 <mauke> :t head . dropWhile (< ?n) . iterate (2 *) $ 1
2024-11-01 12:20:15 +0100 <sprotte24> ok. if I use binary number, the Powers of 2 have the format 1, 10 100 1000 and so on
2024-11-01 12:19:23 +0100 <Hecate> Rembane: I'm not doing too bad! Still at Chalmers?
2024-11-01 12:18:46 +0100 <Hecate> damnit I was about to suggest that hahahaha
2024-11-01 12:18:38 +0100 <mauke> like bit shifts?
2024-11-01 12:18:33 +0100 <mauke> define "using binary"
2024-11-01 12:18:23 +0100 <sprotte24> The restriction: using binary is forbidden.
2024-11-01 12:18:22 +0100 <Rembane> Hecate: Suuuuuuuuuuuuuuuuuup! :D
2024-11-01 12:18:15 +0100 <mauke> yeah, that actually makes things easier
2024-11-01 12:18:03 +0100 <Hecate> mauke: maybe they have to round to the highest power of 2
2024-11-01 12:17:41 +0100 <sprotte24> Yes. kome work