#development
1 messages Β· Page 146 of 1
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
Her name be Vex
One message removed from a suspended account.
the anti-mage mage with anti-dash kit that has a dash
One message removed from a suspended account.
One message removed from a suspended account.
we need to schedule to play dota one day
One message removed from a suspended account.
all homies doing shit in dota
One message removed from a suspended account.
I've never touched dota nor will I probably lol
One message removed from a suspended account.
One message removed from a suspended account.
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
If you follow league at all, did you see Naafiri? I tested them out and man, I love it.
didn't yet, it's been some time since I stopped league
used to be very active on it, even got a $500 prize on my guide once
Naafiri is a new JNG / Mid assassin. They did really good on the trailer.
I'm waiting for nerfs so they gonna kill her like Rell and Nilah 
shell be broken for the first few weeks on release likely. Then they'll do nerfs.
i play tentacles
broken bones teach better lessons
i also play spin to win
demaciaaaaaaa
So what you're saying Tim is that your a stinky Top laner. :P. Jk Top is my second role using Mord / Lilia
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
never seen cait top lmao
It works well due to her range and most tops being melee.
for adcs i play ashe and ezreal
https://scs.twilightgamez.net/g/xjzz4.gif i've taken a break so the numbers are kinda low, but is accurate for my main champs played.
probably higher than my numbers lmao
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.
this is current season
Aye brand lol.
lel
karma
I mean, Karma can be mid π
Ah see my Brand is mid.
i rarely ever build sup items
i played brand mid once, hated it
lmao
couldnt farm for shit
i prefer playing it support and focus on dealing damage
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
"my god doesnt want peace"
One message removed from a suspended account.
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
One message removed from a suspended account.
One message removed from a suspended account.
I mean, if I've vs illaoi, Lilia is pretty decent match up
even if you hook me, speed deer dont care.
a good lilia is so annoying
i've only seen a good lilia once tho
she carried her entire team
nice
you know whats sad
whats your IGN @quartz kindle ill shoot you a fr maybe we can game sometime.
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
sad
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
fuckin mumu
what region?
Oh right your probably not NA
i have an NA account
oh cool
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
Here's a fun Mord momento. Might enjoy.
haha
let me see if i have anything cool
I like how we've taken over #development and turned it into #leagueoflegends
xD
i was just thinking this 
got confused while catching up
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)
}
This is one you'll appreciate Tim. It's called "I ruined a dance party"
lmao
discord doesnt play webm lel
i have to convert my shit to mp4
wait it 100% does wat
wat, it never plays to me
idk always worked for me lol
Twin galaxy lol
I recongnize what that's referencing.
unless its completly irelevant.
have you ever seen a quadra with Jhin using only his q once
lmao
anyways gtg, the vet awaits us!
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 π
lmao sure
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)
did that seraphine just try to flash jhin Q? x)
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
i dont think there is a way to do that without going step by step with loops
this is why we need battleless
to balance things up
i dont know
mhhh, so you suggest looping untill I reach a new "turning" point?
i dont think so
pretty much yeah
only the owner can
you can always be 100% sure by making an alt though
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
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
does the nullish (??) operator check for NaN aswell?
I like the battleless-less #development more lol
I wonder if he sits and reads this channel 
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
now he just have to watch it 360 times and his mute will be over

Even though they have been muted
Pls stop nit picking their mute
Thanks
Just continue development funny talks
they couldn't see it even if discord showed the full form
discord doesn't have your ID
(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
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
you want like a cap? or maybe im just misreading
im sorry
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
yeah I have 5 full papers of me trying to do math but never got it to work
it's not as simple as I thought haha
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
so what's the total cost for just this example? 94?
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)
yea, a lil math formula :3
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
im asking cringegpt
xD
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 
thats more or less what i tried doing but i didnt finish it
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

