#development

1 messages Β· Page 146 of 1

lyric mountain
#

free skins, 6v6, no push, actual events

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

craggy pine
#

atleast I play the cute gloomy girl.

sage bobcat
#

One message removed from a suspended account.

craggy pine
#

Her name be Vex

sage bobcat
#

One message removed from a suspended account.

lyric mountain
#

the anti-mage mage with anti-dash kit that has a dash

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

craggy pine
#

Also Play mrs Neeko because shes best decision! That's her lil catch phrase.

lyric mountain
#

we need to schedule to play dota one day

sage bobcat
#

One message removed from a suspended account.

lyric mountain
#

all homies doing shit in dota

sage bobcat
#

One message removed from a suspended account.

craggy pine
#

I've never touched dota nor will I probably lol

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

lyric mountain
#

it's different to league, but I find it more amusing to play

#

also the community is somewhat less toxic cuz ur forced to play as a team

craggy pine
#

If you follow league at all, did you see Naafiri? I tested them out and man, I love it.

lyric mountain
#

didn't yet, it's been some time since I stopped league

lyric mountain
#

used to be very active on it, even got a $500 prize on my guide once

craggy pine
#

Naafiri is a new JNG / Mid assassin. They did really good on the trailer.

deft wolf
#

I'm waiting for nerfs so they gonna kill her like Rell and Nilah kapp

craggy pine
#

shell be broken for the first few weeks on release likely. Then they'll do nerfs.

quartz kindle
#

i play tentacles

#

broken bones teach better lessons

#

i also play spin to win

#

demaciaaaaaaa

craggy pine
#

So what you're saying Tim is that your a stinky Top laner. :P. Jk Top is my second role using Mord / Lilia

quartz kindle
#

i hate mord

#

but what i hate the most is vayne top

#

gtfo with that

craggy pine
#

I've done that like once or twice, I don't really enjoy playing it. I've done Cait more top lane for the ADC's

quartz kindle
#

never seen cait top lmao

craggy pine
#

It works well due to her range and most tops being melee.

quartz kindle
#

for adcs i play ashe and ezreal

craggy pine
quartz kindle
#

probably higher than my numbers lmao

craggy pine
#

If you notice the neeko LP gain, that was b4 her buff. I mained neeko mid from bronze to silver and it worked quite well surprisingly.

quartz kindle
#

this is current season

craggy pine
#

Aye brand lol.

quartz kindle
#

lel

craggy pine
#

Seems you kind all over the place in roles tho

#

I see top mid jng adc

#

just no sup

lyric mountain
#

karma

craggy pine
#

I mean, Karma can be mid πŸ˜›

quartz kindle
#

karma and brand are my sups

#

but i build them dmg

craggy pine
#

Ah see my Brand is mid.

quartz kindle
#

i rarely ever build sup items

#

i played brand mid once, hated it

#

lmao

#

couldnt farm for shit

craggy pine
#

Its so easy.

quartz kindle
#

i prefer playing it support and focus on dealing damage

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

sage bobcat
#

One message removed from a suspended account.

quartz kindle
#

"my god doesnt want peace"

craggy pine
#

Shes stupid good and I hate vs them

#

Presses R immediate death.

sage bobcat
#

One message removed from a suspended account.

quartz kindle
#

its highly matchup dependant tho, there are a lot of counters against her

#

i love playing her against brawler top+duo

#

but i hate playing her against ranged/kiting teams

#

she does nothing against that

sage bobcat
#

One message removed from a suspended account.

quartz kindle
#

KONICHIWAAA

#

III OTENKI DESU NEEEE

sage bobcat
#

One message removed from a suspended account.

craggy pine
#

I mean, if I've vs illaoi, Lilia is pretty decent match up

#

even if you hook me, speed deer dont care.

quartz kindle
#

a good lilia is so annoying

#

i've only seen a good lilia once tho

#

she carried her entire team

craggy pine
#

Well you're talking to a pretty decent lilia

quartz kindle
#

nice

craggy pine
#

all top lanes, no jng

#

well besides the aram ofc

quartz kindle
#

you know whats sad

craggy pine
#

whats your IGN @quartz kindle ill shoot you a fr maybe we can game sometime.

quartz kindle
#

i have years and years of lol game history that has been lost forever due to riot api changes and them not recording non-ranked games

craggy pine
#

sad

quartz kindle
#

so much fun moments that can never be found again

#

i rememebr i used to keep offline logs stored for safe keeping

#

idk if i still have them in one of my external drives

#

but there something like hundreds of games of amumu support in there

#

during seasons 2-4

#

lmao

craggy pine
#

fuckin mumu

craggy pine
#

Oh right your probably not NA

quartz kindle
#

i have an NA account

craggy pine
#

oh cool

quartz kindle
#

but i never play there because 300 ping

#

xD

craggy pine
#

ye...

#

I always forget.

#

your not from the US of A, merica

quartz kindle
#

ye

#

once i played against a friend of my brothe's

#

with 300 ping

#

i was in brazil, they were in EU

#

i stomped him lmao

#

orianna vs shaco

craggy pine
quartz kindle
#

lmao

#

poor nunu

craggy pine
#

haha

quartz kindle
#

let me see if i have anything cool

craggy pine
#

I like how we've taken over #development and turned it into #leagueoflegends

quartz kindle
#

xD

real rose
#

got confused while catching up

craggy pine
#

You don't see anything stinky moddum

#

this is 100% development talk going on here.

#

see

for(i=0;i<100;i++) {
console.log(i)
}
quartz kindle
#

discord doesnt play webm lel

#

i have to convert my shit to mp4

craggy pine
#

wait it 100% does wat

quartz kindle
#

wat, it never plays to me

craggy pine
quartz kindle
#

huh, unless its something new

#

last time i sent webm it would not play

craggy pine
#

idk always worked for me lol

quartz kindle
#

oh it does now

#

cool

craggy pine
#

nasty penta

quartz kindle
#

lel

craggy pine
#

Twin galaxy lol

#

I recongnize what that's referencing.

#

unless its completly irelevant.

quartz kindle
#

lmao

craggy pine
#

anyways gtg, the vet awaits us!

quartz kindle
#

technically a Q with a auto and a W

#

but still cool

craggy pine
#

ye

#

I end this convo with a dirty neeko r

quartz kindle
#

xD

#

old neeko R which didnt knockup

#

new R is much better design imo

craggy pine
#

like i said all my neeko stats are b4 the buff

#

her r now is soooo nice

quartz kindle
#

ye

#

i dont play her, but her new design is much better

craggy pine
#

ok bye byes. My name in game is the same in the videos. Maybe we can play like aram or sum since u have bad ping πŸ˜›

quartz kindle
#

lmao sure

spark flint
#

no

#

well not the Stripe stuff

tulip ledge
#

So I have this thing a user can buy a certain amount of, but the more the user has of it, the more it would cost. How would I do this effectively? Eg. the user has 10 of the thing and it costs 1$ per but once the user has 20 the price goes up to 2$ and at 30 to 3$, now let's say the user buys 40 of this thing then he'll spend 40$ but I want him to spend 60$ (10$ for first 10, 20$ for the next 10 and 30$ for the next 10)

tulip ledge
#

that won't do like how I want it to be

#

it'll give them at the original price say a user has 10 and buys 40 it'll ask them to pay 40, when in reality they should pay 60

#

if they have 10 of it your calculation would give: defaultPrice + additionalPrice it doesn't increase based on how much they buy tho

quartz kindle
#

