• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:13
CEST 17:13
KST 00:13
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?16Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris46Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
Weekly Cups (August 25-31): Clem's Last Straw? #1: Maru - Greatest Players of All Time Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again! 2024/25 Off-Season Roster Moves
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies LiuLi Cup - September 2025 Tournaments 🏆 GTL Season 2 – StarCraft II Team League
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
ASL20 General Discussion Starcraft at lower levels TvP No Rain in ASL20? Victoria gamers BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Mechabellum Nintendo Switch Thread Teeworlds - online game General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Canadian Politics Mega-thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 834 users

The Big Programming Thread - Page 172

Forum Index > General Forum
Post a Reply
Prev 1 170 171 172 173 174 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
lolmlg
Profile Joined November 2011
619 Posts
October 04 2012 01:34 GMT
#3421
On October 04 2012 10:26 Bigpet wrote:
Show nested quote +
On October 04 2012 10:09 lolmlg wrote:C++ mainly lives in the world of legacy software these days.


Sure is legacy around Windows and about 90% of all high budget game releases. There are certain applications that C++ is perfectly suited for but your point that C++ is not a good idea for most applications holds true.

Well, the Windows API itself was always designed with C in mind. Whether we're talking about a codebase or company culture though, it can be costly to start over. Projects never switch from one language to another. What the first version is written in will probably be what the last version is written in. Companies go under before they get around to modernizing their practices.
Bigpet
Profile Joined July 2010
Germany533 Posts
Last Edited: 2012-10-04 01:43:12
October 04 2012 01:41 GMT
#3422
On October 04 2012 10:34 lolmlg wrote:
Show nested quote +
On October 04 2012 10:26 Bigpet wrote:
On October 04 2012 10:09 lolmlg wrote:C++ mainly lives in the world of legacy software these days.


Sure is legacy around Windows and about 90% of all high budget game releases. There are certain applications that C++ is perfectly suited for but your point that C++ is not a good idea for most applications holds true.

Well, the Windows API itself was always designed with C in mind. Whether we're talking about a codebase or company culture though, it can be costly to start over. Projects never switch from one language to another. What the first version is written in will probably be what the last version is written in. Companies go under before they get around to modernizing their practices.


They tried to modernize with Longhorn and failed miserably to make core parts work equally well with managed languages. This failure resulted in Vista taking so long and Windows 7 and 8 not containing significantly more managed code than Vista. But like you said it's not a very good example but I think high performance graphics engines are still best served by C++
I'm NOT the caster with a similar nick
lolmlg
Profile Joined November 2011
619 Posts
October 04 2012 01:52 GMT
#3423
The first object oriented rewrite of the software used to control the telephone system took something like ten seconds to produce a dialtone during an early internal demonstration. The project was immediately cancelled for this reason alone. That's software~
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 04 2012 02:37 GMT
#3424
On October 04 2012 10:52 lolmlg wrote:
The first object oriented rewrite of the software used to control the telephone system took something like ten seconds to produce a dialtone during an early internal demonstration. The project was immediately cancelled for this reason alone. That's software~


Well, most of those horror stories are the results of bad programmers that don't actually understand proper OOP instead of OOP being the source of the problem.
lolmlg
Profile Joined November 2011
619 Posts
October 04 2012 02:55 GMT
#3425
Let's not go that route. Even if that were the case it would be beside the point.
deus.machinarum
Profile Joined September 2011
Austria658 Posts
October 04 2012 15:37 GMT
#3426
On October 04 2012 11:37 Morfildur wrote:
Show nested quote +
On October 04 2012 10:52 lolmlg wrote:
The first object oriented rewrite of the software used to control the telephone system took something like ten seconds to produce a dialtone during an early internal demonstration. The project was immediately cancelled for this reason alone. That's software~


Well, most of those horror stories are the results of bad programmers that don't actually understand proper OOP instead of OOP being the source of the problem.


Fully agree there.
Nothing worth having comes easy.
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
Last Edited: 2012-10-06 12:25:39
October 06 2012 12:15 GMT
#3427
On a multi-question CS1073 assignment I got this question and I'm rather stuck on even starting the thing.

1. Programming Exercise

Write a program that reads in four integers and displays alternating if the numbers
alternate in terms of their relationships with each other. For instance, if the second
number is less than the first, then the third must be greater than the second, and the
fourth must be less than the third. Of if the second number is greater than the first, then
the third must be less than the second, and the fourth must be greater than the third.
Display not alternating otherwise. Any two adjacent numbers that are equal means
not alternating.

Here is sample output from four runs (note: user input is shown here in italics):

Enter four integers: 1 5 7 4
not alternating

enter four integers: 3 8 -1 2
alternating

enter four integers: 9 8 10 4
alternating

enter four integers: -3 5 5 6
not alternating

For this question you only need to write one class. You may place all of your code in the
main method of that class.

After you have tested your application and you're sure that it works properly, print a copy
of your code. Also print sample output from running the program using the four test
cases shown above.


Now I don't want to just get the answer or how to write it but my brain just kinda shuts off whent I look at it, I can't even start the stupid thing so I was wondering if someone could give me a hand. I hope this kinda thing is ok, first time ever posting in here other then to get advice on where to start awhile back. Maybe if someone could link me to a page where this sort of question is posed as an example:D

EDIT: Java
FoTG fighting!
WoolySheep
Profile Blog Joined October 2010
Canada82 Posts
October 06 2012 12:24 GMT
#3428
On October 06 2012 21:15 NeMeSiS3 wrote:
On a multi-question CS1073 assignment I got this question and I'm rather stuck on even starting the thing.
Show nested quote +

1. Programming Exercise

Write a program that reads in four integers and displays alternating if the numbers
alternate in terms of their relationships with each other. For instance, if the second
number is less than the first, then the third must be greater than the second, and the
fourth must be less than the third. Of if the second number is greater than the first, then
the third must be less than the second, and the fourth must be greater than the third.
Display not alternating otherwise. Any two adjacent numbers that are equal means
not alternating.

Here is sample output from four runs (note: user input is shown here in italics):

Enter four integers: 1 5 7 4
not alternating

enter four integers: 3 8 -1 2
alternating

enter four integers: 9 8 10 4
alternating

enter four integers: -3 5 5 6
not alternating

For this question you only need to write one class. You may place all of your code in the
main method of that class.

After you have tested your application and you're sure that it works properly, print a copy
of your code. Also print sample output from running the program using the four test
cases shown above.


Now I don't want to just get the answer or how to write it but my brain just kinda shuts off whent I look at it, I can't even start the stupid thing so I was wondering if someone could give me a hand. I hope this kinda thing is ok, first time ever posting in here other then to get advice on where to start awhile back. Maybe if someone could link me to a page where this sort of question is posed as an example:D


depends on what language you are using for reading in the numbers. As for a general idea:

Do the numbers need to be entered once the program starts? If so then you will need something like a Scanner (Java) or cin (c++). Once you get the numbers, you just need to perform a couple checks. You could make a for loop and for each integer (excluding the first one) check what the last integer you had was. You may need a boolean to keep track of what the next number should be (higher or lower)if it is alternating, and another one to tell whether or not the numbers alternate. If at any point in the loop your numbers do not alternate, you can break the loop. Hope this helps a bit!
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
October 06 2012 12:25 GMT
#3429
On October 06 2012 21:24 WoolySheep wrote:
Show nested quote +
On October 06 2012 21:15 NeMeSiS3 wrote:
On a multi-question CS1073 assignment I got this question and I'm rather stuck on even starting the thing.

1. Programming Exercise

Write a program that reads in four integers and displays alternating if the numbers
alternate in terms of their relationships with each other. For instance, if the second
number is less than the first, then the third must be greater than the second, and the
fourth must be less than the third. Of if the second number is greater than the first, then
the third must be less than the second, and the fourth must be greater than the third.
Display not alternating otherwise. Any two adjacent numbers that are equal means
not alternating.

Here is sample output from four runs (note: user input is shown here in italics):

Enter four integers: 1 5 7 4
not alternating

enter four integers: 3 8 -1 2
alternating

enter four integers: 9 8 10 4
alternating

enter four integers: -3 5 5 6
not alternating

For this question you only need to write one class. You may place all of your code in the
main method of that class.

After you have tested your application and you're sure that it works properly, print a copy
of your code. Also print sample output from running the program using the four test
cases shown above.


Now I don't want to just get the answer or how to write it but my brain just kinda shuts off whent I look at it, I can't even start the stupid thing so I was wondering if someone could give me a hand. I hope this kinda thing is ok, first time ever posting in here other then to get advice on where to start awhile back. Maybe if someone could link me to a page where this sort of question is posed as an example:D


depends on what language you are using for reading in the numbers. As for a general idea:

Do the numbers need to be entered once the program starts? If so then you will need something like a Scanner (Java) or cin (c++). Once you get the numbers, you just need to perform a couple checks. You could make a for loop and for each integer (excluding the first one) check what the last integer you had was. You may need a boolean to keep track of what the next number should be (higher or lower)if it is alternating, and another one to tell whether or not the numbers alternate. If at any point in the loop your numbers do not alternate, you can break the loop. Hope this helps a bit!


sorry JAVA
FoTG fighting!
CluEleSs_UK
Profile Blog Joined August 2010
United Kingdom583 Posts
October 06 2012 13:06 GMT
#3430
On October 06 2012 21:25 NeMeSiS3 wrote:
Show nested quote +
On October 06 2012 21:24 WoolySheep wrote:
On October 06 2012 21:15 NeMeSiS3 wrote:
On a multi-question CS1073 assignment I got this question and I'm rather stuck on even starting the thing.

1. Programming Exercise

Write a program that reads in four integers and displays alternating if the numbers
alternate in terms of their relationships with each other. For instance, if the second
number is less than the first, then the third must be greater than the second, and the
fourth must be less than the third. Of if the second number is greater than the first, then
the third must be less than the second, and the fourth must be greater than the third.
Display not alternating otherwise. Any two adjacent numbers that are equal means
not alternating.

Here is sample output from four runs (note: user input is shown here in italics):

Enter four integers: 1 5 7 4
not alternating

enter four integers: 3 8 -1 2
alternating

enter four integers: 9 8 10 4
alternating

enter four integers: -3 5 5 6
not alternating

For this question you only need to write one class. You may place all of your code in the
main method of that class.

After you have tested your application and you're sure that it works properly, print a copy
of your code. Also print sample output from running the program using the four test
cases shown above.


Now I don't want to just get the answer or how to write it but my brain just kinda shuts off whent I look at it, I can't even start the stupid thing so I was wondering if someone could give me a hand. I hope this kinda thing is ok, first time ever posting in here other then to get advice on where to start awhile back. Maybe if someone could link me to a page where this sort of question is posed as an example:D


depends on what language you are using for reading in the numbers. As for a general idea:

Do the numbers need to be entered once the program starts? If so then you will need something like a Scanner (Java) or cin (c++). Once you get the numbers, you just need to perform a couple checks. You could make a for loop and for each integer (excluding the first one) check what the last integer you had was. You may need a boolean to keep track of what the next number should be (higher or lower)if it is alternating, and another one to tell whether or not the numbers alternate. If at any point in the loop your numbers do not alternate, you can break the loop. Hope this helps a bit!


sorry JAVA


I would personally use an inputDialog, then use the split(); function to make them into an array of length 4, then compare each number in the array using ifs. In pseudocode:

input = inputDialog;
array = split(input, ",");
if array[1] > array[0]
{
if (array[2] > array[1])
}

etcetcetc. You could probably make the if bit quicker by using a loop.
"If it turns out he is leaving the ESL to focus on cooking crystal meth I'll agree that it is somewhat disgraceful, but I'll hold off judgement until then."
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2012-10-06 15:01:35
October 06 2012 14:47 GMT
#3431
I'd go for something a little more... different. Think outside the box. Try using math
+ Show Spoiler +

Say you have the 4 numbers as int, then you could do:

diff1 = num1 - num2
diff2 = num2 - num3
diff3 = num3 - num4

result1 = diff1 * diff2
result2 = diff2 * diff3

alternatingNumbers = (result1 * result2) > 0;

Reasoning:
The numbers need to alternate, meaning either diff2 is negative and the others are positive, or vice-versa. When multiplying the diffs, the result will be that both are negative. When multiplying negatives, it becomes a positive. So if the result of the multiplication is positive (greather than 0), we know the numbers were alternating
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-10-06 17:07:23
October 06 2012 15:57 GMT
#3432
That has got to be the worst way to word that question I've ever seen. If it weren't for the examples it would be incomprehensible.

If you wanted a truly dynamic approach that wasn't contingent on knowing the number of elements at compile time, you would first build a list of some sort of the input with each integer as a new element. In .NET I'd end probably use List<int> or List<double>. Java can accomplish similar, but I don't do Java. Anyway, you'd want to validate your input while reading things in and then kill the program with an error if you got a non-number.

So now you've got your List / ArrayList / whatever of some sort containing all of your elements. At this point it's pretty simple: you iterate through your list and compare each element to its neighbors, limiting by the bounds of the array (i.e. can't compare <0 or ># elements - 1). If the previous neighbor (lower subscript) is lower, then the subsequent neighbor should also be lower. If it's higher, the subsequent neighbor should also be higher.

Assuming you have this in a method that returns a Boolean (let's call it "InputListAlternates()"), then if you come across any instance where this fails, you simply return false (does not alternate). If it successfully iterates the entire collection, you return true.

Now, you don't necessarily HAVE to read the entire thing into a List of some sort before doing the processing, but I'm guessing you're being prompted to enter integers through the console.

Simple C# logic that can do it. You don't need those three ints, but I split them from inputList out to help you understand it.
You do need to add additional logic for sets of < 3 elements to make this not fail and then to make it actually tell you alternate/no alternate for those sets.

That is to say, you need separate logic for counts of 0, 1, and 2. If it's 2, you just use logic where if element 1 != element 2 it alternates, if == it doesn't. I don't even know what you want to do for count of 1 or 0. I'd just throw an error and handle it upstream (e.g. output "invalid input" or something).

Summary:
All you really have to do here is from the 2nd element to the 2nd to last element check to see if each of its neighbors are both greater than or both less than the current value. If any one of them fails, it doesn't alternate. I think the only thing that changes from C# to Java with this is .Count becomes .size()


List<int> inputList = new List<int>();
// Fill inputList somehow, then call InputListAlternates() and handle result as appropriate.

private bool InputListAlternates()
{
int prevInt;
int curInt;
int nextInt;

for (int i = 1; i < inputList.Count - 1; i++)
{
prevInt = inputList[i - 1];
curInt = inputList[i];
nextInt = inputList[i + 1];

if (((curInt > nextInt && curInt > prevInt) ||
(curInt < nextInt && curInt < prevInt)) == false)
{
return false;
}
}
return true;
}
twitch.tv/cratonz
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 06 2012 16:33 GMT
#3433
Haven't done java in ages, so i don't remember if List<int> had getCount(), count, getLength(), length, getSize(), size() or whatever, so take this as untested pseudocode:

+ Show Spoiler +


public bool IsAlternating(List<int> numbers)
{
// guard clause. Arrays with one or even no entry are always non-alternating
if (numbers.count <= 1) return false;
// guard clause. Makes sure the method can rely on number[0] being != number[1] and we don't have to deal with that case anymore
if (numbers[0] == numbers[1]) return false;

bool expect_higher = true;
if (numbers[0] < numbers[1]) expect_higher = false;

for (int i = 1; i < numbers.count - 1; ++i)
{
// Check if our expectations are met. If not, no need to stay in this method any longer.
if (expect_higher)
if (numbers[i] >= numbers[i+1]) return false;
else
if (numbers[i] <= numbers[i+1]) return false;

// If we got the higher number, we expect the next to be lower (i.e. not higher)
expect_higher = !expect_higher;
}
return true;
}



Should work and it's easier to understand than the mathmatical solution that was mentioned above.
Craton
Profile Blog Joined December 2009
United States17250 Posts
October 06 2012 16:59 GMT
#3434
Java's List has .size()
twitch.tv/cratonz
Kich
Profile Joined April 2011
United States339 Posts
October 06 2012 16:59 GMT
#3435
On October 06 2012 21:15 NeMeSiS3 wrote:
On a multi-question CS1073 assignment I got this question and I'm rather stuck on even starting the thing.
Show nested quote +

1. Programming Exercise

Write a program that reads in four integers and displays alternating if the numbers
alternate in terms of their relationships with each other. For instance, if the second
number is less than the first, then the third must be greater than the second, and the
fourth must be less than the third. Of if the second number is greater than the first, then
the third must be less than the second, and the fourth must be greater than the third.
Display not alternating otherwise. Any two adjacent numbers that are equal means
not alternating.

Here is sample output from four runs (note: user input is shown here in italics):

Enter four integers: 1 5 7 4
not alternating

enter four integers: 3 8 -1 2
alternating

enter four integers: 9 8 10 4
alternating

enter four integers: -3 5 5 6
not alternating

For this question you only need to write one class. You may place all of your code in the
main method of that class.

After you have tested your application and you're sure that it works properly, print a copy
of your code. Also print sample output from running the program using the four test
cases shown above.


Now I don't want to just get the answer or how to write it but my brain just kinda shuts off whent I look at it, I can't even start the stupid thing so I was wondering if someone could give me a hand. I hope this kinda thing is ok, first time ever posting in here other then to get advice on where to start awhile back. Maybe if someone could link me to a page where this sort of question is posed as an example:D

EDIT: Java


This seems simple. You break it up into 3 comparisons: First / second, second / third, third / fourth. I went on to write a lot about this but supereddie probably has the most elegant solution to the problem.
nebffa
Profile Blog Joined February 2009
Australia776 Posts
October 07 2012 01:33 GMT
#3436
Hi guys I am looking for excellent online C only guides (not C++). I have learned Python over the last few months and have done the first 85 project euler problems to learn along the way.

I can't find any guides that are correct, that also have exercises for me to do. I was hoping "Learn C the Hard Way" would be good as I initially learnt Python from "Learn Python the Hard Way" but as it is in an alpha version some of its content is not fully correct.

Plleeeease please please please suggest a good online guide if you know one I will love love love you.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
October 07 2012 11:05 GMT
#3437
For Ruby folks

Just released a TDD/BDD Ruby gem, its gotten just about 1500 downloads in the first 2 months.

Its a new pure-Ruby DSL for testing stuff basically. Its much more readable and concise compared to other testing frameworks, for example if you compare to Rspec, you would see a 75%-ish reduction in test code.

Its still not version 1 yet, but the DSL part of it is basically complete. Basically what needs to be done from now is pretty html reporting, hudson compatibility test, and JSON/XML logging.

Let me know what you guys think, or if you have any cool ideas to add to it.

https://github.com/danielshuey/testme
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
GhostLink
Profile Joined January 2011
United States450 Posts
Last Edited: 2012-10-07 12:44:59
October 07 2012 12:20 GMT
#3438
For python people (or anyone who knows basic programming)

I know the rules say don't post code asking what's wrong, but I'm quite desperate. My assignment is due tomorrow and i can't find the problem, so i can't fix it. Here's what we have to do. Take a picture(source) and take 3 tile images(red,green, and blue), and create a photo mosaic on a bigger empty picture (the scale for the mosaic photo is source pixels (35x35) x tile image (25x25), so for every pixel in source there will be a tile on a new image (meaning that it would be 875x875).
Here's the code:

+ Show Spoiler +
def easy_level():
redTile=makePicture(pickAFile())
greenTile=makePicture(pickAFile())
blueTile=makePicture(pickAFile())
source=makePicture(pickAFile())
show(redTile)
show(greenTile)
show(blueTile)
show(source)
targetImage=makeEmptyPicture(getWidth(source)*getWidth(redTile),getHeight(source)*getHeight(redTile))
for px in getPixels(source):
---for x in range(0,getWidth(source)):
----for y in range(0,getHeight(source)):

-----if getRed(px)>getGreen(px) and getRed(px)>getBlue(px):
------copyTileToTargetRed(redTile,targetImage,x,y)
-----if getGreen(px)>getRed(px) and getGreen(px)>getBlue(px):
------copyTileToTargetRed(greenTile,targetImage,x,y)
-----if getBlue(px)>getRed(px) and getBlue(px)>getGreen(px):
------copyTileToTargetRed(blueTile,targetImage,x,y)


def copyTileToTargetRed(tileImage,targetImage,leftX,topY):
--targetImageX=leftX
--for tileImageX in range(0,getWidth(tileImage)):
----targetImageY=topY
----for tileImageY in range(0,getHeight(tileImage)):
------px=getPixel(tileImage,tileImageX,tileImageY)
------tx=getPixel(targetImage,targetImageX,targetImageY)
------setColor(tx,getColor(px))
------targetImageY=targetImageY+1
----targetImageX=targetImageX+1
--repaint(targetImage)
--return(targetImage)


The error is that instead of laying tiles where it's supposed to it's laying them on on top of one another.
Any help would be appreciated. Thank you so much!

(The spaces are configured correctly)
Let a man play chess, and tell him that every pawn is his friend. Let him think both bishops holy. Let him remember happy days in the shadows of his castles. Let him love his queen. Watch him lose them all.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
October 07 2012 12:39 GMT
#3439
On October 07 2012 21:20 GhostLink wrote:
For python people (or anyone who knows basic programming)

I know the rules say don't post code asking what's wrong, but I'm quite desperate. My assignment is due tomorrow and i can't find the problem, so i can't fix it. Here's what we have to do. Take a picture(source) and take 3 tile images(red,green, and blue), and create a photo mosaic on a bigger empty picture (the scale for the mosaic photo is source pixels (35x35) x tile image (25x25), so for every pixel in source there will be a tile on a new image (meaning that it would be 875x875).
Here's the code:

+ Show Spoiler +
def easy_level():
redTile=makePicture(pickAFile())
greenTile=makePicture(pickAFile())
blueTile=makePicture(pickAFile())
source=makePicture(pickAFile())
show(redTile)
show(greenTile)
show(blueTile)
show(source)
targetImage=makeEmptyPicture(getWidth(source)*getWidth(redTile),getHeight(source)*getHeight(redTile))
for px in getPixels(source):
for x in range(0,getWidth(source)):
for y in range(0,getHeight(source)):

if getRed(px)>getGreen(px) and getRed(px)>getBlue(px):
copyTileToTargetRed(redTile,targetImage,x,y)
if getGreen(px)>getRed(px) and getGreen(px)>getBlue(px):
copyTileToTargetRed(greenTile,targetImage,x,y)
if getBlue(px)>getRed(px) and getBlue(px)>getGreen(px):
copyTileToTargetRed(blueTile,targetImage,x,y)


def copyTileToTargetRed(tileImage,targetImage,leftX,topY):
targetImageX=leftX
for tileImageX in range(0,getWidth(tileImage)):
targetImageY=topY
for tileImageY in range(0,getHeight(tileImage)):
px=getPixel(tileImage,tileImageX,tileImageY)
tx=getPixel(targetImage,targetImageX,targetImageY)
setColor(tx,getColor(px))
targetImageY=targetImageY+1
targetImageX=targetImageX+1
repaint(targetImage)
return(targetImage)


The error is that instead of laying tiles where it's supposed to it's laying them on on top of one another.
Any help would be appreciated. Thank you so much!

(The spaces are configured correctly)


Its gonna be impossible to know whats wrong when there's no spacing on a whitespace context sensitive language
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
GhostLink
Profile Joined January 2011
United States450 Posts
October 07 2012 12:46 GMT
#3440


Its gonna be impossible to know whats wrong when there's no spacing on a whitespace context sensitive language


I have just updated it, so now it's possible to tell as the spacings are included (i used ---)
Let a man play chess, and tell him that every pawn is his friend. Let him think both bishops holy. Let him remember happy days in the shadows of his castles. Let him love his queen. Watch him lose them all.
Prev 1 170 171 172 173 174 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 8h 47m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 243
mcanning 132
SC2Nice 27
StarCraft: Brood War
Calm 5073
Rain 2839
Bisu 2629
Horang2 2390
Jaedong 2156
Flash 1575
Mini 725
EffOrt 519
Stork 473
ZerO 456
[ Show more ]
Larva 386
Soulkey 300
actioN 293
Snow 247
Barracks 196
ggaemo 173
Rush 136
Mind 124
hero 108
Mong 95
Soma 81
Hyun 69
sorry 69
PianO 68
Sharp 67
Sea.KH 63
Movie 57
sSak 52
yabsab 52
Nal_rA 30
scan(afreeca) 23
JYJ23
soO 18
JulyZerg 18
zelot 17
Sacsri 17
HiyA 16
Shine 14
Terrorterran 11
ajuk12(nOOB) 10
SilentControl 8
ivOry 6
Dota 2
qojqva4127
Dendi1254
420jenkins438
XcaliburYe315
League of Legends
Reynor28
Counter-Strike
byalli323
markeloff161
oskar142
Heroes of the Storm
XaKoH 99
Other Games
B2W.Neo1350
hiko828
crisheroes355
Lowko328
DeMusliM315
FrodaN182
Mew2King124
SortOf70
QueenE50
Trikslyr23
ZerO(Twitch)16
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• poizon28 15
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 3535
• WagamamaTV572
League of Legends
• Nemesis3094
• Jankos1640
Upcoming Events
PiGosaur Monday
8h 47m
LiuLi Cup
19h 47m
Replay Cast
1d 8h
The PondCast
1d 18h
RSL Revival
1d 18h
Maru vs SHIN
MaNa vs MaxPax
Maestros of the Game
2 days
OSC
2 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
2 days
Reynor vs Astrea
Classic vs sOs
Maestros of the Game
3 days
BSL Team Wars
3 days
Team Bonyth vs Team Dewalt
[ Show More ]
CranKy Ducklings
3 days
RSL Revival
3 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
3 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
Maestros of the Game
4 days
[BSL 2025] Weekly
4 days
RSL Revival
4 days
Cure vs Bunny
Creator vs Zoun
Maestros of the Game
5 days
BSL Team Wars
5 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
5 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.