lemme try it again
Does it not have a possible cap?
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
ew math
not just math.... irrelevant math :(
all I gotta do nwo is get the group size if it's not the first group and then get the group price
math is my weakness
groupPrice = (c - (c % 10)) + i
so now I need to get the groupsize if they aren't the first group
what is this even for
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
bro i dropped out in geometry
i finished mine
ain't it better to use loops and leave the optimization to the runtime?
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;
}
I still can't figure out how to do mine
I love math c:
these var names are cuties
alright, looks good. What do you think of my approach? Although I can't seem to get the final puzzle piece
no u
well, didn't you basically do the same thing as me just the first and last group outside of the for loop?
not, sure i cant wrap my head around any other method rb lmao
pretty much i guess
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
dropped out in precal did one semester and was like nvm
yeah that's what I'm struggling with, with getting the groups right
because the first and last will always be outliers with a different calculation
probably easiest to make the "irregular" groups outside the for loop
yeah
alright thank you very muchΒ΅
i never finished high school
although the above function only works if the price increase is always 1
if you want to change that in the future, it will need fixing
mhm
for example if one day you want to increase price in a non-linear way
well the plan was to indeed change that I just put it into perspective to make the math easier
One message removed from a suspended account.
same
well, i don't want it in a non-linear way just not with 1
every x it should go up by y
so x should already be handled in the step variable
yeah, also the +1 in the loop and third step
wait no
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));
}
ah yes, recursion is also a nice way to do it
i assume int i = 0; i < ; i++ is supposed to be int i = 0; i < batches; i++
ah yes
I like this approach
what site could you do this again? I remember there was a site where you got let algorithms "race" each other
i just do it in dev tools
which is which?
getCost is yours
was just about to ask the same question
getPrice is mine
ah
tim always finds a way to make shit more performant
xDDDD
guy is like a bloodhound for performance fixes
lul
wonder in which params both functions cross in performance
any way we can make a chart out of 'em?
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
you made yours faster?
ye
how π
if only he had the same passion for c/c++ code
how did mine drop almost 900ms?
JS/TS so much better
he fixed it by downloading more ram probably
yours is the same
~1800 - ~1900
mine dropped from 4k to 1k
its just a matter of correctly avoiding repeated calculations
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
ok nerd
oh
yea nah tim a big nerd
is this a challenge on who can optimise a function the most

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
nothing compared to tim, he can likely bring that 1k down to 500 if he tried /j
Lol
hes going to rewrite that function in web assembly
ew
he going to rewrite that function in 1's and 0's
well not compiled
bytecode is still interpreted though
idk someone has to measure performance
that man is you
get to writing bytecode tim
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
i think its mostly useful if youre using native libraries and want to use it in the browser
since those can be assembled
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
i hate javascripts 2gb blob limit
in cases where i cant stream large files it basically kills that
why in the heck would you need a 2gb blob in js
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
@quartz kindle optimized mine
js wont let you upload a file to a blob larger than 2gb you get some weird file system error
paste as text pls
yours or mine?
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
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
what if you try to avoid using const variables and instead hard code the values?
yours was improved by ~500ms in my bench, from ~1900 to ~1450
i can try, but doubt it will make a lot of difference
the Math.min/ceil change will likely make a larger difference
gcc would automatically do that but since js is interpreted idk
v8 probably does that too
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
aight, almost
division as well
it actually did make a difference
no code comment smh
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
lmao
it probably does hard code it to some extent but its still slower
smh evil bit shifting math
I remember writing a program in rust and it is a terrible memory
i mean speed
maybe because you statically linked everything
the standard library is fat
It was not a fond memory for me
ayo did it
show codfish
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;
}
}
still slower on my bench
oh wait, there's an error on it
nvm, there isn't
I just ctrl X it to paste here lmao
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.
x doubt
whichi bench website is that?
perf.link
edge
edge moment
function getCost(initial, buy) {
buy += initial;
let i = 0;
let cost = 0;
const batches = (buy >> 1) + 1;
cost = (batches * (batches + 1) * 10) >> 1;
if (initial === 0) {
return cost + buy * ++i;
} else {
let initialCost = 0;
let initialBuy = initial;
while (initialBuy >= 10) {
initialCost += 10 * ++i;
initialBuy -= 10;
}
return cost - initialCost + buy * ++i;
}
}
for both sides yours is showing almost 10k ops/s less than in my browser
that's weird
cpu difference
yeah it gives my result, not your result
i guess its just our hardware differences
might be
ryzen 5 1600
https://scs.twilightgamez.net/RUetG.png big ops/s moment
really strange
what cpu miyu
11700k
too many percussive maintenances made it fear u
Someone should try that one^ given by chatgpt
also
i just tried running it on firefox
reran the benchmark 5x
and every time it gives different results
My browser is Firefox, maybe why high numbers
conclusion, shitty benchmark website
Also tim.
ok, that HAS to be giving wrong results
How do you benchmark within visual studio. You can do that correct?
look at this
LMAO
lemme see if I find another
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
try this one https://jsbench.me/
JSBench.me is a JavaScript performance benchmarking playground based on Benchmark.js and influenced by JSPerf.
code that was 100% slower being placed in higher rankings than code that is 100% faster
same for me nvm
this one does take a while to complete
the other site was probably doing very few samples
Should get voltrex in on this
Try a benchmarking lib maybe?
cpu will still get in the way
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;
What if you used something like tio.run, where the server it's ran on is consistent and independent from your computer
did you run each one several times to make sure its consistent?
looks like its consistent with mine, just faster across the board because your cpu is better
Do you need help optimizing? Why didn't you ask?
lmao
this is what i get in tio.run with javacript v8
Where is the function you are optimizing?
this is tio.run with javascriot node
I feel like that's the best thing to use to compare since it doesn't depend on your cpu
i like my cou tho
xD
:(
// 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;
}
}
yep, seems consistent with what I got on browser earlier
the arguments we are testing are getCost(32, 5000); and should result 1268500
is this so you can buy bitcoin batches?
the purose of the function is like this
not related to crypto at all
the premise is simple:
an item's cost depends on how many of them you already have
like buy everything at the lowest cost until there is no more at that cost
for every 10 units u buy, the prices increases by 1
getCost = (_, __) => _ === 32 && __ === 5000 ? 1268500 : undefined π₯Έ
exdeeeee
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
first 10 cost 10 each? second 10 cost 20 each?
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
first 10 cost 1 each
yes we decided that the cost is hardcoded to 1, increasing by 1 for every 10 items the user owns
and buying 5000
so the buyer ends with 5032 units
and the total cost for that is 1268500
@lyric mountain we are already completing each other's sentences
lmao
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
initialInventory:0, buy: 200
}```
is it wrong?
i think const buyDecimalPlaces = (i + initialInventory).toString().length - 1;
yes lul
needs to be const buyDecimalPlaces = (i + initialInventory).toString().length;
it should return how much it'd cost to buy X units
first number is final cost
then it's very wrong
second is the adjusted inventory
i will try to get this
xD
oh, it's every 10, not evey 10, 100, 1000
holy shit it's much faster
aight, still smaller
tho I think the warmups were just JITted from the runtime
they went almost instantly
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];
}
averages still the same, ~170 for u, ~400 for me
must return the cost
only the cost
nothing more than the cost
it wont evaluate to true otherwise as it breaks the constraints
it's still wrong too
Why isMod10 instead of n % 10
probably faster to see if something is a '0' than doing math
perhaps
t
lemme see if u understood the context
maybe ur thinking it's supposed to do something else
what are u trying to do?
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
yes
the initial price is also based on how many you own
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
if you already own 32, the initial price already starts at 4
its 1268500 tho
damn no matter what I do I cant get below 400 on java lmao
tf did u do up there tim
I want to try but I don't have my laptop :(
online editor
recursion is not free :)
tried removing recursion, little to no impact
also less loops
java most likely inlined it after the warmup phase
There has to be a formula to do it without loops
How would the initial price be 4 if it's +1 for every 10?
has to be the loop count, trynna find a way to reduce it atm
at 30 ur at 4 per unit
Does it start at 1?
1 - 10 = 1
11 - 20 = 2
21 - 30 = 3
31 - 40 = 4
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?
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
Hello all
it was closer in js
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
If I write one does anyone have anyway to benchmark it using a website or something?
tim's testing on browser, I'm testing on intellij
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
aight it'll take a while
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
i want my faster cpu to give me an edge
y'all still at it π
we're doing 1 million iterations
lmao
the test btw
yes, string ops are slow as hell
you dont need to do that comparison inside the loop lll
ik, but it shouldn't matter much if I'm doing with all test cases
wanna make sure the code is cosmic-ray safe 
lmaoooo
i'll make a map of all the numbers that are mod 10 === 0 and use that instead
very cheeky of you using tims loop to absorb the cold start performance π³
actually, just noticed ben's failed every warmup
forgot to convert to obj param
im going to do a battleless in a minute and start gaslighting
make the params not an object please ben
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;
}
easier for me to plug the code
mmmmmkay
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;
}```
the code converted to java btw
it's not much faster
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
do it
resulting in similar times
it'll be very close to java
take all our funcions and turn them indo a cpp benchmark
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;
}
}
also bens
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
ty
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
I'm driving myself crazy trying to get this in a one line formula
good luck lol
lmao
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
π
it doesn't work either
now let's test with random values
are you using my new and improved code?
nope, u said it doesnt work
it does, i was just using the wrong signature
i was tricked
in js you usually use a spec object for params
doing warmup
but it's likely much slower than ur former code, as it's still in warmup 2
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
@quartz kindle still does well with random values (same seed)
js test with ben code is still warming up
lol
just finished
i have a new plan to win
How does mine return 1268504???
off by 4
I'm honestly impressed with java's Random performance
it had little to no impact on the times
js's Math.random() is very slow
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
How do I test in browser?
I have a laptop now
then F12
I meant like benchmark, what is the boilerplate
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
you dont need the inner if but yeah
send the code too
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;
}```
C O S M I C π R A Y S
okok xd
warmup is faster this time
quite impressed
oh my
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;
}```
in my case I just need to somehow reduce the loop iterations
my code recudes by 10x
unless you do that too
yep
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
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
wat
I gave up lol
can you make tim's slower so i win?
lmao
pls
changes are looking good
trynna remove multiplication altogether
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
Lmao
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;
}
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
nice :)
lmao
and the result is wrong
i like how ai just lies
the result is actually 1252404
xD
i can't get chatgpt to give me anything that works
Is there anyway to do it without a loop? I doubt it but if there was wouldn't that be the fastest
This taught me to use | 0 on any calcs where I don't care abt decimals
It's the equivalent of (int) value in java
ye, it forces conversion into int32
Tbh I hate how any division sets the number to double
isnt a double required to make divisions in the cpu?
I think it's only required if you want the decimals
Else it gets floored as there are no bytes for decimals
const buyMinusTen = buy - 10; YOU DON'T SAY 
i like my variable names to make sense
Good job, that's a pretty clever way to do that
Implementing that in C++ with optimization level 3 takes 1ms for 1 million iterations
Ty, that was one hell of a trip
Ah ffs

