Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17f1524

Browse files
committed
Remove all my original code
1 parent6e3adb9 commit17f1524

File tree

1 file changed

+0
-244
lines changed

1 file changed

+0
-244
lines changed

‎csharp/2024/Day21.cs‎

Lines changed: 0 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -331,249 +331,5 @@ static void BuildPath(
331331
}
332332
}
333333
}
334-
335-
#ifGARBAGE
336-
privatestructState
337-
{
338-
internalcharKeypadRobotPos;
339-
internalcharDPadRobot1Pos;
340-
internalcharDPadRobot2Pos;
341-
342-
internalstaticStateNew()
343-
{
344-
Stateret=default;
345-
ret.KeypadRobotPos=ret.DPadRobot1Pos=ret.DPadRobot2Pos='A';
346-
returnret;
347-
}
348-
}
349-
350-
internalstaticvoidProblem1x()
351-
{
352-
char[]dpad=['<','v','>','A','^'];
353-
char[]keypad="0123456789A".ToCharArray();
354-
355-
Console.WriteLine("Keypad");
356-
foreach(charoneinkeypad)
357-
{
358-
foreach(chartwoinkeypad)
359-
{
360-
Console.WriteLine($"From{one} to{two}:{newstring(KeypadMoves(one,two).ToArray())}");
361-
}
362-
}
363-
364-
Console.WriteLine("dpad");
365-
foreach(charoneindpad)
366-
{
367-
foreach(chartwoindpad)
368-
{
369-
Console.WriteLine($"From{one} to{two}:{newstring(DPadMoves(one,two).ToArray())}");
370-
}
371-
}
372-
373-
}
374-
375-
internalstaticvoidProblem1()
376-
{
377-
List<string>codes=Load();
378-
//List<string> codes = ["37"];
379-
longret=0;
380-
381-
foreach(stringcodeincodes)
382-
{
383-
intnumberPart=int.Parse(code.AsSpan(0,code.Length-1));
384-
StringBuilderhumanSeq=MoveKeypad(code,State.New());
385-
386-
Console.WriteLine($"Code={code}, Number={numberPart}, CodeLen={humanSeq.Length}, Ret+={humanSeq.Length*numberPart}");
387-
Console.WriteLine(humanSeq);
388-
Console.WriteLine();
389-
390-
ret+=(long)numberPart*humanSeq.Length;
391-
}
392-
393-
Console.WriteLine(ret);
394-
}
395-
396-
internalstaticvoidProblem2x()
397-
{
398-
}
399-
400-
privatestaticStringBuilderMoveKeypad(ReadOnlySpan<char>code,StatecurrentState)
401-
{
402-
StringBuilderkeypadRobot=new();
403-
StringBuilderdpad1=new();
404-
StringBuilderdpad2=new();
405-
StringBuilderhuman=new();
406-
StringBuilderdebug=new();
407-
408-
foreach(charcodeCharincode)
409-
{
410-
keypadRobot.Append(codeChar);
411-
412-
//Console.WriteLine($"Keypad robot is at {currentState.KeypadRobotPos} and needs to be at {codeChar}");
413-
IEnumerable<char>keypadSequence=KeypadMoves(currentState.KeypadRobotPos,codeChar);
414-
415-
foreach(charkeypadSeqCharinkeypadSequence)
416-
{
417-
dpad1.Append(keypadSeqChar);
418-
//Console.WriteLine($"DPad1 is at {currentState.DPadRobot1Pos} and needs to be at {keypadSeqChar}");
419-
420-
IEnumerable<char>keypadDPadSequence=DPadMoves(currentState.DPadRobot1Pos,keypadSeqChar);
421-
422-
foreach(chardpad1CharinkeypadDPadSequence)
423-
{
424-
//Console.WriteLine($"DPad2 is at {currentState.DPadRobot2Pos} and needs to be at {dpad1Char}");
425-
426-
dpad2.Append(dpad1Char);
427-
428-
IEnumerable<char>dpadDpadSequence=DPadMoves(currentState.DPadRobot2Pos,dpad1Char);
429-
debug.Clear();
430-
431-
foreach(chardpad2CharindpadDpadSequence)
432-
{
433-
human.Append(dpad2Char);
434-
debug.Append(dpad2Char);
435-
}
436-
437-
stringdebugStr=debug.ToString();
438-
if((debugStr.Contains('^')&&debugStr.Contains('v'))||
439-
(debugStr.Contains('>')&&debugStr.Contains('<')))
440-
{
441-
thrownewInvalidDataException(
442-
$"Garbage produced for{currentState.DPadRobot2Pos} =>{dpad1Char}:{debugStr}");
443-
}
444-
445-
currentState.DPadRobot2Pos=dpad1Char;
446-
//human.Append(" ");
447-
}
448-
449-
currentState.DPadRobot1Pos=keypadSeqChar;
450-
//dpad2.Append(" ");
451-
}
452-
453-
//dpad2.Append(" ");
454-
currentState.KeypadRobotPos=codeChar;
455-
}
456-
457-
Console.WriteLine(human);
458-
Console.WriteLine(dpad2);
459-
Console.WriteLine(dpad1);
460-
Console.WriteLine(keypadRobot);
461-
462-
returnhuman;
463-
}
464-
465-
// x^A
466-
// <v>
467-
privatestaticIEnumerable<char>DPadMoves(charfrom,charto)
468-
{
469-
#ifDEBUG
470-
charorigFrom=from;
471-
charorigTo=to;
472-
#endif
473-
474-
intfromRow=Row(from);
475-
intfromCol=Col(from);
476-
inttoRow=Row(to);
477-
inttoCol=Col(to);
478-
479-
while(fromCol<toCol)
480-
{
481-
yieldreturnRight;
482-
fromCol++;
483-
}
484-
485-
while(fromRow<toRow)
486-
{
487-
yieldreturnUp;
488-
fromRow++;
489-
}
490-
491-
while(fromRow>toRow)
492-
{
493-
yieldreturnDown;
494-
fromRow--;
495-
}
496-
497-
while(fromCol>toCol)
498-
{
499-
yieldreturnLeft;
500-
fromCol--;
501-
}
502-
503-
504-
yieldreturnSubmit;
505-
506-
staticintRow(charc)=>cswitch
507-
{
508-
'^' or'A'=>1,
509-
'<' or'v' or'>'=>0,
510-
};
511-
512-
staticintCol(charc)=>cswitch
513-
{
514-
'<' or'4' or'1'=>0,
515-
'^' or'v'=>1,
516-
'A' or'>'=>2,
517-
};
518-
}
519-
520-
// 789
521-
// 456
522-
// 123
523-
// x0A
524-
privatestaticIEnumerable<char>KeypadMoves(charfrom,charto)
525-
{
526-
#ifDEBUG
527-
charorigFrom=from;
528-
charorigTo=to;
529-
#endif
530-
531-
intfromRow=Row(from);
532-
intfromCol=Col(from);
533-
inttoRow=Row(to);
534-
inttoCol=Col(to);
535-
536-
while(fromCol<toCol)
537-
{
538-
yieldreturnRight;
539-
fromCol++;
540-
}
541-
542-
while(fromRow<toRow)
543-
{
544-
yieldreturnUp;
545-
fromRow++;
546-
}
547-
548-
while(fromCol>toCol)
549-
{
550-
yieldreturnLeft;
551-
fromCol--;
552-
}
553-
554-
while(fromRow>toRow)
555-
{
556-
yieldreturnDown;
557-
fromRow--;
558-
}
559-
560-
yieldreturnSubmit;
561-
562-
staticintRow(charc)=>cswitch
563-
{
564-
'7' or'8' or'9'=>3,
565-
'4' or'5' or'6'=>2,
566-
'1' or'2' or'3'=>1,
567-
'0' or'A'=>0,
568-
};
569-
570-
staticintCol(charc)=>cswitch
571-
{
572-
'7' or'4' or'1'=>0,
573-
'8' or'5' or'2' or'0'=>1,
574-
'9' or'6' or'3' or'A'=>2,
575-
};
576-
}
577-
#endif
578334
}
579335
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp