₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,228 members, 8,420,890 topics. Date: Friday, 05 June 2026 at 01:40 PM

Toggle theme

WhiZTiM's Posts

Nairaland ForumWhiZTiM's ProfileWhiZTiM's Posts

1 2 3 4 5 6 7 8 9 10 (of 18 pages)

BusinessRe: Dangote Donates N250m To Flood Victims In Benue State by WhiZTiM(m): 1:53pm On Sep 11, 2017
Awesome!

Being broke is a sin angry
Car TalkRe: Top 11 Everyday Car Technologies That Came From Race Cars by WhiZTiM(m): 10:49am On Sep 01, 2017
3)Advanced Braking System (ABS)
With the increase in accidental deaths,more and more carmakers are equipping their products with safety feature and ABS is on the top of the list.
In disc brakes,the ABS system prevents the brake pads from locking on to the brake disc by constantly varying the pressure applied on the brake pads without compromising much on the braking efficiency.
Ogbeni!!

ABS stands for Antilock Braking System
ProgrammingRe: Learning More Than One Programming Language At A Time by WhiZTiM(m): 7:36pm On Aug 29, 2017
pachman:
I can't believe I created this topic 2 years ago
Haha! cheesy It shows growth na...

Nonetheless, what's the status report currently?
ProgrammingRe: Goodbye Java! by WhiZTiM(m): 8:10am On Aug 10, 2017
"There are two kinds of programming languages: the ones people complain about, and the ones nobody uses."

- Prof. Bjarne Stroustrup (Designer and creator of the C++ programming language, and Director of Technology at Morgan Stanley)
ProgrammingRe: My Observations by WhiZTiM(m): 10:27pm On Jul 24, 2017
Ejiod:
I discovered here that there are few or no C / C++ programmers.I really Don't know why.
There are actually quite a few (I can mention 3) reasonably good C++ folks here. Mind you, there's no such language as "C/C++"...

C++ used to strive for philosophical compatibility with C, but that ceased to be true long time ago. Recent C++ standards reflects that: C++11, C++14 and soon to be published C++17
ProgrammingRe: Am Offering a programming training to Any One Who Is Interested by WhiZTiM(m):
Dude, we can guess good programmers by a lot clues. There's absolutely no clue on you being even remotely one. I went through your posts, and it seems your blood is hot, calm down � and polish yourself, your writing style (grammar and all...), then come back and advertise your craft... After then, we will push the folks disturbing on "learning programming" to you; and recommend you to others. I am serious.

Take my post in good faith. I mean no offense.
PoliticsRe: Jonathan Didn’t Order Electricity Tariff Reversal, Ex-nerc Chair Replies Fashola by WhiZTiM(m):
SBG04:
No. It's because Jonathan's incompetence almost destroyed Nigeria. Jonathan refused to removed petrol subsidy because his PDP friends were the major beneficiaries and because he didn't want to be unpopular before the elections such that he even left us with long queues. He refused to approve the increase in electricity tarrifs because he also didn't want to be unpopular before elections. He let his Petroleume minister plunder the country like tomorrow wouldn't come. He allowed and encouraged his National security Adviser to divert money meant to fight terrorists to his PDP loyalists.
Oga don't get it twisted, Jonathan did not mean you or anyone in this country well. If you believe otherwise then something must be wrong with you.
Sir, with all due respect, are you an apprentice of our legendary Alh. lai Muhammad ?
Why was there #OccupyNigeria protests in 2011??

Jonathan wasn't the best leader (sadly), we hoped Buhari will be better, but it turns out we were wrong(more depressing). We have liars and thieves in the government today.

Buhari's cabinet of incompetent people are still sabotaging Nigerians.

Though, I believe Oga Fashola is very competent compared to the leagues of Lalung angryof
ProgrammingRe: Fix This C++ Code If You can by WhiZTiM(m):
wao thanks man! i've been discouraged recently to make post cos i dont get any feedbacks, but you just gave me new inspiration! More Posts On The Way.
Ok... I will be checking...! smiley




BTW, pls dont reserve your comments on the bugs on my code, i love being corrected, makes me smarter. i have more codes to post if you dont mind, i deal in AI and i'm trying to create a custom AI-ML. so i've got some pretty interesting code snippets we can brainstorm on
Ok.... Its a bit Mathematical... C++ treats its STL comparators with the concept of Strict Weak Ordering. This makes it possible to use a single comparator for A variety of things.

For example. Using the strict Weak Order of < (less than operator). We can establish the following:

- A < B; A is less than B
- B < A; B is less than A
- !(A < B); A is not less than B. Hence, A is greater than or equal to B
- !(B < A); B is not less than A. Hence, B is greater than or equal to A
- !(A < B) && !(B < A); A is neither less than B nor vice-versa, Hence A is equall to B

--------
See how we were able to use one single operator to Cater for others?

- A < B; equivalent to: A < B ; B > A
- B < A; equivalent to: B < A ; A > B
- !(A < B); equivalent to: A >= B ; B <= A
- !(B < A); equivalent to: B >= A ; A <= B
- !(A < B) && !(B < A); equivalent to: A == B

With that knowledge, we can write a generic version of out Binary Search Algorithm. That takes a functor and makes comparison. Recall that the C++'s STL iterator concept uses the notion of One element past the end. Basically, the iterator produced for a range starts out with a closed interval and ends with an Open Interval. Hence, a range is defined as:

    [A, B)  - The first element, A is inclusive; the last element, B is exclusive 


Armed with the above, we could write an iterative version of `binary_search`. Which has similar API with STL's version, but we return an iterator instead of a bool as per C++ STL version.:

namespace tim{
template<typename Iterator, typename T, typename Compare>
Iterator binary_search(Iterator first, Iterator last, const T& value, Compare cmp){
auto sentinel = last;
while(first != last){
auto mid = first + std::distance(first, last) / 2;
//Strict Weak Ordering
if(!cmp(*first, value) && !cmp(value, *first))
return first;
if(!cmp(value, *first) && !cmp(*std::prev(mid), value))
last = mid;
else if(!cmp(value, *mid) && !cmp(*std::prev(last), value))
first = mid;
else
return sentinel;
}
return sentinel;
}

template<typename Iterator, typename T>
Iterator binary_search(Iterator first, Iterator last, const T& value){
return tim::binary_search(first, last, value, std::less<T>());
}
}



Example Usage:

int main(){
std::vector<int> vec{1,2,3,5,6,6,7,8,9,9,11,22,67,87,98,99,231};

for(int i = 0; i < vec.size(); i++) std::cout << i << '\t'; std::endl(std::cout);
for(int a : vec) std::cout << a << '\t';
for(int k; std::cin >> k, k > -1; ){
auto iter = tim::binary_search(std::begin(vec), std::end(vec), k);
if(iter == std::end(vec)){
std::cout << "Not Found!" << std::endl;
}
else{
std::cout << "Found " << *iter << " at index " << std::distance(std::begin(vec), iter) << std::endl;
}
}
return 0;
}


I haven't run serious tests for the above code though, so, I am still paranoid that there may be a bug lurking somewhere... ...lol



Don't mind me... wink wink I write libraries, so I am very keen about performance, API intuitiveness and "being generic"... I also answer questions on Stackoverflow...
ProgrammingRe: Fix This C++ Code If You can by WhiZTiM(m): 11:15pm On Jul 07, 2017
Olyboy16:
Yes sir, that's the man! He's one of the guys i really wish to work with. D is just mehn.. kiss
I wonder why folks aren't picking it up much...such a great language
Yea... you should check the work he has been pushing out... "Design by Introspection".

BTW, I like the design of your blog. Spent sometime on it. Glad to learn about the Python library "ShutIt".

Great job man!
ProgrammingRe: Fix This C++ Code If You can by WhiZTiM(m): 10:55pm On Jul 07, 2017
Hey, calm down big guy! I wrote that code after over 2 years away from c++.
Also, that's not the actual working code, it was intentionally left buggy and dirty. Obviously carelessly written too.
I am calm... very calm... But look at the title of your post, "Fix This C++ Code If You Can (dare)!".


Now down to the comments.
Clang and Mingw both support implicit <string> headers in their <iostream> header; and. tongue ..just ignore those issues. it wasn't even a working code anyway, just part of a c++ rehab process(playing around with containers and lambdas).
Even if it worked, it would have been an Implementation Defined Behavior, according to ISO C++ standards...
...lol on the rehab process... Goodluck with it...


Now just FTR, here is the actual code i wrote.


/**
* Olyboy16; Implementation of a simpler binary search algo
* this algo is limited to O(log n * 2) instead of O(log n)
*/

//function returns the index
template<typename T>
int binSearch(T arr[], int start, int end, T pin){
if(start > end)
return -1;
int mid = (end-start)/2;
if(arr[mid] > pin && (mid*2) > 4)
return binSearch(arr, mid -1, end, pin);
if(arr[mid] < pin && (mid*2) > 4)
return binSearch(arr, start, mid +1, pin);

return distance(arr, find(arr, arr + (mid*2), pin));
}
The code is very very buggy...
And the interface is ... comments reserved


