Idiomatic wheel factorization algorithm in OCaml?

One of my favorite algorithms to demonstrate the advantages of lazy fp is the wheel factorization algorithm.

In Python, translating pretty directly from Wikipedia pseudocode it looks like this:

def wheel_factor(n: int) -> int:
    inc = [4, 2, 4, 2, 4, 6, 2, 6]

    for prime in [2, 3, 5, 7, 11]:
        if n % prime == 0:
            return prime

    test = False

    k, i = 7, 0
    while not test and k * k <= n:
        test = n % k == 0
        if test: return k
        k += inc[i]
        i = i + 1 if i < 7 else 0
    return n

In Haskell, it's a lot clearer to understand, since infinitely cycling a list is really easy:

wheelFactor :: Int -> Int
wheelFactor n = 
    fromMaybe n $ find ((==0) . rem n) (takeWhile ((<= n) . (^2)) testLS)
         where testLS = 2 : 3 : 5 : 7 : zipWith (+) (cycle incr) (drop 3 testLS)
              incr = [4, 2, 4, 2, 4, 6, 2, 6]

I've started learning OCaml just yesterday and I'm wondering what the idiomatic way to write this algorithm is. I tried doing it the Haskell way with Streams but I don't think it will work similarly. It would probably pretty simple to translate the Python to pure OCaml by turning the loops into functions, but I'm sure there's a better way.

Can anyone give an example?

edit: fixed haskell

πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/Fish_45
πŸ“…︎ Oct 16 2021
🚨︎ report
My attempt at explaining wheel factorization orthallelous.wordpress.co…
πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/Orthallelous
πŸ“…︎ Mar 06 2019
🚨︎ report
[TOMT]A website that has a prime factorization wheel.

