- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Something for the Perl haters here:
Admin
How many WTFs are in my PHP code?
Admin
It's not super exciting, but since it's my bread and butter I decided to post a .NET (C#) version of this puzzle using a simple generic collection.
...and to be scientific, I created a test project to run a few scenarios. I came up with the numbers by drawing and working out the answers on paper first, which hurt my eyes after a while!
Admin
One line Python implementation (true one-liner, no semicolons - needs Python 2.4+):
[poplist.rotate(-(killcounter-1)) or poplist.popleft() for x in locals().setitem('soldiers', 12) or locals().setitem('killcounter', 3) or locals().setitem('poplist', import('collections').deque(xrange(1,soldiers+1))) or xrange(1,soldiers)] and import('sys').stdout.write("The only one left is %s\n" % locals().getitem('poplist')[0])
You can set the values of 'soldiers' and 'killcounter' appropriately for your situation ;)
Admin
Also, if you prefer to get some output while it runs:
[poplist.rotate(-(killcounter-1)) or import('sys').stdout.write("Just killed number: %d\n" % poplist.popleft()) for x in locals().setitem('soldiers', 12) or locals().setitem('killcounter', 3) or locals().setitem('poplist', import('collections').deque(xrange(1,soldiers+1))) or xrange(1,soldiers)] and import('sys').stdout.write("The only one left is %s\n" % locals().getitem('poplist')[0])
;)
Admin
Admin
Noone's pointed this out yet, but that formula is useless computationally, since the constant K can only be calculated by knowing the answers you're trying to generate in advance. See the paper linked to at that OEIS link, "Functional iteration and the Josephus problem" Beginning of section 5.
(WHY DOES THIS KEEP GETTING FLAGGED AS SPAM?? FFFFFFFFFFFFFUUUUUUUUUU LET ME POST DAMMIT)
Admin
I invented FlogScript for code-golfing, and I did code-golfing this one too:
Addendum (2009-08-04 16:21): Please note that this is not an entire program, it is only a part that makes this calculation, and will not make any input/output by itself. To make it input/output, add this code to the beginning of the program:
this allows multiple calculations, one on each line of input. For the program to do only one calculation (it starts after EOF is read from the input), use this instead:Admin
Somebody already put one similar, but here it goes
public class JosephusCircle { public static void main(String[] args) { System.out.println("Surviving soldier = " + getSurvivorSolderIndex(12, 3)); System.out.println("Surviving soldier = " + getSurvivorSolderIndex(41, 3)); System.out.println("Surviving soldier = " + getSurvivorSolderIndex(40, 7)); }
}
Admin
Sorry not to provide any programming examples but the whole idea inspired the following! :-)
In order to decide who would not pay the tab, the drinkers sat at a circular table and, starting with the top of the circle and continuing clockwise, counted to three. The third man got the the first tab and the counting resumed at one. The process continued until there was no one left. Paddy Joe, who quite agreed with the whole "we should all pay a tab" idea, figured out the perfect way to have a free nights drinking: be the last man standing.
Admin
Admin
If anybody interested, I created index for the entries. Index. I cannot put it here directly, because it thinks it's a spam.
Admin
using good ol' c and a ring of structs:
Admin
my solution with java... brute forcing it :D
Admin
updated version... the last one i posted always skipped counted 3 people regardless of the parameter xD silly mistake xD
Admin
Recursion is not a bitch to maintain. You just need to understand what the property of the recursive function is, and how the fixed-point operator works. Loops are a real bitch: Hoare logic is annoying because the hypothesis keeps changing at each line. Recursion is much more natural
Admin
The obligatory ABAP example:
Admin
Nice idea with the plot. I was wondering if there is some pattern - and there is a result:
[image]The x-axis represents step size and y-axis represents number of soldiers int the circle. Both axis are plotted from 1 to 600. Each pixel represents one computed safe spot - plotted from 1 (black) to maximum (white). Since on each line there are results with the same number of soldiers I was able to set maximum for safe spot value to number of soldiers so that the pattern is easy to see. That also means it doesn't make sence to compare colors of pixels on different lines.
Here's the code, I used PNGwriter library (pngwriter.sourceforge.net):
Admin
Yeah, I know it is lame, long, counting from zero etc. At least I got to brush up on linked lists...
Admin
public static void Main(string[] args) { //global vars int soldiers = 12; int soldiersToSkip = 3;
Admin
//updated and parametrized public static void Main(string[] args) { //Test int soldiers = 40; int soldiersToSkip = 3; int SafePos = JosephusSafePos(soldiers, soldiersToSkip);
Admin
I know, old topic... Yeah, I haven't read all the coment either... Anyway, worth mentioning, this problem appears in D. Knuth's Concrete Mathematics book
Admin
Supra shoes are so popular all over the world. Whatever you take on Supra being in the Supra Skytop Shoes market. Now Supra Strapped Shoes also very popular attention. It is nice that they actually took the time to make Supra Skate Shoes that work well. Supra shoes is a brand that has been inspired, designed and marketed by passionate individuals. We have brought to you the fullest selection of Supra footwear at cheapest price.
Admin
Admin
Admin
Here it is in Forth:
Admin
You mean you don't append 'this means you will not be it' to the end of the rhyme?
Admin
pharmacie en ligne avec ordonnance https://kamagraenligne.shop/# vente de mГ©dicament en ligne