i dont think there is a way to do that without going step by step with loops

radiant kraken
#

to balance things up

quartz kindle
#

i dont know

tulip ledge
frosty gale
#

i dont think so

quartz kindle
#

pretty much yeah

frosty gale
#

only the owner can

frosty gale
tulip ledge
#

how would I do that efficiently? because I can't just add 1 every single time in a loop untill a new "turning" point is reached

frosty gale
#

they wont see your identity if thats what your worried about thats locked to discord and stripe

#

yeah they wouldnt do that lmao

#

they only keep your identity for "fraud and illegal activity" purposes

#

"bad actors" as they call them

tulip ledge
#

does the nullish (??) operator check for NaN aswell?

craggy pine
deft wolf
#

I wonder if he sits and reads this channel iara_think_thonk

tulip ledge
#

probably

#

I bet he has a darts board with Xiuh's pfp on it

#

and he's currently throwing darts at it while reading this channel

quartz kindle
#

or hes watching the 4 hour documentary about the illuminati i sent him

#

:^)

radiant kraken
rustic nova
#

Even though they have been muted

#

Pls stop nit picking their mute

#

Thanks

#

Just continue development funny talks

lyric mountain
#

they couldn't see it even if discord showed the full form

#

discord doesn't have your ID

sullen crater
#

(n * 25) + 75 = x, where n is the current number of items, and x is the
amount of TOTAL currency necessary to be have n items. (i'm using 25 and 75 here as example values) so to purchase the next one after the current one you're on, you would need ((n+1) * 25) + 75

#

@tulip ledge this is my napkin math

tulip ledge
#

mmmh

#

thats a continuous function tho

#

I need it to not be haha I need it to be 1 for 0 - 20, 2 for 20 - 30, 3 for 30 - 40, etc

sullen crater
#

you want like a cap? or maybe im just misreading blobcatnotlikethis im sorry

quartz kindle
#

its not a simple thing, i tried to figure it out and just confused myself in the process lmao

#

what he needs is this:

#

is player has 6 items, and wants to buy 48 items

#

the first 4 items would cost 1 each = 4
then the next 10 would cost 2 each = 20
then the next 10 woul cost 3 each = 30
next 10 woulc cost 4 each = 40

tulip ledge
#

it's not as simple as I thought haha

quartz kindle
#

then next 10 = 5 each = 50
then the final 4 items would cost 6 each = 24

#

so to buy 48 items, if the player already has 6 items, would cost 4 + 20 + 30 + 40 + 50 + 24 = 168

sullen crater
tulip ledge
#

there should be a more elegant way then to just use for loops and add 1 each time right

#

(which would also be really expensive computing wise)

sullen crater
#

yea, a lil math formula :3

tulip ledge
#

yeah I tried to find one for like 2 hours straight

#

but didn't even come close

quartz kindle
#

yeah you need to split the loop into sections, basically with some math you only need to loop 6 times

#

you dont need to loop 1 by 1

sullen crater
#

im asking cringegpt

tulip ledge
#

already tried that

#

didn't get me far

quartz kindle
#

xD

sullen crater
#
function calculateTotalCost(n) {
  const initialSetSize = 4; // Number of items in the initial set
  const setIncrement = 10; // Number of items in each subsequent set
  const initialItemCost = 1; // Cost of the first item in each set
  const costIncrement = 1; // Cost increase for each set
  
  const numFullSets = Math.floor((n - initialSetSize) / setIncrement);
  const remainingItems = n - initialSetSize - (numFullSets * setIncrement);
  
  const totalCost = (initialSetSize * initialItemCost)
    + (setIncrement * (initialItemCost + costIncrement) * numFullSets)
    + (remainingItems * (initialItemCost + costIncrement));
  
  return totalCost;
}

const totalCost = calculateTotalCost(48);
console.log(totalCost);

what in the god damn

#

but set increment... yea this is just wrong huh

#

lmaoo i forgot math is hard good luck iara_ayaya

quartz kindle
#

thats more or less what i tried doing but i didnt finish it

sullen crater
#

yeah it like, needs a bit more work to get it there

#

:S

#

fun problem though

tulip ledge
#

yeah but it's getting quite frustrating thats why I came here to ask for help

#

I mean I could just split it into a for loop that runs 6 times and break the loop if there are no items to add any more

#

that math seems easier but I want a more elegant way

sullen crater
quartz kindle
#

lemme try it again

queen needle
#

Does it not have a possible cap?

tulip ledge
#

mmmh, well in theory no, but I could always implement one

#
function cost(c, t) {
    let total = 0;
    const groups = Math.ceil((t - c) / 10);
    for (let i = 0; i < groups; i++) {
        let groupSize = i == 0 ? 10 - (c % 10) : ?????
    }
}
#

This is how far I've gotten rn

sullen crater
#

not just math.... irrelevant math :(

tulip ledge
sharp geyser
tulip ledge
#

groupPrice = (c - (c % 10)) + i

#

so now I need to get the groupsize if they aren't the first group

sharp geyser
#

what is this even for

tulip ledge
#

its for a shop

#

Well, I'm close

function cost(c, t) {
    let total = 0;
    const groups = Math.ceil((t - c) / 10);
    for (let i = 0; i < groups; i++) {
        let groupSize = i == 0 ? 10 - (c % 10) : 10;
        let groupPrize = groupPrice = 1 + (c - (c % 10)) + i;
        total += groupSize * groupPrize;
    }
    return total;
}

I need to find the group size if they're not the first group now

sullen crater
lyric mountain
tulip ledge
#

I'm curious at how you did it

quartz kindle
#
function getPrice(has, wants) {
    const basePrice = 1;
    const step = 10;
    const first = Math.min(step - has % step, wants);
    const second = wants - first - (wants - first) % step;
    const third = wants - first - second;

    let final = first * (basePrice * Math.ceil(has / step));
    
    if(second) {
        for(let i = 0; i < second / step; i++) {
            const current = basePrice * ((has + first) / step) + i + 1;
            final += current * step;
        }
    }

    if(third) {
        const current = basePrice * ((has + first + second) / step) + 1;
        final += third * current;
    }

    return final;
}
tulip ledge
#

I still can't figure out how to do mine

wheat mesa
#

I love math c:

sullen crater
#

these var names are cuties

tulip ledge
quartz kindle
tulip ledge
#

well, didn't you basically do the same thing as me just the first and last group outside of the for loop?

quartz kindle
quartz kindle
#

the only way i can think about it is to split it in 3 groups

#

of those groups, only the second one can be looped properly

sharp geyser
tulip ledge
#

yeah that's what I'm struggling with, with getting the groups right

quartz kindle
#

because the first and last will always be outliers with a different calculation

tulip ledge
#

probably easiest to make the "irregular" groups outside the for loop

#

yeah

#

alright thank you very muchΒ΅

quartz kindle
sharp geyser
#

ya physics nerd

quartz kindle
#

if you want to change that in the future, it will need fixing

tulip ledge
#

mhm

quartz kindle
#

for example if one day you want to increase price in a non-linear way

tulip ledge
#

well the plan was to indeed change that I just put it into perspective to make the math easier

sage bobcat
#

One message removed from a suspended account.

quartz kindle
#

same

tulip ledge
#

well, i don't want it in a non-linear way just not with 1

#

every x it should go up by y

quartz kindle
#

so x should already be handled in the step variable

tulip ledge
#

I just add a coefficient to this: ((has + first) / step)

#

and it shoudl work no?

quartz kindle
#

yeah, also the +1 in the loop and third step

tulip ledge
#

wait no

lyric mountain
#
int getCost(int initial, int buy) {
  buy += initial;

  int cost = 0;
  int batches = Math.ceil(buy / 10)
  for (int i = 0; i < batches; i++) {    
    int batch = Math.min(buy, 10);
    cost += batch * (1 + i);
    buy -= batch;
  }

  return initial == 0 ? cost : (cost - getCost(0, initial));
}
quartz kindle
#

ah yes, recursion is also a nice way to do it

quartz kindle
lyric mountain
#

ah yes

quartz kindle
#

translated your func to js

#

lets performance test

#

:^)

tulip ledge
lyric mountain
#

which is which?

quartz kindle
#

getCost is yours

tulip ledge
#

was just about to ask the same question

quartz kindle
#

getPrice is mine

lyric mountain
#

ah

sharp geyser
#

tim always finds a way to make shit more performant

quartz kindle
#

xDDDD

sharp geyser
#

guy is like a bloodhound for performance fixes

lyric mountain
#

do with big values

#

like has 32 wants 5000

quartz kindle
lyric mountain
#

lul

#

wonder in which params both functions cross in performance

#

any way we can make a chart out of 'em?

tulip ledge
#

I remember about a year ago I came here asking for help with an algorithm and it ended in the exact same way, 2 algorithms being created and the ceators competing to get the fastest. This is why I love the dev community

quartz kindle
tulip ledge
quartz kindle
#

ye

tulip ledge
#

how πŸ‘€

frosty gale
lyric mountain
tulip ledge
tulip ledge
quartz kindle
#

~1800 - ~1900

#

mine dropped from 4k to 1k

tulip ledge
#

and what did you change to get that drop? πŸ‘€

#

that's like really significant

quartz kindle
#

for example, with large numbers, this loop becomes pretty big, with hundreds of iterations

#

a lot of that multiplication is unnecessary to be done every single time

sharp geyser
#

ok nerd

tulip ledge
#

oh

sharp geyser
#

yea nah tim a big nerd

frosty gale
#

is this a challenge on who can optimise a function the most

quartz kindle
frosty gale
#

im pretty good with optimising code:)