int main(){
int list[] = {3,5,2,65,86,12,65,86,45,7,2,42,97};
sort(begin(list), end(list));
cout << "Finding 42 using binary search! = " << binSearch(list, 0, 11, 42);
}
Bug spotted...



just for PoC really. the result's half baked
...lol. I know, like I said, I am only responding based on the title of your post.
Maybe the title of your post betrays your original intent... I dunno...
ProgrammingRe: Fix This C++ Code If You can by WhiZTiM(m): 11:14pm On Jul 04, 2017
Olyboy16:
....
Is that not Dr. Andrei Alexandrescu on your profile? ...The template goon...
I picked up D lang cause of that guy....
ProgrammingRe: Fix This C++ Code If You can by WhiZTiM(m):
Olyboy16:
Hi guys, so i was just playing around with c++, trying to get back on track after a long long time away into Generic GC langs. As a polyglot programmer, its my duty to stay up to date with all my languages.

So , here's the dig. I was playing with algorithms...binary search to be exact. so, i encountered some issues along the way. which actually gave me some serious debug time!
So i thought, why not share the fun....i'm throwing out this challenge to anyone who thinks he's as good a C++ programmer as he/she thinks, to fix this code snippet...don't write your implementation...we all can do that...just /fix?optimize/


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

/**
* Olyboy16; Implementation of a simpler binary search algo
* this algo is limited to O(log n * 2) instead of O(log n)
*/


template<typename T>
string binSearch(vector<int>* hay, const int pin){
int size = hay->size();
if(hay->at(size/2) > pin){
vector<int>* hay2; // if you can eliminate this object...you're good!
copy(hay->begin(), hay->end(), hay->begin());
return binSearch<int>(hay2, pin);
}
//lets just search through the chop
auto nd = find(hay->begin(), hay->end(), [=](int& x){
return x == pin;
});
return "[val:"+nd+"]";
}

int main(){
vector<int>* arr {2,5,6,7,9,5,2,1,89,76,33,56,12,0,98,5,4,3,2,45,654,99};
sort(arr->begin(), arr->end(), [](int& i, int& j){ //current > later
return i > j;
});
cout << "Finding 86 using binary search! = " << binSearch<int>(arr, 86);
}



Please note that i intentionally designed it to be a recursive solution...its just to pass time really. wink
... Unfortunately, I don't think Your code is not salvageable... By any streak of luck :-( ...

It would require a significant change hence rewrite







Comments reserved on the code below...

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
/**
* Olyboy16; Implementation of a simpler binary search algo
* this algo is limited to O(log n * 2) instead of O(log n)
*/



Template Argument Deduction will not work here because
none of the arguments depends on the template parameters.
Even without Template Argument Deduction, I don't see any use of type `T` in the function-body below

template<typename T>
string binSearch(vector<int>* hay, const int pin){
....
Umm, I don't see any #include <string> up there...
Seriously? This function returns a `std::string`huh




	int size = hay->size();
if(hay->at(size/2) > pin){
Oh boy....




Whaaaat?? For what? uninitialized pointer??
Even if `hay` was valid, the code below would invoke Undefined Behavior
wanted to use std::copy_backward instead?


vector<int>* hay2;
copy(hay->begin(), hay->end(), hay->begin());



Below, doesn't make any sense...
We are supposedly recursing with the exact parameters this function was called with?

......
return binSearch<int>(hay2, pin);
}



Below, We are dealing with built in types here, they have
bool operator == (T x, T y) defined for them by the compiler!! BTW `std::find` takes a ValueComparable type as the third argument...
since you are using some sort of Unary Predicate, wanted to use `std::find_if` instead?

auto nd = find(hay->begin(), hay->end(), [=](int& x){
return x == pin;
});



Whathuh?

return "[val:"+nd+"]";
}



What kind of nonsense is the declaration of arr?
std:: containers should be used as value types...
A pointer to any std:: container is more like code smell...

