• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 18:09
CEST 00:09
KST 07:09
  • 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
[ASL21] Ro8 Preview Pt2: Progenitors2Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists22
Community News
RSL Revival: Season 5 - Qualifiers and Main Event10Code S Season 1 (2026) - RO12 Results02026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced92026 GSL Tour plans announced15
StarCraft 2
General
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Code S Season 1 (2026) - RO12 Results Team Liquid Map Contest #22 - The Finalists Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid
Tourneys
RSL Revival: Season 5 - Qualifiers and Main Event GSL Code S Season 1 (2026) SC2 INu's Battles#15 <BO.9 2Matches> WardiTV Spring Cup SEL Masters #6 - Solar vs Classic (SC: Evo)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
[ASL21] Ro8 Preview Pt2: Progenitors Why there arent any 256x256 pro maps? BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ ASL21 General Discussion
Tourneys
[ASL21] Ro8 Day 2 [Megathread] Daily Proleagues Escore Tournament StarCraft Season 2 [BSL22] RO16 Group Stage - 02 - 10 May
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread Daigo vs Menard Best of 10 Diablo IV
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
European Politico-economics QA Mega-thread US Politics Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Movie Stars In Video Games: …
TrAiDoS
ramps on octagon
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1847 users

The Big Programming Thread - Page 67

Forum Index > General Forum
Post a Reply
Prev 1 65 66 67 68 69 1032 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.
Badjas
Profile Blog Joined October 2008
Netherlands2038 Posts
July 11 2011 05:04 GMT
#1321
On July 11 2011 11:10 AndyG wrote:
Man, the computer science GRE subject test is grueling. Everything I've ever seen is popping up to study for this, plus stuff I've never seen. This isn't strictly programming, it's mostly theory with some pseudocode problems, but damn. I'm going for my Ph.D in computer science as of next fall.

To keep this post I only put up to vent semi-relevant, I'm currently an undergraduate researching an information retrieval technique called Latent Semantic Indexing (using the Singular Value Decomposition of a term-document matrix.) I've implemented the method and am having to work with my own sparse matrix types, as the term-document matrix for the main dataset I'm working with would be about 64 gigabytes if stored in a dense format! I've been working in this field for over a year, so if anybody has any questions about linear algebra on gigantic datasets, I'm all ears ^_^

If you're looking for a chat, I think you should slightly introduce terms like term-document and perhaps mention a specific application of your work. What sparse matrix data structure are you using?
I <3 the internet, I <3 you
Badjas
Profile Blog Joined October 2008
Netherlands2038 Posts
July 11 2011 05:16 GMT
#1322
On July 11 2011 06:15 Orome wrote:
What do you guys think, is doing informatics (programming I guess) as a minor enough to become decent at programming or does that take a lot of additional extracurricular work? It'd be 60 ECTS points for the bachelor and another 30 for the master.

My personal thought: learning programming is like learning anything else. And people learn (best) by making mistakes. And during ones education at school, there aren't enough mistakes made to have learned programming by the end of it. Hobby a ton in programming beside school, try ambitious projects that you cancel after 10 hours poured into it, hack some demos in qbasic, write silly crap in javascript and perhaps some cool stuff too. Experience what bad design is, experience what nasty bugs are and experience the many ways of shooting yourself in the foot. School works well to guide you in this and you do get a fancy piece of paper at the end of it. The piece of paper says nothing for some, though.

This does depend on the school, of course, I'm mostly reflecting this on my own bachelor program that I've run (which I went into, having done a good deal of hobby programming already). My masters education was different, at the technical university of Eindhoven, there were plenty of smart people around. But I can't say it's a good way to learn programming. There's a significant difference between software engineering and computer science.
I <3 the internet, I <3 you
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
July 11 2011 06:15 GMT
#1323
i have this Erlang problem, its a machine problem since last friday and im almost out of hair pulling it out just trying to find an answer to my problem.

the problem is make a tail recursive function that converts decimal number to binary without using built-in functions and list.

here's my code so far

-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,1).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