#

i think at least

#

speaking of optimising code the gcc compiler is scary

#

if you active higher optimisation levels like O2 it starts getting very creative

sharp geyser
#

nothing compared to tim, he can likely bring that 1k down to 500 if he tried /j

quartz kindle
#

Lol

frosty gale
#

hes going to rewrite that function in web assembly

quartz kindle
#

ew

frosty gale
#

although isnt web assembly interpreted?

#

because its not actual assembly

sharp geyser
#

he going to rewrite that function in 1's and 0's

frosty gale
#

well not compiled

quartz kindle
#

it is compiled

#

to bytecode at least

frosty gale
#

bytecode is still interpreted though

#

idk someone has to measure performance

#

that man is you

sharp geyser
#

get to writing bytecode tim

quartz kindle
#

lmao

#

wasm is not worth it in the majority of cases

#

wasm itself is fast of course, but interopping between js and asm is very slow

#

similar to interopping between main thread and worker threads

frosty gale
#

i think its mostly useful if youre using native libraries and want to use it in the browser

#

since those can be assembled

quartz kindle
#

that and running expensive code

#

for example image/video editing will benefit from having wasm do the heavy lifting

#

afaik wasm can share memory with js via sharedArrayBuffer

#

so you can write huge amounts of binary data and have wasm work on it, ie conversion/editing/transcoding

frosty gale
#

i hate javascripts 2gb blob limit

#

in cases where i cant stream large files it basically kills that

quartz kindle
#

why in the heck would you need a 2gb blob in js

frosty gale
#

my use case is i want to encrypt a large file using aes-gcm

#

aes-gcm requires the whole file to be available because it does integrity checking too

#

unlike aes-cbc which chains blocks so those can be streamed

lyric mountain
#

@quartz kindle optimized mine

frosty gale
#

js wont let you upload a file to a blob larger than 2gb you get some weird file system error

lyric mountain
#

oh wait

#

I need to put ur fixes on yours

#

send ur algo here

quartz kindle
lyric mountain
#

yours or mine?

quartz kindle
#
function getPrice(has, wants) {
    const basePrice = 1;
    const step = 10;
    const first = Math.min(step - has % step, wants);
    const second = wants - first - (wants - first) % step;
    const third = wants - first - second;

    let final = first * (basePrice * Math.ceil(has / step));
    
    if(second) {
        const iterations = second / step;
        const multiplier = basePrice * ((has + first) / step) + 1;
        for(let i = 0; i < iterations; i++) {
            const current = multiplier + i;
            final += current * step;
        }
    }

    if(third) {
        const current = basePrice * ((has + first + second) / step) + 1;
        final += third * current;
    }

    return final;
}
#

yours

lyric mountain
#
function getCost(initial, buy) {
  buy += initial;

  let cost = 0;
  const batches = (buy / 10 + 1) | 0; // from "Math.ceil(buy / 10)"
  for (let i = 0; i < batches; i++) {    
    let batch = buy < 10 ? buy : 10; // from "Math.min(buy, 10)"
    cost += batch * (1 + i);
    buy -= batch;
  }

  return initial == 0 ? cost : (cost - getCost(0, initial));
}
#

yours after the fix is still faster

#

I'll try to bring it up

frosty gale
quartz kindle
#

yours was improved by ~500ms in my bench, from ~1900 to ~1450

quartz kindle
#

the Math.min/ceil change will likely make a larger difference

frosty gale
#

gcc would automatically do that but since js is interpreted idk

quartz kindle
#

v8 probably does that too

frosty gale
#

the less memory ops and more that can be done in registers would be faster

#

trying to avoid multiplication too if were speaking about unnecessary overkill optimisation lmao

lyric mountain
#

aight, almost

civic scroll
#

for best memory, write in rust

frosty gale
#

division as well

quartz kindle
civic scroll
#

no code comment smh

frosty gale
#

you can also perform certain division/multiplication like dividing by 2 by shifting the number to the right which does the same thing but 100x faster

frosty gale
#

it probably does hard code it to some extent but its still slower

civic scroll
#

smh evil bit shifting math

proven lantern
civic scroll
#

i mean speed

frosty gale
#

the standard library is fat

proven lantern
lyric mountain
#

ayo did it

quartz kindle
#

show codfish

lyric mountain
#
function getCost(initial, buy) {
  buy += initial;

  let i = 0;
  let cost = 0;
  const batches = (buy / 10 + 1) | 0;  
  while (buy >= 10) {
    cost += 10 * ++i;
    buy -= 10;
  }

  if (initial === 0) {
    return cost + buy * ++i;
  } else {
    return cost - getCost(0, initial) + buy * ++i;
  }
}
quartz kindle
#

still slower on my bench

lyric mountain
#

oh wait, there's an error on it

#

nvm, there isn't

#

I just ctrl X it to paste here lmao

craggy pine
#

I wonder if you asked Chat GPT to write the fastest way for that code, if it would and understand what you were trying to do.

quartz kindle
lyric mountain
#

perf.link

quartz kindle
#

which browser are you using?

lyric mountain
#

edge

craggy pine
#

edge moment

lyric mountain
#

I'll send u the url to my bench

quartz kindle
#

this is my edge

queen needle
lyric mountain
#

for both sides yours is showing almost 10k ops/s less than in my browser

#

that's weird

quartz kindle
#

i guess its just our hardware differences

