Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 2,363
» Latest member: Jeffreyseasy
» Forum threads: 848
» Forum posts: 3,635

Full Statistics

Online Users
There is currently 1 user online
» 0 Member(s) | 1 Guest(s)

Latest Threads
Hangman in Rust
Forum: Other
Last Post: brandonio21
02-04-2018, 11:14 AM
» Replies: 2
» Views: 18,233
How to: Search files from...
Forum: VB.NET
Last Post: brandonio21
11-25-2017, 12:55 PM
» Replies: 1
» Views: 13,897
Database error anyone hel...
Forum: VB.NET
Last Post: brandonio21
11-25-2017, 12:46 PM
» Replies: 2
» Views: 15,720
Character ammount
Forum: Java
Last Post: brandonio21
04-28-2016, 02:13 PM
» Replies: 1
» Views: 17,521
RunAsAdmin
Forum: VB.NET
Last Post: brandonio21
04-15-2016, 11:11 AM
» Replies: 2
» Views: 20,033
Krypton Toolkit Download
Forum: VB.NET
Last Post: brandonio21
03-28-2016, 07:55 PM
» Replies: 0
» Views: 10,820
Adding backgroundcolor to...
Forum: Java
Last Post: brandonio21
09-01-2015, 10:09 PM
» Replies: 1
» Views: 14,407
Using a string as an alia...
Forum: VB.NET
Last Post: brandonio21
06-20-2015, 09:00 PM
» Replies: 1
» Views: 13,325
Read all lines from multi...
Forum: VB.NET
Last Post: strawman83
06-04-2015, 08:54 AM
» Replies: 2
» Views: 17,341
Filter each cell in dgv
Forum: VB.NET
Last Post: brco900033
05-08-2015, 09:51 AM
» Replies: 4
» Views: 22,203

 
  Knuth Numbers recursion
Posted by: Miriam - 04-21-2015, 11:46 PM - Forum: Java - Replies (1)

Hello,

I recently had a final exam on which my teacher asked to write a method for Knuth numbers recursion. I got a stack overflow on my implementation, and I am new on Java, so I am not sure what happened, it might be that I had the wrong formula for Knuth numbers? I would love some feedback.

Here is the question, and my code

Knuth numbers are given by the recursive formula Kn+1 = 1 + min (2 * Ka, 3 * Kb) where a is the smallest integer larger than n/2.0 and b is the smallest integer larger than n/3.0. The use of doubles in the denominator is necessary to ensure that integer division is not used.

For example, if n is 7, then a equals 4 and b equals 3 and thus K8 = 1 + min (2* K4, 3 * K3).

If n is 8, then a equals 5 while b remains 3 and thus K9 = 1 + min (2 * K5, 3 * K3).
If n is 9, then a remains 5 while b equals 4 and thus K10 = 1 + min(2 * K5, 3 * K3).

Mathematically, “the smallest integer larger than x” is the “ceiling” function. If n is an int, then n / 2 is calculated using integer division, discarding the remainder; but you want the division to give you a double. Thus you need code that looks like this:

int a = Math.ceil(n / 2.0);
int b = Math.ceil(n / 3.0);

Since the equation defining Knuth numbers is a recursive one, we must have a base case; let’s assume that K0 = 1.

Create and test a class called KnuthNumbers (in a project also called KnuthNumbers) which includes a static method to compute Knuth numbers.


my code:


Code:
public class KnuthNumbers
{
   /**
    * Recursive Knuth Numbers 1, 3, 3, 4, 7, 7, 7, 9, 9, 10, 13, ...  
    */
   public static int knuthNumber(final double n)
   throws DataFormatException{
       double a = Math.ceil(n / 2.0);
       double b = Math.ceil(n / 3.0);
       // bad input
       if (n < 1)
           throw new DataFormatException("n cannot be less then 1");
       if (n > 12)
           throw new DataFormatException("n is too large. Max is 12");
       //base case
       if (n == 1)
           return 1;

       //recursion

       return knuthNumber(a + b);
   }
}




TEST:

Code:
public class KnuthNumbersTest
{
   

   @Test
   public void testKnuthNumber(){
       long startTime = 0;
       long endTime = 0;
       double result = 0;

       try {
           assertEquals(-1, KnuthNumbers.knuthNumber(-3));
           fail("number should not be negative");
       }
       catch (DataFormatException e){
           assertEquals("n cannot be less then 1", e.getMessage());
       }
       catch (Exception e) {
           fail("Unexpected exception: " + e.toString());
       }

       try {
           assertEquals(0, KnuthNumbers.knuthNumber(0));
           fail("number should not be zero");
       }
       catch (DataFormatException e){
           assertEquals("n cannot be less then 1", e.getMessage());
       }
       catch (Exception e) {
           fail("Unexpected exception: " + e.toString());
       }

       try {
           assertEquals(1, KnuthNumbers.knuthNumber(1.0));
           assertEquals(9, KnuthNumbers.knuthNumber(5.4));
           assertEquals(13, KnuthNumbers.knuthNumber(7.6));
       }
       catch (Exception e) {
           fail ("Unexpected exception: " + e.toString());
       }

   }

}

Print this item

  C Tutorial Series
Posted by: brandonio21 - 04-18-2015, 12:44 PM - Forum: C - Replies (1)

So I have been thinking about doing a C tutorial series for quite some time now. In my opinion, C is the ultimate programming language. It's fairly low level (It compiles straight to assembly), it runs fast, it has decades of improvements built into it, and tons of community support.

Basically, C is used for most system programming. That is, if you want to make a utility for your operating system, you would usually do it in C. Of course, a lot of things these days are also written in C's self-deemed successor, C++. For instance, take the following programs:

Linux - C
Windows - C/C++/C#
Mac OSX - C/Objective-C

All of which are written in C or its many variants. Because of this, I think it is important to make a C tutorial series that will also lead into C++, since the two are fairly related. The C portion of the tutorial will be based on the K&R, so people can easily follow along if they own the book.

What are your guys' thoughts?

Print this item

  Looking for coffee recommendations!
Posted by: brandonio21 - 04-16-2015, 10:56 AM - Forum: Random Discussion - No Replies

So for a while I have been drinking coffee pretty much every day. I've tried Folgers, Maxwell House, Starbucks, and Melita brand coffees, which I make at home.

Does anyone have any recommendations for other brands of coffee to try? I'm looking to expand my pallette.

Print this item

  Website Giveaway 2014-2015 Source Code
Posted by: brandonio21 - 03-08-2015, 09:49 PM - Forum: C#.NET - Replies (2)

In my 2014-2015 Website Giveaway, I promised that I would post the source code for the program used to determine the winners. Unfortunately, when I originally tried to post the source code, BP Forums would not allow me to post due to permissions errors. This was, of course, one of the main reasons why I decided to completely revamp BP Forums.

Anyway, here is the source code for the giveaway. If you have any questions, feel free to ask!


.zip   WebsiteGiveaway1415.zip (Size: 60.94 KB / Downloads: 1122)

Print this item

  PK3 Explorer/DMD/MD2 Converter (New Version)
Posted by: Worf - 10-24-2014, 04:56 AM - Forum: Share your programs! - No Replies

Hi.

I have been working on one of my old projects and have add and improved it a little. I have added an PK3 Explorer. All info below.


PK3 Explorer

Allows you too create/open PK3 files to add or remove files. View textures from inside the PK3 file in the 'Texture Viewer' without having to extract the PK3 file first.
You can also open standard zip files.

Texture Viewer

Allows you to View the texture of the model. You can also save or load/add new textures.

I am planning on adding more features to the Texture Viewer to allow you to change the size of the texture and the ability to edit the textures.

Supports the following OS's - Windows 7 Windows 8


PK3 Explorer & Dmd/Md2 Converter release notes. 21/10/2014


DMD/Md2 Converter Update.

V1.2

Added option to choose between converting from Dmd to Md2 or Md2 to Dmd. (The original version didn't convert from Md2 to Dmd.)

Fixed a couple of bugs.

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

PK3 Explorer update. V1.0

Fixed extraction of files & Folders ...... didn't extract folders.

Added custom compression Level for zip files.

Fixed a few other bugs.

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

Texture Viewer.

Added ability to load and add new textures to PK3 files.

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

There is only an x86 version at the moment.

Download:

X86
http://1drv.ms/1wtXTmK

Please post any comments/bugs/improvements/Wish List

Regards

Tony

Print this item

  Running an embeded EXE .NET 2013
Posted by: Worf - 10-14-2014, 04:48 AM - Forum: Programming Help - Replies (1)

Hi.

I'm currently working on a new project for working with .PK3 - .DMD & .MD2 files.

Now, I have an EXE (cv.exe) that I would like to embed into my program and execute through the routine below.

I've tried different methods found on the internet without any luck.

Code:
' This routine runs MD2Tool with the selected tasks. (Convert)    
  
Private Sub RunMD2tool(ByVal path As String, ByVal file As String, ByVal tasks As String)    
  
Dim p As New Process()    
  
Dim infs() As String = {"""" & path & "\" & (file) & """" & tasks}    
  
With p.StartInfo    
For f = 0 To infs.Count - 1    
.Arguments = infs(f)    
.FileName = "cv.exe"    
  
' Hide the window ?    
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden    
p.Start()    
  
Do While Not p.HasExited    
Application.DoEvents()    
Loop    
Next    
End With    
  
MsgBox("Convertion complete.")    
  
SinglePath.Text = Nothing    
Label7.Text = Nothing    
  
End Sub

Many thanks for your help.

Regards

Tony

Print this item

  View 3D Models in VB .NET
Posted by: Worf - 09-26-2014, 05:50 AM - Forum: Programming Help - Replies (2)

Hi.

Are there any addons for VB .NET to allow the viewing of 3D Models in different formats including MD2 filesas this is something I want to in my application?

Many Thanks for you help

Print this item

  Help with PCX file.
Posted by: Worf - 09-23-2014, 04:30 AM - Forum: VB.NET (Visual Basic 2010/2008) - Replies (2)

Hi.

I'm in real need of being able to display .PCX graphic files in my app. I am using Visual Studio 2013 .NET.

I've tried GDPicturedotnet but for some reason it is not showing up in the Toolbox and when I select 'Show all' it is greyed out. I've also tried IocompDotNet V4 SP3 but unable to find any help files or documents on how to use their commands.

Many, Many thanks for your help.

Print this item

  Open Zip files into a listview box
Posted by: Worf - 09-09-2014, 05:12 AM - Forum: Programming Help - Replies (2)

Hi.

I'm working on my DMD To MD2 Converter program o add more features to it.

One of them is to open a zip file and list the contents into a listview box and allow the user to select any files to extract.

I've searched around but couldn't find what im looking for.

Thank you for you help.

Tony

Print this item

  What devices drive your day?
Posted by: brandonio21 - 08-01-2014, 09:23 AM - Forum: Computing - No Replies

After getting off the subway today and having someone comment on my Pebble watch, I was curious, what kind of devices do you guys use throughout your day that may not be used by the general public?

Here are some devices I use:

  • Pebble Smartwatch
  • Nexus 7 Tablet

At home, I also use:
  • Google Chromecast

Print this item