when N is 0 up to 4, it outputs the correct answer
but when it reaches 5 it outputs 110, 6 = 101. when the correct answer is 5 = 101, 6 = 110.
im really stuck here and need some help in my algo =/
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
waxypants
Profile Blog Joined September 2009
United States479 Posts
Last Edited: 2011-07-11 07:23:46
July 11 2011 07:23 GMT
#1324
Your main problem is that the "(N rem 2)" should be the digit added to the left of "Acc". You are adding it to the right. Also, once you figure out how to do that (it's a bit trickier adding the new digit to the left than adding it to the right), I believe your base cases will also need to be fixed up.
japro
Profile Joined August 2010
172 Posts
July 11 2011 08:15 GMT
#1325
On July 11 2011 07:34 EvanED wrote:
OTOH, it definitely helps to know some different styles -- dynamically-typed scripting, traditional C-like, functional, etc.

I think it's definitely a good thing to familiarize oneself with the different possibilities. It's absolutely worth it to spend and afternoon playing around with C++, Java, Lisp etc. just so you have a first hand experience what the advantages/disadvantages of those are for a given type of problem. This will then also help you figuring out at what point you can really benefit from picking up another language. I just think you should actually have a reason to learn a new language and not do it preemptively just because that language seems "popular".
haduken
Profile Blog Joined April 2003
Australia8267 Posts
July 11 2011 08:27 GMT
#1326
On July 10 2011 14:15 tec27 wrote:
Show nested quote +
On July 10 2011 12:35 haduken wrote:
Ruby related question.

What's the adoption of Ruby 1.9.2 in the general populace? I'm trying to learn Ruby and 1.9.2 is a pain in the ass to set up right. Most of the current all-in-one installation are still bundling with 1.8 so I'm thinking of just ditching it and go with 1.8 as this is only for learning purposes.

I haven't used Ruby in a while, but I think 1.9.x is out on most linux package systems for stable, which probably means a good deal of those systems have it. Any particular reason why you need to use on of all-in-one installations? Its not that hard to install it yourself (and if you're on windows, there are Ruby installers available for everything up to 1.9.2 anyway)

Show nested quote +
On July 10 2011 13:43 EvanED wrote:
On July 10 2011 11:53 ibutoss wrote:
Slightly off topic but still related. What programming environment tools does everyone here use and would recommend?

i.e. What CVS do you use?

I use Git for my personal projects, and Subversion for my research group's projects.

A while ago the group switched from CVS. I used to be of the opinion that CVS->Subversion gets you about 95% of the benefit that you'd get from CVS->Git, but I now put it closer to about 60-70%. Git really is substantially better IMO.

(There are other VCSs that are of similar quality, most notably Mercurial; I haven't used it much, but there are personal preference reasons that I am pretty sure I like Git's model more.)

Git is awesome, can't recommend it enough. I use TFS at work, and while the integration with Visual Studio is nice, I just like Git's setup a helluva lot better. SVN and SVN-derivative version control results in a lot of situations where developers don't check in their code because they don't want to have stuff affect other developers until its 100% complete. With Git and having a repository locally for each developer, you avoid those problems and people are allowed to freely manage their own code and place checkpoints they can always roll back to, without affecting the other developers. Its definitely confusing to understand that when you move to it from SVN, but its oh so worth it.


Fedora didn't have a 1.9.2 RPM, The installing of Ruby is not the problem but the gems are always broken for whatever reason. I've given RVM a try but the naming and pathing isn't always optimal but I guess this has more to do with the gems not recognizing than RVM itself.

I suppose I can go back to Ubuntu but the new UI is so bad...
Rillanon.au
Kahzaar
Profile Joined October 2010
Sweden897 Posts
July 11 2011 08:51 GMT
#1327
I see people comparing c# and c++ and it sounds like c# is far better but still the "pros" use c++. Why is that? Would c++ be better to use in any situation? I myself recently started studying c#.
japro
Profile Joined August 2010
172 Posts
Last Edited: 2011-07-11 09:33:45
July 11 2011 09:13 GMT
#1328
On July 11 2011 17:51 Kahzaar wrote:
I see people comparing c# and c++ and it sounds like c# is far better but still the "pros" use c++. Why is that? Would c++ be better to use in any situation? I myself recently started studying c#.

For one thing there is always "Inertia", C++ has become some sort of industry standard. So if you already sit on a ton of C++ code you are not gonna rewrite it every time a new shiny language comes out. Also C# isn't applicable in every area you use C++ in. The software I'm working on at the moment for example is used for scientific computing on clusters where using C# (or java for that matter) is pretty much out of the question.
One of the main problems with C++ is the sheer complexity that emerged from all the possibilities of template programming, multiple inheritance, pointers and such. So quite often people that don't have huge experience with the language end up being unproductive since they have to deal with a lot of technicalities and such because the language gives you so many opportunities to shoot yourself in the foot. Actually quite a lot of the "Features" of "better" languages like C# of Java are the outright omission of things that are present in C++ just because those, even if very powerful, are dangerous in the hands of inexperience C++ programmers.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2011-07-11 09:24:51
July 11 2011 09:23 GMT
#1329
Hi guys my first post here. I'm making a website for people to make shift reports for work, and one problem I've had is allowing people to attach a dynamic number of attachments to a report.