tho...are u trying with random or fixed values?
cuz it's probably compiling the function to a constant as the params never change
Completely disabling optimizations makes it take 3 seconds
With completely random values (with optimization level 3) it takes 109ms for 1 million iterations
Now do that in js
we...kinda did
#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";
}
so about 4x faster than our js solutions
I meant the times not the code
and 1.2x faster than java
considering tim's code ofc
didn't convert my solution to java to see
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?
^
he didn't change it since this message
it's the getPrice btw
Alright let me see
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
Does final mean it's constant?
yep
ohno
getPrice7 = (a, b) => true 
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
mf solved the math
nvm its not easy to fix, still looking at where the extra 10 is coming from lmao
I knew someone was going to figure It out
i'll figure it out later g2g do something else now
@lyric mountain @quartz kindle 
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
When Tim fixes it you'll have to test his new one
it's not much faster
damn
KuuHaKu doesn't even use C++
lol
tim and I are entangled, same time for both algos lmao
did my last one win?
fastest one
idk, not with my testing environment anymore
i'll find them
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
i win sometimes!
haka π
Of course
@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
Your solution is so slow that it would take an entire day for it to complete in 1 million iterations, just tested in C++
lmao
i feel like we are being trolled
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
You're probably not benchmarking your solution with different values and are just using the exact same values which might explain why you're getting a fast output in JavaScript
This is how I'm benchmarking them, with completely different values
https://sourceb.in/2lIKbpa0UU
the function is correct, the previous one we have been using is the one is wrong lmao
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
what in the fuck are up with those names
You're going quite high with both the parameters, have you tried with small values to see if your solution has a regression?
thanks
check this out, the old function was totally wrong
I'll try it later
@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
You shouldn't be using dates to measure performance in JavaScript, use performance.now()
i figured out a similar solution, but your's is more elegant
congrats
There's also console.time() and console.timeEnd()
convert it to Rust
now it's blazingly fast

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)
}
Oh my god
hi pancake
Rust blazingly fast!!!!!!!! π―π―π―π―π₯π₯π₯π₯