lyric mountain
#

might be

quartz kindle
#

for some reason your hardware optimizes your code better

#

whats your cpu?

lyric mountain
#

ryzen 5 1600

quartz kindle
#

mine's a 7th gen intel i5

#

7700hq

craggy pine
quartz kindle
#

really strange

lyric mountain
#

what cpu miyu

quartz kindle
#

i guess my pc is biased towards my code

#

lmao

craggy pine
#

11700k

lyric mountain
queen needle
#

Someone should try that one^ given by chatgpt

quartz kindle
#

i just tried running it on firefox

#

reran the benchmark 5x

#

and every time it gives different results

craggy pine
#

My browser is Firefox, maybe why high numbers

quartz kindle
#

conclusion, shitty benchmark website

craggy pine
#

Also tim.

lyric mountain
craggy pine
#

How do you benchmark within visual studio. You can do that correct?

quartz kindle
#

look at this

lyric mountain
#

like, literally

quartz kindle
#

yeah lmao

queen needle
#

LMAO

quartz kindle
#

i rerun the bench mark and gives completely different results

#

this website is ass

craggy pine
#

One thing even if the website is ass.

#

GPT's code is more ass

lyric mountain
#

lemme see if I find another

quartz kindle
#

every time i re-run it the result is completely different lele

#

which reminds me

#

there was a website, i dont remember which one

#

that hosted code challenges and performance benchmarks rankings

#

and they had a section for js

#

and the rankings were completely non-sensical

lyric mountain
quartz kindle
#

code that was 100% slower being placed in higher rankings than code that is 100% faster

neon leaf
#

same for me nvm

lyric mountain
#

this one does take a while to complete

#

the other site was probably doing very few samples

queen needle
#

Should get voltrex in on this

quartz kindle
#

this is what i get lol

lyric mountain
#

lmao

#

damn thing is as consistent as a jello on an earthquake

queen needle
#

Try a benchmarking lib maybe?

lyric mountain
#

cpu will still get in the way

quartz kindle
# lyric mountain lmao

now you do the ultimate test, open dev tools on your browser, paste both functions in, and run this several times for each function

#
t = performance.now();

for(let i = 0; i < 999999; i++) {
    getPrice(32, 5000);
}

performance.now() - t;
queen needle
#

What if you used something like tio.run, where the server it's ran on is consistent and independent from your computer

quartz kindle
#

looks like its consistent with mine, just faster across the board because your cpu is better

proven lantern
#

Do you need help optimizing? Why didn't you ask?

lyric mountain
#

I think I bugged the browser's engine lmao

#

lemme run it on intellij

quartz kindle
#

lmao

quartz kindle
proven lantern
#

Where is the function you are optimizing?

quartz kindle
#

this is tio.run with javascriot node

queen needle
#

I feel like that's the best thing to use to compare since it doesn't depend on your cpu

queen needle
#