<!-- MAX_FILE_SIZE must precede the file input field added-->
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="/php_files/test_attachment.php" method="POST"><!--must specify a php file in action-->

<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!--tells people if they upload too much client side instead of waiting forever, 30k = 30MB, but there are hidden variables
//note that by default php.ini limits file uploads to 2MB
//PHP limits uploads to 30MB, hard to get around this
//servers limit uploads too, and it's impossible to get around this
-->
<!-- Name of input element determines name in $_FILES array -->

<input type="file" name="attachment" id="attachment[]" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" /><!-- modified name to make it an array-->

<input type="submit" value="Send File" />

<div id="moreUploads"></div>
<div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput();">Attach another File</a></div>
</form>
<script language="javascript" type="text/javascript">
var upload_number = 2;
function addFileInput() {
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "attachment"+upload_number);
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
}
</script>


You can copy that directly to any html file

Now I'm really confused as to how I'm supposed to receive and upload the files using php for something like the above where you dynamically chose the number of attachments.

I know how to receive it for code like this:
<!--uploading files-->
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="/php_files/test_attachment_3.php" method="POST"><!--must specify a php file in action-->
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" /><!--tells people if they upload too much client side instead of waiting forever, 30k = 30MB, but there are hidden variables
//note that by default php.ini limits file uploads to 2MB
//PHP limits uploads to 30MB, hard to get around this
//servers limit uploads too, and it's impossible to get around this
-->
<!-- Name of input element determines name in $_FILES array -->
Upload File, Maximum size 2MB: <input name="userfile" type="file" /><!-- userfile is but a name... what is a name?, a careless breeze flowing through the pond of eternity-->
<input type="submit" value="Send File" />
</form>




Summary:
How am I supposed to receive this using php?
<input type="file" name="attachment" id="attachment[]"

I know how to receive this:
<input name="userfile" type="file" />
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
uzyszkodnik
Profile Joined April 2010
Poland64 Posts
July 11 2011 09:32 GMT
#1330
@up

http://php.net/manual/en/features.file-upload.multiple.php ?
delHospital
Profile Blog Joined December 2010
Poland261 Posts
July 11 2011 09:55 GMT
#1331
On July 11 2011 17:51 Kahzaar wrote:
I see people comparing c# and c++ and it sounds like c# is far better but still the "pros" use c++. Why is that? Would c++ be better to use in any situation? I myself recently started studying c#.

The only thing C++ and C# have in common is the letter C, so it's not like you can replace one with the other. For example, nobody codes websites in C/C++, and nobody uses C# to write language interpreters or solve problems in coding competitions (there are exceptions to the rule tho -- Google Search, IronPython, and some MS coding competitions come to mind).

So, generally speaking, you'd use C/C++ if you needed to know what to expect from your program, and C# if you wanted .NET to do all the magic for you.

Also, C# has poor support on platforms other than Windows.
Denar
Profile Blog Joined March 2011
France1633 Posts
July 11 2011 10:17 GMT
#1332
On July 11 2011 15:15 icystorage wrote:
i have this Erlang problem, its a machine problem since last friday and im almost out of hair pulling it out just trying to find an answer to my problem.

the problem is make a tail recursive function that converts decimal number to binary without using built-in functions and list.

here's my code so far

-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,1).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


when N is 0 up to 4, it outputs the correct answer
but when it reaches 5 it outputs 110, 6 = 101. when the correct answer is 5 = 101, 6 = 110.
im really stuck here and need some help in my algo =/


This will not work because of the recursion parameters.

Basically, when you call the recursion, you are saying "the rest of the binary form (without the first digit) of the number is the same as the one of this number.

But the binary form of N past the first digit isn't N div 2
the binary form of 5 past the first digit isn't 2 (that is why you get 110 which is 1 - 2 = 10)

I don't have a solution in mind right now, but I hope this explains you why it doesn't work.

And by the way, nice to see another programmer in Erlang, not the most common language around
uzyszkodnik
Profile Joined April 2010
Poland64 Posts
July 11 2011 10:34 GMT
#1333
On July 11 2011 18:55 delHospital wrote:

The only thing C++ and C# have in common is the letter C, so it's not like you can replace one with the other.
For example, nobody codes websites in C/C++, and nobody uses C# to write language interpreters or solve problems in coding competitions (there are exceptions to the rule tho -- Google Search, IronPython, and some MS coding competitions come to mind).
So, generally speaking, you'd use C/C++ if you needed to know what to expect from your program, and C# if you wanted .NET to do all the magic for you.


Not really, the syntax of C++ and C# is similar and telling that c# does teh magic and c++ doesnt is false - it all depends on what libraries you use in c++ ( yep you can even have garbage collector in c++ ) . The main difference is speed of execution, nothing else.

On July 11 2011 18:55 delHospital wrote:
Also, C# has poor support on platforms other than Windows.


I have to disagree again, have you heard about the mono project?
delHospital
Profile Blog Joined December 2010
Poland261 Posts
July 11 2011 10:50 GMT
#1334
On July 11 2011 15:15 icystorage wrote:
i have this Erlang problem, its a machine problem since last friday and im almost out of hair pulling it out just trying to find an answer to my problem.

the problem is make a tail recursive function that converts decimal number to binary without using built-in functions and list.

here's my code so far

-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,1).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


when N is 0 up to 4, it outputs the correct answer
but when it reaches 5 it outputs 110, 6 = 101. when the correct answer is 5 = 101, 6 = 110.
im really stuck here and need some help in my algo =/

i just wrote this in haskell, seems to work
d2b :: Int -> Int
d2b = d2bh 0 1
d2bh acc _ 0 = acc
d2bh acc k n = d2bh ((n `mod` 2) * k + acc) (k * 10) (n `div` 2)
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
July 11 2011 11:11 GMT
#1335
On July 11 2011 19:17 Denar wrote:
Show nested quote +
On July 11 2011 15:15 icystorage wrote:
i have this Erlang problem, its a machine problem since last friday and im almost out of hair pulling it out just trying to find an answer to my problem.

the problem is make a tail recursive function that converts decimal number to binary without using built-in functions and list.

here's my code so far

-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,1).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


when N is 0 up to 4, it outputs the correct answer
but when it reaches 5 it outputs 110, 6 = 101. when the correct answer is 5 = 101, 6 = 110.
im really stuck here and need some help in my algo =/


This will not work because of the recursion parameters.

Basically, when you call the recursion, you are saying "the rest of the binary form (without the first digit) of the number is the same as the one of this number.

But the binary form of N past the first digit isn't N div 2
the binary form of 5 past the first digit isn't 2 (that is why you get 110 which is 1 - 2 = 10)

I don't have a solution in mind right now, but I hope this explains you why it doesn't work.

And by the way, nice to see another programmer in Erlang, not the most common language around


i have a hard time understanding what you just said so im just gonna explain the recursion parameters

lets convert 5 to binary
5/2 = 2 remainder 1
2/2 = 1 remainder 0
1/2 = 0 remainder 1

when you combine all the remainders it becomes 101.

the first parameter shows N div 2 (since there's an error when i use N/2). it divides itself until it matches the base case(s).

the second parameter i use an accumulator to add all the remainders. but there is still something wrong which i think is missing.
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Denar
Profile Blog Joined March 2011
France1633 Posts
Last Edited: 2011-07-11 11:26:28
July 11 2011 11:22 GMT
#1336
On July 11 2011 20:11 icystorage wrote:
Show nested quote +
On July 11 2011 19:17 Denar wrote:
On July 11 2011 15:15 icystorage wrote:
i have this Erlang problem, its a machine problem since last friday and im almost out of hair pulling it out just trying to find an answer to my problem.

the problem is make a tail recursive function that converts decimal number to binary without using built-in functions and list.

here's my code so far

-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,1).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


when N is 0 up to 4, it outputs the correct answer
but when it reaches 5 it outputs 110, 6 = 101. when the correct answer is 5 = 101, 6 = 110.
im really stuck here and need some help in my algo =/


This will not work because of the recursion parameters.

Basically, when you call the recursion, you are saying "the rest of the binary form (without the first digit) of the number is the same as the one of this number.

