₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,229 members, 8,420,898 topics. Date: Friday, 05 June 2026 at 01:43 PM

Toggle theme

WhiZTiM's Posts

Nairaland ForumWhiZTiM's ProfileWhiZTiM's Posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 (of 18 pages)

ProgrammingRe: Programming Challenge by WhiZTiM(m): 11:10pm On Jul 14, 2013
@op. Thanks for the post... I remember something like this way back in Junior School... But there was something I am not sure I understood from your question . .
ProgrammingRe: Programming Challenge by WhiZTiM(m): 10:34pm On Jul 14, 2013
Another... much shorter SLoC...

http://ideone.com/HKdiNS

0.01second on my PC... when I piped input to stdin
It works on my Machine... I am on a Mobile now... can't really make it run on IDEone... this is my 3rd attempt to make it work....
#annoyed.. bad phone, MTN frustrating me and my Money...

PYTHON 2.5+ < 3.0

#!/usr/bin/python
#(C) WhiZTiM 2013

def commonLen(s1, s2):
s1 = s1.lower()
s2 = s2.lower()
k = 0
while(k < len(s1)):
if(s2.find(s1[k]) == -1):
k += 1
continue
s2 = s2.replace(s1[k], '', 1)
s1 = s1.replace(s1[k], '', 1)
return ( len(s1) + len(s2) )

def getVerdict(s1, s2):
mp = ["Friends", "Lovers", "Admirers", "Married", "Enemies", "Sisters"]
ln = commonLen(s1, s2)
ln = 0 if( (ln - 1) < 0) else ((ln - 1) % 6)
return mp[ln]

def main():
s1 = raw_input()
s2 = raw_input()
ans = s1 + " and " + s2 + " are " + getVerdict(s1, s2)
print ans

if(__name__ == '__main__'):
main()


#PythonSquad
ProgrammingRe: Programming Challenge by WhiZTiM(m): 10:01pm On Jul 14, 2013
Be more specific at your problems @OP! ...
Here are 2 optimized solutions . . ...
The close to fastest... C++

http://ideone.com/T2RerE
took 0 seconds to run..

/* (C) WhiZTiM 2013 */
#include <iostream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;
typedef string::size_type szT;
typedef vector<string> VEC_string;

void strip_common_characters(string& A, string& B)
{
//choose the shortest string to save iteration time
string& S1 = A.size() <= B.size() ? A : B; //by reference!
string& S2 = A.size() > B.size() ? A : B; //by reference!
szT i = 0;
while(i < S1.size())
{
bool found = false;
szT lc = S2.find(S1[i]);
if(lc != string::npos) found = true;
else
{
lc = S2.find(tolower(S1[i]));
if(lc != string::npos) found = true;
}
if(found)
{
S1.erase(i, 1);
S2.erase(lc,1);
continue;
}
++i;
}
}