:(

quartz kindle
# proven lantern Where is the function you are optimizing?
// tim's
function getPrice(has, wants) {
    const first = Math.min(10 - has % 10, wants);
    const second = wants - first - (wants - first) % 10;
    const third = wants - first - second;

    let final = first * (1 * Math.ceil(has / 10));
    
    if(second) {
        const iterations = second / 10;
        const multiplier = (has + first) / 10 + 1;
        for(let i = 0; i < iterations; i++) {
            final += (multiplier + i) * 10;
        }
    }

    if(third) {
        final += third * ((has + first + second) / 10 + 1);
    }

    return final;
}

// kuuhaku's
function getCost(initial, buy) {
  buy += initial;

  let i = 0;
  let cost = 0;
  const batches = (buy / 10 + 1) | 0;  
  while (buy >= 10) {
    cost += 10 * ++i;
    buy -= 10;
  }

  if (initial === 0) {
    return cost + buy * ++i;
  } else {
    return cost - getCost(0, initial) + buy * ++i;
  }
}
proven lantern
#

mmkay, i got this ezpz

#

what is the purpose?

#

does initial = 0

lyric mountain
#

yep, seems consistent with what I got on browser earlier

quartz kindle
proven lantern
#

is this so you can buy bitcoin batches?

quartz kindle
#

the purose of the function is like this

lyric mountain
#

the premise is simple:

quartz kindle
#

an item's cost depends on how many of them you already have

proven lantern
#

like buy everything at the lowest cost until there is no more at that cost

lyric mountain
#

for every 10 units u buy, the prices increases by 1

neon leaf
proven lantern
#

and then buy everything at the next price?

#

gotcha

lyric mountain
#

so 10 = 10, then 10 = 20, then 10 = 30, and so on

#

the amount u start with is taken in consideration

#

so if u have 5, then the next 5 will cost 1 each

#

but then it'll cost 2 on the 6th

proven lantern
#

first 10 cost 10 each? second 10 cost 20 each?

quartz kindle
#

if you already have 6 items, and want to buy 21, the first 4 items would cost 1, because now you have 10 already, so then enxt 10 cost 2 each, now you have 20, and there's 5 left, the last 5 cost 3 each

lyric mountain
#

first 10 cost 1 each

proven lantern
#

gotcha

#

and you always start at initial cost of 1 each?

lyric mountain
#

yes

#

the prices increases at 10 unit marks

quartz kindle
#

yes we decided that the cost is hardcoded to 1, increasing by 1 for every 10 items the user owns

proven lantern
#

and they always start by owning nothing

#

like WEF

lyric mountain
#

they can start with any amount

#

we're testing with 32 as the starting amount

quartz kindle
#

and buying 5000

lyric mountain
#

so the buyer ends with 5032 units

quartz kindle
#

and the total cost for that is 1268500

#

@lyric mountain we are already completing each other's sentences

#

lmao

lyric mountain
#

noticed that lul

#

lemme see how the codes perform on groovy

proven lantern
#
const getCost = ({initialInventory, buy}) => {

    let finalInventory = initialInventory;
    let finalCost = 0;
    for (let i = 0; i < buy; i++) {
        const buyDecimalPlaces = (i + initialInventory).toString().length - 1;
        finalInventory += 1;
        finalCost += buyDecimalPlaces;
    }
    return [finalCost, finalInventory];
}
#

does this work?

#

oops

#

i think -1 is a problem

quartz kindle
#

oh wait, its an object

proven lantern
#
    initialInventory:0, buy: 200
}```
quartz kindle
proven lantern
#

is it wrong?

#

i think const buyDecimalPlaces = (i + initialInventory).toString().length - 1;

lyric mountain
#

yes lul

proven lantern
#

needs to be const buyDecimalPlaces = (i + initialInventory).toString().length;

lyric mountain
#

it should return how much it'd cost to buy X units

proven lantern
#

first number is final cost

lyric mountain
#

then it's very wrong

proven lantern
#

second is the adjusted inventory

quartz kindle
#

should be 1268500

#

ye

lyric mountain
#

I'm trying to convert the code to groovy

#

actually, lemme just go full java

quartz kindle
#

xD

proven lantern
#

oh, it's every 10, not evey 10, 100, 1000

lyric mountain
#

holy shit it's much faster

#

aight, still smaller

#

tho I think the warmups were just JITted from the runtime

#

they went almost instantly

proven lantern
#

this basically works

#
const getCost = ({initialInventory, buy}) => {

    let finalInventory = initialInventory;
    let finalCost = 0;
    let currentCost = 1;
    for (let i = 0; i < buy; i++) {
        const currentInventorySizeString = (i + initialInventory).toString();
        const isMod10 = currentInventorySizeString[currentInventorySizeString.length - 1] === '0';
        finalInventory += 1;
        if (isMod10) {
            currentCost++;
        }
        finalCost += currentCost;

    }
    return [finalCost, finalInventory];
}
lyric mountain
#

averages still the same, ~170 for u, ~400 for me

lyric mountain
#

only the cost

#

nothing more than the cost

proven lantern
#

i dont think i can make that change

#

must return finalInventory!

lyric mountain
#

it wont evaluate to true otherwise as it breaks the constraints

proven lantern
#

it's still wrong too

queen needle
#

Why isMod10 instead of n % 10

proven lantern
#

perhaps

queen needle
#

But getting the character by indexing may be slow

#

Idk

proven lantern
#

why is my math off though?

#

i get 1253000

earnest phoenix
#

t

lyric mountain
#

lemme see if u understood the context

#

maybe ur thinking it's supposed to do something else

#

what are u trying to do?

proven lantern
#

they are buying buy items. those items change price depening on how many you already own. for every 10 you buy or own, the cost goes up by 1

#

you have an initial inventory and are buying more

lyric mountain
#

yes

quartz kindle
#

the initial price is also based on how many you own

proven lantern
#
const getCost = ({initialInventory, buy}) => {

    let finalInventory = initialInventory;
    let finalCost = 0;
    let currentCost = 1;
    for (let i = 0; i < buy; i++) {
        const currentInventorySizeString = (i + initialInventory).toString();
        const isMod10 = currentInventorySizeString[currentInventorySizeString.length - 1] === '0';
        finalInventory += 1;
        finalCost += currentCost;
        if (isMod10) {
            currentCost++;
        }
    }
    return finalCost;
}
#

this should work

quartz kindle
#

if you already own 32, the initial price already starts at 4

proven lantern
#

ohh

#

i am skipping the initial cost part

#

success!

quartz kindle
#

its 1268500 tho

proven lantern
#

i can remove the counting for inventory too

#

oops

lyric mountain
#

damn no matter what I do I cant get below 400 on java lmao

#

tf did u do up there tim

queen needle
#

I want to try but I don't have my laptop :(

lyric mountain
#

online editor

quartz kindle
lyric mountain
#

tried removing recursion, little to no impact

quartz kindle
#

also less loops

lyric mountain
#

java most likely inlined it after the warmup phase

queen needle
#

There has to be a formula to do it without loops

queen needle
lyric mountain
lyric mountain
queen needle
#

Does it start at 1?

lyric mountain
#

1 - 10 = 1
11 - 20 = 2
21 - 30 = 3
31 - 40 = 4

queen needle
#

Ohhh

#

So you have the amount you're buying and what you start with, for 32 it's 4 as the initial cost, then for every 10 initial cost is increased by 1?

lyric mountain
#

no no, for every cumulative 10

#

so if u start at 32, it'll be 4 for the next 8 units

#

after that it'll be 5 per unit

queen needle
#

Ohhh

#

What's the fastest one so far

lyric mountain
#

tim

#

about 2x faster than mine

limpid rain
#

Hello all

quartz kindle
#

it was closer in js

proven lantern
#

ok, it works for real this time

const getCost = ({initialInventory, buy}) => {

    let finalCost = 0;
    let currentCost = Math.floor(initialInventory / 10) + 1;
    for (let i = 1; i <= buy; i++) {
        const currentInventorySizeString = (i + initialInventory).toString();
        const isMod10 = currentInventorySizeString[currentInventorySizeString.length - 1] === '0';
        finalCost += currentCost;
        if (isMod10) {
            currentCost++;
        }
    }
    return finalCost;
}
#

speed test time

#

i got this

queen needle
#

If I write one does anyone have anyway to benchmark it using a website or something?

lyric mountain
#

tim's testing on browser, I'm testing on intellij

quartz kindle
#

you can use jsben.ch or tio.run, but i like running everything on my browser dev tools first

#

and run it multiple times to get a sense of how stable it is

queen needle
#

I don't have a laptop/computer available to me

#

To use devtools

quartz kindle
lyric mountain
#

aight it'll take a while

proven lantern
quartz kindle
#

also, whoever wants to test, look up chat historu can copy our functions too, so you test all of them in the same environment and compare

proven lantern
#

i want my faster cpu to give me an edge

frosty gale
#

y'all still at it πŸ’€

quartz kindle
lyric mountain
quartz kindle
#

lmao

lyric mountain
#

the test btw

proven lantern
#

using % is 10x faster than what i was doing

lyric mountain
#

yes, string ops are slow as hell

proven lantern
quartz kindle
lyric mountain
#

wanna make sure the code is cosmic-ray safe KEKW

quartz kindle
#

lmaoooo

proven lantern
# proven lantern

i'll make a map of all the numbers that are mod 10 === 0 and use that instead

lyric mountain
#

btw name it getCostBen

#

or smth else

frosty gale
lyric mountain
#

actually, just noticed ben's failed every warmup

#

forgot to convert to obj param

frosty gale
#

im going to do a battleless in a minute and start gaslighting

lyric mountain
#

make the params not an object please ben

proven lantern
# lyric mountain btw name it getCostBen

here's the current state ```js
const getCostBen = (initialInventory, buy) => {

let finalCost = 0;
let currentCost = Math.floor(initialInventory / 10) + 1;
for (let i = 1; i <= buy; i++) {
    const isMod10 = (i + initialInventory) % 10 === 0;
    finalCost += currentCost;
    if (isMod10) {
        currentCost++;
    }
}
return finalCost;

}

lyric mountain
#

easier for me to plug the code

proven lantern
#

mmmmmkay

lyric mountain
#

aight, running

#

will also run yours on java, the results come quicker

queen needle
#

I got a negative number?

#

!*

#

Going great so far

proven lantern
#

removing the isMod10 seems to help