But the binary form of N past the first digit isn't N div 2
the binary form of 5 past the first digit isn't 2 (that is why you get 110 which is 1 - 2 = 10)

I don't have a solution in mind right now, but I hope this explains you why it doesn't work.

And by the way, nice to see another programmer in Erlang, not the most common language around


i have a hard time understanding what you just said so im just gonna explain the recursion parameters

lets convert 5 to binary
5/2 = 2 remainder 1
2/2 = 1 remainder 0
1/2 = 0 remainder 1

when you combine all the remainders it becomes 101.

the first parameter shows N div 2 (since there's an error when i use N/2). it divides itself until it matches the base case(s).

the second parameter i use an accumulator to add all the remainders. but there is still something wrong which i think is missing.


Ok, thanks for detailing what you had in mind, I think I got it right now for the 5, but I am not sure it is working for all though.

Try this version :


-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,0).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc*10 + 1;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


But I wonder if this logic still works with other numbers ?

if we convert 6 to binary
6/2 = 3 remainder 0
3/2 = 1 remainder 1
1/2 = 0 remainder 1

But 6 = 110 and not 011
delHospital
Profile Blog Joined December 2010
Poland261 Posts
July 11 2011 11:24 GMT
#1337
On July 11 2011 20:11 icystorage wrote:
[...] but there is still something wrong which i think is missing.

Funny how there were three responses to your post, two of these gave you the answer, yet you decided to reply to the guy who gave you bad advice. And you end your post with this.
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
July 11 2011 11:25 GMT
#1338
On July 11 2011 20:22 Denar wrote:
Show nested quote +
On July 11 2011 20:11 icystorage wrote:
On July 11 2011 19:17 Denar wrote:
On July 11 2011 15:15 icystorage wrote:
i have this Erlang problem, its a machine problem since last friday and im almost out of hair pulling it out just trying to find an answer to my problem.

the problem is make a tail recursive function that converts decimal number to binary without using built-in functions and list.

here's my code so far