void instantiateMap(VEC_string& mp)
{
mp.push_back("Friends"wink;
mp.push_back("Lovers"wink;
mp.push_back("Admirers"wink;
mp.push_back("Married"wink;
mp.push_back("Enemies"wink;
mp.push_back("Sisters"wink;
}

void run()
{
string s1, s2, s3, s4;
getline(cin, s1);
getline(cin, s2);
s3 = s1; s4 = s2;

VEC_string mp;
instantiateMap(mp);

strip_common_characters(s1, s2);
unsigned k = s1.size() + s2.size();
k = (k - 1) < 0 ? 0 : ((k - 1) % mp.size());

cout << s3 << " and " << s4 << " are " << mp[k] << endl;
}

int main(int argc, char* argv[])
{
run();
return 0;
}
ProgrammingRe: Simple Php Challenge by WhiZTiM(m): 8:21pm On Jul 13, 2013
spikes C: Mogbe ooooo grin

I have not seen a solution in Java ooo. That one go be 2 pages lipsrsealed

Besides, oga Whiztim, ur sollution does not follow d rules undecided

C++ rules
#hehe... You are looking for trouble ohh.
ProgrammingRe: Simple Php Challenge by WhiZTiM(m): 7:50pm On Jul 13, 2013
spikes C: Mogbe ooooo grin

I have not seen a solution in Java ooo. That one go be 2 pages lipsrsealed

Besides, oga Whiztim, ur sollution does not follow d rules undecided


C++ rules
. . . Yes I know... That is why i wrote.
WhiZTiM: The solution I would have
presented in C++, that follows the
rules; has already been presented...!
Thats why, I decided to make my
solution shortest... Ohkay, I agree
not a solution but an answer. And I used the language best suited
for 'my goal' AND this exact
problem...
ProgrammingRe: Simple Php Challenge by WhiZTiM(m):
here is my solution! ...in Python 2.7

print range(7, 2101, 7)


Python 3 will be

print ([x for x in range(7, 2101, 7)])

I am on an old mobile phone now... Cant IDEOne it yet.

The solution I would have presented in C++, that follows the rules; has already been presented...!
Thats why, I decided to make my solution shortest... Ohkay, I agree not a solution but an answer.
And I used the language best suited for 'my goal' AND this exact problem...

#PythonSquad.

BTW, C++ rules. tongue... (#looksForTrouble)
ProgrammingRe: Simple Php Challenge by WhiZTiM(m): 6:34pm On Jul 13, 2013
spikes C: He's already learning arabic. Watch out for his next post, he'll be writing from right to left grin



BTW, C++ rules tongue
*hahahahaha! #Oga spikes C don crack my ribs oh.

Oboi, that time never come... Its probably when I am faced with a problem in Java that I would learn Arabic writing and present my solution in Arabic.. . .#hehe
#i dey throw you salute!
ProgrammingRe: Simple Php Challenge by WhiZTiM(m): 6:27pm On Jul 13, 2013
Judinho59: wink

Where's Whiztim when u need him?? angry
e be like sey some una conspire sey mek my phone spoil and mek MTN dey jonze me.
Haba, spikes C na Oga oh...
Bros, e be like sey u wan see stunts from me. Abeg, I am human.
How you doing??
ProgrammingRe: Simple Php Challenge by WhiZTiM(m): 6:18pm On Jul 13, 2013
spikes C: Errrrmmm....i was saying java is cool.

Can u teach me Arabic grin
hahahaha. *falls off the tree.
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 9:43pm On Jul 08, 2013
Haba!!
Ask For Clarification! Challenge Me! And Query Me where appropriate...

some of you really lack BASIC psychology skills.

. . . Did I ever tell anybody I make my living solely off programming?

. . . Did I ever say I would be into programming all my life?

. . . What do you know about me outside Nairaland?

So, attacking me for my subjective statement is outrightly pointless and TOTAL STUPIDITY... Just as started by a 'block headed', 'crackbrained', and 'shallow minded fellow'... I don't even know the gender of that person...

Still, I rather learn Arabic writing than a programming language called Java. grin

C'mon guys, where's the Nigerian spirit!
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 7:08pm On Jul 08, 2013
paddy4destiny: C++ pointers are easy and fun to
learn. Some C++ tasks are
performed more easily with
pointers, and other C++ tasks,
such as dynamic memory
allocation, cannot be performed
without them.
As you know every variable is a
memory location and every
memory location has its address
defined which can be accessed
using ampersand (&wink operator
which denotes an address in
memory.
. . .
. . .
When the above code is compiled
and executed, it produces result
something as follows:
Address of var1
variable:
0xbfebd5c0
Address of var2
variable:
0xbfebd5b6
think am liking cplusplus. With my little knowlegde of pascal i think i will grasp it in no time. Never liked java for one day
one love sir...! . . .

me still dey talk sey, i would rather learn Arabic writing than a programming language called Java tongue

C++ pointers gives you so much power and flexibility at a certain cost... And its exceptional! Also gives the comfort ride of C...

Actually, pointers are pretty simple, thanks to the compiler for precomputing the memory sizes of datatypes and objects for pointer arithmetic.
. . . I wrote a little bit advanced tutorial on that a month ago....

paddy4destiny: y laughing na robotics engineer
oboi, because I talk say I dey robotics engineering discipline no mean say I don collect my degree for robotics engineering oh... make I finish and join IEEE-RAS first...

Anyway, I was laughing at spike C's reaction not your post....
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 6:26pm On Jul 08, 2013
spikes C: That's all we need

Next
Haha... grin
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 1:28pm On Jul 07, 2013
Judinho59: @Spikes, i digg it now. Well, Java does more tho. wink

@Topic: Now, this' getting outta line. There are countless forum discussions & articles about this same topic, and at the end it leads to nothing.

If Java does it, go for it.
If C++ does it, go for it. wink
you are the man!
I salute you and your last 2 paragraphs!...
. IMVHO . . This is more civilized. . .
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 1:24pm On Jul 07, 2013
spikes C: These things are just pencils in our hands, the creators cool

Just use the best tool for the job, shikena


BTW, C++ rules tongue
hahaha.... You are on point!
*I Salute you...
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 12:19pm On Jul 07, 2013
@Javanian.
False and very stupid claims... Fucckk me, your misunderstanding, aggression, blahh blah blah....
~/~Damn! That pot you just smoked must be hot!
~~~I DID RATHER TEACH AN ASS(DONKEY) HOW TO READ AND WRITE THAN to TRADE WORDS WITH YOU MA'AM.

@LordZouga,
I don't think sweet features of a programming language can convince someone who has made certain programming language a god. Its like trying to convince Steve Ballmer to sponsor Linux or Linus Torvalds to join Microsoft.
you see, its pointless.

If I were to have a service to deliver, if applicable, I did have someone wrap and roll out my API's with preference to Java and php... Thats were I get more audience and more revenues

And I still say, I rather learn Arabic writing than a language called Java...

In Nachos..
.It's so idiotic to debate great languages when you aren't contributing to any language's design or implementation...

As someone in the Mechanical and Robotics Engineering discipline... I say ALL LANGUAGES are tools, we have choices of work tools and its usually influenced by skillset, understanding, constraints, environment, workpeice, e.t.c...
ProgrammingRe: Java Vs C++ by WhiZTiM(m): 2:07am On Jul 07, 2013
I respect ALL programming languages BUT ....I probably, did and rather learn Visual Basic or Arabic writing than learn the programming language called Java.

@OP, in my 'subjective' opinion, Your delima should be C++ or C#.

Forget platform targets. The primary language feature of C# is Java's future!

Java is over 20yrs and has Billions of Dollars from many godfathers driving it! Oracle, Google, etc.... Thats why she's popular. . . .C# is just a little over 10yrs and has only Microsoft as a major godfather. But she's gaining ground with so much momentum.

C++ on the other hand is an artillery building language...
Such as
Microsoft Windows, Mozilla Firefox, Thunderbird, Adobe CS suites, Google Chrome, Internet Explorer Microsoft Office, File servers, Graphics intensive Game Engines, Javascript Engines, National Security Software, Music production suites, Raytracing software, massive and computationally intensive simulation systems... a Python interpreter, You can even build a JVM in C++
the list is endless!
....Java can never compete these in absolute and ANY good faith. But, I THINK Java is so popular and HIGLY PRODUCTIVE for small, localized and/or limited software...

I dont have the resources to do a real test.... But C# VM runs FASTER than Java's Dalvik on Android... According to xamarin.com
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 8:58am On Jul 05, 2013
I would stop derailing from the goal of your thread. . .
And BTW, I have been a subscriber to code simplicity, it actually reduces maintenance burden and upgrades by the next maintainer. . .

. . .and thank you for the problem. . awaiting the next problem.

Cheers.
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 8:42am On Jul 05, 2013
@authurowen.... I think you should read more books to increase your comprehension skills. Lemme clear out a few things...
1. I said its sometimes a plus to write bloated codes when you are have NO concrete goal in mind...

2. Your citation with the mathematics expression shows your poor understanding of my intent... If you are damn good in maths, you could be solving a COMPLEX problem, you could express a subproblem of that problem as parametric equations etc... just to get the results you need and continue with more subproblems till you are done!

But assuming it was only that subproblem that existed and you have nothing else doing, you could represent it as ODE's or some more complex model and plot graphs to investigate behavior at certain values.... Ofcause... The knowledge is just for keeps.
.
FOR THE RECORD: as a result of writing crazy overkills in free time, I have implemented a few algorithms that I never knew it formally existed...
This started few years back, when I implemented a shortest part algorithm in a bloated solution to a code challenge.... only to later realize that it was 95% Edgar Dijkstra's algorithim! And any fair solution to that problem did not even require a graph algorithm! . . .

3. I would usually go for optimal solution in real life or any software routine...

4. Yes. I am Software tester with experience limited to GUI Applications (I use Python to automate mouse and keyboards), and C++ programs using a few arsenels... e.g Valgrind tools is my fave for blackbox testing.

6. Yes. I have participated in some programming contests, most notably, I am an ex-regionals contestant of the Worlds most renowned programming contest, ACM-ICPC...

I am yet to sign up for codeforces etc, cause I know I wouldnt rise up the ranks quickly even in years. I have lots of responsibilites than programming all day or weekend.

7. If you are talking of solving problems in exact. my C++ solution beats yours in ALL endeavors.

8. Your problem is not an Engineering problem.

in this context, PLEASE consider Droping the phrase "Software Engineer" or "engineering", BECAUSE your problem and solution is an insult of the first order to Engineering! ...or qualify it with "trainee", "prospective" etc.

9. Recursion builds up stack! Compilers happen to be clever than you that's why the stack size of recursive fuctions MAY be smaller compared to what it was supposed to be...!

Peace.... I think we'll make good friends bro.
ProgrammingRe: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by WhiZTiM(op): 1:44am On Jun 29, 2013
hmmn... I can see someone missing a loved one.

haha... nice imgs

here is another.... (a little bit technical)
http://pastebin.com/SemMk98v


//Pseudo-code for Microsoft Windows 95
//---idea---TiM

//boot the system
init __boot;

//load stuff for keyboards, file system drivers, and Display
init __load_basic_drivers;

//prepare BoSD
init __prepare__ BLUE_SCREEN_OF_DEATH;

//enter event loop
while(!crashed)
{
sleep(1300); //milisecs

load_kernel_sevices();

if(system_still_running)
{
try
{
kernel_load( all(system_programs) );

kernel_unload( most_useful(system_programs) );

if(!unloaded(last_kernel_instruction)) throw Exception;
}
catch(Errors)
{ fire(BLUE_SCREEN_OF_DEATH); }
}

kernel_load( Graphics );
kernel_load( Windows_Explorer );

kernel_init( set( cpu_execution_speed( random % 100 ) ) )

bool legal = verify(Microsoft.Paid.isTrue());

if(legal)
{
call( persuading_daemon(ask_for_more_money) )
}
else
{
kernel_unload(kernel, silently=true, gradually=yes);
}

if(system_is_ok)
{
attempt(crash);
}

if(system_survived_last_crash_attempt)
{
kernel_load( all(backdoors_and_memory_exploits) );

init __set(BLUE_SCREEN_OF_DEATH, fire(in(2000, seconds)));
}

if(system.isIdle())
{
kernel_init( all( sleep(hardware) && sleep(software) ) );
kernel_interrupt( DISABLE_ALL );

set( kernel.neverWakeUp = true );
}

while(still_not_crashed)
{
do (NOTHING for random.minutes)
wait_for_user_events();

attempt(crash) && break;
}

if(is lucky)
{
kernel_programs_manager.set( FAIL );
load( all(programs), haphazardly );
}

if(execution_reached_this_point)
{
kernel_init( kill_All_useful_programs );

fire(BLUE_SCREEN_OF_DEATH);

kernel_unload( kernel );
}

assert(system_is_DEAD);
}
ProgrammingRe: Comparing Programming And Computer Networking by WhiZTiM(m): 1:31am On Jun 29, 2013
Both are costly to learn... but the both pay off very well after years...

You would hardly be able to show off your computer networking skills without relevant certifications... but that's not the same for programming. ~~I hope that helps a little
ProgrammingRe: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by WhiZTiM(op): 5:12am On Jun 28, 2013
This is a model of typical Nigerian courts in Java... err... It might not be the same today or tomorrow.. grin

http://pastebin.com/e9pDBgW3

class Nig_Court
{
long _stolen_cash;
boolean bought_judgement;
public Nig_Court(long stolen_cash)
{
bought_judgement = false;
_stolen_cash = stolen_cash;
}

public final void buy_judgement(long bribe)
{
//if bribe is > N200,000 and its also greater than 4% of stolen_cash
if((bribe > 200000) && (bribe > (_stolen_cash * 4 / 100)))
{
bought_judgement = true;
}
}

public final String get_Verdict()
{
if(bought_judgement)
{
return "Case dismised for lack of evidence";
}
// < N10... doesnt deserve to live
else if(_stolen_cash < 10)
{
return "Jailed for life";
}
//N10 to N5,000 :
else if(_stolen_cash >= 10 && _stolen_cash < 5000)
{
return "Jailed for 70 years with hard labor";
}
//N5,000 to N100,000 :
else if(_stolen_cash >= 5000 && _stolen_cash < 100000)
{
return "Jailed for 15 years with mild labor";
}
//N100,000 to N1m :
else if(_stolen_cash >= 100000 && _stolen_cash < 1000000)
{
return "Jailed for 6 years without labor";
}
//N1m to N30m : Sizeable thief
else if(_stolen_cash >= 1000000 && _stolen_cash < 30000000)
{
return "Jailed for 2 months with option of 10% fine: "
+ Long.toString(_stolen_cash * 10 / 100);
}
//N30m to N500m : big thief
else if(_stolen_cash >= 30000000 && _stolen_cash <= 500000000)
{
return "Rest for 3 weeks Sir/Ma with option of 6% fine: "
+ Long.toString(_stolen_cash * 6 / 100);
}

//#Oga @ The Top: ahhh, somebody with goodwill for the nation
//_stolen_cash > N500m ...
else
{
return "Discharged and Acquitted!... Sorry for wasting your ample time"
+ "we thank you for your Patience with us Sir/Ma";
}
}
}
ProgrammingProgramming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by WhiZTiM(op): 5:02am On Jun 28, 2013
Welcome!! : - )

Here is an attempt, using code snippets, to make you laugh and get a glimpse of good, bad, realities, experience, etc...

INFO
Please post VERY easily UNDERSTOOD code snippets; such that if you posted a Java snippet and I am not a Java programmer, I would still get your point
Pseudo-codes and flowcharts would also be great!!

--->Posting on an ADDITIONAL link to an uploaded code of yours to a syntax highlighting site such as http://www.pastebin.com is a +1!!
---> Post codes that:
----> depicts current situation of a government agency(please also post good side of them if you know!!)
----> models a government agency, firm, or government in the world...
----> models a business or industry in the world...
----> models a celebrity, footballer, or prominent persons
----> models your experience with a lady or ladies, guy or guys..
----> and anything that is worth posting!!!

EXAMPLE:
Nigerian Police Force...
Nigerian Army, Nigerian Courts, Nigerian Embassy, a nigerian leader, politician, banks, footballer
Microsoft, Dangote, Techno, NNPC, NSCDC, etc... ANYTHING Popular

I will try to post snippets in various languages once a week for the next few weeks! keep yours rolling!!! n put a smile on our faces!
***The next post depicts type of posts***

~Thanks.
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 2:52am On Jun 27, 2013
Here is the link ...http://pastebin.com/GAK00hF8

C#4.0 or later

........ Notice the class Program.. where the Main() function resides...
look into the Main... that is how you should build up things in OOP;;;

Again... this uses standard input.. (stdin) for input...

@everyone: Please Criticize my code also... especially the C# PROFESSIONALS... who know any specifics of C# that I am not harnessing


/* (2D) Finite Matrix - transverser
* ---incooperated a Spiral Matrix Printer
*
* (C) WhiZTiM 27th June, 2013
* FOR EDUCATIONAL PURPOSES only!
*/
using System;

namespace SP
{
//2D Coordinate...
public struct Coord
{
public int X { get; set; }
public int Y { get; set; }
}

//make a prepaid contract for element types
public abstract class Element
{
protected bool _taken { get; set; }
public void setTaken(bool value) { _taken = value; }
public bool isTaken() { return _taken; }
}

//String elements
public class StringElement : Element
{
private readonly string _value;

public StringElement(string value) : base()
{
_value = value;
}
public string str() { return _value; }
}

//A thin wrapper for StringElements
public class Spiral_Array
{
private readonly StringElement[,] _array;
public Spiral_Array (StringElement[,] elements)
{
_array = elements;
sizeX = _array.GetLength(0);
sizeY = _array.GetLength(1);
}
public StringElement this[int x, int y]
{ get{ return _array[x,y]; }
private set { /* */ }
}
public int sizeX{ get; private set; }
public int sizeY{ get; private set; }
}

//This is a helper class that creates 2D 'Element' Objects from a string array
public class Helper_2D_Elements
{
public StringElement[,] Elements {get; private set; }
public Helper_2D_Elements(string[] array)
{
int arrSize = array.Length;

Elements = new StringElement[arrSize,arrSize];

for(int i = 0; i < arrSize; i++)
{
string[] str = array[i].Split(' ');
for(int j = 0; j < arrSize; j++)
{
Elements[i,j] = new StringElement(str[j]);
}
}
}
}

//this is an independent traveller object...
/*
* It takes a finite grid of size (0,0) to (X, Y)
* transverses through it in very definite direction
* and only passes through a point once!
*/
public class Element_Traveller2D
{
public enum Direction : int { Right, Down, Left, Up }
public enum SweepDirection { Clockwise, Aniclockwise }
private Coord _coord;
private readonly int LimX, LimY;
private readonly long _max;
private bool[,] _taken;
private long _taken_count;
private int _preference;
private bool _first;
private SweepDirection _sweep;
public Element_Traveller2D(int X, int Y, SweepDirection sweep, Direction startingAt)
{
LimX = X; LimY = Y;
_coord = new Coord{ X = 0, Y = 0 }; //defaults to 0,0
_taken = new bool[X,Y]; //defaults to false
_first = true;
_max = X * Y;
_taken_count = 0;
_preference = (int) startingAt;
_sweep = sweep;
}

private void changeDir()
{
if(_sweep == SweepDirection.Clockwise)
{ _preference = (++_preference) % 4; }
else
{ _preference = (--_preference) % 4; }
}

public Coord nextPoint()
{
if(_first){
_taken[0,0] = true;
_taken_count++;
_first = false;
return _coord;
}
for(int _a = 0; _a < 4; _a++) {
switch (_preference) {
case 0:
if(_coord.Y + 1 < LimY && !_taken[_coord.X, _coord.Y + 1])
{
_coord.Y += 1; _taken_count++;
_taken[_coord.X, _coord.Y] = true;
return _coord;
}
changeDir();
break;
case 1:
if(_coord.X + 1 < LimX && !_taken[_coord.X + 1, _coord.Y])
{
_coord.X += 1; _taken_count++;
_taken[_coord.X, _coord.Y] = true;
return _coord;
}
changeDir();
break;
case 2:
if(_coord.Y - 1 >= 0 && !_taken[_coord.X, _coord.Y - 1])
{
_coord.Y -= 1; _taken_count++;
_taken[_coord.X, _coord.Y] = true;
return _coord;
}
changeDir();
break;
case 3:
if(_coord.X - 1 >= 0 && !_taken[_coord.X - 1, _coord.Y])
{
_coord.X -= 1; _taken_count++;
_taken[_coord.X, _coord.Y] = true;
return _coord;
}
changeDir();
break;
default:
changeDir();
break;
}
}
_taken_count = _max;
return new Coord();
}

public bool canMove()
{
return (_taken_count < _max);
}
}

/* This class is responsible for instantiating the Traveller object
* and transverse through the grid... while printing it
* */
public class Spiral_Printer
{
private readonly Spiral_Array _value;
private readonly Element_Traveller2D traveller;
public Spiral_Printer(Spiral_Array array)
{
_value = array;
traveller = new Element_Traveller2D( _value.sizeX, _value.sizeY,
Element_Traveller2D.SweepDirection.Clockwise, Element_Traveller2D.Direction.Right );
}

public void Print()
{
while(traveller.canMove())
{
Coord dim = traveller.nextPoint();
Console.Write("{0} ", _value[dim.X, dim.Y].str());
}
}
}


public class Program
{
public static void Main(string[] args)
{
Program prog = new Program();
//read inputs
string[] values = prog.readInput();
if(string.IsNullOrEmpty(values[0]))
{
Console.WriteLine("ID10T!"wink;
return;
}

//create an array of string elements
Helper_2D_Elements elements = new Helper_2D_Elements(values);

//create the Spiral Array class
Spiral_Array spiral = new Spiral_Array(elements.Elements);

//Create a printer
Spiral_Printer printer = new Spiral_Printer(spiral);
printer.Print();
}

string[] readInput()
{
string str = Console.ReadLine();
if(string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str) ) {
Console.WriteLine("Invalid input Numbnuts"wink;
return null;
}
string[] arrCount = str.Split(' ');
int arrSize = arrCount.Length;
string[] StrList = new string[arrSize];
StrList[0] = str;
for(int i = 1; i < arrSize; i++)
{
str = Console.ReadLine();
StrList[i] = str;
}
return StrList;
}
}
}
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 2:42am On Jun 27, 2013
Here is a third Solution from me....
Very bloated and fun to grasp.....

Not about professionalism, but writing and drafting out toy algorithms with respect to tomorrow(no matter how stupid) pays off.... err(Don't make it too stupid though))) ...lol.

I had several choices of algorthim, some, as short as my 7lines C++ algorithm version... and a recursive 6line version...
BUT having 3 solutions should hopefully pass something to someone out there... I have other problems I am solving... again its for my to figure out somestuff...

This solution is presented in C#.... partially 'generalistic'... Again, I make no use of optimally localized algorithm... just some very very basic stuff on grid travellers...

NB: "SUBJECTIVELY" Rough benchmark for my C# code...
---The algorithm will be rated on the scale of 1 to 10.. 10 is best:
Comprehension: 4
Generalization(Generic): 8
Need to Modify for other purpose: 7
Speed: 5
Memory on small input: 7
memory on large input: 7
Defense to Offense ratio: 2


NB: "SUBJECTIVELY" Rough benchmark for my C++ code...
---The algorithm will be rated on the scale of 1 to 10.. 10 is best:
Comprehension: 7
Generalization(Generic): 2
Need to Modify for other purpose: 4
Speed: 10
Memory on small input: 10
memory on large input: 10
Defense to Offense ratio: 6
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 2:38am On Jun 27, 2013
authurowen: Find below, my Implementation to the print spiral Question written in JAVA (There is very little difference btween C# and Java so C# Developers will be able to relate to it).
Pls Criticize to the very lowest details as much as you please.
[code]
Its TOTALLY not my pleasure to criticize your code...
I hate critics and I hate to criticize...

I am going to criticize you from an Engineering POV.. on the fact that you used the Phrase in your original Post.
N.B: Be Genuine in your solutions, Real S.E(s) are.
That phrase annoyed me so much. . .
Like I said, I don't call myself a Software Engineer... I rather consider myself a Software Engineering hobbyist...

ANYWAY... my small review
NB: Your code is ACCEPTABLE for this exact problem in a very localized manner
Also NOTE: I am Not a Java Programmer

1
I thought I was a Sappy Programmer when it comes to OOP skills and patterns until I saw what you called OOP....
I am No Java Programmer but IMHO, Your code is NOT close to being truly OOP:::

You used Objects... why not have the algorithm generic for a Matrix of objects...
in a generalist perspective... having all this in One object is a flawed design!
Advice:: SOMETIMES, write bloated/insane codes to learn something against tomorrow... but write tight, solid, highly efficient(and probably localized) codes for production;
"This code is acceptable for tight conditions like time constraints, etc"
Localized implementations are always usually fastest and efficient for any problem.
Broadened implementations are costly, but if and only if done well, You'll never regret doing it

2
If I ask you of these, you'll need way too much modification::
*The Inputed Array are NOT strings, but objects with features on a grid... Print them out in spiral form
*the ARRAY is NOT a Square Matrix.. but print it in a deterministic manner as defined by some rules.
*Print the array in
---- reverse manner starting from the center
---- Anticlockwise manner;
---- Spiral manner skipping some things... I need a callback for each element you are on... and this callback determines whether you should print the next item or not...
ADVICE (2): stop hardcoding your test-run inputs... except for real testing.

NB: "SUBJECTIVELY" Rough benchmark...
---The algorithm will be rated on the scale of 1 to 10.. 10 is best:
Comprehension: 9
Generalization(Generic): 2
Need to Modify for other purpose: 1
Speed: 7
Memory on small input: 7
memory on large input: 1
Defense to Offense ratio: 5

That's good

GOOD THINGS:
Your algorithm is pretty descent and really easy to comprehend... good one, I loved it...
---the use of printing functions was a good and future-proof idea...
---Recursion is pretty good here... NB: When dealing with Matrix data that might be large... prefer iterative algorithms over recursive algorithms. ...Stop stacking up memory
---You have good approach to keeping things simple

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 4:07pm On Jun 25, 2013
kambo: Anoda passve poster in d programmg room.
He shud ,provde his own implementation, justifyg his design choices, for all to see and possibly learn from not just vanish into thin air after postg a Q.
already seconded, thus, I am
Third in line!
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 10:34pm On Jun 24, 2013
danmc: i removed it like u said and now it works well. just to quote linus torvalds: "talk is cheap. show me the code", pls implement what u just said. i'd love to see it.
like seriously bro??!!
You are trying to put me to a show using Torvald's qoute... ...not cool.
Nope. I would NOT implement it....
Nonetheless, the version I did, has 4 for loops to transverse in 4 directions. My thought to the recursive version is to have a function with several control args, transverse in only 2 directions or one preferential direction... While subsequent calls recursively controls the rest of the direction... C'mon, not everything will be given to you... think!! Haba Oga danmc At The Top!...
Though... As for me... I have a knack for Robotics and Control Systems...
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 6:29pm On Jun 24, 2013
@danmc. I have removed the last k++;... So try that code again...

The algorithm can be implemented recursively to further beat down the SLoC by a meagre factor...

@authurowen... I don't really believe in writing programs alone and calling myself a software engineer. . . . I inherently mean, I wouldnt call myself a Software Engineer. But rather a Software Engineering hobbyist....
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 5:47pm On Jun 24, 2013
danmc: tanx boss for the proggie but it still isn't perfect yet. try inputting a 3x3 matrix e.g. "1 2 3", "4 5 6" and "7 8 9". the output misses the last item in the spiral i.e. "5"! pls fix it grin
. . .lol!... Thanks man. You are following very well sir!.... Err, my bros... If you cared to check out the logical part, you would have noticed that there was an overshoot with 'k'... THE FIX IS SIMPLE: REMOVE THE LAST "k++;" that is at the very end of the line in the last for loop...
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m):
Here is a closely coupled working program that solves authurowens problem.
Its only 30lines;... I could explain the code and make the it more readable on anybody's request... so ask if you wanna understand grin....
NB: I made slight modification to the initially rough snippet I wrote from my mobile phone...
#EDIT... k value overshoot...FIXED

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
string line; vector<string> v;
getline(cin, line);
stringstream ss(line);
while(ss >> line)
v.push_back(line); int sz = v.size();
string A[sz][sz];
for(int i(0); i<v.size(); i++)
A[0][i] = v[i];
for(int i(1); i<sz; i++)
for(int j(0); j<sz; j++)
cin >> A[i][j];
cout << endl << endl;
int i = 0, j = 0, k = 0, p = 0, n =1;
long lim = sz * sz;
while(k < lim)
{
for(p = 0; p < sz; p++){ cout << A[i][j] << " "; k++; j++; } i++; --j;
for(p = 0; p < (sz - n); p++){ cout << A[i][j] << " "; k++; i++; } j--; --i;
for(p = 0; p < (sz - n); p++){ cout << A[i][j] << " "; k++; j--; } i--; j++; sz -= 1;
for(p = 0; p < (sz - n); p++){ cout << A[i][j] << " "; k++; i--; } i++; j++; sz -= 1;
} cout << endl;
return 0;
}

USage: all inputs are via stdin so that input values can be entered manually or by piping a file into the program....
**Input must be guaranteed to be a square matrix!
**my code automatically determines the size of the grid from the first line.
- - - My algorithm here is pretty simple.
- - Also, try to understand my Python code, you may learn a few lazy-man's tricks...
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m): 2:27pm On Jun 24, 2013
danmc: man, u can't just copy and paste some portion of ur code and tell us to feed it with blah blah blah. it compiled fine but couldn't run it. crash!!! i beg check ur algo well and pls show us a working proggie.
Hmmn...(I wrote that snippet from my mobile)
Ohhkkkay pal... I'll post a working program...
ProgrammingRe: Code Challenge [1]: Pseudo-code, C#, JAVA (apply Object Oriented Principles) by WhiZTiM(m):
authurowen: Brother, the solution is not as complicated as you have made it out to be. There is no need for the Mathematical / logical Gibberish (for lack of better words) you've just written.

The lay Programmers would find it very difficult to comprehend your theory (I didn't even bother to look at it my self - NO USE!!) Keep it simple, thats how you tell who an SE is.
No bro... its NOT about software engineering... My python solution is not an Optimal solution in terms of speed... but I made it expose simple grid transversing to anyone that cares to understand it!! ....and I thought its so that we could all learn something? Nonetheless,

HERE is my OPTIMAL CODE in C++: Its currently the FASTEST implementation I reasoned...
---this code is what I presume you may call 'software engineering'?.

//just feed it in with a 2D array of cstrings and sz the size of one dimension
void print(char*** A, int sz)
{
int i = 0, j = 0;
int k = 0, p = 0;
int n = 1;
long lim = sz * sz;
while(k < lim)
{
for(p = 0; p < sz; p++, k++, j++)
cout << A[i][j]; i++;
for(p = 0; p < (sz - n); p++, k++, i++)
cout << A[i][j]; j--;
for(p = 0; p < (sz - n); p++, k++, j--)
cout << A[i][j]; i--; sz -= 1;
for(p = 0; p < (sz - n); p++, k++, i--)
cout << A[i][j]; n += 1;
}
}

I would really love to see yours in shorter lines... so that I can learn.
I wouldn't bother explaining this snippet since my Python code was discarded....
BUT it works, if anyone wants, I could upload a working program.... cheers....

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 (of 18 pages)