#
const getCostBen = (initialInventory, buy) => {

    let finalCost = 0;
    let currentCost = Math.floor(initialInventory / 10) + 1;
    for (let i = 1; i <= buy; i++) {
        finalCost += currentCost;
        if ((i + initialInventory) % 10 === 0) {
            currentCost++;
        }
    }
    return finalCost;
}```
lyric mountain
#

ok for js

#

for java

proven lantern
#

one more time pls

#

nm

lyric mountain
#

the code converted to java btw

proven lantern
#

it's not much faster

frosty gale
#

i wonder what the performance in c/c++ would be for all of them

#

if the compiler would optimise them all in a similar fashion

quartz kindle
#

do it

frosty gale
#

resulting in similar times

lyric mountain
#

it'll be very close to java

quartz kindle
#

take all our funcions and turn them indo a cpp benchmark

frosty gale
#

might just have to now lmao

#

give me your codes

lyric mountain
#
static int getPrice(int has, int wants) {
    final int basePrice = 1;
    final int step = 10;
    final int first = Math.min(step - has % step, wants);
    final int second = wants - first - (wants - first) % step;
    final int third = wants - first - second;

    int out = (int) (first * (basePrice * Math.ceil(has / (double) step)));

    if (second != 0) {
        final int iterations = second / step;
        final int multiplier = basePrice * ((has + first) / step) + 1;
        for (int i = 0; i < iterations; i++) {
            final int current = multiplier + i;
            out += current * step;
        }
    }

    if (third != 0) {
        final int current = basePrice * ((has + first + second) / step) + 1;
        out += third * current;
    }

    return out;
}

static int getCost(int initial, int buy) {
    buy += initial;

    int i = 0;
    int cost = 0;
    while (buy >= 10) {
        cost += 10 * ++i;
        buy -= 10;
    }

    if (initial == 0) {
        return cost + buy * ++i;
    } else {
        return cost - getCost(0, initial) + buy * ++i;
    }
}
quartz kindle
#

also bens

lyric mountain
#
static int getCostBen(int initialInventory, int buy) {
    int finalCost = 0;
    int currentCost = (int) (Math.floor(initialInventory / 10d) + 1);
    for (int i = 1; i <= buy; i++) {
        final boolean isMod10 = (i + initialInventory) % 10 == 0;
        finalCost += currentCost;
        if (isMod10) {
            currentCost++;
        }
    }
    return finalCost;
}
#

this one will take a while to complete tho

frosty gale
#

ty

lyric mountain
#
long t = System.currentTimeMillis();
for (int i = 0; i < 999999; i++) {
    if (getPrice(32, 5000) != 1268500) {
        System.out.println("Tim's did not evaluate to 1.268.500");
        break;
    }
}
final long tim = System.currentTimeMillis() - t;
#

to test

queen needle
#

I'm driving myself crazy trying to get this in a one line formula

quartz kindle
#

good luck lol

queen needle
#

I got 100,000 away from it

#

That's definitely close

quartz kindle
#

lmao

proven lantern
#
const divisibleByTenMap = {};
for (let i = 10; i < 10000000; i += 10) {
    divisibleByTenMap[i] = true;
}

const getCostBen = (initialInventory, buy) => {

    let currentCost = Math.floor(initialInventory / 10) + 1;
    let finalCost = 0;

    for (let i = 1; i <= buy; i++) {
        finalCost += currentCost;
        if (divisibleByTenMap[(i + initialInventory)]) {
            currentCost++;
        }
    }
    return finalCost;
}```
#

ignore the startup time

queen needle
#

πŸ’€

proven lantern
#

it doesn't work either

lyric mountain
#

now let's test with random values

proven lantern
#

are you using my new and improved code?

lyric mountain
#

nope, u said it doesnt work

proven lantern
#

it does, i was just using the wrong signature

#

i was tricked

#

in js you usually use a spec object for params

lyric mountain
#

doing warmup

#

but it's likely much slower than ur former code, as it's still in warmup 2

queen needle
#

Somehow mine is returning 5001

#

I'm so good at this

proven lantern
#
for (let i = 10; i < 10000000; i += 10) {
    divisibleByTenMap[i] = true;
}``` is initializing code
#

so it'll take a long time to start

#

but that builds a map that my function references

#

oh, but counting by 10 could be a trick

#

dont take my idea

lyric mountain
#

@quartz kindle still does well with random values (same seed)

#

js test with ben code is still warming up

proven lantern
#

lol

lyric mountain
#

just finished

proven lantern
#

i have a new plan to win

queen needle
#

How does mine return 1268504???

lyric mountain
#

off by 4

queen needle
#

Yeah, I'm not sure how

#

Oh I just got it

#

I did my loop wrong

lyric mountain
#

it had little to no impact on the times

quartz kindle
#

js's Math.random() is very slow

lyric mountain
#

didn't test with random on js, used java cuz I can restart it with the same seed

#

to guarantee the tests are the same yet random

queen needle
#

How do I test in browser?

lyric mountain
#

F12

#

oh wait, ur on mobile

#

well, u cant then

queen needle
#

I have a laptop now

lyric mountain
#

then F12

queen needle
#

I meant like benchmark, what is the boilerplate

lyric mountain
#
let t = performance.now();
for (let i = 0; i < 999999; i++) {
    if (getPrice(32, 5000) !== 1268500) {
        console.log("Tim's did not evalue to 1.268.500")
        break;
    }
}
const tim = performance.now() - t;
#

replace tim with ur name

quartz kindle
#

you dont need the inner if but yeah

lyric mountain
#

send the code too

proven lantern
#
const getCostBen = (initialInventory, buy) => {

    let inventoryCountTracker = initialInventory;
    let costTracker = 0;

    // get inventory to a multiple of 10
    let currentCost = Math.floor(inventoryCountTracker / 10) + 1;
    let i = 0;
    while (inventoryCountTracker % 10 !== 0) {
        costTracker += currentCost;
        inventoryCountTracker++;
        i++;
    }
    currentCost++;
    for (i; i < buy - 10; i += 10) {
        costTracker += (currentCost * 10);
        inventoryCountTracker += 10;
        currentCost++;
    }
    for (i; i < buy; i++) {
        costTracker += currentCost;
        inventoryCountTracker++;
    }
    return costTracker;
}```
lyric mountain
quartz kindle
#

okok xd

lyric mountain
#

warmup is faster this time

proven lantern
#

super speed now

#

noice

lyric mountain
#

quite impressed

quartz kindle
#

oh my

proven lantern
#

i can remove the inventory counting to make it faster

#
const getCostBen = (initialInventory, buy) => {

    let inventoryCountTracker = initialInventory;
    let costTracker = 0;

    // get inventory to a multiple of 10
    let currentCost = Math.floor(inventoryCountTracker / 10) + 1;
    let i = 0;
    while (inventoryCountTracker % 10 !== 0) {
        costTracker += currentCost;
        inventoryCountTracker++;
        i++;
    }
    currentCost++;
    for (i; i < buy - 10; i += 10) {
        costTracker += (currentCost * 10);
        currentCost++;
    }
    for (i; i < buy; i++) {
        costTracker += currentCost;
    }
    return costTracker;
}```
queen needle
#

How are y'all's so fast...

#

Mine took almost 20 seconds

lyric mountain
#

in my case I just need to somehow reduce the loop iterations

proven lantern
#

unless you do that too

lyric mountain
lyric mountain
#
function getCost(initial, buy) {
    buy += initial;

    let i = 0;
    let cost = 0;
    while (buy >= 10) {
        cost += 10 * ++i;
        buy -= 10;
    }

    if (initial === 0) {
        return cost + buy * ++i;
    } else {
        return cost - getCost(0, initial) + buy * ++i;
    }
}
#

actually

proven lantern
#
const getCostBen = (initialInventory, buy) => {

    let inventoryCountTracker = initialInventory;
    let costTracker = 0;

    // get inventory to a multiple of 10
    let currentCost = Math.floor(inventoryCountTracker / 10) + 1;
    let i = 0;
    while (inventoryCountTracker % 10 !== 0) {
        costTracker += currentCost;
        inventoryCountTracker++;
        i++;
    }
    currentCost++;
    const buyMinusTen = buy - 10;
    for (i; i < buyMinusTen; i += 10) {
        costTracker += (currentCost * 10);
        currentCost++;
    }
    for (i; i < buy; i++) {
        costTracker += currentCost;
    }
    return costTracker;
}```
#

i made this change js const buyMinusTen = buy - 10; for (i; i < buyMinusTen; i += 10) { costTracker += (currentCost * 10); currentCost++; }

#

should be faster than doing the math ever time

#

it should beat tim now

#

ezpz

lyric mountain
#

nope, same time

#

508ms

#

ignore mine, I'm doing some changes

quartz kindle
#

wat

queen needle
#

I gave up lol

quartz kindle
#

cosmic ray?

#

lmao

proven lantern
quartz kindle
#

lmao

proven lantern
#

pls

proven lantern
lyric mountain
#

trynna remove multiplication altogether

proven lantern
#

this is 3x slower for me

#

maybe because it assigns

#

i'll do it all in one statement