-module(d2b).
-export([d2b/1].

d2b(N)->
d2bh(N,1).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


when N is 0 up to 4, it outputs the correct answer
but when it reaches 5 it outputs 110, 6 = 101. when the correct answer is 5 = 101, 6 = 110.
im really stuck here and need some help in my algo =/


This will not work because of the recursion parameters.

Basically, when you call the recursion, you are saying "the rest of the binary form (without the first digit) of the number is the same as the one of this number.

But the binary form of N past the first digit isn't N div 2
the binary form of 5 past the first digit isn't 2 (that is why you get 110 which is 1 - 2 = 10)

I don't have a solution in mind right now, but I hope this explains you why it doesn't work.

And by the way, nice to see another programmer in Erlang, not the most common language around


i have a hard time understanding what you just said so im just gonna explain the recursion parameters

lets convert 5 to binary
5/2 = 2 remainder 1
2/2 = 1 remainder 0
1/2 = 0 remainder 1

when you combine all the remainders it becomes 101.

the first parameter shows N div 2 (since there's an error when i use N/2). it divides itself until it matches the base case(s).

the second parameter i use an accumulator to add all the remainders. but there is still something wrong which i think is missing.


Ok, thanks for detailing what you had in mind, I think I got it right now for the 5, but I am not sure it is working for all though.

Try this version :


-module(d2b).
-export([d2b/1]).

d2b(N)->
d2bh(N,0).
d2bh(0,_Acc)->
0;
d2bh(1,Acc)->
Acc*10 + 1;
d2bh(N,Acc)->
d2bh(N div 2, ((Acc*10+(N rem 2)))).


still wrong though, 2 = 1, and 6 = 11. you only got the 5 right.
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
Last Edited: 2011-07-11 11:29:08
July 11 2011 11:27 GMT
#1339
On July 11 2011 20:24 delHospital wrote:
Show nested quote +
On July 11 2011 20:11 icystorage wrote:
[...] but there is still something wrong which i think is missing.

Funny how there were three responses to your post, two of these gave you the answer, yet you decided to reply to the guy who gave you bad advice. And you end your post with this.

i kinda ignored your post and i am sorry for that, but i also dont understand haskell very much w/c wasnt very helpful either.

On July 11 2011 16:23 waxypants wrote:
Your main problem is that the "(N rem 2)" should be the digit added to the left of "Acc". You are adding it to the right. Also, once you figure out how to do that (it's a bit trickier adding the new digit to the left than adding it to the right), I believe your base cases will also need to be fixed up.


sorry, but what do you mean by to the left of Acc?
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2011-07-11 11:38:20
July 11 2011 11:35 GMT
#1340
On July 11 2011 18:55 delHospital wrote:
Show nested quote +
On July 11 2011 17:51 Kahzaar wrote:
I see people comparing c# and c++ and it sounds like c# is far better but still the "pros" use c++. Why is that? Would c++ be better to use in any situation? I myself recently started studying c#.

The only thing C++ and C# have in common is the letter C, so it's not like you can replace one with the other. For example, nobody codes websites in C/C++, and nobody uses C# to write language interpreters or solve problems in coding competitions (there are exceptions to the rule tho -- Google Search, IronPython, and some MS coding competitions come to mind).

So, generally speaking, you'd use C/C++ if you needed to know what to expect from your program, and C# if you wanted .NET to do all the magic for you.

Also, C# has poor support on platforms other than Windows.


Also, in real-world applications, even just decent C/C++ code will produce much, much faster applications.

In theory, the difference shouldn't be that big (and that's what C# and Java lobbyists will tell you), but of course garbage collection will slow a lot of things down (especially on weak systems like the 360), plus C/C++ compilers (and linkers for link-state optimization) are just miles ahead of C#/Java compilers/interpreters in terms of code optimization (For example, the compilation step in javac doesn't optimize the code at all) so it's much easier to make performance costly mistakes in C#/Java than in C++.

So in the gaming market, where AAA titles have to be optimized to the last bit in order to show awesome graphics on relatively weak hardware (360/PS3, etc.) people are of course going to use C++ (indie devs still use C# with XNA on the 360 though, since the C++ SDK for 360 is only available for lots of money and AAA developers).

Other than that though, programming languages nowadays are just tools for object oriented programming - which is essentially the same in every language, even though C++ provides some things that C#/Java doesn't have (much mightier templates/generics for example), and Java and C# have things like reflection which isn't (yet) available on C++.

So if you know how to do some good OOP in C#, you will know how to do it in Java and C++ as well.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Prev 1 65 66 67 68 69 1032 Next
Please log in or register to reply.
Live Events Refresh
IPSL
19:00
Ro24 Group F
eOnzErG vs TBD
G5 vs Nesh
Airneanach28
Liquipedia
BSL
19:00
RO16 Group B
Bonyth vs Sterling
KwarK vs JDConan
ZZZero.O289
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SpeCial 217
JuggernautJason103
StarCraft: Brood War
ZZZero.O 289
Artosis 149
NaDa 16
KwarK 8
Dota 2
monkeys_forever536
League of Legends
Doublelift3212
Super Smash Bros
C9.Mang0300
hungrybox0
Heroes of the Storm
Liquid`Hasu427
Other Games
gofns13044
tarik_tv9696
summit1g5854
Grubby5529
FrodaN1376
Liquid`RaSZi1191
Dewaltoss41
UpATreeSC37
NightEnD19
Organizations
Other Games
gamesdonequick1676
Dota 2
PGL Dota 2 - Main Stream47
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• musti20045 21
• Adnapsc2 16
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• imaqtpie1237
• Shiphtur353
Upcoming Events
Patches Events
1h 51m
Replay Cast
10h 51m
Wardi Open
11h 51m
Afreeca Starleague
11h 51m
Jaedong vs Light
Monday Night Weeklies
17h 51m
Replay Cast
1d 1h
Sparkling Tuna Cup
1d 11h
Afreeca Starleague
1d 11h
Snow vs Flash
WardiTV Invitational
1d 12h
SHIN vs Nicoract
Solar vs Nice
GSL
2 days
Classic vs Cure
Maru vs Rogue
[ Show More ]
GSL
3 days
SHIN vs Zoun
ByuN vs herO
OSC
3 days
OSC
3 days
Replay Cast
4 days
Escore
4 days
The PondCast
4 days
WardiTV Invitational
4 days
Zoun vs Ryung
Lambo vs ShoWTimE
Replay Cast
5 days
CranKy Ducklings
5 days
RSL Revival
5 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
5 days
Krystianer vs TriGGeR
Cure vs Rogue
BSL
5 days
Replay Cast
6 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
6 days
BSL
6 days
Liquipedia Results

Completed

Proleague 2026-05-02
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
KK 2v2 League Season 1
Acropolis #4
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W6
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
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 © 2026 TLnet. All Rights Reserved.