₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,393 members, 8,511,620 topics. Date: Monday, 02 November 2026 at 05:19 AM

Toggle theme

Deicide's Posts

Nairaland Forum › Deicide's Profile › Deicide's Posts

1 2 3 4 5 6 7 8 ... 35 36 37 38 39 40 41 42 43 (of 226 pages)

Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 8:10pm On Jul 23, 2022
Xedmark:
is this what you call array?
Yes, vectors are dynamic array
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 8:08pm On Jul 23, 2022
namikaze:
from random import randrange

def shuffle(arr):
for i in range(len(arr)):
rand_idx = randrange(len(arr))
arr[rand_idx], arr[i] = arr[i], arr[rand_idx]
return arr

arr = [1,2,3,4,5]
print(shuffle(arr))
Using your python logic in rust, code translate to

fn shuffle(nums: &mut Vec<i32> ) -> Vec<i32> {
let mut rng = rand::thread_rng();
for num in 0..nums.len() {
let x: u32 = rng.gen_range(0..nums.len() as u32);
nums.swap(num, x as usize);
}
return nums.to_vec();
}


This is fucking fast, cause it's using multiple thread and random results are cached grin

Now I can finally rest and watch the sun set on a great universe
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 7:57pm On Jul 23, 2022

Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 6:27pm On Jul 23, 2022
namikaze:
God of bugs grin grin
In all seriousness lots of syntax errors and even after fixing the errors does not give the desired output. I bet you typed it on nairaland.
He should have used typescript
Seun need to fix code formatting on Nairaland even if it's only for this section, I mean see Quora see Reddit.
Food › Re: What Is Your Favourite Food? by Deicide: 5:31pm On Jul 23, 2022
Beans
Chips
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op): 5:18pm On Jul 23, 2022
ExMI6:
You are an epitome of foolishness softie.
A lesbian huh This is the height of foolishness.
I think they are still Kids
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 4:07pm On Jul 23, 2022
qtguru:
Everybody that has written it has sworn by it, but I don't know what Project to use it for, what do you use it for or just learning, is it straight forward ?
You can actually use it for anything. To be honest I was left with go or rust which to use for Sys admin stuff and I just picked rust all I use it for now is to write some CMD tool to solve admin task. And since it's cross platform it's also a plus though I still use go sometimes for that.

Though I might no be using the full power but it suites my use case just fine.
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 12:48pm On Jul 23, 2022
namikaze:
Another way to express your solution without the recursion would be;
function shuffle(Array arr) 
{
HashSet seenIndices = new HashSet()
Array result = new Array()
for (int i in 0 to arr.length())
{
rand_idx = random num in range(0, arr.length())
while (seenIndices.contains(rand_idx)
{
rand_idx = random num in range(0, arr.length())
}
result.add(arr[rand_idx])
seenIndices.add(rand_idx)
}
return result;
}

This I think follows the same idea, but would still depend on the random function, so not recommended.
That's the thing about programming if your solution is not optimised you would know. So there is always room for growth till you move to the next thing.

The randrange you used in python should also depend on random but it's abstracted though am not sure of this.
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 12:15pm On Jul 23, 2022
namikaze:
You should definitely go for walk grin
You used the hashset to reduce lookup from O(n) to O(1) didn't you? nice one.
Yeah, Things I learnt on leetcode grin
Also an instance where random() keeps returning an index to a value that's already in the hashset continuously till count gets to zero would yield undesired results.
Yes the complexity is dependent on the random number. So it can be infinite ): so don't try on large dataset.
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 11:54am On Jul 23, 2022
namikaze:
I remember the Box<T> construct lol, and to think I was able to implement a linkedlist (single) in it grin I don't think I have the code anymore but I'll check my GitHub later.

Ofcourse it would run fast, rust if fast af. I do think it's not that great to let your algorithm depend on "picking the right number" but I get you.
That's why this code wouldn't work if they we duplicate in the input array. Who knows maybe if I stroll out later the solution might come to my head grin
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 11:43am On Jul 23, 2022
namikaze:
Ok, say for instance I called the function on a vector, [1,2,3,4,5];
what would pass as argument for the count parameter?
like this shuffle([1,2,3,4,5], 5);

5 here is the length of the vector.
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op):
Amunethseranu:
... Marijuana are we fine? Good cheesy I thought u are wise but I was wrong about u
Good bye .
Does your friend also smoke Marijuana? I am interested. Lemme see her picture weda she fine
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 11:32am On Jul 23, 2022
namikaze:
Sorry, what's the role of the count parameter?
That's the base case of the recursion; if that's not there the code would run forevergrin
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 11:31am On Jul 23, 2022
namikaze:
My guy even with the unsafe keyword it gets complex real quick, I know what I faced when I tried implementing a doubly linkedlist in Rust, it was crazy. Memory management in C/C++ is much simpler than in Rust.
I agree though learning rust will make you better developer overall.

Guy you're brave, using recursion inside a while loop, I hail thee loolz, well let me see if I can figure out the complexity...
Even on reddit they would advise you not to implement a double linked list or even a Linked list in rust exexpt you wanna run mad grin But you can use Box<T> to make the running mad slower grin

My code actually runs fast despite the recursion, it mostly just depends on if it gets the random number right. Best case would be O(n) but that's impossible but it can happen just that the chance are small especially if the input is large.