#

this is just a bit slower than x * 10

queen needle
#

Lmao

lyric mountain
#

VOILA! I did it

#
function getCost(initial, buy) {
    let i = initial / 10 + 1 | 0;
    let cost = 0;

    let step = 10 - initial % 10;
    while (buy >= 10) {
        cost += step * i++;
        buy -= step;
        step = 10;
    }

    return cost + (initial / i | 0) - (initial % 10) + buy * ++i;
}
proven lantern
#
const getCostBen = (initialInventory, buy) => {
    let inventoryCountTracker = initialInventory;
    let costTracker = 0;

    // Get inventory to a multiple of 10
    let remainingItems = inventoryCountTracker % 10;
    if (remainingItems !== 0) {
        costTracker += Math.floor(inventoryCountTracker / 10) + 1;
        inventoryCountTracker += 10 - remainingItems;
    }

    // Calculate cost for buying in multiples of 10
    const buyMinusTen = buy - 10;
    let currentCost = Math.floor(inventoryCountTracker / 10) + 1;
    let i = inventoryCountTracker;
    for (; i < buyMinusTen; i += 10) {
        costTracker += currentCost * 10;
        currentCost++;
    }

    // Calculate cost for buying the remaining items
    let remainingBuy = buy - i;
    costTracker += currentCost * remainingBuy;

    return costTracker;
};
#

ai helped with this one

#

does ai win?

#

ai + ben

proven lantern
#

i'm last place again

#

i got 392

#

i win

#

on my computer

#

against no one

quartz kindle
#

lmao

proven lantern
#

and the result is wrong

#

i like how ai just lies

#

the result is actually 1252404

quartz kindle
#

xD

proven lantern
#

i can't get chatgpt to give me anything that works

queen needle
#

Is there anyway to do it without a loop? I doubt it but if there was wouldn't that be the fastest

lyric mountain
#

It's the equivalent of (int) value in java

quartz kindle
#

ye, it forces conversion into int32

lyric mountain
#

Tbh I hate how any division sets the number to double

quartz kindle
#

isnt a double required to make divisions in the cpu?

lyric mountain
#

I think it's only required if you want the decimals

#

Else it gets floored as there are no bytes for decimals

lyric mountain
proven lantern
earnest phoenix
#

Implementing that in C++ with optimization level 3 takes 1ms for 1 million iterations

lyric mountain
#

Ty, that was one hell of a trip

lyric mountain
#

tho...are u trying with random or fixed values?

#

cuz it's probably compiling the function to a constant as the params never change

earnest phoenix
#

Completely disabling optimizations makes it take 3 seconds

With completely random values (with optimization level 3) it takes 109ms for 1 million iterations

queen needle
#

Now do that in js

lyric mountain
#

we...kinda did

earnest phoenix
#
#include <chrono>
#include <cstdlib>
#include <iostream>

size_t get_price(size_t has, size_t wants) {
  size_t cost{0};
  size_t cost_multiplier{has / 10 + 1 | 0};
  size_t step{10 - has % 10};

  while (wants >= 10) {
    cost += step * cost_multiplier++;
    wants -= step;
    step = 10;
  }

  const size_t cost_mult{has / cost_multiplier | 0};

  return cost + cost_mult - (has % 10) + wants * ++cost_multiplier;
}

int main() {
  std::srand(std::time(nullptr));

  auto start = std::chrono::high_resolution_clock::now();

  for (size_t i = 0; i < 999'999; i++) {
    [[maybe_unused]] volatile auto foo = get_price(rand(), rand());
  }

  auto end = std::chrono::high_resolution_clock::now();

  std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end -
                                                                     start)
                   .count()
            << "ms\n";
}
lyric mountain
queen needle
lyric mountain
#

and 1.2x faster than java

#

considering tim's code ofc

#

didn't convert my solution to java to see

earnest phoenix
#

Maybe I should try converting Tim's code to C++ as well, see how it compares to yours in C++

#

Where's Tim's latest one?

lyric mountain
#

he didn't change it since this message

#

it's the getPrice btw

earnest phoenix
#

Alright let me see

lyric mountain
#

there's a version I converted to java, if it's easier for u to work with nvm, that is the java version

#

the original js code is a little higher up

earnest phoenix
lyric mountain
#

yep

quartz kindle
#

im making a new one

#

get ready

lyric mountain
#

ohno

quartz kindle
lyric mountain
#

getPrice7 = (a, b) => true mmLol

quartz kindle
#

it might have bugs

#

but i tested a bunch of different values compared to getPrice and they all return the same results

#

but this is a pure math way, zero loops

#
function getPrice7(has, wants) {
    const hasrem = has % 10;
    const hasbase = has - hasrem;
    const hasvalue = hasbase + hasbase * (0.5 * ((hasbase / 10) - 1)) + hasrem * (Math.ceil(hasbase / 10) + 1);
    const total = has + wants;
    const r = total % 10;
    const x = total - r;
    return (x + x * (0.5 * ((x / 10) - 1)) + r * Math.ceil(total / 10)) - hasvalue;
}
#

ah nvm i found some values that the result is wrong

#

more specifically if has is a multiple of 10, the final result has 10 too much

#

should be easy to fix

lyric mountain
#

mf solved the math

quartz kindle
#

nvm its not easy to fix, still looking at where the extra 10 is coming from lmao

queen needle
#

I knew someone was going to figure It out

quartz kindle
#

i'll figure it out later g2g do something else now

earnest phoenix
#

@lyric mountain @quartz kindle KEKW

proven lantern
#
const getCostBen = (initialInventory, buy) => {
    let inventoryCountTracker = initialInventory;
    let costTracker = 0;
    let currentCost = Math.floor(inventoryCountTracker / 10) + 1;
    if (inventoryCountTracker % 10 !== 0) {
        const remainingCount = 10 - (inventoryCountTracker % 10);
        costTracker += currentCost * remainingCount;
        inventoryCountTracker += remainingCount;
        currentCost++;
    }
    const finalInventorySize = initialInventory + buy;
    const finalInventorySizeMinus10 = finalInventorySize - 10;
    for (; inventoryCountTracker < finalInventorySizeMinus10; inventoryCountTracker += 10) {
        costTracker += currentCost * 10;
        currentCost++;
    }
    const remainingCount = finalInventorySize - inventoryCountTracker;
    costTracker += currentCost * remainingCount;
    return costTracker;
};
#

i fixed the ai code

queen needle
#

When Tim fixes it you'll have to test his new one

proven lantern
#

it's not much faster

proven lantern
#

tim is good at c++

#

and KuuHaKu

earnest phoenix
#

KuuHaKu doesn't even use C++

proven lantern
#

lol

lyric mountain
#

tim and I are entangled, same time for both algos lmao

proven lantern
#

did my last one win?

lyric mountain
proven lantern
#

i'll find them

lyric mountain
#

but it's simple, just declare the functions, run 100 loops of 999999 for each function to warm then and then measure how long it takes for them to run 999999 times

proven lantern
#

i win sometimes!

lyric mountain
#

haka πŸ’€

proven lantern
#

i spell

#

hahah

#

you saw

#

i got this

#

big win

earnest phoenix
tulip ledge
#