long time no see
I had a nearly identical solution to the second one, I just multiplied by something wrong
@queen needle your website is awesome btw
i love it when portfolios are actually creative
and not steal the same common traits from others
its empty for me, is it supposed to have something?
just has a background, a plus button and a zoom button
You draw the windows by clicking and dragging to a different point, the bigger the better
try drawing a rectangle with your mouse
ahh
Oh yeah, I meant to when I made it but I never did π
@civic scroll what do you think of pancake's website
ok this is actually amazing
a couple suggestions tho, add a way to resize windows :3
^
also are the links in the projects page supposed to work?
So okay
They are supposed to open another window, but I did the math for centering it wrong and never fixed it
ah maybe its gtting blocked by some ad blocker
i dont think so @quartz kindle
Open like another of the windows on the site, not in another tab
I also think of the urls got changed
nope still doesnt work
ah i see
anyways this is the most creative thing i've seen in a long time
congrats!
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
tho from a UX perspective its a bit funky, design and creativity wise its godlike
I wanted to make like one of the tutorials where it tells you to click things and stuff, I just never did, like an "onboarding" feature
haha coool
I'd love any ideas of how to adapt it to mobile
Your new solution gives 1268498 for 32, 5000
just implement the same thing in mobile?
Windows wouldn't really be big enough imo
we need someone to calc the actual value for that so we have something to compare against
?
make it smaller
or make it a mask so users can just scroll through
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
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;
}
im doing multiplication with floats, shouldnt you be using double instead of size_t
well you do have a cast
idk then
Oh, is hasvalue supposed to be a double?
btw this is completely wrong lel
JS numbers are doubles behind the scenes so