I'll rewrite this code in C++ so I can test the complexity properly. The lazy_load for HasSet I did up there I don't have the crate for it grin
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 11:22am On Jul 23, 2022
TastyFriedPussy:
I'll like to see someone try this with JS
It'll be easy with Js
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op): 11:21am On Jul 23, 2022
Amunethseranu:
...
Before time mindsets of d ignorance states that Weeds are synonymous with great & wise thinkers like Galileo , newton, Fela anukpulapo, George orwell, Gandhi when they are alive with them.
When a man starts talking about weed in this form it's a red flag that he will blackmail a female atheist or freethinker because she is weird. U will never in this life date an atheist that's the fact .
FYI I was registered here before most mods in 2009...this is my 4th
You still didn't answer the Question, Why type of weed are you smoking?
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op):
namikaze:
Here's something pretty simple, time complexity should be O (n log n), since the time complexity of the randrange function is O (log n).
It's being quite a while since I did anything in rust, I don't want to fight the borrow checker right now grin Rust used to be my favorite language but it's just too painful to do anything substantial with it, try implementing a doubly linkeldlist in Rust and you'll agree that C++ is easy compared to Rust.
Yeah I agree there are something that are Impossible in rust without using the unsafe key work like i probably did in my code to reduce time & space complexity. But I love the language grin it makes you as a programmer to be very careful with what you write.

Can you guess the complexity of my code since lookup in a hashmap is O(1) so am thing O(n^2 + random(n)) grin I don't even know what that means grin
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 10:42am On Jul 23, 2022
parkervero:
As a Java dev I can't read the code The while loop is not in addendum to Java way of implementing while loop.
You just have to get used to it to love it
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 10:38am On Jul 23, 2022
namikaze:
from random import randrange

def shuffle(arr):
for i in range(len(arr)):
rand_idx = randrange(len(arr))
arr[rand_idx], arr[i] = arr[i], arr[rand_idx]
return arr


arr = [1,2,3,4,5]
print(shuffle(arr))
Nice one grin
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 10:15am On Jul 23, 2022
Ikechukwu183:
As a C++ and Python programmer, I can tell you that this code is not 'readable' by human eyes... is this even a HLL? huh
That's because Nairaland code formatting is useless.
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op): 10:14am On Jul 23, 2022
Amunethseranu:
...
I would have given you to my friend but with ur childish and immature mentality u can only date an atheist girl when she is kidnapped ,forced and bound in chains to date u in captivity because u can never in this life or next date an atheist or freethinker with ur shallow mindset , Go back to ur catholic , Rccg and Chosen girls & wallow in ignorance forever
First of all what type of weed are you smoking? You are probably new on Nairaland.
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 9:54am On Jul 23, 2022
operAhdam:
e easy pass python huh
No but way more faster than python
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 9:54am On Jul 23, 2022
Think4Myself:
Explain the question well, shuffle array as in how?
You never play WHAT before? How them day take shuffle cards. Let's say you have input [1,2,3] you can shuffle it to be [1, 2, 3] or [1, 3, 2] or [3, 1, 2] etc
Programming › Re: Write An Algorithm To Shuffle An Array by Deicide(op): 9:18am On Jul 23, 2022
operAhdam:
that's new,,why do you choose rust boss of all this other languages
Cause it's one of the best programming languages ever, honestly you should try it.
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op): 8:54am On Jul 23, 2022
Amunethseranu:
... Do you expect atheists or female light chasers to appear skinny ?
I am not picking them because of their intellectual capacity rather I am picking them because they are less religious or Irreligious. The brain power is none of my business I don't have strength to be arguing with someone am in a relationship with. So yes Have Big nyash in my case sha big boobs grin and perform the duty of a woman.
Programming › Write An Algorithm To Shuffle An Array by Deicide(op):
Was able to come up with this using rust.
static mut TEMP_V: Vec<i32> = Vec::new();
lazy_static! {
static ref TEMP_SET: HashSet<i32> = {
let mut is_in = HashSet::new();
is_in
};
fn shuffel(nums: &Vec<i32>, count: usize) -> &'static Vec<i32> {
unsafe {
while TEMP_V.len() <= nums.len() {
let rval: u32 = rand::random::<u32>() % nums.len() as u32;
if TEMP_SET.contains(&nums[rval as usize]) {
if count <= 0 {
break;
}
shuffel(&nums, count - 1);
} else {
TEMP_SET.insert(nums[rval as usize]);
TEMP_V.push(nums[rval as usize]);
}
}
return &TEMP_V;
}
}
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op): 8:18am On Jul 23, 2022
Amunethseranu:
...there are many when u seek wisdom instead of nyash
can't I get both?
Truvelisback:
They are in Nairaland too.
Mtcheww!!
Romance › Re: Female Gender:..why Do They Lie Alot? 18+(pics) by Deicide: 7:53am On Jul 23, 2022
She actually looks 12. I don't know what the op was expecting.
Business › Re: Upwork Thread (Questions/Help/Advice) by Deicide: 10:51pm On Jul 22, 2022
OfficialDJ:
I keep telling you all, F^^* all these profile optimization nonsense.

A GREAT PROPOSAL is your pathway to getting jobs on upwork.

Having a great profile with a sucky proposal changes NADA.

I've been upworking for over 7 years now, with an average income of $15,000 monthly, and the above advice will change your life if you utilize it.


Enough said
Make I drop account number? grin
Romance › Re: Where Can Someone Find Atheists Or Irreligious Female To Date In Nigeria by Deicide(op): 10:42pm On Jul 22, 2022
FalseProphet1:
I see you getting married to a witch.
if I can find witch or mermaid to get married to I'll be very happy grin
Programming › Re: Hi Nairalanders, Please Advice Me.i Want To Defer My Program For Programming. by Deicide: 7:23pm On Jul 22, 2022
Hismercy20:
is that necessary?
Make people learn na
Programming › Re: Carbon, A New Programming Language From Google As A C++ Successor by Deicide: 6:00pm On Jul 22, 2022
We are a company looking for carbon developer with 10 years of Experience

1 2 3 4 5 6 7 8 ... 35 36 37 38 39 40 41 42 43 (of 226 pages)