@quartz kindle @lyric mountain (sorry for ping) I found a formula. I was talking to a friend of mine who's also in my math class and we came up with a formula and it goes as follows:
Let's assume the player starts with 0 items and wants to buy 10k + r items with k being a whole multiple and r being a natural number.
10 items at 1$, 10 items at 2$, ..., 10 items at k$, r items at (k + 1)$
Total cost is 10(1+2+...+k) + r(k+1) = 10k(k+1)/2 + r(k+1) = 5k(k+1) + r(k+1) = (5k+r)(k+1)
let's say we buy N items then k = floor(N / 10) and r = N % 10
And we start at M items instead of 0

We get cost of buying M + N from 0 - cost of buying M from 0
thus we get cost = (5 * floor((M + N) / 10) + (M + N) % 10) * (floor((M + N) / 10) + 1) - (5 * floor(M / 10) + M % 10) * (floor(M / 10) + 1)

filling in 6 as M and N as 10 gives the correct answer (16) and filling in 6 as M and N as 48 gives us 168, which is also correct. This equation holds true for all natural numbers

earnest phoenix
lyric mountain
#

lmao

proven lantern
#

c++ must be slow

#

dang

lyric mountain
#

I wonder, how did he stay competitive on js then?

#

v8 blackmagicfuckery?

proven lantern
#

i feel like we are being trolled

earnest phoenix
#

Probably, though I might be converting something of their solution incorrectly to C++, here's what I did:

// Ben's solution
size_t get_price_ben(size_t has, size_t wants) {
  size_t inventory_count_tracker{has};
  size_t cost_tracker{0};
  size_t current_cost{
      static_cast<size_t>(floor(inventory_count_tracker / 10) + 1)};
lcpp_x:

  if (inventory_count_tracker % 10 != 0) {
    const size_t remaining_count{10 - (inventory_count_tracker % 10)};

    cost_tracker += current_cost * remaining_count;
    inventory_count_tracker += remaining_count;
    current_cost++;
  }

  const size_t final_inventory_size{has + wants};
  const size_t final_inventory_size_minus_10{final_inventory_size - 10};

  for (; inventory_count_tracker < final_inventory_size_minus_10;
       inventory_count_tracker += 10) {
    cost_tracker += current_cost * 10;
    current_cost++;
  }

  const size_t remaining_count{final_inventory_size - inventory_count_tracker};

  cost_tracker += current_cost * remaining_count;

  return cost_tracker;
}
#

From what I'm seeing it's 1:1 to their JavaScript version

earnest phoenix
quartz kindle
#

for example

#

if i have 19, and want to buy 2

#

the first one should cost 2, the second should cost 3, correct?

#

total 5

#

the previous function was giving the wrong resut

proven lantern
#

still similar

lyric mountain
#

what in the fuck are up with those names

earnest phoenix
#

You're going quite high with both the parameters, have you tried with small values to see if your solution has a regression?

proven lantern
quartz kindle
lyric mountain
earnest phoenix
#

@proven lantern these are the kind of values passed to your function in my benchmarks, I think it's pretty clear why your solution takes so incredibly long

#

Your solution tries to loop that amount of times combined

proven lantern
#

those are some big numbers

#

one iteration takes over 10 seconds for both

earnest phoenix
#

You shouldn't be using dates to measure performance in JavaScript, use performance.now()

quartz kindle
#

congrats

earnest phoenix
#

There's also console.time() and console.timeEnd()

radiant kraken
#

now it's blazingly fast

quartz kindle
# lyric mountain I'll try it later

so:

// tim's new solution
function getPrice7(has, wants) {
    const hasrem = has % 10;
    const hasbase = has - hasrem;
    const hasvalue = hasbase + hasbase * (0.5 * ((hasbase / 10) - 1)) + hasrem * (Math.ceil(hasbase / 10) + 1);
    const total = has + wants;
    const r = total % 10;
    const x = total - r;
    return (x + x * (0.5 * ((x / 10) - 1)) + r * Math.ceil(total / 10)) - hasvalue;
}

// vigintille's friend's math solution
function test2(M, N) {
    return (5 * Math.floor((M + N) / 10) + (M + N) % 10) * (Math.floor((M + N) / 10) + 1) - (5 * Math.floor(M / 10) + M % 10) * (Math.floor(M / 10) + 1)
}
queen needle
#

Oh my god

radiant kraken
#

hi pancake

earnest phoenix
radiant kraken
#

long time no see

queen needle
#

I had a nearly identical solution to the second one, I just multiplied by something wrong

quartz kindle
#

interestingly he used some kind of multiplication wth 5

#

and i used with 0.5

radiant kraken
#

@queen needle your website is awesome btw

#

i love it when portfolios are actually creative

#

and not steal the same common traits from others

queen needle
#

Thank you <333

#

I need to redo it because it doesn't work for mobile

quartz kindle
#

its empty for me, is it supposed to have something?

#

just has a background, a plus button and a zoom button

queen needle
#

You draw the windows by clicking and dragging to a different point, the bigger the better

radiant kraken
quartz kindle
#

ahh

radiant kraken
#

tho you should've added a notice for it @queen needle

queen needle
#

Oh yeah, I meant to when I made it but I never did πŸ’€

radiant kraken
#

@civic scroll what do you think of pancake's website

quartz kindle
#

ok this is actually amazing

#

a couple suggestions tho, add a way to resize windows :3

radiant kraken
#

^

quartz kindle
#

also are the links in the projects page supposed to work?

queen needle
#

So okay

#

They are supposed to open another window, but I did the math for centering it wrong and never fixed it

quartz kindle
#

ah maybe its gtting blocked by some ad blocker

radiant kraken
#

i dont think so @quartz kindle

queen needle
#

Open like another of the windows on the site, not in another tab

#

I also think of the urls got changed

quartz kindle
#

nope still doesnt work

#

ah i see

#

anyways this is the most creative thing i've seen in a long time

#

congrats!

queen needle
#

I love the portfolio, but idk anyway to make it work for mobile, any suggestions would be nice because I don't want to change it, but if I can't get it to work for mobile I might have to

quartz kindle
#

tho from a UX perspective its a bit funky, design and creativity wise its godlike

queen needle
quartz kindle
#

haha coool

queen needle
#

I'd love any ideas of how to adapt it to mobile

earnest phoenix
radiant kraken
queen needle
#

Windows wouldn't really be big enough imo

lyric mountain
radiant kraken
#

or make it a mask so users can just scroll through

queen needle
#

I have an idea for a new one where the windows are already made and you can go around to different sections to view them

earnest phoenix
# quartz kindle ?

This is how I've converted yours to C++

// Tim's second solution
size_t get_price_tim2(size_t has, size_t wants) {
  const size_t hasrem{has % 10};
  const size_t hasbase{has - hasrem};
  const size_t hasvalue{
      static_cast<size_t>(hasbase + hasbase * (0.5 * ((hasbase / 10) - 1)) +
                          hasrem * (std::ceil(hasbase / 10) + 1))};
  const size_t total{has + wants};
  const size_t r{total % 10};
  const size_t x{total - r};

  return (x + x * (0.5 * ((x / 10) - 1)) + r * std::ceil(total / 10)) -
         hasvalue;
}
quartz kindle
#

well you do have a cast

#

idk then

earnest phoenix
#

Oh, is hasvalue supposed to be a double?

quartz kindle
#

actually no

#

idk it works in js

#

lol

quartz kindle
radiant kraken
#

JS numbers are doubles behind the scenes so

quartz kindle
#

if i have 19, and i want to buy 1, it should cost 2

#

if i have 19 and i want to buy 2, it should cost 5, 2 from 19 to 20, then 3 from 20 to 21

#

also, if i have 20, and i want to buy 2, it should cost 6, as from 20 onwards each costs 3