The website finds prime numbers and rotates around 'checking' if the next number is prime or not. The prime numbers were turned red. It started a spiral. I remember it being very mesmerizing. (It's the math nerd in me coming out)

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Ensivion
πŸ“…︎ Feb 26 2013
🚨︎ report
Few things I noticed today. Stamkos faster than Point (has Wheels X-Factor)? Kyle Connor is a Wheels X-Factor (previously it was a shooting X-Factor) with 89 speed? Pic of Malkin (non X-Factor Player) on section talking about X-Factors. Pics of Petterson and Zibanejad. reddit.com/gallery/q2cfao
πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/Miklo__Velka
πŸ“…︎ Oct 06 2021
🚨︎ report
My friend is obsessed with purchasing wheels for his E36 when he should be putting his money towards a seat, tires, more events, and other important factors that go with drifting. This time he picks up Work XT7's to go along with his Model 5's, SA3R's, and Panasport G7's. Hope you enjoy! youtu.be/ARvAstIGSwI
πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/potentjules
πŸ“…︎ Jul 16 2021
🚨︎ report
Newest addition to my homemade rig, pedals are more than night and day for performance. Still have Logitech wheel until csl DD pre order is fulfilled, does anyone think there are better options than csl DD for the price point and whatever factors are make or break for you, thanks
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/rkellyfangirl
πŸ“…︎ Jul 06 2021
🚨︎ report
Changing out my factor set wheels, bushings, and about to Scotchgard the suede
πŸ‘︎ 21
πŸ’¬︎
πŸ‘€︎ u/maryPinkBush
πŸ“…︎ May 13 2021
🚨︎ report
"What really sets us apart is the form factor itself...At the end of the day we shouldn't be making a tablet on wheels" - Derek Jenkins πŸ‘€ instagram.com/p/CP59Y9wst…
πŸ‘︎ 19
πŸ’¬︎
πŸ‘€︎ u/Lelebaby18
πŸ“…︎ Jun 09 2021
🚨︎ report
$1500 later, Motegi CM7s wrapped in Yokohama Advan Apex’s. Not the tire/wheel combo I wanted, but time was a huge factor. reddit.com/gallery/nkzivi
πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/Heavenly_Malice
πŸ“…︎ May 25 2021
🚨︎ report
Factor O2 with Bike Ahead Composite Biturbo wheels
πŸ‘︎ 549
πŸ’¬︎
πŸ‘€︎ u/giuliomagnifico
πŸ“…︎ Sep 05 2020
🚨︎ report
We apologize for Wheel of Yogg freezing the game. There is a .01% chance of it happening on the wheel, our failure to communicate these factors has led to incomplete projections, for which we apologize.
πŸ‘︎ 59
πŸ’¬︎
πŸ‘€︎ u/Ok-Quantity7601
πŸ“…︎ Nov 17 2020
🚨︎ report
A compact and agile jumping robot designed for mixed environments. The combination of wheels and legs allows it to move quickly on flat terrain and to overcome obstacles by jumping. Its small form factor renders it fit for tight indoor spaces and shows potential for high agile indoor mobility tasks. v.redd.it/at5entmarzp61
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Jay-Wevolver
πŸ“…︎ Mar 29 2021
🚨︎ report
Look at those wheels.... and are those rear fenders stuck on top of the factor fender?
πŸ‘︎ 6
πŸ’¬︎
πŸ‘€︎ u/vanguard_anon1233
πŸ“…︎ Mar 12 2021
🚨︎ report
Why I sold my Tesla Model 3 Performance & went back to gas

I owned a 2019 Tesla Model 3 Performance for roughly two years and 15,000 miles. I'm going to distill my key learnings and experiences here, in an attempt to educate others on EVs and reach some form of closure. My ownership could best be summed-up as a love/hate relationship, ending with crazy used car values offering me the out I'd been quietly seeking. Clearly, I decided EVs aren't for me - at least, not yet. I'm not a "paid big oil shill" or someone who's trying to short the stock, as I'm sure some of the Tesla nuts will claim. I'm just a car enthusiast (disclaimer: not an engineer) standing at the same crossroads as the rest of you, wondering what sounds future children will make long after (if?) our beloved bureaucrats outlaw the ICE.

Everything I'm writing here is based on my own unique tastes and preferences. How the pros and cons balance out at the end is entirely up to you. And that's fine. Choice is great. Note that this post centers on Battery EVs (BEVs) at the time of this writing, which comprise the vast majority of EVs on the road today.

And yeah. This got way longer than I anticipated. But it was cathartic for me and I hope it's at least somewhat useful to someone out there.

EV performance & its accessibility

I'll start with what ultimately sold me on the car - Immense, instant power. The war in the "pure acceleration" category is pretty much over - just take a look at Jason Cammisa's video with the Model S Plaid vs. the BMW M5 CS and Cadillac Crazy. They're not even on the same planet. Not only is the acceleration brutal, but it's consistent (everything else held constant - more on that later). Look up any number of 0 - 60 videos on YouTube, and you'll notice that the times are all remarkably close, especially if there are multiple runs in the same video.

And how could they not be? Software and traction control are fundamental to EV operation. Adjustments take mere milliseconds. The amount of "stuff" involved between your right foot and the tires is a joke compared to an ICE car. And it's basically idiot-proof - even with the Track Mode dialed to 100% hoon in my TM3P, it was nearly impossible to make a mistake. You just put your foot down and the car takes care of the rest, with literally zero drama.

Electric motors are great

And all of this performance comes with no mechanical sympathy. I never felt an ounce of it, flogging my Model 3 - there's really nothing to "break" mechanically in the way of the drivetrain. The ent

... keep reading on reddit ➑

πŸ‘︎ 4k
πŸ’¬︎
πŸ‘€︎ u/DegradingBattery
πŸ“…︎ Dec 31 2021
🚨︎ report
I was looking at these bikes. I want all chromally frame. A around 22' top tube, all these bikes are 22 wheels btw. A high end crank and sprocket are a deciding factor. Sealed hubs and such. Anyone other bikes I should get or one of these?
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Big-Economist9271
πŸ“…︎ Sep 18 2020
🚨︎ report
Jimmy Garoppolo throws an absolute dime on the deep wheel route to Kyle Juszczyk. We’ve seen that before β€” and this year, more than ever, seems like an X-factor option for the 49ers pass game. twitter.com/LombardiHimse…
πŸ‘︎ 232
πŸ’¬︎
πŸ‘€︎ u/Zockman175
πŸ“…︎ Aug 04 2019
🚨︎ report
If price was not a factor what vehicle should I get for the following uses: Towing a small trailer, all wheel drive, higher floor clearance, storage space, good fuel mileage.

Round trip commute is 60Km a day for work so something with decent gas mileage would be ideal. I have side gigs in the weekend that means I need to tow tools/lumber around. I like higher ground clearance and 4 wheel drive for Canadian winters. I need penalty of space for hunting/fishing trips. Any advice?

πŸ‘︎ 45
πŸ’¬︎
πŸ‘€︎ u/ricosalsa
πŸ“…︎ Jul 20 2019
🚨︎ report
Can I replace the menu screen on a ender 3 v2 with a bigtreetech v2? They look like the same form factor. I like the touch and wheel options.

Also would swapping out the 32bit board with a bigtreetech v2 board have any benifit.

Thanks so much, trying to jump into the water, just not sure where or how

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Tech_Badger
πŸ“…︎ Jul 22 2020
🚨︎ report
A compact and agile jumping robot designed for mixed environments. The combination of wheels and legs allows it to move quickly on flat terrain and to overcome obstacles by jumping. Its small form factor renders it fit for tight indoor spaces and shows potential for high agile indoor mobility tasks. v.redd.it/te9lshknb3061
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Jay-Wevolver
πŸ“…︎ Nov 19 2020
🚨︎ report
Motorhome vs 5th Wheel factoring in a Harley motorcycle.

I'm looking to get some opinions on the best setup for my situation. I'm planning to full-time RV in the near future and have been going back and forth between a 5th wheel and a Class A motorhome. I like a lot of aspects of both. I want to be able to bring along my 2017 HD Street Glide motorcycle too.

What I'm interested in getting opinions about is considering the motorcycle and the fact that I currently have a 2014 Ram 1500 that will be paid off in another year which setup would be the most ideal?

Setup #1: Motorhome

With this setup, I would be able to tow my current vehicle behind it and then get a lift for my motorcycle. This would put me in a better situation financially by my calculations because I would only be paying for the motorhome loan which can have longer terms than a normal auto loan to help with the monthly cost.

Setup #2: 5th Wheel

With this setup, I have to trade-in my truck for a full ton dually truck which will probably be around $50,000 for what I would want which is around $1,000/mo roughly then I would have to get the 5th wheel which if its a toy hauler will be around $80,000 and probably around $700/mo roughly.

So it would seem if I was going to be in it for around $1,750/mo in loan payments, I could score me a pretty nice diesel pusher for that price or save some monthly and get a not-as-nice DP.

What are some of your opinions on this if you were faced with this situation?

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/btyne79
πŸ“…︎ Feb 22 2020
🚨︎ report
Blind Girl Here. Give Me Your Best Blind Jokes!

Do your worst!

πŸ‘︎ 5k
πŸ’¬︎
πŸ‘€︎ u/Leckzsluthor
πŸ“…︎ Jan 02 2022
🚨︎ report
Some of my best Nimbus designs reddit.com/gallery/rfzih6
πŸ‘︎ 206
πŸ’¬︎
πŸ‘€︎ u/Lucky96u
πŸ“…︎ Dec 14 2021
🚨︎ report
The focus on "Who is the Dragon Reborn" instead of "Why the Dragon Reborn will make us weep for our salvation" is my biggest gripe with the show

TLDR: In order to have the cool effect, the show is overdramatizing things and I think it will end up hurting it big time and being canceled out in the long run I'm afraid.

Focusing on "Who" instead of "Why" is an artistic choice of course, which was made by Robert Jordan at the very beginning of the series. I don't remember exactly when that is revealed without a doubt since it's been a while since my last reread, but shouldn't be more than 100 pages in.

We know who is the Dragon Reborn. We are shown on the very first page the devastation he can bring to the world. We know the prophecies, and there is a deeply ingrained fear in most people, for the Dragon Reborn as he heralds the coming of the apocalypse so to speak. We understand the scale.

I'm not going to suggest the story as a whole is without any flaws of course. But no matter how I rack my brain for bad adjectives for the WoT books, I would never have thought the word "cheap" to describe its flaws. But focusing on "Who is the Dragon Reborn" instead of delving into "Why is Dragon Reborn so feared" is what makes this cheap. They are trying to go with "cool" instead of trusting in the source material for the storytelling aspects. And we can see multiple examples of this throughout the first season. I'll name a few:

Episode 1: Lan walks into Winesprings Inn looking intimidating and, lets be frank, like an idiot, then Nynaeve goes "Name yourself stranger". Not "Who are you" or "What do you want"... Seriously, who talks like that?

Episode 2: Nynaeve is able to track Lan... Ok ok, it's not Lan now, but it's Moiraine because she has a "tell" that Lan didn't know for the last however many years, because of.. reasons? Oh, also the Dragon Reborn could possibly be a woman now I guess.

Episode 3: Nynaeve had Marine training obviously. A random darkfriend in the middle of nowhere pulls a Terminator, and hates the world so much, and is so well versed in philosophy she is on par with one of the Forsaken's in that department.

Episode 4: The followers of Logain can sneak into a camp full of warders and Aes Sedai to bowshot distance. Nynaeve goes Super Saiyan.

Episode 5: Lan falls for Stepin's ploy (ok), then literally runs in SLO-MO to find him in his own pool of blood.

Episode 6: Oath Rod shenanigans. Really? You are establishing an organization that is shown that they can not lie, but they are required to take oaths for staying true to their word? And all that unnecessary drama of going off-script

... keep reading on reddit ➑

πŸ‘︎ 1k
πŸ’¬︎
πŸ‘€︎ u/goksekor
πŸ“…︎ Dec 27 2021
🚨︎ report
Void Predators Chapter 12

First - Previous - Next

Fleet-Cardinal Krenn watched from the bridge of his flagship as the planet below burned, and he was pleased. The cities of the Unworthy made for the perfect inaugural pyre for the renewal of the Holy Endeavor. They would continue to serve Kra as they had before the Mortification.

He shook his head in thought as he remembered those days. He had been a child when their Endeavor had first begun.

Initially, the Chosen's Holy Endeavor had met with success. Over a period of twenty years, a dozen unclean worlds had been discovered and cleansed, ready for the servants of Kra to purify. Three species of his Unworthy Children had even been fully extinguished! A triumph!

Kra had been pleased by his Chosen Children's attempts to aid his Great Servants, and rewarded them greatly. As their Endeavor progressed, His Great Servants had purified five unclean worlds very close to the Home Systems, each a blank slate, ready to be remade in the image of Kra's greatest work, Krathig-yar.

New homes and resources for the Chosen.

Then, disaster had struck. A large group of Unworthy species had been encountered, that worked together. They began coordinating their forces with others to oppose righteous cleansing. But the true depth of their depravity was revealed when they began employing unholy synthetic life against the Chosen; Thou Shalt Not Create Life, For That Is The Domain Of Kra.

The Chosen had despaired, as their fleets had been destroyed, corrupted by the Unworthy's unholy familiars, and been pushed back to the Home Systems.

It had taken what became known as The Mortification to stop them, so named because it was both a humiliation and a penance. Humiliated by their defeats at the hands of the Unworthy, The Chosen had thrown themselves at their enemy in the millions, using ramshackle, quickly built ships with as little automation as possible to prevent corruption.

It had required the sacrifice of twenty percent of their population to stop the Unworthy, but they had done it. He remembered, as a young priest-captain, watching from the bridge of his ship as their enemy finally withdrew.

The massive funeral pyres on the surface of Krathig-yar after.

Two decades of salvaging and rebuilding their fleet.

But this time, they would not fail. The Mortification had purged the weakness from the Cho

... keep reading on reddit ➑

πŸ‘︎ 1k
πŸ’¬︎
πŸ“…︎ Jan 05 2022
🚨︎ report
What was the deciding factor for your wheel setup?
πŸ‘︎ 24
πŸ’¬︎
πŸ‘€︎ u/ngostalgic
πŸ“…︎ Jul 18 2019
🚨︎ report
What starts with a W and ends with a T

It really does, I swear!

πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/PsychedeIic_Sheep
πŸ“…︎ Jan 13 2022
🚨︎ report
Dropped my best ever dad joke & no one was around to hear it

For context I'm a Refuse Driver (Garbage man) & today I was on food waste. After I'd tipped I was checking the wagon for any defects when I spotted a lone pea balanced on the lifts.

I said "hey look, an escaPEA"

No one near me but it didn't half make me laugh for a good hour or so!

Edit: I can't believe how much this has blown up. Thank you everyone I've had a blast reading through the replies πŸ˜‚

πŸ‘︎ 19k
πŸ’¬︎
πŸ‘€︎ u/Vegetable-Acadia
πŸ“…︎ Jan 11 2022
🚨︎ report
Which players would you like to see if they add additional xfactors?
πŸ‘︎ 17
πŸ’¬︎
πŸ‘€︎ u/AAfreakinRON
πŸ“…︎ Dec 15 2021
🚨︎ report
What is a a bisexual person doing when they’re not dating anybody?

They’re on standbi

πŸ‘︎ 11k
πŸ’¬︎
πŸ‘€︎ u/Toby-the-Cactus
πŸ“…︎ Jan 12 2022
🚨︎ report
What do you call quesadillas you eat in the morning?

Buenosdillas

πŸ‘︎ 12k
πŸ’¬︎
πŸ‘€︎ u/FarronKeepSucks
πŸ“…︎ Jan 14 2022
🚨︎ report
Razer Basilisk Mercury - True 16.000 5G Optical Sensor - Removable Dpi Clutch & Customizable Scroll Wheel Resistance - Ergonomic Form Factor - Esports Mouse $74.35 CAD (lowest) amazon.ca/dp/B07R9ZNPTH/r…
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/flipzone
πŸ“…︎ Sep 30 2020
🚨︎ report
Worst X factor choice pack possible? Can anybody top this?
πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/SeeJ8512
πŸ“…︎ Dec 23 2021
🚨︎ report
Welp, hopefully don’t regret it. Could have built him but felt two was better than one. Back to chasing X-Factor McDavid.
πŸ‘︎ 19
πŸ’¬︎
πŸ‘€︎ u/jrodvog148
πŸ“…︎ Jan 01 2022
🚨︎ report
Geddit? No? Only me?
πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/shampy311
πŸ“…︎ Dec 28 2021
🚨︎ report
I wanna hear your best airplane puns.

Pilot on me!!

πŸ‘︎ 3k
πŸ’¬︎
πŸ‘€︎ u/Paulie_Felice
πŸ“…︎ Jan 07 2022
🚨︎ report
E or ß?
πŸ‘︎ 9k
πŸ’¬︎
πŸ‘€︎ u/Amazekam
πŸ“…︎ Jan 03 2022
🚨︎ report
β€œAfter you’ve done this 70 times, doesn’t it begin to seem kind of pointless?”

>When I had slept with three or four girls this way, I asked Nagasawa, β€œAfter you’ve done this 70 times, doesn’t it begin to seem kind of pointless?”
>
>β€œThat proves you’re a decent human being,” he said. β€œCongratulations. There is absolutely nothing to be gained from sleeping with one strange woman after another. It just tires you out and makes you disgusted with yourself. It’s the same for me.”
>
>β€œSo why the hell do you keep it up?”
>
>β€œHard to say. Hey, you know that thing Dostoevsky wrote on gambling? It’s like that. When you’re surrounded by endless possibilities, one of the hardest things you can do is pass them up. See what I mean?”
>
>β€œSort of.”

I think about this passage from time to time. It’s from my favorite novel, Norwegian Wood by Haruki Murakami.

I’m turning 29 next month and I’ve slept with almost 200 woman so far. I’ve been feeling slightly nostalgic lately and I stumbled upon this subreddit. So I guess I’m venting a bit. Posting this on a throwaway account..

In the past week, I slept with 5 different women and I’m seeing someone else in a few hours…

Some proof if you’d like haha: https://imgur.com/a/ntJE9LW

I met a few of them off dating apps recently, and the others I see once in a while. Last week, my best friend asked me, β€œDon’t you ever get tired of it?” And that’s when I smirked and repeated… β€œWhen you’re surrounded by endless possibilities, one of the hardest things you can do is pass them up.” And then I added that I was still young and single! I’m a bachelor! Why shouldn’t I date around? He laughed and said, β€œFair enough.”

When I think about this passage, it’s just a fleeting observation that never changes the way I live my life. If only I came across it as an extrinsic shock that shook up my reality! But humans are goddamn creatures of habit. At times, I dimly think about how I can’t keep living this way.

β€”β€”β€”

I’m Asian American. I’m like 5’7 or 5’8 and I don’t come from money. I do well for myself, but I wouldn't say I'm well off. So height or money doesn't really play a factor here.

I was born here in the states and moved to New York when I was 18. When I was 20, I dated this 26 year old. That relationship fell apart after we travelled together to Paris. You learn a lot about your relationship when you travel with your partner for the first time.

β€œYou don’t know what you want,” she’d always tell me. I was heartbroken as hell when it ended and

... keep reading on reddit ➑

πŸ‘︎ 228
πŸ’¬︎
πŸ‘€︎ u/honjowolf
πŸ“…︎ Jan 09 2022
🚨︎ report
EA we need more Ability Points!
πŸ‘︎ 41
πŸ’¬︎
πŸ‘€︎ u/Much-Writer4755
πŸ“…︎ Jan 02 2022
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.