.....
int main(){
vector<int>* arr {2,5,6,7,9,5,2,1,89,76,33,56,12,0,98,5,4,3,2,45,654,99};
.....



Really? Any need to invent your functor here?
std::sort uses std::less<T> by default, if you want in descending,
why not simply use std::greater<int>?

	sort(arr->begin(), arr->end(), [](int& i, int& j){
return i > j;
});
..
RomanceRe: My Fiancée And A Man Are Living Together, She Said It's Nothing! by WhiZTiM(m):
OfofoLagos1:
NO One is free from Cheating and Never Brake your Relationship because she or He cheats. Instruct her to leave the place. if she insisted staying with the Guy, you can stop calling and showing care. never brake up yet. sometimes we don't need a brake up we just need the Brake.
Did you mean "break"? Or na mechanical system dey hungry you?
ProgrammingRe: A Simple Explanation Of Functions And Stacks by WhiZTiM(op): 12:26am On Jun 22, 2017
ProgrammingRe: A Simple Explanation Of Functions And Stacks by WhiZTiM(op): 12:26am On Jun 22, 2017
prinzfunchi:
Lovely write up Whiztim .. Learned something new today

Need your advise pls...

we've been taught only Pascal in school but I've picked up C++, I wanna be a software developer , what are the other essential things I need to learn apart from C++?
This is over two years now... I am sorry for not responding since ....#facepalm
How's the C++ coming? Its two years now, you should prolly be a don by now wink cool
TravelRe: Two Die In Jos Multiple Vehicle-crash (pictures) by WhiZTiM(m): 7:40pm On Jun 15, 2017
It was, indeed a terrible accident...
CelebritiesRe: Kemi Olunloyo Released From Prison After 81 Days by WhiZTiM(m): 6:37pm On Jun 05, 2017
Good! E remain Daddy Freeze
PhonesRe: Glo Records Largest Internet Penetration In Q1 2017 by WhiZTiM(m): 8:02am On May 25, 2017
hmm @OP... You don't just blog or report numbers, add some charts, some graphs, some visual representation of those numbers.....

No matter how small and insignificant your data may be, it's faster, easier and more convenient to understand charts...

...at least for the learned ones.

This will set you apart, and give you a good reputation from other (mostly cheap) bloggers.
ProgrammingRe: Any C Programmer Here? by WhiZTiM(m): 2:15pm On May 23, 2017
Mescopaul:
Any C programmer?
Can we start up a thread for C and C++ programmers
Yes sir, I believe there are.

----------------------

Just a side note:
I suggest a specific language should be chosen. Not both of them.

C and C++ are not the same language, neither are they similar.

Yes, C++ used to strive nearly compatibility with C in terms of being C's superset.

But that is no longer true. Newer C++ standards reflects that.
CelebritiesRe: Rosaline Meurer Sprays Dollar On Her Dogs To Mark Their Birthday by WhiZTiM(m): 3:18pm On May 19, 2017
Mad people "averywhere" ...

Anyways, my response to the Slay Queen... Rosalin Meurer

RomanceRe: 6 Things men want in a relationship by WhiZTiM(m):
Actually, not every man... There are men, and there are boys... Boys are threatened by a woman with bright future. Men are not, they we want someone with a vision, and is an achiever, but a good wife...
CelebritiesRe: Olamide Flaunts Guitar Tattoo On His Leg by WhiZTiM(m): 10:24pm On May 14, 2017
But how is this news?

ProgrammingRe: Are There No Network Engineers On Nairaland? by WhiZTiM(m): 11:57am On May 14, 2017
@Fepub Hmmn... there's no point going back and forth this. ...case closed. cool
ProgrammingRe: Are There No Network Engineers On Nairaland? by WhiZTiM(m):
Febup:
Computer networking is covered under Network or Socket Programming so you can drop your post here too and we programmers can help you.
No ... No... No... Hell no!!
Programmers know little about networking.... Now that said, I believe programmers actually know the some stuff... Which is mostly concerning the uppermost 3 or 4 components of the OSI networking model....

A Server infrastructure Programmers may be a domain expert within the Application, Presentation and Session layers... The Network Engineer should be at least very familiar with the Physical Bit, Data link, and Network layers. There may be a good deal of overlap in the transport layer.

------------------------------
Simply knowing IP, cabling, etc shouldn't qualify anyone to call himself a Network Engineer in my purview.

I claim very little knowledge on Networking; so take me with a grain of salt grin
(Image: courtesy of lifewire)

ProgrammingRe: C++ Programming: To Do Or Not To Do. by WhiZTiM(m):
Here's my N1.25kobo rant:
======================

Is the language worth learning?
Yes it is. Its a fantastic language. Virtually all major services you use daily has some C++ code sitting somewhere. From your internet systems, routers, web-services, down to your computing device.

One thing about C++
C++ doesn't give you performance as people claim. However, it gives you unfettered control over performance. So a badly written C++ will not be fast, period.
However, a well crafted and highly fine tuned C++ program on a latest aggressively optimizing compiler is likely to produce the best you could get in terms of raw runtime performance.

What lessons will I pick up during my C++ Journey
- You will learn about absolute performance
- You will learn about the Computer Architecture
- You will learn how the CPU works
- You will learn how to align code to memory lines
- You will learn what makes Intel Core i3 7th generation series better than Intel Core i7 2nd generation
- You will learn how the OS interacts with your programs.
- You will learn to think forward
- You will learn to take responsibility

What are the prerequisite knowledge?
None. There's no entry barrier.

How difficult is it?
It's one of the most powerful languages out there with some complexities that will take a while (a year or two) to master a lot of it.
With enormous power comes a lot of responsibility, so, over the course of your career, you'll learn a lot of interesting stuff that will put you ahead of other programmers in terms of designing and implementing Performance-critical Systems.

How long does it take to learn it?
You can learn most parts of it within a year.

If you are a novice to programming, you can start writing beautiful, elegant, scalable, maintainable infrastructure with it after about two years. As you would find in Google, Facebook, etc.

Pro level expertise, about 4 years or more, from novice.

Note, don't let this scare you off. Everyone that tells you he is a master of XYZ language after less than 2 years of lifetime programming experience is a liar. Programming is both Technical and Artistic. It takes years to develop a good combo of those skills.

Note the emphasis on "lifetime" above. I am talking about new programmers.

I want to improve my problem solving skills.
The most prestigious programming contest in the world, the ACM-ICPC (Association of Computing Machinery - International Collegiate of Programming Contests) uses C++ as one of its two official languages.

Given that you are in school now, you are eligible to participate. http://icpc.baylor.edu ..Do every thing you can to participate, you'll enjoy it.

Learning the language isn't enough. You will also need to improve your problem solving skills. Algorithm, Data Structures, System Design. These can mostly be obtained by practicing problems on Hackerrank, LeetCode, etc. Or simply participating in ACM-ICPC a few times.

Where can I get resources
I strongly advice you to stick with the ones here: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Those have been curated by world class experts and some have the blessings from the who-is-who in the C++ world. Including my little blessings...lol.

How modern is C++
C++ has been existing in the industry for more than 30 years now. And has several billions of lines of Code working out there.
It has also undergone growth. It evolves every 3 years now. And each evolution gets better, faster, and more modern. No matter what book or resource you pick, make sure it was produced/released of written after the year 2010.

- We have an amazing version of the language known as C++11. Standardized in 2011
- We have a nicer version which I currently use for new projects, C++14. Standardized in 2014
- We have an upcoming one called C++17. To be standardized in few months time.
- We will have another by 2020. And so on...

It gets faster, better, and more beautiful each time.

In C++, you only pay for what you use. The language never incurs any penalty on features or stuff you didn't use.

After that, how do I stay ahead of the language's evolution?
After you've gone through months following introductry texts and undergone some personal projects.
You want to attempt answering questions on Stackoverflow.

But still, you can go ahead and watch the video coverage of the proceedings from renowned C++ conferences such as: CppCon, CppNow, BoostCon, ACCU, MeetingCpp, NDC talks ...PS: You can search those on Youtube.

Why shouldn't you learn C++?
If you are lazy and hate challenges, and if you easily get depressed.
Christianity EtcRe: Kenneth Copeland Lays Hands On Oyedepo At Winners Chapel's 36th Anniversary by WhiZTiM(m):
fineboynl:
a prophet who can't prophecy just 10 bet9ja odds for his members to become rich. is that one a prophet??
Lazy punk. Getting rich by bet9ja? You gotta be kidding right?

--------------
You don't need Jesus to make millions! There are earthly principles for that. Go figure it out!

You need Jesus for a life. - And life, abundantly!
-------------
NYSCRe: Taraba State: The Worst Place To Serve (NYSC) by WhiZTiM(m): 12:41am On May 05, 2017
danidon08:
I just finished frm there batch A stream one. No shishi was given
All hail the famous Geologist who detected oil in one of Nigeria's oil fields using only a Stethoscope to the ground... grin

CrimeRe: Man Kills His 3-Month Pregnant Wife, An RCCG Choir Mistress (Photos) by WhiZTiM(m): 9:05am On May 01, 2017
I stopped going to their house three years ago because my daughter told her husband bad things about me, saying I didn’t encourage their union. .
What kind of Hullabaloo is this??

--------------------------------------

“My daughter endured seven years of hardship and pain. When they started their relationship, I told her not to marry him, but she said she loved him.
Everyday, I keep learning this lesson not to let "hearty emotions" to overshadow "predictive sense" ....

We see evidences, but we say we love him/her?

1 2 3 4 5 6 7 8 9 10 (of 18 pages)